Changeset View
Changeset View
Standalone View
Standalone View
src/test/test_bitcoin.cpp
Show First 20 Lines • Show All 158 Lines • ▼ Show 20 Lines | std::unique_ptr<CBlockTemplate> pblocktemplate = | ||||
BlockAssembler(config).CreateNewBlock(scriptPubKey); | BlockAssembler(config).CreateNewBlock(scriptPubKey); | ||||
CBlock &block = pblocktemplate->block; | CBlock &block = pblocktemplate->block; | ||||
// Replace mempool-selected txns with just coinbase plus passed-in txns: | // Replace mempool-selected txns with just coinbase plus passed-in txns: | ||||
block.vtx.resize(1); | block.vtx.resize(1); | ||||
for (const CMutableTransaction &tx : txns) { | for (const CMutableTransaction &tx : txns) { | ||||
block.vtx.push_back(MakeTransactionRef(tx)); | block.vtx.push_back(MakeTransactionRef(tx)); | ||||
} | } | ||||
// Order transactions by canonical order | |||||
std::sort(std::begin(block.vtx) + 1, std::end(block.vtx), | |||||
[](const std::shared_ptr<const CTransaction> &txa, | |||||
const std::shared_ptr<const CTransaction> &txb) -> bool { | |||||
return txa->GetId() < txb->GetId(); | |||||
}); | |||||
// IncrementExtraNonce creates a valid coinbase and merkleRoot | // IncrementExtraNonce creates a valid coinbase and merkleRoot | ||||
unsigned int extraNonce = 0; | unsigned int extraNonce = 0; | ||||
IncrementExtraNonce(config, &block, chainActive.Tip(), extraNonce); | IncrementExtraNonce(config, &block, chainActive.Tip(), extraNonce); | ||||
while (!CheckProofOfWork(block.GetHash(), block.nBits, config)) { | while (!CheckProofOfWork(block.GetHash(), block.nBits, config)) { | ||||
++block.nNonce; | ++block.nNonce; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 95 Lines • Show Last 20 Lines |