Functions to handle block creation for mining functionality as well as mining.  
More...
#include "base_tx.h"
#include "base_block.h"
Go to the source code of this file.
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 
 
 
◆ calc_block_reward()
      
        
          | unsigned long calc_block_reward  | 
          ( | 
          unsigned long  | 
          blockchain_height | ) | 
           | 
        
      
 
Calculate the reward for mining this block. 
- Parameters
 - 
  
    | blockchain_height | not 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()
Calculate the transaction fees from a single tx. 
- Parameters
 - 
  
  
 
- 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
 - 
  
    | block | block to increment the nonce on  | 
  
   
 
 
◆ create_block()
      
        
          | void create_block  | 
          ( | 
          Block *  | 
          block | ) | 
           | 
        
      
 
Create a block from mempool to then be mined. 
- Parameters
 - 
  
    | block | destination 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()
Create block header from a set of transactions. 
- Parameters
 - 
  
    | block | block to write block header into  | 
    | txs | txs to use for the block/header  | 
    | num_txs | number of txs in txs  | 
  
   
 
 
◆ create_block_header_alloc()
Creats a block header and allocates memory for it. 
- Parameters
 - 
  
    | txs | txs to use for the block/header  | 
    | num_txs | number 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_fees | cumulative 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_pts | return 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
 - 
  
    | txs | set of txs to hash  | 
    | num_txs | number in set of transactions  | 
  
   
- Returns
 - unsigned char* cumulative hash of 32 bytes (from mbed) 
 
 
 
◆ mine_block()
Try mining a block. 
- Parameters
 - 
  
  
 
- Returns
 - int 0 if proof-of-work met, 1 if not 
 
 
 
◆ try_header_hash()
Hash header and compare against difficulty, determine if Proof-of-Work is met. 
- Parameters
 - 
  
    | block_header | block header to try hashing/comparing  | 
  
   
- Returns
 - int 0 if proof-of-work met, 1 if not