Bitcoin Core  28.1.0
P2P Digital Currency
mining.h
Go to the documentation of this file.
1 // Copyright (c) 2024 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #ifndef BITCOIN_INTERFACES_MINING_H
6 #define BITCOIN_INTERFACES_MINING_H
7 
8 #include <node/types.h>
9 #include <uint256.h>
10 
11 #include <memory>
12 #include <optional>
13 
14 namespace node {
15 struct CBlockTemplate;
16 struct NodeContext;
17 } // namespace node
18 
20 class CBlock;
21 class CScript;
22 
23 namespace interfaces {
24 
27 
28 class Mining
29 {
30 public:
31  virtual ~Mining() = default;
32 
34  virtual bool isTestChain() = 0;
35 
37  virtual bool isInitialBlockDownload() = 0;
38 
40  virtual std::optional<uint256> getTipHash() = 0;
41 
49  virtual std::unique_ptr<node::CBlockTemplate> createNewBlock(const CScript& script_pub_key, const node::BlockCreateOptions& options={}) = 0;
50 
58  virtual bool processNewBlock(const std::shared_ptr<const CBlock>& block, bool* new_block) = 0;
59 
62  virtual unsigned int getTransactionsUpdated() = 0;
63 
74  virtual bool testBlockValidity(const CBlock& block, bool check_merkle_root, BlockValidationState& state) = 0;
75 
78  virtual node::NodeContext* context() { return nullptr; }
79 };
80 
82 std::unique_ptr<Mining> MakeMining(node::NodeContext& node);
83 
84 } // namespace interfaces
85 
86 #endif // BITCOIN_INTERFACES_MINING_H
Definition: block.h:68
virtual ~Mining()=default
virtual std::optional< uint256 > getTipHash()=0
Returns the hash for the tip of this chain.
virtual unsigned int getTransactionsUpdated()=0
Return the number of transaction updates in the mempool, used to decide whether to make a new block t...
NodeContext struct containing references to chain state and connection state.
Definition: context.h:55
Interface giving clients (RPC, Stratum v2 Template Provider in the future) ability to create block te...
Definition: mining.h:28
virtual bool processNewBlock(const std::shared_ptr< const CBlock > &block, bool *new_block)=0
Processes new block.
virtual std::unique_ptr< node::CBlockTemplate > createNewBlock(const CScript &script_pub_key, const node::BlockCreateOptions &options={})=0
Construct a new block template.
virtual bool isInitialBlockDownload()=0
Returns whether IBD is still in progress.
Definition: messages.h:20
virtual node::NodeContext * context()
Get internal node context.
Definition: mining.h:78
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:413
virtual bool testBlockValidity(const CBlock &block, bool check_merkle_root, BlockValidationState &state)=0
Check a block is completely valid from start to finish.
std::unique_ptr< Mining > MakeMining(node::NodeContext &node)
Return implementation of Mining interface.
Definition: interfaces.cpp:929
is a home for public enum and struct type definitions that are used by internally by node code...
virtual bool isTestChain()=0
If this chain is exclusively used for testing.