Bitcoin Core  21.99.0
P2P Digital Currency
node.h
Go to the documentation of this file.
1 // Copyright (c) 2018-2019 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_NODE_H
6 #define BITCOIN_INTERFACES_NODE_H
7 
8 #include <amount.h> // For CAmount
9 #include <net.h> // For CConnman::NumConnections
10 #include <net_types.h> // For banmap_t
11 #include <netaddress.h> // For Network
12 #include <support/allocators/secure.h> // For SecureString
13 #include <util/translation.h>
14 
15 #include <functional>
16 #include <memory>
17 #include <stddef.h>
18 #include <stdint.h>
19 #include <string>
20 #include <tuple>
21 #include <vector>
22 
23 class BanMan;
24 class CCoinControl;
25 class CFeeRate;
26 class CNodeStats;
27 class Coin;
28 class RPCTimerInterface;
29 class UniValue;
30 class proxyType;
31 enum class SynchronizationState;
32 struct CNodeStateStats;
33 struct NodeContext;
34 struct bilingual_str;
35 
36 namespace interfaces {
37 class Handler;
38 class WalletClient;
39 struct BlockTip;
40 
43 {
45  int64_t block_time;
47  int64_t header_time;
49 };
50 
52 class Node
53 {
54 public:
55  virtual ~Node() {}
56 
58  virtual void initLogging() = 0;
59 
61  virtual void initParameterInteraction() = 0;
62 
64  virtual bilingual_str getWarnings() = 0;
65 
66  // Get log flags.
67  virtual uint32_t getLogCategories() = 0;
68 
70  virtual bool baseInitialize() = 0;
71 
73  virtual bool appInitMain(interfaces::BlockAndHeaderTipInfo* tip_info = nullptr) = 0;
74 
76  virtual void appShutdown() = 0;
77 
79  virtual void startShutdown() = 0;
80 
82  virtual bool shutdownRequested() = 0;
83 
85  virtual void mapPort(bool use_upnp) = 0;
86 
88  virtual bool getProxy(Network net, proxyType& proxy_info) = 0;
89 
91  virtual size_t getNodeCount(CConnman::NumConnections flags) = 0;
92 
94  using NodesStats = std::vector<std::tuple<CNodeStats, bool, CNodeStateStats>>;
95  virtual bool getNodesStats(NodesStats& stats) = 0;
96 
98  virtual bool getBanned(banmap_t& banmap) = 0;
99 
101  virtual bool ban(const CNetAddr& net_addr, int64_t ban_time_offset) = 0;
102 
104  virtual bool unban(const CSubNet& ip) = 0;
105 
107  virtual bool disconnectByAddress(const CNetAddr& net_addr) = 0;
108 
110  virtual bool disconnectById(NodeId id) = 0;
111 
113  virtual int64_t getTotalBytesRecv() = 0;
114 
116  virtual int64_t getTotalBytesSent() = 0;
117 
119  virtual size_t getMempoolSize() = 0;
120 
122  virtual size_t getMempoolDynamicUsage() = 0;
123 
125  virtual bool getHeaderTip(int& height, int64_t& block_time) = 0;
126 
128  virtual int getNumBlocks() = 0;
129 
131  virtual uint256 getBestBlockHash() = 0;
132 
134  virtual int64_t getLastBlockTime() = 0;
135 
137  virtual double getVerificationProgress() = 0;
138 
140  virtual bool isInitialBlockDownload() = 0;
141 
143  virtual bool getReindex() = 0;
144 
146  virtual bool getImporting() = 0;
147 
149  virtual void setNetworkActive(bool active) = 0;
150 
152  virtual bool getNetworkActive() = 0;
153 
155  virtual CFeeRate estimateSmartFee(int num_blocks, bool conservative, int* returned_target = nullptr) = 0;
156 
158  virtual CFeeRate getDustRelayFee() = 0;
159 
161  virtual UniValue executeRpc(const std::string& command, const UniValue& params, const std::string& uri) = 0;
162 
164  virtual std::vector<std::string> listRpcCommands() = 0;
165 
167  virtual void rpcSetTimerInterfaceIfUnset(RPCTimerInterface* iface) = 0;
168 
170  virtual void rpcUnsetTimerInterface(RPCTimerInterface* iface) = 0;
171 
173  virtual bool getUnspentOutput(const COutPoint& output, Coin& coin) = 0;
174 
176  virtual WalletClient& walletClient() = 0;
177 
179  using InitMessageFn = std::function<void(const std::string& message)>;
180  virtual std::unique_ptr<Handler> handleInitMessage(InitMessageFn fn) = 0;
181 
183  using MessageBoxFn =
184  std::function<bool(const bilingual_str& message, const std::string& caption, unsigned int style)>;
185  virtual std::unique_ptr<Handler> handleMessageBox(MessageBoxFn fn) = 0;
186 
188  using QuestionFn = std::function<bool(const bilingual_str& message,
189  const std::string& non_interactive_message,
190  const std::string& caption,
191  unsigned int style)>;
192  virtual std::unique_ptr<Handler> handleQuestion(QuestionFn fn) = 0;
193 
195  using ShowProgressFn = std::function<void(const std::string& title, int progress, bool resume_possible)>;
196  virtual std::unique_ptr<Handler> handleShowProgress(ShowProgressFn fn) = 0;
197 
199  using NotifyNumConnectionsChangedFn = std::function<void(int new_num_connections)>;
200  virtual std::unique_ptr<Handler> handleNotifyNumConnectionsChanged(NotifyNumConnectionsChangedFn fn) = 0;
201 
203  using NotifyNetworkActiveChangedFn = std::function<void(bool network_active)>;
204  virtual std::unique_ptr<Handler> handleNotifyNetworkActiveChanged(NotifyNetworkActiveChangedFn fn) = 0;
205 
207  using NotifyAlertChangedFn = std::function<void()>;
208  virtual std::unique_ptr<Handler> handleNotifyAlertChanged(NotifyAlertChangedFn fn) = 0;
209 
211  using BannedListChangedFn = std::function<void()>;
212  virtual std::unique_ptr<Handler> handleBannedListChanged(BannedListChangedFn fn) = 0;
213 
215  using NotifyBlockTipFn =
216  std::function<void(SynchronizationState, interfaces::BlockTip tip, double verification_progress)>;
217  virtual std::unique_ptr<Handler> handleNotifyBlockTip(NotifyBlockTipFn fn) = 0;
218 
220  using NotifyHeaderTipFn =
221  std::function<void(SynchronizationState, interfaces::BlockTip tip, double verification_progress)>;
222  virtual std::unique_ptr<Handler> handleNotifyHeaderTip(NotifyHeaderTipFn fn) = 0;
223 
226  virtual NodeContext* context() { return nullptr; }
227  virtual void setContext(NodeContext* context) { }
228 };
229 
231 std::unique_ptr<Node> MakeNode(NodeContext* context = nullptr);
232 
234 struct BlockTip {
236  int64_t block_time;
238 };
239 
240 } // namespace interfaces
241 
242 #endif // BITCOIN_INTERFACES_NODE_H
std::vector< std::tuple< CNodeStats, bool, CNodeStateStats > > NodesStats
Get stats for connected nodes.
Definition: node.h:94
int64_t block_time
Definition: node.h:236
RPC timer "driver".
Definition: server.h:60
Block tip (could be a header or not, depends on the subscribed signal).
Definition: node.h:234
SynchronizationState
Current sync state passed to tip changed callbacks.
Definition: validation.h:106
Definition: banman.h:57
A UTXO entry.
Definition: coins.h:30
Bilingual messages:
Definition: translation.h:16
std::function< void(bool network_active)> NotifyNetworkActiveChangedFn
Register handler for network active messages.
Definition: node.h:203
std::function< void(SynchronizationState, interfaces::BlockTip tip, double verification_progress)> NotifyBlockTipFn
Register handler for block tip messages.
Definition: node.h:216
Wallet chain client that in addition to having chain client methods for starting up, shutting down, and registering RPCs, also has additional methods (called by the GUI) to load and create wallets.
Definition: wallet.h:309
virtual void setContext(NodeContext *context)
Definition: node.h:227
Coin Control Features.
Definition: coincontrol.h:22
std::function< void(SynchronizationState, interfaces::BlockTip tip, double verification_progress)> NotifyHeaderTipFn
Register handler for header tip messages.
Definition: node.h:221
NodeContext struct containing references to chain state and connection state.
Definition: context.h:36
std::function< void()> NotifyAlertChangedFn
Register handler for notify alert messages.
Definition: node.h:207
virtual ~Node()
Definition: node.h:55
Network
A network type.
Definition: netaddress.h:43
Block and header tip information.
Definition: node.h:42
int64_t NodeId
Definition: net.h:92
NumConnections
Definition: net.h:191
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: transaction.h:26
std::function< void(const std::string &message)> InitMessageFn
Register handler for init messages.
Definition: node.h:179
std::function< void()> BannedListChangedFn
Register handler for ban list messages.
Definition: node.h:211
int flags
Definition: bitcoin-tx.cpp:506
std::function< void(int new_num_connections)> NotifyNumConnectionsChangedFn
Register handler for number of connections changed messages.
Definition: node.h:199
Network address.
Definition: netaddress.h:119
256-bit opaque blob.
Definition: uint256.h:124
std::function< bool(const bilingual_str &message, const std::string &non_interactive_message, const std::string &caption, unsigned int style)> QuestionFn
Register handler for question messages.
Definition: node.h:191
virtual NodeContext * context()
Get and set internal node context.
Definition: node.h:226
Fee rate in satoshis per kilobyte: CAmount / kB.
Definition: feerate.h:29
std::function< void(const std::string &title, int progress, bool resume_possible)> ShowProgressFn
Register handler for progress messages.
Definition: node.h:195
std::map< CSubNet, CBanEntry > banmap_t
Definition: net_types.h:13
std::function< bool(const bilingual_str &message, const std::string &caption, unsigned int style)> MessageBoxFn
Register handler for message box messages.
Definition: node.h:184
std::unique_ptr< Node > MakeNode(NodeContext *context)
Return implementation of Node interface.
Definition: node.cpp:301
Top-level interface for a bitcoin node (bitcoind process).
Definition: node.h:52
uint256 block_hash
Definition: node.h:237