@@ -871,7 +871,7 @@ class ChainImpl : public Chain
871
871
class BlockTemplateImpl : public BlockTemplate
872
872
{
873
873
public:
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 )
875
875
{
876
876
assert (m_block_template);
877
877
}
@@ -916,7 +916,32 @@ class BlockTemplateImpl : public BlockTemplate
916
916
return BlockMerkleBranch (m_block_template->block );
917
917
}
918
918
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
+
919
941
const std::unique_ptr<CBlockTemplate> m_block_template;
942
+
943
+ ChainstateManager& chainman () { return *Assert (m_node.chainman ); }
944
+ NodeContext& m_node;
920
945
};
921
946
922
947
class MinerImpl : public Mining
@@ -990,7 +1015,7 @@ class MinerImpl : public Mining
990
1015
{
991
1016
BlockAssembler::Options assemble_options{options};
992
1017
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 );
994
1019
}
995
1020
996
1021
NodeContext* context () override { return &m_node; }
0 commit comments