@@ -871,7 +871,7 @@ class ChainImpl : public Chain
871871class BlockTemplateImpl : public BlockTemplate
872872{
873873public:
874- explicit BlockTemplateImpl (std::unique_ptr<CBlockTemplate> block_template) : m_block_template(std::move(block_template))
874+ explicit BlockTemplateImpl (std::unique_ptr<CBlockTemplate> block_template, NodeContext& node ) : m_block_template(std::move(block_template)), m_node(node )
875875 {
876876 assert (m_block_template);
877877 }
@@ -916,7 +916,32 @@ class BlockTemplateImpl : public BlockTemplate
916916 return BlockMerkleBranch (m_block_template->block );
917917 }
918918
919+ bool submitSolution (uint32_t version, uint32_t timestamp, uint32_t nonce, CMutableTransaction coinbase) override
920+ {
921+ CBlock block{m_block_template->block };
922+
923+ auto cb = MakeTransactionRef (std::move (coinbase));
924+
925+ if (block.vtx .size () == 0 ) {
926+ block.vtx .push_back (cb);
927+ } else {
928+ block.vtx [0 ] = cb;
929+ }
930+
931+ block.nVersion = version;
932+ block.nTime = timestamp;
933+ block.nNonce = nonce;
934+
935+ block.hashMerkleRoot = BlockMerkleRoot (block);
936+
937+ auto block_ptr = std::make_shared<const CBlock>(block);
938+ return chainman ().ProcessNewBlock (block_ptr, /* force_processing=*/ true , /* min_pow_checked=*/ true , /* new_block=*/ nullptr );
939+ }
940+
919941 const std::unique_ptr<CBlockTemplate> m_block_template;
942+
943+ ChainstateManager& chainman () { return *Assert (m_node.chainman ); }
944+ NodeContext& m_node;
920945};
921946
922947class MinerImpl : public Mining
@@ -990,7 +1015,7 @@ class MinerImpl : public Mining
9901015 {
9911016 BlockAssembler::Options assemble_options{options};
9921017 ApplyArgsManOptions (*Assert (m_node.args ), assemble_options);
993- return std::make_unique<BlockTemplateImpl>(BlockAssembler{chainman ().ActiveChainstate (), context ()->mempool .get (), assemble_options}.CreateNewBlock (script_pub_key));
1018+ return std::make_unique<BlockTemplateImpl>(BlockAssembler{chainman ().ActiveChainstate (), context ()->mempool .get (), assemble_options}.CreateNewBlock (script_pub_key), m_node );
9941019 }
9951020
9961021 NodeContext* context () override { return &m_node; }
0 commit comments