@@ -115,9 +115,9 @@ static RPCHelpMan getnetworkhashps()
115
115
};
116
116
}
117
117
118
- static bool GenerateBlock (ChainstateManager& chainman, CBlock& block, uint64_t & max_tries, uint256& block_hash )
118
+ static bool GenerateBlock (ChainstateManager& chainman, CBlock& block, uint64_t & max_tries, std::shared_ptr< const CBlock>& block_out )
119
119
{
120
- block_hash. SetNull ();
120
+ block_out. reset ();
121
121
block.hashMerkleRoot = BlockMerkleRoot (block);
122
122
123
123
while (max_tries > 0 && block.nNonce < std::numeric_limits<uint32_t >::max () && !CheckProofOfWork (block.GetHash (), block.nBits , chainman.GetConsensus ()) && !ShutdownRequested ()) {
@@ -131,12 +131,11 @@ static bool GenerateBlock(ChainstateManager& chainman, CBlock& block, uint64_t&
131
131
return true ;
132
132
}
133
133
134
- std::shared_ptr< const CBlock> shared_pblock = std::make_shared<const CBlock>(block);
135
- if (!chainman.ProcessNewBlock (shared_pblock , /* force_processing=*/ true , /* min_pow_checked=*/ true , nullptr )) {
134
+ block_out = std::make_shared<const CBlock>(block);
135
+ if (!chainman.ProcessNewBlock (block_out , /* force_processing=*/ true , /* min_pow_checked=*/ true , nullptr )) {
136
136
throw JSONRPCError (RPC_INTERNAL_ERROR, " ProcessNewBlock, block not accepted" );
137
137
}
138
138
139
- block_hash = block.GetHash ();
140
139
return true ;
141
140
}
142
141
@@ -147,16 +146,15 @@ static UniValue generateBlocks(ChainstateManager& chainman, const CTxMemPool& me
147
146
std::unique_ptr<CBlockTemplate> pblocktemplate (BlockAssembler{chainman.ActiveChainstate (), &mempool}.CreateNewBlock (coinbase_script));
148
147
if (!pblocktemplate.get ())
149
148
throw JSONRPCError (RPC_INTERNAL_ERROR, " Couldn't create new block" );
150
- CBlock *pblock = &pblocktemplate->block ;
151
149
152
- uint256 block_hash ;
153
- if (!GenerateBlock (chainman, *pblock , nMaxTries, block_hash )) {
150
+ std::shared_ptr< const CBlock> block_out ;
151
+ if (!GenerateBlock (chainman, pblocktemplate-> block , nMaxTries, block_out )) {
154
152
break ;
155
153
}
156
154
157
- if (!block_hash. IsNull () ) {
155
+ if (block_out ) {
158
156
--nGenerate;
159
- blockHashes.push_back (block_hash .GetHex ());
157
+ blockHashes.push_back (block_out-> GetHash () .GetHex ());
160
158
}
161
159
}
162
160
return blockHashes;
@@ -376,15 +374,15 @@ static RPCHelpMan generateblock()
376
374
}
377
375
}
378
376
379
- uint256 block_hash ;
377
+ std::shared_ptr< const CBlock> block_out ;
380
378
uint64_t max_tries{DEFAULT_MAX_TRIES};
381
379
382
- if (!GenerateBlock (chainman, block, max_tries, block_hash ) || block_hash. IsNull () ) {
380
+ if (!GenerateBlock (chainman, block, max_tries, block_out ) || !block_out ) {
383
381
throw JSONRPCError (RPC_MISC_ERROR, " Failed to make block." );
384
382
}
385
383
386
384
UniValue obj (UniValue::VOBJ);
387
- obj.pushKV (" hash" , block_hash .GetHex ());
385
+ obj.pushKV (" hash" , block_out-> GetHash () .GetHex ());
388
386
return obj;
389
387
},
390
388
};
0 commit comments