Programming Homework Help
Bitcoin Miner Simulation Mining & Receiving Transactions Simple C Programming Exercise
Write a program that simulates a bitcoin miner. Your program must be compiled to an executable called
miner. The program will read in a sequence of four kinds of events
(i) mine a block (mine),
(ii) receive a
transaction and add it to the mempool (transaction),
iii) receive a block that was mined by another miner
(block), and
(iv) end the simulation (end). For each of these events your program will need to perform a
specific action as described below. These events correspond to actual events experienced by a real miner.
For example, the transaction and block events correspond to the miner receiving transactions and blocks
from the peer-to-peer network, and the mine event corresponds to the miner deciding to begin the creation of a new block.
On a mine event, your program must
1. select transactions from its mempool in the order that the transactions were added
2. create a new block from the selected transactions
3. remove the selected transactions from the mempool
4. print out the created block On a transaction event, your program must
1. decode the transaction in the event
2. add the transaction to the mempool
3. print out the transaction
On a block event, your program must
1. decode the block. In the event
2. remove any transactions in the mempool that were listed in the block
3. print out the removed transactions in the order they were listed in the block
On an end event, your program must
1. exit
Note: the simulator will focus on the high-level operations. It will not need to perform any cryptographic
functions or verify the correctness of a block or transaction