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/settings.h> // For util::SettingsValue
15 #include <util/translation.h>
16 
17 #include <cstddef>
18 #include <cstdint>
19 #include <functional>
20 #include <memory>
21 #include <string>
22 #include <tuple>
23 #include <vector>
24 
25 class BanMan;
26 class CCoinControl;
27 class CFeeRate;
28 struct CNodeStateStats;
29 struct CNodeStats;
30 class Coin;
31 class Config;
33 class proxyType;
34 class RPCServer;
35 class RPCTimerInterface;
36 enum class SynchronizationState;
37 class UniValue;
38 struct bilingual_str;
39 namespace node {
40 struct NodeContext;
41 } // namespace node
42 
43 namespace interfaces {
44 class Handler;
45 class WalletClient;
46 struct BlockTip;
47 
51  int64_t block_time;
53  int64_t header_time;
55 };
56 
58 class Node {
59 public:
60  virtual ~Node() {}
61 
63  virtual void initLogging() = 0;
64 
66  virtual void initParameterInteraction() = 0;
67 
69  virtual bilingual_str getWarnings() = 0;
70 
72  virtual bool baseInitialize(Config &config) = 0;
73 
75  virtual bool
76  appInitMain(Config &config, RPCServer &rpcServer,
77  HTTPRPCRequestProcessor &httpRPCRequestProcessor,
78  interfaces::BlockAndHeaderTipInfo *tip_info = nullptr) = 0;
79 
81  virtual void appShutdown() = 0;
82 
84  virtual void startShutdown() = 0;
85 
87  virtual bool shutdownRequested() = 0;
88 
91  virtual bool isPersistentSettingIgnored(const std::string &name) = 0;
92 
94  virtual util::SettingsValue
95  getPersistentSetting(const std::string &name) = 0;
96 
98  virtual void updateRwSetting(const std::string &name,
99  const util::SettingsValue &value) = 0;
100 
103  virtual void forceSetting(const std::string &name,
104  const util::SettingsValue &value) = 0;
105 
108  virtual void resetSettings() = 0;
109 
111  virtual void mapPort(bool use_upnp, bool use_natpmp) = 0;
112 
114  virtual bool getProxy(Network net, proxyType &proxy_info) = 0;
115 
118 
120  using NodesStats =
121  std::vector<std::tuple<CNodeStats, bool, CNodeStateStats>>;
122  virtual bool getNodesStats(NodesStats &stats) = 0;
123 
125  virtual bool getBanned(banmap_t &banmap) = 0;
126 
128  virtual bool ban(const CNetAddr &net_addr, int64_t ban_time_offset) = 0;
129 
131  virtual bool unban(const CSubNet &ip) = 0;
132 
134  virtual bool disconnectByAddress(const CNetAddr &net_addr) = 0;
135 
137  virtual bool disconnectById(NodeId id) = 0;
138 
140  virtual int64_t getTotalBytesRecv() = 0;
141 
143  virtual int64_t getTotalBytesSent() = 0;
144 
146  virtual size_t getMempoolSize() = 0;
147 
149  virtual size_t getMempoolDynamicUsage() = 0;
150 
152  virtual bool getHeaderTip(int &height, int64_t &block_time) = 0;
153 
155  virtual int getNumBlocks() = 0;
156 
159 
161  virtual int64_t getLastBlockTime() = 0;
162 
164  virtual double getVerificationProgress() = 0;
165 
167  virtual bool isInitialBlockDownload() = 0;
168 
170  virtual bool getReindex() = 0;
171 
173  virtual bool getImporting() = 0;
174 
176  virtual void setNetworkActive(bool active) = 0;
177 
179  virtual bool getNetworkActive() = 0;
180 
182  virtual CFeeRate getDustRelayFee() = 0;
183 
185  virtual UniValue executeRpc(const Config &config,
186  const std::string &command,
187  const UniValue &params,
188  const std::string &uri) = 0;
189 
191  virtual std::vector<std::string> listRpcCommands() = 0;
192 
195 
197  virtual void rpcUnsetTimerInterface(RPCTimerInterface *iface) = 0;
198 
200  virtual bool getUnspentOutput(const COutPoint &output, Coin &coin) = 0;
201 
203  virtual WalletClient &walletClient() = 0;
204 
206  using InitMessageFn = std::function<void(const std::string &message)>;
207  virtual std::unique_ptr<Handler> handleInitMessage(InitMessageFn fn) = 0;
208 
210  using MessageBoxFn =
211  std::function<bool(const bilingual_str &message,
212  const std::string &caption, unsigned int style)>;
213  virtual std::unique_ptr<Handler> handleMessageBox(MessageBoxFn fn) = 0;
214 
216  using QuestionFn =
217  std::function<bool(const bilingual_str &message,
218  const std::string &non_interactive_message,
219  const std::string &caption, unsigned int style)>;
220  virtual std::unique_ptr<Handler> handleQuestion(QuestionFn fn) = 0;
221 
223  using ShowProgressFn = std::function<void(
224  const std::string &title, int progress, bool resume_possible)>;
225  virtual std::unique_ptr<Handler> handleShowProgress(ShowProgressFn fn) = 0;
226 
229  std::function<void(int new_num_connections)>;
230  virtual std::unique_ptr<Handler>
232 
235  std::function<void(bool network_active)>;
236  virtual std::unique_ptr<Handler>
238 
240  using NotifyAlertChangedFn = std::function<void()>;
241  virtual std::unique_ptr<Handler>
243 
245  using BannedListChangedFn = std::function<void()>;
246  virtual std::unique_ptr<Handler>
248 
251  std::function<void(SynchronizationState, interfaces::BlockTip tip,
252  double verification_progress)>;
253  virtual std::unique_ptr<Handler>
255 
257  using NotifyHeaderTipFn = std::function<void(
258  SynchronizationState, interfaces::BlockTip tip, bool presync)>;
259  virtual std::unique_ptr<Handler>
261 
264  virtual node::NodeContext *context() { return nullptr; }
266 };
267 
269 std::unique_ptr<Node> MakeNode(node::NodeContext *context);
270 
272 struct BlockTip {
274  int64_t block_time;
276 };
277 
278 } // namespace interfaces
279 
280 #endif // BITCOIN_INTERFACES_NODE_H
int flags
Definition: bitcoin-tx.cpp:533
Definition: banman.h:58
Coin Control Features.
Definition: coincontrol.h:21
NumConnections
Definition: net.h:847
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:20
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:58
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:245
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:219
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:235
virtual void setNetworkActive(bool active)=0
Set network active.
std::function< bool(const bilingual_str &message, const std::string &caption, unsigned int style)> MessageBoxFn
Register handler for message box messages.
Definition: node.h:212
virtual bilingual_str getWarnings()=0
Get warnings.
virtual std::unique_ptr< Handler > handleNotifyNumConnectionsChanged(NotifyNumConnectionsChangedFn fn)=0
virtual void appShutdown()=0
Stop node.
virtual bool isPersistentSettingIgnored(const std::string &name)=0
Return whether a particular setting in <datadir>/settings.json would be ignored because it is also sp...
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 resetSettings()=0
Clear all settings in <datadir>/settings.json and store a backup of previous settings in <datadir>/se...
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:121
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:224
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:240
virtual int64_t getLastBlockTime()=0
Get last block time.
virtual bool getBanned(banmap_t &banmap)=0
Get ban map entries.
std::function< void(SynchronizationState, interfaces::BlockTip tip, bool presync)> NotifyHeaderTipFn
Register handler for header tip messages.
Definition: node.h:258
virtual void forceSetting(const std::string &name, const util::SettingsValue &value)=0
Force a setting value to be applied, overriding any other configuration source, but not being persist...
virtual BlockHash getBestBlockHash()=0
Get best block hash.
virtual size_t getMempoolSize()=0
Get mempool size.
virtual void updateRwSetting(const std::string &name, const util::SettingsValue &value)=0
Update a setting in <datadir>/settings.json.
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:60
virtual node::NodeContext * context()
Get and set internal node context.
Definition: node.h:264
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 util::SettingsValue getPersistentSetting(const std::string &name)=0
Return setting value from <datadir>/settings.json or bitcoin.conf.
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:206
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:229
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:265
std::function< void(SynchronizationState, interfaces::BlockTip tip, double verification_progress)> NotifyBlockTipFn
Register handler for block tip messages.
Definition: node.h:252
Wallet chain client that in addition to having chain client methods for starting up,...
Definition: wallet.h:304
std::unique_ptr< Node > MakeNode(node::NodeContext *context)
Return implementation of Node interface.
Definition: interfaces.cpp:785
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
const char * name
Definition: rest.cpp:48
A BlockHash is a unqiue identifier for a block.
Definition: blockhash.h:13
POD that contains various stats about a node.
Definition: net.h:290
Bilingual messages:
Definition: translation.h:17
Block and header tip information.
Definition: node.h:49
Block tip (could be a header or not, depends on the subscribed signal).
Definition: node.h:272
int64_t block_time
Definition: node.h:274
BlockHash block_hash
Definition: node.h:275
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:117