Bitcoin ABC  0.26.3
P2P Digital Currency
node.h
Go to the documentation of this file.
1 // Copyright (c) 2018 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 <consensus/amount.h>
9 #include <net.h> // For CConnman::NumConnections
10 #include <net_types.h> // For banmap_t
11 #include <netaddress.h> // For Network
12 
13 #include <support/allocators/secure.h> // For SecureString
14 #include <util/translation.h>
15 
16 #include <cstddef>
17 #include <cstdint>
18 #include <functional>
19 #include <memory>
20 #include <string>
21 #include <tuple>
22 #include <vector>
23 
24 class BanMan;
25 class CCoinControl;
26 class CFeeRate;
27 struct CNodeStateStats;
28 struct CNodeStats;
29 class Coin;
30 class Config;
32 class proxyType;
33 class RPCServer;
34 class RPCTimerInterface;
35 enum class SynchronizationState;
36 class UniValue;
37 struct bilingual_str;
38 namespace node {
39 struct NodeContext;
40 } // namespace node
41 
42 namespace interfaces {
43 class Handler;
44 class WalletClient;
45 struct BlockTip;
46 
50  int64_t block_time;
52  int64_t header_time;
54 };
55 
57 class Node {
58 public:
59  virtual ~Node() {}
60 
62  virtual void initLogging() = 0;
63 
65  virtual void initParameterInteraction() = 0;
66 
68  virtual bilingual_str getWarnings() = 0;
69 
71  virtual bool baseInitialize(Config &config) = 0;
72 
74  virtual bool
75  appInitMain(Config &config, RPCServer &rpcServer,
76  HTTPRPCRequestProcessor &httpRPCRequestProcessor,
77  interfaces::BlockAndHeaderTipInfo *tip_info = nullptr) = 0;
78 
80  virtual void appShutdown() = 0;
81 
83  virtual void startShutdown() = 0;
84 
86  virtual bool shutdownRequested() = 0;
87 
89  virtual void mapPort(bool use_upnp, bool use_natpmp) = 0;
90 
92  virtual bool getProxy(Network net, proxyType &proxy_info) = 0;
93 
96 
98  using NodesStats =
99  std::vector<std::tuple<CNodeStats, bool, CNodeStateStats>>;
100  virtual bool getNodesStats(NodesStats &stats) = 0;
101 
103  virtual bool getBanned(banmap_t &banmap) = 0;
104 
106  virtual bool ban(const CNetAddr &net_addr, int64_t ban_time_offset) = 0;
107 
109  virtual bool unban(const CSubNet &ip) = 0;
110 
112  virtual bool disconnectByAddress(const CNetAddr &net_addr) = 0;
113 
115  virtual bool disconnectById(NodeId id) = 0;
116 
118  virtual int64_t getTotalBytesRecv() = 0;
119 
121  virtual int64_t getTotalBytesSent() = 0;
122 
124  virtual size_t getMempoolSize() = 0;
125 
127  virtual size_t getMempoolDynamicUsage() = 0;
128 
130  virtual bool getHeaderTip(int &height, int64_t &block_time) = 0;
131 
133  virtual int getNumBlocks() = 0;
134 
137 
139  virtual int64_t getLastBlockTime() = 0;
140 
142  virtual double getVerificationProgress() = 0;
143 
145  virtual bool isInitialBlockDownload() = 0;
146 
148  virtual bool getReindex() = 0;
149 
151  virtual bool getImporting() = 0;
152 
154  virtual void setNetworkActive(bool active) = 0;
155 
157  virtual bool getNetworkActive() = 0;
158 
160  virtual CFeeRate getDustRelayFee() = 0;
161 
163  virtual UniValue executeRpc(const Config &config,
164  const std::string &command,
165  const UniValue &params,
166  const std::string &uri) = 0;
167 
169  virtual std::vector<std::string> listRpcCommands() = 0;
170 
173 
175  virtual void rpcUnsetTimerInterface(RPCTimerInterface *iface) = 0;
176 
178  virtual bool getUnspentOutput(const COutPoint &output, Coin &coin) = 0;
179 
181  virtual WalletClient &walletClient() = 0;
182 
184  using InitMessageFn = std::function<void(const std::string &message)>;
185  virtual std::unique_ptr<Handler> handleInitMessage(InitMessageFn fn) = 0;
186 
188  using MessageBoxFn =
189  std::function<bool(const bilingual_str &message,
190  const std::string &caption, unsigned int style)>;
191  virtual std::unique_ptr<Handler> handleMessageBox(MessageBoxFn fn) = 0;
192 
194  using QuestionFn =
195  std::function<bool(const bilingual_str &message,
196  const std::string &non_interactive_message,
197  const std::string &caption, unsigned int style)>;
198  virtual std::unique_ptr<Handler> handleQuestion(QuestionFn fn) = 0;
199 
201  using ShowProgressFn = std::function<void(
202  const std::string &title, int progress, bool resume_possible)>;
203  virtual std::unique_ptr<Handler> handleShowProgress(ShowProgressFn fn) = 0;
204 
207  std::function<void(int new_num_connections)>;
208  virtual std::unique_ptr<Handler>
210 
213  std::function<void(bool network_active)>;
214  virtual std::unique_ptr<Handler>
216 
218  using NotifyAlertChangedFn = std::function<void()>;
219  virtual std::unique_ptr<Handler>
221 
223  using BannedListChangedFn = std::function<void()>;
224  virtual std::unique_ptr<Handler>
226 
229  std::function<void(SynchronizationState, interfaces::BlockTip tip,
230  double verification_progress)>;
231  virtual std::unique_ptr<Handler>
233 
236  std::function<void(SynchronizationState, interfaces::BlockTip tip,
237  double verification_progress)>;
238  virtual std::unique_ptr<Handler>
240 
243  virtual node::NodeContext *context() { return nullptr; }
245 };
246 
248 std::unique_ptr<Node> MakeNode(node::NodeContext *context = nullptr);
249 
251 struct BlockTip {
253  int64_t block_time;
255 };
256 
257 } // namespace interfaces
258 
259 #endif // BITCOIN_INTERFACES_NODE_H
int flags
Definition: bitcoin-tx.cpp:538
Definition: banman.h:58
Coin Control Features.
Definition: coincontrol.h:21
NumConnections
Definition: net.h:909
Fee rate in satoshis per kilobyte: Amount / kB.
Definition: feerate.h:21
Network address.
Definition: netaddress.h:121
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: transaction.h:22
A UTXO entry.
Definition: coins.h:27
Definition: config.h:17
Class for registering and managing all RPC calls.
Definition: server.h:39
RPC timer "driver".
Definition: server.h:99
Top-level interface for a bitcoin node (bitcoind process).
Definition: node.h:57
virtual void rpcSetTimerInterfaceIfUnset(RPCTimerInterface *iface)=0
Set RPC timer interface if unset.
std::function< void()> BannedListChangedFn
Register handler for ban list messages.
Definition: node.h:223
virtual std::unique_ptr< Handler > handleNotifyBlockTip(NotifyBlockTipFn fn)=0
virtual std::unique_ptr< Handler > handleNotifyAlertChanged(NotifyAlertChangedFn fn)=0
virtual bool disconnectById(NodeId id)=0
Disconnect node by id.
virtual std::vector< std::string > listRpcCommands()=0
List rpc commands.
virtual std::unique_ptr< Handler > handleNotifyHeaderTip(NotifyHeaderTipFn fn)=0
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:197
virtual std::unique_ptr< Handler > handleNotifyNetworkActiveChanged(NotifyNetworkActiveChangedFn fn)=0
virtual bool getImporting()=0
Get importing.
virtual bool ban(const CNetAddr &net_addr, int64_t ban_time_offset)=0
Ban node.
std::function< void(bool network_active)> NotifyNetworkActiveChangedFn
Register handler for network active messages.
Definition: node.h:213
virtual void setNetworkActive(bool active)=0
Set network active.
std::function< void(SynchronizationState, interfaces::BlockTip tip, double verification_progress)> NotifyHeaderTipFn
Register handler for header tip messages.
Definition: node.h:237
std::function< bool(const bilingual_str &message, const std::string &caption, unsigned int style)> MessageBoxFn
Register handler for message box messages.
Definition: node.h:190
virtual bilingual_str getWarnings()=0
Get warnings.
virtual std::unique_ptr< Handler > handleNotifyNumConnectionsChanged(NotifyNumConnectionsChangedFn fn)=0
virtual void appShutdown()=0
Stop node.
virtual std::unique_ptr< Handler > handleQuestion(QuestionFn fn)=0
virtual std::unique_ptr< Handler > handleShowProgress(ShowProgressFn fn)=0
virtual bool appInitMain(Config &config, RPCServer &rpcServer, HTTPRPCRequestProcessor &httpRPCRequestProcessor, interfaces::BlockAndHeaderTipInfo *tip_info=nullptr)=0
Start node.
virtual void rpcUnsetTimerInterface(RPCTimerInterface *iface)=0
Unset RPC timer interface.
std::vector< std::tuple< CNodeStats, bool, CNodeStateStats > > NodesStats
Get stats for connected nodes.
Definition: node.h:99
virtual bool getProxy(Network net, proxyType &proxy_info)=0
Get proxy.
std::function< void(const std::string &title, int progress, bool resume_possible)> ShowProgressFn
Register handler for progress messages.
Definition: node.h:202
virtual bool getReindex()=0
Get reindex.
virtual void initParameterInteraction()=0
Init parameter interaction.
virtual std::unique_ptr< Handler > handleInitMessage(InitMessageFn fn)=0
virtual void startShutdown()=0
Start shutdown.
std::function< void()> NotifyAlertChangedFn
Register handler for notify alert messages.
Definition: node.h:218
virtual int64_t getLastBlockTime()=0
Get last block time.
virtual bool getBanned(banmap_t &banmap)=0
Get ban map entries.
virtual BlockHash getBestBlockHash()=0
Get best block hash.
virtual size_t getMempoolSize()=0
Get mempool size.
virtual bool getNetworkActive()=0
Get network active.
virtual bool unban(const CSubNet &ip)=0
Unban node.
virtual std::unique_ptr< Handler > handleMessageBox(MessageBoxFn fn)=0
virtual size_t getNodeCount(CConnman::NumConnections flags)=0
Get number of connections.
virtual double getVerificationProgress()=0
Get verification progress.
virtual bool getHeaderTip(int &height, int64_t &block_time)=0
Get header tip height and time.
virtual ~Node()
Definition: node.h:59
virtual node::NodeContext * context()
Get and set internal node context.
Definition: node.h:243
virtual bool disconnectByAddress(const CNetAddr &net_addr)=0
Disconnect node by address.
virtual WalletClient & walletClient()=0
Get wallet client.
virtual int64_t getTotalBytesRecv()=0
Get total bytes recv.
virtual std::unique_ptr< Handler > handleBannedListChanged(BannedListChangedFn fn)=0
virtual UniValue executeRpc(const Config &config, const std::string &command, const UniValue &params, const std::string &uri)=0
Execute rpc command.
virtual void initLogging()=0
Init logging.
virtual int64_t getTotalBytesSent()=0
Get total bytes sent.
virtual size_t getMempoolDynamicUsage()=0
Get mempool dynamic usage.
virtual void mapPort(bool use_upnp, bool use_natpmp)=0
Map port.
virtual int getNumBlocks()=0
Get num blocks.
virtual bool shutdownRequested()=0
Return whether shutdown was requested.
std::function< void(const std::string &message)> InitMessageFn
Register handler for init messages.
Definition: node.h:184
virtual bool getNodesStats(NodesStats &stats)=0
virtual bool isInitialBlockDownload()=0
Is initial block download.
std::function< void(int new_num_connections)> NotifyNumConnectionsChangedFn
Register handler for number of connections changed messages.
Definition: node.h:207
virtual bool getUnspentOutput(const COutPoint &output, Coin &coin)=0
Get unspent outputs associated with a transaction.
virtual bool baseInitialize(Config &config)=0
Initialize app dependencies.
virtual CFeeRate getDustRelayFee()=0
Get dust relay fee.
virtual void setContext(node::NodeContext *context)
Definition: node.h:244
std::function< void(SynchronizationState, interfaces::BlockTip tip, double verification_progress)> NotifyBlockTipFn
Register handler for block tip messages.
Definition: node.h:230
Wallet chain client that in addition to having chain client methods for starting up,...
Definition: wallet.h:308
std::unique_ptr< Node > MakeNode(node::NodeContext *context=nullptr)
Return implementation of Node interface.
Definition: interfaces.cpp:775
Definition: init.h:28
std::map< CSubNet, CBanEntry > banmap_t
Definition: net_types.h:13
Network
A network type.
Definition: netaddress.h:44
int64_t NodeId
Definition: nodeid.h:10
A BlockHash is a unqiue identifier for a block.
Definition: blockhash.h:13
POD that contains various stats about a node.
Definition: net.h:274
Bilingual messages:
Definition: translation.h:17
Block and header tip information.
Definition: node.h:48
Block tip (could be a header or not, depends on the subscribed signal).
Definition: node.h:251
int64_t block_time
Definition: node.h:253
BlockHash block_hash
Definition: node.h:254
NodeContext struct containing references to chain state and connection state.
Definition: context.h:38
SynchronizationState
Current sync state passed to tip changed callbacks.
Definition: validation.h:121