Bitcoin ABC  0.22.13
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 <amount.h> // For Amount
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 
15 #include <cstddef>
16 #include <cstdint>
17 #include <functional>
18 #include <memory>
19 #include <string>
20 #include <tuple>
21 #include <vector>
22 
23 class BanMan;
24 class CCoinControl;
25 class CFeeRate;
26 struct CNodeStateStats;
27 struct CNodeStats;
28 class Coin;
29 class Config;
31 struct NodeContext;
32 class proxyType;
33 class RPCServer;
34 class RPCTimerInterface;
35 enum class SynchronizationState;
36 class UniValue;
37 enum class WalletCreationStatus;
38 struct bilingual_str;
39 
40 namespace interfaces {
41 class Handler;
42 class Wallet;
43 
45 class Node {
46 public:
47  virtual ~Node() {}
48 
50  virtual void initLogging() = 0;
51 
53  virtual void initParameterInteraction() = 0;
54 
56  virtual std::string getWarnings() = 0;
57 
59  virtual bool baseInitialize(Config &config) = 0;
60 
62  virtual bool
63  appInitMain(Config &config, RPCServer &rpcServer,
64  HTTPRPCRequestProcessor &httpRPCRequestProcessor) = 0;
65 
67  virtual void appShutdown() = 0;
68 
70  virtual void startShutdown() = 0;
71 
73  virtual bool shutdownRequested() = 0;
74 
76  virtual void mapPort(bool use_upnp) = 0;
77 
79  virtual bool getProxy(Network net, proxyType &proxy_info) = 0;
80 
82  virtual size_t getNodeCount(CConnman::NumConnections flags) = 0;
83 
85  using NodesStats =
86  std::vector<std::tuple<CNodeStats, bool, CNodeStateStats>>;
87  virtual bool getNodesStats(NodesStats &stats) = 0;
88 
90  virtual bool getBanned(banmap_t &banmap) = 0;
91 
93  virtual bool ban(const CNetAddr &net_addr, int64_t ban_time_offset) = 0;
94 
96  virtual bool unban(const CSubNet &ip) = 0;
97 
99  virtual bool disconnectByAddress(const CNetAddr &net_addr) = 0;
100 
102  virtual bool disconnectById(NodeId id) = 0;
103 
105  virtual int64_t getTotalBytesRecv() = 0;
106 
108  virtual int64_t getTotalBytesSent() = 0;
109 
111  virtual size_t getMempoolSize() = 0;
112 
114  virtual size_t getMempoolDynamicUsage() = 0;
115 
117  virtual bool getHeaderTip(int &height, int64_t &block_time) = 0;
118 
120  virtual int getNumBlocks() = 0;
121 
123  virtual int64_t getLastBlockTime() = 0;
124 
126  virtual double getVerificationProgress() = 0;
127 
129  virtual bool isInitialBlockDownload() = 0;
130 
132  virtual bool getReindex() = 0;
133 
135  virtual bool getImporting() = 0;
136 
138  virtual void setNetworkActive(bool active) = 0;
139 
141  virtual bool getNetworkActive() = 0;
142 
144  virtual CFeeRate estimateSmartFee() = 0;
145 
147  virtual CFeeRate getDustRelayFee() = 0;
148 
150  virtual UniValue executeRpc(Config &config, const std::string &command,
151  const UniValue &params,
152  const std::string &uri) = 0;
153 
155  virtual std::vector<std::string> listRpcCommands() = 0;
156 
158  virtual void rpcSetTimerInterfaceIfUnset(RPCTimerInterface *iface) = 0;
159 
161  virtual void rpcUnsetTimerInterface(RPCTimerInterface *iface) = 0;
162 
164  virtual bool getUnspentOutput(const COutPoint &output, Coin &coin) = 0;
165 
167  virtual std::string getWalletDir() = 0;
168 
170  virtual std::vector<std::string> listWalletDir() = 0;
171 
173  virtual std::vector<std::unique_ptr<Wallet>> getWallets() = 0;
174 
178  virtual std::unique_ptr<Wallet>
179  loadWallet(const CChainParams &params, const std::string &name,
181  std::vector<bilingual_str> &warnings) const = 0;
182 
184  virtual std::unique_ptr<Wallet>
185  createWallet(const CChainParams &params, const SecureString &passphrase,
186  uint64_t wallet_creation_flags, const std::string &name,
187  bilingual_str &error, std::vector<bilingual_str> &warnings,
188  WalletCreationStatus &status) = 0;
189 
191  using InitMessageFn = std::function<void(const std::string &message)>;
192  virtual std::unique_ptr<Handler> handleInitMessage(InitMessageFn fn) = 0;
193 
195  using MessageBoxFn =
196  std::function<bool(const bilingual_str &message,
197  const std::string &caption, unsigned int style)>;
198  virtual std::unique_ptr<Handler> handleMessageBox(MessageBoxFn fn) = 0;
199 
201  using QuestionFn =
202  std::function<bool(const bilingual_str &message,
203  const std::string &non_interactive_message,
204  const std::string &caption, unsigned int style)>;
205  virtual std::unique_ptr<Handler> handleQuestion(QuestionFn fn) = 0;
206 
208  using ShowProgressFn = std::function<void(
209  const std::string &title, int progress, bool resume_possible)>;
210  virtual std::unique_ptr<Handler> handleShowProgress(ShowProgressFn fn) = 0;
211 
213  using LoadWalletFn = std::function<void(std::unique_ptr<Wallet> wallet)>;
214  virtual std::unique_ptr<Handler> handleLoadWallet(LoadWalletFn fn) = 0;
215 
218  std::function<void(int new_num_connections)>;
219  virtual std::unique_ptr<Handler>
221 
224  std::function<void(bool network_active)>;
225  virtual std::unique_ptr<Handler>
227 
229  using NotifyAlertChangedFn = std::function<void()>;
230  virtual std::unique_ptr<Handler>
232 
234  using BannedListChangedFn = std::function<void()>;
235  virtual std::unique_ptr<Handler>
237 
239  using NotifyBlockTipFn =
240  std::function<void(SynchronizationState, int height, int64_t block_time,
241  double verification_progress)>;
242  virtual std::unique_ptr<Handler>
244 
246  using NotifyHeaderTipFn =
247  std::function<void(SynchronizationState, int height, int64_t block_time,
248  double verification_progress)>;
249  virtual std::unique_ptr<Handler>
251 
254  virtual NodeContext *context() { return nullptr; }
255  virtual void setContext(NodeContext *context) {}
256 };
257 
259 std::unique_ptr<Node> MakeNode(NodeContext *context = nullptr);
260 
261 } // namespace interfaces
262 
263 #endif // BITCOIN_INTERFACES_NODE_H
virtual CFeeRate estimateSmartFee()=0
Estimate smart fee.
virtual std::unique_ptr< Handler > handleNotifyHeaderTip(NotifyHeaderTipFn fn)=0
std::vector< std::tuple< CNodeStats, bool, CNodeStateStats > > NodesStats
Get stats for connected nodes.
Definition: node.h:86
RPC timer "driver".
Definition: server.h:98
std::function< void(SynchronizationState, int height, int64_t block_time, double verification_progress)> NotifyBlockTipFn
Register handler for block tip messages.
Definition: node.h:241
virtual bool isInitialBlockDownload()=0
Is initial block download.
SynchronizationState
Current sync state passed to tip changed callbacks.
Definition: validation.h:128
Definition: banman.h:58
virtual bool getNetworkActive()=0
Get network active.
virtual void initLogging()=0
Init logging.
A UTXO entry.
Definition: coins.h:27
Bilingual messages:
Definition: translation.h:17
virtual double getVerificationProgress()=0
Get verification progress.
virtual size_t getMempoolDynamicUsage()=0
Get mempool dynamic usage.
virtual bool getProxy(Network net, proxyType &proxy_info)=0
Get proxy.
virtual bool unban(const CSubNet &ip)=0
Unban node.
virtual void startShutdown()=0
Start shutdown.
virtual void rpcUnsetTimerInterface(RPCTimerInterface *iface)=0
Unset RPC timer interface.
virtual std::vector< std::string > listWalletDir()=0
Return available wallets in wallet directory.
virtual int64_t getTotalBytesRecv()=0
Get total bytes recv.
virtual bool getImporting()=0
Get importing.
std::function< void(bool network_active)> NotifyNetworkActiveChangedFn
Register handler for network active messages.
Definition: node.h:224
virtual size_t getMempoolSize()=0
Get mempool size.
std::basic_string< char, std::char_traits< char >, secure_allocator< char > > SecureString
Definition: secure.h:56
virtual UniValue executeRpc(Config &config, const std::string &command, const UniValue &params, const std::string &uri)=0
Execute rpc command.
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system...
Definition: chainparams.h:47
std::function< bool(const bilingual_str &message, const std::string &caption, unsigned int style)> MessageBoxFn
Register handler for message box messages.
Definition: node.h:197
virtual std::vector< std::unique_ptr< Wallet > > getWallets()=0
Return interfaces for accessing wallets (if any).
WalletCreationStatus
Definition: wallet.h:68
virtual std::unique_ptr< Handler > handleNotifyBlockTip(NotifyBlockTipFn fn)=0
virtual void setContext(NodeContext *context)
Definition: node.h:255
virtual CFeeRate getDustRelayFee()=0
Get dust relay fee.
virtual bool ban(const CNetAddr &net_addr, int64_t ban_time_offset)=0
Ban node.
Coin Control Features.
Definition: coincontrol.h:19
virtual void rpcSetTimerInterfaceIfUnset(RPCTimerInterface *iface)=0
Set RPC timer interface if unset.
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:204
virtual std::unique_ptr< Handler > handleMessageBox(MessageBoxFn fn)=0
virtual std::unique_ptr< Wallet > createWallet(const CChainParams &params, const SecureString &passphrase, uint64_t wallet_creation_flags, const std::string &name, bilingual_str &error, std::vector< bilingual_str > &warnings, WalletCreationStatus &status)=0
Create a wallet from file.
virtual std::unique_ptr< Handler > handleNotifyNumConnectionsChanged(NotifyNumConnectionsChangedFn fn)=0
Definition: config.h:19
NodeContext struct containing references to chain state and connection state.
Definition: context.h:35
std::function< void()> NotifyAlertChangedFn
Register handler for notify alert messages.
Definition: node.h:229
virtual std::string getWalletDir()=0
Return default wallet directory.
const char * name
Definition: rest.cpp:43
virtual std::unique_ptr< Handler > handleShowProgress(ShowProgressFn fn)=0
virtual ~Node()
Definition: node.h:47
virtual bool disconnectByAddress(const CNetAddr &net_addr)=0
Disconnect node by address.
Network
Definition: netaddress.h:19
Class for registering and managing all RPC calls.
Definition: server.h:41
int64_t NodeId
Definition: net.h:99
NumConnections
Definition: net.h:167
virtual std::unique_ptr< Handler > handleBannedListChanged(BannedListChangedFn fn)=0
std::function< void(std::unique_ptr< Wallet > wallet)> LoadWalletFn
Register handler for load wallet messages.
Definition: node.h:213
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: transaction.h:22
virtual bool shutdownRequested()=0
Return whether shutdown was requested.
std::function< void()> BannedListChangedFn
Register handler for ban list messages.
Definition: node.h:234
std::function< void(const std::string &message)> InitMessageFn
Register handler for init messages.
Definition: node.h:191
std::function< void(const std::string &title, int progress, bool resume_possible)> ShowProgressFn
Register handler for progress messages.
Definition: node.h:209
int flags
Definition: bitcoin-tx.cpp:529
virtual void initParameterInteraction()=0
Init parameter interaction.
virtual std::unique_ptr< Handler > handleLoadWallet(LoadWalletFn fn)=0
std::function< void(int new_num_connections)> NotifyNumConnectionsChangedFn
Register handler for number of connections changed messages.
Definition: node.h:218
IP address (IPv6, or IPv4 using mapped IPv6 range (::FFFF:0:0/96))
Definition: netaddress.h:30
virtual bool getReindex()=0
Get reindex.
virtual int64_t getLastBlockTime()=0
Get last block time.
virtual void appShutdown()=0
Stop node.
virtual std::unique_ptr< Handler > handleQuestion(QuestionFn fn)=0
virtual void mapPort(bool use_upnp)=0
Map port.
virtual std::vector< std::string > listRpcCommands()=0
List rpc commands.
virtual bool getHeaderTip(int &height, int64_t &block_time)=0
Get header tip height and time.
virtual bool baseInitialize(Config &config)=0
Initialize app dependencies.
virtual bool appInitMain(Config &config, RPCServer &rpcServer, HTTPRPCRequestProcessor &httpRPCRequestProcessor)=0
Start node.
virtual NodeContext * context()
Get and set internal node context.
Definition: node.h:254
virtual bool getNodesStats(NodesStats &stats)=0
Fee rate in satoshis per kilobyte: Amount / kB.
Definition: feerate.h:21
POD that contains various stats about a node.
Definition: net.h:645
virtual bool getBanned(banmap_t &banmap)=0
Get ban map entries.
std::map< CSubNet, CBanEntry > banmap_t
Definition: net_types.h:13
virtual int getNumBlocks()=0
Get num blocks.
virtual std::unique_ptr< Handler > handleNotifyAlertChanged(NotifyAlertChangedFn fn)=0
virtual bool disconnectById(NodeId id)=0
Disconnect node by id.
virtual std::string getWarnings()=0
Get warnings.
virtual std::unique_ptr< Handler > handleNotifyNetworkActiveChanged(NotifyNetworkActiveChangedFn fn)=0
std::unique_ptr< Node > MakeNode(NodeContext *context)
Return implementation of Node interface.
Definition: node.cpp:353
virtual int64_t getTotalBytesSent()=0
Get total bytes sent.
virtual void setNetworkActive(bool active)=0
Set network active.
Top-level interface for a bitcoin node (bitcoind process).
Definition: node.h:45
bool error(const char *fmt, const Args &... args)
Definition: system.h:47
virtual size_t getNodeCount(CConnman::NumConnections flags)=0
Get number of connections.
virtual std::unique_ptr< Wallet > loadWallet(const CChainParams &params, const std::string &name, bilingual_str &error, std::vector< bilingual_str > &warnings) const =0
Attempts to load a wallet from file or directory.
std::function< void(SynchronizationState, int height, int64_t block_time, double verification_progress)> NotifyHeaderTipFn
Register handler for header tip messages.
Definition: node.h:248
virtual bool getUnspentOutput(const COutPoint &output, Coin &coin)=0
Get unspent outputs associated with a transaction.
virtual std::unique_ptr< Handler > handleInitMessage(InitMessageFn fn)=0