MCPcopy Create free account
hub / github.com/BTCGPU/BTCGPU / CreateAndProcessBlock

Method CreateAndProcessBlock

src/test/test_bitcoin.cpp:147–175  ·  view source on GitHub ↗

Create a new block with just given transactions, coinbase paying to scriptPubKey, and try to add it to the current chain.

Source from the content-addressed store, hash-verified

145// scriptPubKey, and try to add it to the current chain.
146//
147CBlock
148TestChain100Setup::CreateAndProcessBlock(const std::vector<CMutableTransaction>& txns, const CScript& scriptPubKey)
149{
150 const CChainParams& chainparams = Params();
151 std::unique_ptr<CBlockTemplate> pblocktemplate = BlockAssembler(chainparams).CreateNewBlock(scriptPubKey);
152 CBlock& block = pblocktemplate->block;
153
154 // Replace mempool-selected txns with just coinbase plus passed-in txns:
155 block.vtx.resize(1);
156 for (const CMutableTransaction& tx : txns)
157 block.vtx.push_back(MakeTransactionRef(tx));
158 // IncrementExtraNonce creates a valid coinbase and merkleRoot
159 {
160 LOCK(cs_main);
161 unsigned int extraNonce = 0;
162 IncrementExtraNonce(&block, chainActive.Tip(), extraNonce);
163 }
164
165 // TODO(h4x3rotab): Generate Equihash solution if applicable.
166 while (!CheckProofOfWork(block.GetHash(), block.nBits, false, chainparams.GetConsensus())) {
167 block.nNonce = ArithToUint256(UintToArith256(block.nNonce) + 1);
168 }
169
170 std::shared_ptr<const CBlock> shared_pblock = std::make_shared<const CBlock>(block);
171 ProcessNewBlock(chainparams, shared_pblock, true, nullptr);
172
173 CBlock result = block;
174 return result;
175}
176
177TestChain100Setup::~TestChain100Setup()
178{

Callers 1

TestGUIFunction · 0.80

Calls 13

BlockAssemblerClass · 0.85
MakeTransactionRefFunction · 0.85
IncrementExtraNonceFunction · 0.85
CheckProofOfWorkFunction · 0.85
ArithToUint256Function · 0.85
UintToArith256Function · 0.85
ProcessNewBlockFunction · 0.85
CreateNewBlockMethod · 0.80
ParamsClass · 0.50
resizeMethod · 0.45
push_backMethod · 0.45
TipMethod · 0.45

Tested by

no test coverage detected