OlinCoin
Test
Functions
create_block.h File Reference

Functions to handle block creation for mining functionality as well as mining. More...

#include "base_tx.h"
#include "base_block.h"
Include dependency graph for create_block.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

unsigned int calc_num_tx_target ()
 Get the current number of desired transactions for within a block. More...
 
unsigned int get_difficulty ()
 Get difficulty (number of zeros desired in hash for proof-of-work. More...
 
unsigned long calc_block_reward (unsigned long blockchain_height)
 Calculate the reward for mining this block. More...
 
Transactioncreate_coinbase_tx (unsigned long total_tx_fees)
 Create coinbase transaction by adding the block reward and the fees. More...
 
unsigned int calc_tx_fees (Transaction *tx)
 Calculate the transaction fees from a single tx. More...
 
unsigned int get_txs_from_mempool (Transaction ***tx_pts)
 Collect Transactions for a new block, including coinbase tx. More...
 
void hash_all_tx (unsigned char *dest, Transaction **txs, unsigned int num_txs)
 Create the hash of all the transaction hashes, used in block header. More...
 
void create_block_header (BlockHeader *header, Transaction **txs, unsigned int num_txs)
 Create block header from a set of transactions. More...
 
BlockHeadercreate_block_header_alloc (Transaction **txs, unsigned int num_txs)
 Creats a block header and allocates memory for it. More...
 
void create_block (Block *block)
 Create a block from mempool to then be mined. More...
 
Blockcreate_block_alloc ()
 Creates a block and allocates the memory for it. More...
 
void change_nonce (Block *block)
 increments nonce of a block to try hashing/mining again More...
 
int try_header_hash (BlockHeader *block_header)
 Hash header and compare against difficulty, determine if Proof-of-Work is met. More...
 
Blockmine_block ()
 Try mining a block. More...
 

Detailed Description

Functions to handle block creation for mining functionality as well as mining.

Author
Nathan Faber (nfabe.nosp@m.r@ol.nosp@m.in.ed.nosp@m.u.co.nosp@m.m)
Version
0.1
Date
2022-03-17

Function Documentation

◆ calc_block_reward()

unsigned long calc_block_reward ( unsigned long  blockchain_height)

Calculate the reward for mining this block.

Parameters
blockchain_heightnot used(static block reward)
Returns
unsigned long reward in olincoins

◆ calc_num_tx_target()

unsigned int calc_num_tx_target ( )

Get the current number of desired transactions for within a block.

Returns
unsigned int of transactions to include

◆ calc_tx_fees()

unsigned int calc_tx_fees ( Transaction tx)

Calculate the transaction fees from a single tx.

Parameters
txTransaction to calculate the fees of
Returns
unsigned int tx_fee in olincoins

◆ change_nonce()

void change_nonce ( Block block)

increments nonce of a block to try hashing/mining again

Parameters
blockblock to increment the nonce on

◆ create_block()

void create_block ( Block block)

Create a block from mempool to then be mined.

Parameters
blockdestination for created block

◆ create_block_alloc()

Block * create_block_alloc ( )

Creates a block and allocates the memory for it.

Returns
Block* new block ready to mine, freeing responsibility of caller

◆ create_block_header()

void create_block_header ( BlockHeader header,
Transaction **  txs,
unsigned int  num_txs 
)

Create block header from a set of transactions.

Parameters
blockblock to write block header into
txstxs to use for the block/header
num_txsnumber of txs in txs

◆ create_block_header_alloc()

BlockHeader * create_block_header_alloc ( Transaction **  txs,
unsigned int  num_txs 
)

Creats a block header and allocates memory for it.

Parameters
txstxs to use for the block/header
num_txsnumber of txs in txs
Returns
New blockheader

◆ create_coinbase_tx()

Transaction * create_coinbase_tx ( unsigned long  total_tx_fees)

Create coinbase transaction by adding the block reward and the fees.

Parameters
total_tx_feescumulative fees for the block
Returns
Transaction* to a new coinbase tx, freeing responsibility of caller

◆ get_difficulty()

unsigned int get_difficulty ( )

Get difficulty (number of zeros desired in hash for proof-of-work.

Returns
unsigned int num of zeros

◆ get_txs_from_mempool()

unsigned int get_txs_from_mempool ( Transaction ***  tx_pts)

Collect Transactions for a new block, including coinbase tx.

Parameters
tx_ptsreturn destination of set of transactions
Returns
unsigned int number of transactions included

◆ hash_all_tx()

void hash_all_tx ( unsigned char *  dest,
Transaction **  txs,
unsigned int  num_txs 
)

Create the hash of all the transaction hashes, used in block header.

Parameters
txsset of txs to hash
num_txsnumber in set of transactions
Returns
unsigned char* cumulative hash of 32 bytes (from mbed)

◆ mine_block()

Block * mine_block ( )

Try mining a block.

Parameters
blockblock to mine
Returns
int 0 if proof-of-work met, 1 if not

◆ try_header_hash()

int try_header_hash ( BlockHeader block_header)

Hash header and compare against difficulty, determine if Proof-of-Work is met.

Parameters
block_headerblock header to try hashing/comparing
Returns
int 0 if proof-of-work met, 1 if not