Bitcoin ABC 0.30.5
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 NodeId
10#include <net_types.h> // For banmap_t
11#include <netaddress.h> // For Network
12#include <netbase.h> // For ConnectionDirection
13
14#include <support/allocators/secure.h> // For SecureString
15#include <util/settings.h> // For util::SettingsValue
16#include <util/translation.h>
17
18#include <cstddef>
19#include <cstdint>
20#include <functional>
21#include <memory>
22#include <string>
23#include <tuple>
24#include <vector>
25
26class BanMan;
27class CCoinControl;
28class CFeeRate;
29struct CNodeStateStats;
30struct CNodeStats;
31class Coin;
32class Config;
34class proxyType;
35class RPCServer;
37enum class SynchronizationState;
38class UniValue;
39struct bilingual_str;
40namespace node {
41struct NodeContext;
42} // namespace node
43
44namespace interfaces {
45class Handler;
46class WalletClient;
47struct BlockTip;
48
52 int64_t block_time;
54 int64_t header_time;
56};
57
59class Node {
60public:
61 virtual ~Node() {}
62
64 virtual void initLogging() = 0;
65
67 virtual void initParameterInteraction() = 0;
68
71
73 virtual bool baseInitialize(Config &config) = 0;
74
76 virtual bool
77 appInitMain(Config &config, RPCServer &rpcServer,
78 HTTPRPCRequestProcessor &httpRPCRequestProcessor,
79 interfaces::BlockAndHeaderTipInfo *tip_info = nullptr) = 0;
80
82 virtual void appShutdown() = 0;
83
85 virtual void startShutdown() = 0;
86
88 virtual bool shutdownRequested() = 0;
89
92 virtual bool isPersistentSettingIgnored(const std::string &name) = 0;
93
96 getPersistentSetting(const std::string &name) = 0;
97
99 virtual void updateRwSetting(const std::string &name,
100 const util::SettingsValue &value) = 0;
101
104 virtual void forceSetting(const std::string &name,
105 const util::SettingsValue &value) = 0;
106
109 virtual void resetSettings() = 0;
110
112 virtual void mapPort(bool use_upnp, bool use_natpmp) = 0;
113
115 virtual bool getProxy(Network net, proxyType &proxy_info) = 0;
116
119
122 std::vector<std::tuple<CNodeStats, bool, CNodeStateStats>>;
123 virtual bool getNodesStats(NodesStats &stats) = 0;
124
126 virtual bool getBanned(banmap_t &banmap) = 0;
127
129 virtual bool ban(const CNetAddr &net_addr, int64_t ban_time_offset) = 0;
130
132 virtual bool unban(const CSubNet &ip) = 0;
133
135 virtual bool disconnectByAddress(const CNetAddr &net_addr) = 0;
136
138 virtual bool disconnectById(NodeId id) = 0;
139
141 virtual int64_t getTotalBytesRecv() = 0;
142
144 virtual int64_t getTotalBytesSent() = 0;
145
147 virtual size_t getMempoolSize() = 0;
148
150 virtual size_t getMempoolDynamicUsage() = 0;
151
153 virtual bool getHeaderTip(int &height, int64_t &block_time) = 0;
154
156 virtual int getNumBlocks() = 0;
157
160
162 virtual int64_t getLastBlockTime() = 0;
163
165 virtual double getVerificationProgress() = 0;
166
168 virtual bool isInitialBlockDownload() = 0;
169
171 virtual bool isLoadingBlocks() = 0;
172
174 virtual void setNetworkActive(bool active) = 0;
175
177 virtual bool getNetworkActive() = 0;
178
181
183 virtual UniValue executeRpc(const Config &config,
184 const std::string &command,
185 const UniValue &params,
186 const std::string &uri) = 0;
187
189 virtual std::vector<std::string> listRpcCommands() = 0;
190
193
196
198 virtual bool getUnspentOutput(const COutPoint &output, Coin &coin) = 0;
199
202
204 using InitMessageFn = std::function<void(const std::string &message)>;
205 virtual std::unique_ptr<Handler> handleInitMessage(InitMessageFn fn) = 0;
206
209 std::function<bool(const bilingual_str &message,
210 const std::string &caption, unsigned int style)>;
211 virtual std::unique_ptr<Handler> handleMessageBox(MessageBoxFn fn) = 0;
212
215 std::function<bool(const bilingual_str &message,
216 const std::string &non_interactive_message,
217 const std::string &caption, unsigned int style)>;
218 virtual std::unique_ptr<Handler> handleQuestion(QuestionFn fn) = 0;
219
221 using ShowProgressFn = std::function<void(
222 const std::string &title, int progress, bool resume_possible)>;
223 virtual std::unique_ptr<Handler> handleShowProgress(ShowProgressFn fn) = 0;
224
227 std::function<void(int new_num_connections)>;
228 virtual std::unique_ptr<Handler>
230
233 std::function<void(bool network_active)>;
234 virtual std::unique_ptr<Handler>
236
238 using NotifyAlertChangedFn = std::function<void()>;
239 virtual std::unique_ptr<Handler>
241
243 using BannedListChangedFn = std::function<void()>;
244 virtual std::unique_ptr<Handler>
246
249 std::function<void(SynchronizationState, interfaces::BlockTip tip,
250 double verification_progress)>;
251 virtual std::unique_ptr<Handler>
253
255 using NotifyHeaderTipFn = std::function<void(
256 SynchronizationState, interfaces::BlockTip tip, bool presync)>;
257 virtual std::unique_ptr<Handler>
259
262 virtual node::NodeContext *context() { return nullptr; }
264};
265
267std::unique_ptr<Node> MakeNode(node::NodeContext *context);
268
270struct BlockTip {
272 int64_t block_time;
274};
275
276} // namespace interfaces
277
278#endif // BITCOIN_INTERFACES_NODE_H
int flags
Definition: bitcoin-tx.cpp:541
Definition: banman.h:58
Coin Control Features.
Definition: coincontrol.h:21
Fee rate in satoshis per kilobyte: Amount / kB.
Definition: feerate.h:21
Network address.
Definition: netaddress.h:121
A UTXO entry.
Definition: coins.h:28
Definition: config.h:19
Class for registering and managing all RPC calls.
Definition: server.h:40
RPC timer "driver".
Definition: server.h:100
Top-level interface for a bitcoin node (bitcoind process).
Definition: node.h:59
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:243
virtual bool disconnectById(NodeId id)=0
Disconnect node by id.
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:217
virtual std::unique_ptr< Handler > handleInitMessage(InitMessageFn fn)=0
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:233
virtual std::unique_ptr< Handler > handleShowProgress(ShowProgressFn fn)=0
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:210
virtual bilingual_str getWarnings()=0
Get warnings.
virtual std::vector< std::string > listRpcCommands()=0
List rpc commands.
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 bool appInitMain(Config &config, RPCServer &rpcServer, HTTPRPCRequestProcessor &httpRPCRequestProcessor, interfaces::BlockAndHeaderTipInfo *tip_info=nullptr)=0
Start node.
virtual std::unique_ptr< Handler > handleNotifyBlockTip(NotifyBlockTipFn fn)=0
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.
virtual std::unique_ptr< Handler > handleNotifyAlertChanged(NotifyAlertChangedFn fn)=0
virtual std::unique_ptr< Handler > handleNotifyHeaderTip(NotifyHeaderTipFn fn)=0
virtual std::unique_ptr< Handler > handleMessageBox(MessageBoxFn fn)=0
std::vector< std::tuple< CNodeStats, bool, CNodeStateStats > > NodesStats
Get stats for connected nodes.
Definition: node.h:122
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:222
virtual void initParameterInteraction()=0
Init parameter interaction.
virtual void startShutdown()=0
Start shutdown.
std::function< void()> NotifyAlertChangedFn
Register handler for notify alert messages.
Definition: node.h:238
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:256
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 bool isLoadingBlocks()=0
Is loading blocks.
virtual std::unique_ptr< Handler > handleQuestion(QuestionFn fn)=0
virtual size_t getNodeCount(ConnectionDirection 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:61
virtual bool disconnectByAddress(const CNetAddr &net_addr)=0
Disconnect node by address.
virtual int64_t getTotalBytesRecv()=0
Get total bytes recv.
virtual std::unique_ptr< Handler > handleBannedListChanged(BannedListChangedFn fn)=0
virtual WalletClient & walletClient()=0
Get wallet client.
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 std::unique_ptr< Handler > handleNotifyNetworkActiveChanged(NotifyNetworkActiveChangedFn fn)=0
virtual int64_t getTotalBytesSent()=0
Get total bytes sent.
virtual node::NodeContext * context()
Get and set internal node context.
Definition: node.h:262
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:204
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:227
virtual bool getUnspentOutput(const COutPoint &output, Coin &coin)=0
Get unspent outputs associated with a transaction.
virtual std::unique_ptr< Handler > handleNotifyNumConnectionsChanged(NotifyNumConnectionsChangedFn fn)=0
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:263
std::function< void(SynchronizationState, interfaces::BlockTip tip, double verification_progress)> NotifyBlockTipFn
Register handler for block tip messages.
Definition: node.h:250
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:792
Definition: init.h:28
std::map< CSubNet, CBanEntry > banmap_t
Definition: net_types.h:13
Network
A network type.
Definition: netaddress.h:44
ConnectionDirection
Definition: netbase.h:32
int64_t NodeId
Definition: nodeid.h:10
const char * name
Definition: rest.cpp:47
A BlockHash is a unqiue identifier for a block.
Definition: blockhash.h:13
POD that contains various stats about a node.
Definition: net.h:287
Bilingual messages:
Definition: translation.h:17
Block and header tip information.
Definition: node.h:50
Block tip (could be a header or not, depends on the subscribed signal).
Definition: node.h:270
int64_t block_time
Definition: node.h:272
BlockHash block_hash
Definition: node.h:273
NodeContext struct containing references to chain state and connection state.
Definition: context.h:43
SynchronizationState
Current sync state passed to tip changed callbacks.
Definition: validation.h:114