(This article is using the Bitcoin v0.1.0 version click to download source) New miners thread generate public and private key create a new block and save a currency transaction collect the latest validation through the transaction acquisition of target difficulty in obtaining random generation of difficult workload
Bitcoin source interpretation of the threading process is divided into two pieces, miners threading and other threading two, this article describes the miners threading, mainly contains the creation of currency transactions, the current transaction packaging, workload and other related content. The flowchart looks like this:
New Miner Thread
if (_beginthread (threadbitcoinminer, 0, NULL) = = 1) printf ("Error: _beginthread (Threadbitcoinminer) failed\n");
Perform miner handler function
void Threadbitcoinminer (void* parg) {vfthreadrunning[3] = true; Checkforshutdown (3); try {bool FRet = Bitcoinminer (); printf ("Bitcoinminer returned%s\n\n\n", FRet?) "True": "false"); } catch_print_exception ("Bitcoinminer ()") vfthreadrunning[3] = false; }
generate public and private keys
Using the OpenSSL library to generate
Ckey key; Key. Makenewkey (); void Makenewkey () {if (! Ec_key_generate_key (Pkey)) throw Key_error ("Ckey::makenewkey (): Ec_key_generate_key failed"); }
Create a currency transaction
Input as NULL, output as this node address
CTransaction txnew; TxNew.vin.resize (1); Txnew.vin[0].prevout. SetNull (); Txnew.vin[0].scriptsig << nbits << ++bnextranonce; TxNew.vout.resize (1); Txnew.vout[0].scriptpubkey << key. Getpubkey () << Op_checksig;
Create a new block and save a currency transaction
Auto_ptr<cblock> pblock (New Cblock ()); if (!pblock.get ()) return false;