Created
August 25, 2019 12:37
-
-
Save kafaichoi/f47e2fa2feec68fb23018af0cbbccab5 to your computer and use it in GitHub Desktop.
BitcoinMiner - 1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bool BitcoinMiner() | |
{ | |
printf("BitcoinMiner started\n"); | |
SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_LOWEST); | |
CKey key; | |
key.MakeNewKey(); | |
CBigNum bnExtraNonce = 0; | |
while (fGenerateBitcoins) | |
{ | |
Sleep(50); | |
CheckForShutdown(3); | |
while (vNodes.empty()) | |
{ | |
Sleep(1000); | |
CheckForShutdown(3); | |
} | |
unsigned int nTransactionsUpdatedLast = nTransactionsUpdated; | |
CBlockIndex* pindexPrev = pindexBest; | |
unsigned int nBits = GetNextWorkRequired(pindexPrev); | |
// | |
// Create coinbase tx | |
// | |
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 new block | |
// | |
auto_ptr<CBlock> pblock(new CBlock()); | |
if (!pblock.get()) | |
return false; | |
// Add our coinbase tx as first transaction | |
pblock->vtx.push_back(txNew); | |
// Collect the latest transactions into the block | |
int64 nFees = 0; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment