/Users/eugenesiegel/btc/bitcoin/src/interfaces/node.h
| Line | Count | Source (jump to first uncovered line) | 
| 1 |  | // Copyright (c) 2018-present 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 <common/settings.h> | 
| 9 |  | #include <consensus/amount.h> | 
| 10 |  | #include <logging.h> | 
| 11 |  | #include <net.h> | 
| 12 |  | #include <net_types.h> | 
| 13 |  | #include <netaddress.h> | 
| 14 |  | #include <netbase.h> | 
| 15 |  | #include <support/allocators/secure.h> | 
| 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 |  |  | 
| 26 |  | class BanMan; | 
| 27 |  | class CFeeRate; | 
| 28 |  | class CNodeStats; | 
| 29 |  | class Coin; | 
| 30 |  | class UniValue; | 
| 31 |  | class Proxy; | 
| 32 |  | enum class SynchronizationState; | 
| 33 |  | struct CNodeStateStats; | 
| 34 |  | struct bilingual_str; | 
| 35 |  | namespace node { | 
| 36 |  | enum class TransactionError; | 
| 37 |  | struct NodeContext; | 
| 38 |  | } // namespace node | 
| 39 |  | namespace wallet { | 
| 40 |  | class CCoinControl; | 
| 41 |  | } // namespace wallet | 
| 42 |  |  | 
| 43 |  | namespace interfaces { | 
| 44 |  | class Handler; | 
| 45 |  | class WalletLoader; | 
| 46 |  | struct BlockTip; | 
| 47 |  |  | 
| 48 |  | //! Block and header tip information | 
| 49 |  | struct BlockAndHeaderTipInfo | 
| 50 |  | { | 
| 51 |  |     int block_height; | 
| 52 |  |     int64_t block_time; | 
| 53 |  |     int header_height; | 
| 54 |  |     int64_t header_time; | 
| 55 |  |     double verification_progress; | 
| 56 |  | }; | 
| 57 |  |  | 
| 58 |  | //! External signer interface used by the GUI. | 
| 59 |  | class ExternalSigner | 
| 60 |  | { | 
| 61 |  | public: | 
| 62 |  |     virtual ~ExternalSigner() = default; | 
| 63 |  |  | 
| 64 |  |     //! Get signer display name | 
| 65 |  |     virtual std::string getName() = 0; | 
| 66 |  | }; | 
| 67 |  |  | 
| 68 |  | //! Top-level interface for a bitcoin node (bitcoind process). | 
| 69 |  | class Node | 
| 70 |  | { | 
| 71 |  | public: | 
| 72 | 0 |     virtual ~Node() = default; | 
| 73 |  |  | 
| 74 |  |     //! Init logging. | 
| 75 |  |     virtual void initLogging() = 0; | 
| 76 |  |  | 
| 77 |  |     //! Init parameter interaction. | 
| 78 |  |     virtual void initParameterInteraction() = 0; | 
| 79 |  |  | 
| 80 |  |     //! Get warnings. | 
| 81 |  |     virtual bilingual_str getWarnings() = 0; | 
| 82 |  |  | 
| 83 |  |     //! Get exit status. | 
| 84 |  |     virtual int getExitStatus() = 0; | 
| 85 |  |  | 
| 86 |  |     // Get log flags. | 
| 87 |  |     virtual BCLog::CategoryMask getLogCategories() = 0; | 
| 88 |  |  | 
| 89 |  |     //! Initialize app dependencies. | 
| 90 |  |     virtual bool baseInitialize() = 0; | 
| 91 |  |  | 
| 92 |  |     //! Start node. | 
| 93 |  |     virtual bool appInitMain(interfaces::BlockAndHeaderTipInfo* tip_info = nullptr) = 0; | 
| 94 |  |  | 
| 95 |  |     //! Stop node. | 
| 96 |  |     virtual void appShutdown() = 0; | 
| 97 |  |  | 
| 98 |  |     //! Start shutdown. | 
| 99 |  |     virtual void startShutdown() = 0; | 
| 100 |  |  | 
| 101 |  |     //! Return whether shutdown was requested. | 
| 102 |  |     virtual bool shutdownRequested() = 0; | 
| 103 |  |  | 
| 104 |  |     //! Return whether a particular setting in <datadir>/settings.json is or | 
| 105 |  |     //! would be ignored because it is also specified in the command line. | 
| 106 |  |     virtual bool isSettingIgnored(const std::string& name) = 0; | 
| 107 |  |  | 
| 108 |  |     //! Return setting value from <datadir>/settings.json or bitcoin.conf. | 
| 109 |  |     virtual common::SettingsValue getPersistentSetting(const std::string& name) = 0; | 
| 110 |  |  | 
| 111 |  |     //! Update a setting in <datadir>/settings.json. | 
| 112 |  |     virtual void updateRwSetting(const std::string& name, const common::SettingsValue& value) = 0; | 
| 113 |  |  | 
| 114 |  |     //! Force a setting value to be applied, overriding any other configuration | 
| 115 |  |     //! source, but not being persisted. | 
| 116 |  |     virtual void forceSetting(const std::string& name, const common::SettingsValue& value) = 0; | 
| 117 |  |  | 
| 118 |  |     //! Clear all settings in <datadir>/settings.json and store a backup of | 
| 119 |  |     //! previous settings in <datadir>/settings.json.bak. | 
| 120 |  |     virtual void resetSettings() = 0; | 
| 121 |  |  | 
| 122 |  |     //! Map port. | 
| 123 |  |     virtual void mapPort(bool enable) = 0; | 
| 124 |  |  | 
| 125 |  |     //! Get proxy. | 
| 126 |  |     virtual bool getProxy(Network net, Proxy& proxy_info) = 0; | 
| 127 |  |  | 
| 128 |  |     //! Get number of connections. | 
| 129 |  |     virtual size_t getNodeCount(ConnectionDirection flags) = 0; | 
| 130 |  |  | 
| 131 |  |     //! Get stats for connected nodes. | 
| 132 |  |     using NodesStats = std::vector<std::tuple<CNodeStats, bool, CNodeStateStats>>; | 
| 133 |  |     virtual bool getNodesStats(NodesStats& stats) = 0; | 
| 134 |  |  | 
| 135 |  |     //! Get ban map entries. | 
| 136 |  |     virtual bool getBanned(banmap_t& banmap) = 0; | 
| 137 |  |  | 
| 138 |  |     //! Ban node. | 
| 139 |  |     virtual bool ban(const CNetAddr& net_addr, int64_t ban_time_offset) = 0; | 
| 140 |  |  | 
| 141 |  |     //! Unban node. | 
| 142 |  |     virtual bool unban(const CSubNet& ip) = 0; | 
| 143 |  |  | 
| 144 |  |     //! Disconnect node by address. | 
| 145 |  |     virtual bool disconnectByAddress(const CNetAddr& net_addr) = 0; | 
| 146 |  |  | 
| 147 |  |     //! Disconnect node by id. | 
| 148 |  |     virtual bool disconnectById(NodeId id) = 0; | 
| 149 |  |  | 
| 150 |  |     //! Return list of external signers (attached devices which can sign transactions). | 
| 151 |  |     virtual std::vector<std::unique_ptr<ExternalSigner>> listExternalSigners() = 0; | 
| 152 |  |  | 
| 153 |  |     //! Get total bytes recv. | 
| 154 |  |     virtual int64_t getTotalBytesRecv() = 0; | 
| 155 |  |  | 
| 156 |  |     //! Get total bytes sent. | 
| 157 |  |     virtual int64_t getTotalBytesSent() = 0; | 
| 158 |  |  | 
| 159 |  |     //! Get mempool size. | 
| 160 |  |     virtual size_t getMempoolSize() = 0; | 
| 161 |  |  | 
| 162 |  |     //! Get mempool dynamic usage. | 
| 163 |  |     virtual size_t getMempoolDynamicUsage() = 0; | 
| 164 |  |  | 
| 165 |  |     //! Get mempool maximum memory usage. | 
| 166 |  |     virtual size_t getMempoolMaxUsage() = 0; | 
| 167 |  |  | 
| 168 |  |     //! Get header tip height and time. | 
| 169 |  |     virtual bool getHeaderTip(int& height, int64_t& block_time) = 0; | 
| 170 |  |  | 
| 171 |  |     //! Get num blocks. | 
| 172 |  |     virtual int getNumBlocks() = 0; | 
| 173 |  |  | 
| 174 |  |     //! Get network local addresses. | 
| 175 |  |     virtual std::map<CNetAddr, LocalServiceInfo> getNetLocalAddresses() = 0; | 
| 176 |  |  | 
| 177 |  |     //! Get best block hash. | 
| 178 |  |     virtual uint256 getBestBlockHash() = 0; | 
| 179 |  |  | 
| 180 |  |     //! Get last block time. | 
| 181 |  |     virtual int64_t getLastBlockTime() = 0; | 
| 182 |  |  | 
| 183 |  |     //! Get verification progress. | 
| 184 |  |     virtual double getVerificationProgress() = 0; | 
| 185 |  |  | 
| 186 |  |     //! Is initial block download. | 
| 187 |  |     virtual bool isInitialBlockDownload() = 0; | 
| 188 |  |  | 
| 189 |  |     //! Is loading blocks. | 
| 190 |  |     virtual bool isLoadingBlocks() = 0; | 
| 191 |  |  | 
| 192 |  |     //! Set network active. | 
| 193 |  |     virtual void setNetworkActive(bool active) = 0; | 
| 194 |  |  | 
| 195 |  |     //! Get network active. | 
| 196 |  |     virtual bool getNetworkActive() = 0; | 
| 197 |  |  | 
| 198 |  |     //! Get dust relay fee. | 
| 199 |  |     virtual CFeeRate getDustRelayFee() = 0; | 
| 200 |  |  | 
| 201 |  |     //! Execute rpc command. | 
| 202 |  |     virtual UniValue executeRpc(const std::string& command, const UniValue& params, const std::string& uri) = 0; | 
| 203 |  |  | 
| 204 |  |     //! List rpc commands. | 
| 205 |  |     virtual std::vector<std::string> listRpcCommands() = 0; | 
| 206 |  |  | 
| 207 |  |     //! Get unspent output associated with a transaction. | 
| 208 |  |     virtual std::optional<Coin> getUnspentOutput(const COutPoint& output) = 0; | 
| 209 |  |  | 
| 210 |  |     //! Broadcast transaction. | 
| 211 |  |     virtual node::TransactionError broadcastTransaction(CTransactionRef tx, CAmount max_tx_fee, std::string& err_string) = 0; | 
| 212 |  |  | 
| 213 |  |     //! Get wallet loader. | 
| 214 |  |     virtual WalletLoader& walletLoader() = 0; | 
| 215 |  |  | 
| 216 |  |     //! Register handler for init messages. | 
| 217 |  |     using InitMessageFn = std::function<void(const std::string& message)>; | 
| 218 |  |     virtual std::unique_ptr<Handler> handleInitMessage(InitMessageFn fn) = 0; | 
| 219 |  |  | 
| 220 |  |     //! Register handler for message box messages. | 
| 221 |  |     using MessageBoxFn = | 
| 222 |  |         std::function<bool(const bilingual_str& message, const std::string& caption, unsigned int style)>; | 
| 223 |  |     virtual std::unique_ptr<Handler> handleMessageBox(MessageBoxFn fn) = 0; | 
| 224 |  |  | 
| 225 |  |     //! Register handler for question messages. | 
| 226 |  |     using QuestionFn = std::function<bool(const bilingual_str& message, | 
| 227 |  |         const std::string& non_interactive_message, | 
| 228 |  |         const std::string& caption, | 
| 229 |  |         unsigned int style)>; | 
| 230 |  |     virtual std::unique_ptr<Handler> handleQuestion(QuestionFn fn) = 0; | 
| 231 |  |  | 
| 232 |  |     //! Register handler for progress messages. | 
| 233 |  |     using ShowProgressFn = std::function<void(const std::string& title, int progress, bool resume_possible)>; | 
| 234 |  |     virtual std::unique_ptr<Handler> handleShowProgress(ShowProgressFn fn) = 0; | 
| 235 |  |  | 
| 236 |  |     //! Register handler for wallet loader constructed messages. | 
| 237 |  |     using InitWalletFn = std::function<void()>; | 
| 238 |  |     virtual std::unique_ptr<Handler> handleInitWallet(InitWalletFn fn) = 0; | 
| 239 |  |  | 
| 240 |  |     //! Register handler for number of connections changed messages. | 
| 241 |  |     using NotifyNumConnectionsChangedFn = std::function<void(int new_num_connections)>; | 
| 242 |  |     virtual std::unique_ptr<Handler> handleNotifyNumConnectionsChanged(NotifyNumConnectionsChangedFn fn) = 0; | 
| 243 |  |  | 
| 244 |  |     //! Register handler for network active messages. | 
| 245 |  |     using NotifyNetworkActiveChangedFn = std::function<void(bool network_active)>; | 
| 246 |  |     virtual std::unique_ptr<Handler> handleNotifyNetworkActiveChanged(NotifyNetworkActiveChangedFn fn) = 0; | 
| 247 |  |  | 
| 248 |  |     //! Register handler for notify alert messages. | 
| 249 |  |     using NotifyAlertChangedFn = std::function<void()>; | 
| 250 |  |     virtual std::unique_ptr<Handler> handleNotifyAlertChanged(NotifyAlertChangedFn fn) = 0; | 
| 251 |  |  | 
| 252 |  |     //! Register handler for ban list messages. | 
| 253 |  |     using BannedListChangedFn = std::function<void()>; | 
| 254 |  |     virtual std::unique_ptr<Handler> handleBannedListChanged(BannedListChangedFn fn) = 0; | 
| 255 |  |  | 
| 256 |  |     //! Register handler for block tip messages. | 
| 257 |  |     using NotifyBlockTipFn = | 
| 258 |  |         std::function<void(SynchronizationState, interfaces::BlockTip tip, double verification_progress)>; | 
| 259 |  |     virtual std::unique_ptr<Handler> handleNotifyBlockTip(NotifyBlockTipFn fn) = 0; | 
| 260 |  |  | 
| 261 |  |     //! Register handler for header tip messages. | 
| 262 |  |     using NotifyHeaderTipFn = | 
| 263 |  |         std::function<void(SynchronizationState, interfaces::BlockTip tip, bool presync)>; | 
| 264 |  |     virtual std::unique_ptr<Handler> handleNotifyHeaderTip(NotifyHeaderTipFn fn) = 0; | 
| 265 |  |  | 
| 266 |  |     //! Get and set internal node context. Useful for testing, but not | 
| 267 |  |     //! accessible across processes. | 
| 268 | 0 |     virtual node::NodeContext* context() { return nullptr; } | 
| 269 | 0 |     virtual void setContext(node::NodeContext* context) { } | 
| 270 |  | }; | 
| 271 |  |  | 
| 272 |  | //! Return implementation of Node interface. | 
| 273 |  | std::unique_ptr<Node> MakeNode(node::NodeContext& context); | 
| 274 |  |  | 
| 275 |  | //! Block tip (could be a header or not, depends on the subscribed signal). | 
| 276 |  | struct BlockTip { | 
| 277 |  |     int block_height; | 
| 278 |  |     int64_t block_time; | 
| 279 |  |     uint256 block_hash; | 
| 280 |  | }; | 
| 281 |  |  | 
| 282 |  | } // namespace interfaces | 
| 283 |  |  | 
| 284 |  | #endif // BITCOIN_INTERFACES_NODE_H |