Bit-Currency source code interpretation of threading-Miner thread

Source: Internet
Author: User
Tags openssl library

(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;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.