interfaces: refactor: move submitSolution implementation to miner

- Create a new function `AddMerkleRootAndCoinbase` that compute the
  block's merkle root, insert the coinbase transaction and the merkle
  root into the block.
This commit is contained in:
ismaelsadeeq
2025-04-28 17:00:50 +01:00
parent 02d4bc776b
commit e6c2f4ce7a
3 changed files with 18 additions and 16 deletions

View File

@@ -929,22 +929,8 @@ public:
bool submitSolution(uint32_t version, uint32_t timestamp, uint32_t nonce, CTransactionRef coinbase) override
{
CBlock block{m_block_template->block};
if (block.vtx.size() == 0) {
block.vtx.push_back(coinbase);
} else {
block.vtx[0] = coinbase;
}
block.nVersion = version;
block.nTime = timestamp;
block.nNonce = nonce;
block.hashMerkleRoot = BlockMerkleRoot(block);
auto block_ptr = std::make_shared<const CBlock>(block);
return chainman().ProcessNewBlock(block_ptr, /*force_processing=*/true, /*min_pow_checked=*/true, /*new_block=*/nullptr);
AddMerkleRootAndCoinbase(m_block_template->block, std::move(coinbase), version, timestamp, nonce);
return chainman().ProcessNewBlock(std::make_shared<const CBlock>(m_block_template->block), /*force_processing=*/true, /*min_pow_checked=*/true, /*new_block=*/nullptr);
}
std::unique_ptr<BlockTemplate> waitNext(BlockWaitOptions options) override