@@ -850,7 +850,7 @@ class ChainImpl : public Chain
850850class BlockTemplateImpl : public BlockTemplate
851851{
852852public:
853- explicit BlockTemplateImpl (std::unique_ptr<CBlockTemplate> block_template) : m_block_template(std::move(block_template))
853+ explicit BlockTemplateImpl (std::unique_ptr<CBlockTemplate> block_template, NodeContext& node ) : m_block_template(std::move(block_template)), m_node(node )
854854 {
855855 assert (m_block_template);
856856 }
@@ -895,7 +895,32 @@ class BlockTemplateImpl : public BlockTemplate
895895 return BlockMerkleBranch (m_block_template->block );
896896 }
897897
898+ bool submitSolution (uint32_t version, uint32_t timestamp, uint32_t nonce, CMutableTransaction coinbase) override
899+ {
900+ CBlock block{m_block_template->block };
901+
902+ auto cb = MakeTransactionRef (std::move (coinbase));
903+
904+ if (block.vtx .size () == 0 ) {
905+ block.vtx .push_back (cb);
906+ } else {
907+ block.vtx [0 ] = cb;
908+ }
909+
910+ block.nVersion = version;
911+ block.nTime = timestamp;
912+ block.nNonce = nonce;
913+
914+ block.hashMerkleRoot = BlockMerkleRoot (block);
915+
916+ auto block_ptr = std::make_shared<const CBlock>(block);
917+ return chainman ().ProcessNewBlock (block_ptr, /* force_processing=*/ true , /* min_pow_checked=*/ true , /* new_block=*/ nullptr );
918+ }
919+
898920 const std::unique_ptr<CBlockTemplate> m_block_template;
921+
922+ ChainstateManager& chainman () { return *Assert (m_node.chainman ); }
923+ NodeContext& m_node;
899924};
900925
901926class MinerImpl : public Mining
@@ -948,7 +973,7 @@ class MinerImpl : public Mining
948973 {
949974 BlockAssembler::Options assemble_options{options};
950975 ApplyArgsManOptions (*Assert (m_node.args ), assemble_options);
951- return std::make_unique<BlockTemplateImpl>(BlockAssembler{chainman ().ActiveChainstate (), context ()->mempool .get (), assemble_options}.CreateNewBlock (script_pub_key));
976+ return std::make_unique<BlockTemplateImpl>(BlockAssembler{chainman ().ActiveChainstate (), context ()->mempool .get (), assemble_options}.CreateNewBlock (script_pub_key), m_node );
952977 }
953978
954979 NodeContext* context () override { return &m_node; }
0 commit comments