LCOV - code coverage report
Current view: top level - src/interfaces - node.h (source / functions) Hit Total Coverage
Test: coverage.lcov Lines: 1 4 25.0 %
Date: 2022-08-30 15:50:09 Functions: 1 4 25.0 %
Legend: Modified by patch:
Lines: hit not hit | Branches: + taken - not taken # not executed

Not modified by patch:
Lines: hit not hit | Branches: + taken - not taken # not executed
Branches: 0 0 -

           Branch data     Line data    Source code
#       1                 :            : // Copyright (c) 2018-2021 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>          // For CAmount
#       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                 :            : #include <support/allocators/secure.h> // For SecureString
#      14                 :            : #include <util/settings.h>             // For util::SettingsValue
#      15                 :            : #include <util/translation.h>
#      16                 :            : 
#      17                 :            : #include <functional>
#      18                 :            : #include <memory>
#      19                 :            : #include <stddef.h>
#      20                 :            : #include <stdint.h>
#      21                 :            : #include <string>
#      22                 :            : #include <tuple>
#      23                 :            : #include <vector>
#      24                 :            : 
#      25                 :            : class BanMan;
#      26                 :            : class CFeeRate;
#      27                 :            : class CNodeStats;
#      28                 :            : class Coin;
#      29                 :            : class RPCTimerInterface;
#      30                 :            : class UniValue;
#      31                 :            : class Proxy;
#      32                 :            : enum class SynchronizationState;
#      33                 :            : enum class TransactionError;
#      34                 :            : struct CNodeStateStats;
#      35                 :            : struct bilingual_str;
#      36                 :            : namespace node {
#      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                 :          0 :     virtual ~ExternalSigner() {};
#      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                 :          1 :     virtual ~Node() {}
#      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 log flags.
#      84                 :            :     virtual uint32_t getLogCategories() = 0;
#      85                 :            : 
#      86                 :            :     //! Initialize app dependencies.
#      87                 :            :     virtual bool baseInitialize() = 0;
#      88                 :            : 
#      89                 :            :     //! Start node.
#      90                 :            :     virtual bool appInitMain(interfaces::BlockAndHeaderTipInfo* tip_info = nullptr) = 0;
#      91                 :            : 
#      92                 :            :     //! Stop node.
#      93                 :            :     virtual void appShutdown() = 0;
#      94                 :            : 
#      95                 :            :     //! Start shutdown.
#      96                 :            :     virtual void startShutdown() = 0;
#      97                 :            : 
#      98                 :            :     //! Return whether shutdown was requested.
#      99                 :            :     virtual bool shutdownRequested() = 0;
#     100                 :            : 
#     101                 :            :     //! Return whether a particular setting in <datadir>/settings.json is or
#     102                 :            :     //! would be ignored because it is also specified in the command line.
#     103                 :            :     virtual bool isSettingIgnored(const std::string& name) = 0;
#     104                 :            : 
#     105                 :            :     //! Return setting value from <datadir>/settings.json or bitcoin.conf.
#     106                 :            :     virtual util::SettingsValue getPersistentSetting(const std::string& name) = 0;
#     107                 :            : 
#     108                 :            :     //! Update a setting in <datadir>/settings.json.
#     109                 :            :     virtual void updateRwSetting(const std::string& name, const util::SettingsValue& value) = 0;
#     110                 :            : 
#     111                 :            :     //! Force a setting value to be applied, overriding any other configuration
#     112                 :            :     //! source, but not being persisted.
#     113                 :            :     virtual void forceSetting(const std::string& name, const util::SettingsValue& value) = 0;
#     114                 :            : 
#     115                 :            :     //! Clear all settings in <datadir>/settings.json and store a backup of
#     116                 :            :     //! previous settings in <datadir>/settings.json.bak.
#     117                 :            :     virtual void resetSettings() = 0;
#     118                 :            : 
#     119                 :            :     //! Map port.
#     120                 :            :     virtual void mapPort(bool use_upnp, bool use_natpmp) = 0;
#     121                 :            : 
#     122                 :            :     //! Get proxy.
#     123                 :            :     virtual bool getProxy(Network net, Proxy& proxy_info) = 0;
#     124                 :            : 
#     125                 :            :     //! Get number of connections.
#     126                 :            :     virtual size_t getNodeCount(ConnectionDirection flags) = 0;
#     127                 :            : 
#     128                 :            :     //! Get stats for connected nodes.
#     129                 :            :     using NodesStats = std::vector<std::tuple<CNodeStats, bool, CNodeStateStats>>;
#     130                 :            :     virtual bool getNodesStats(NodesStats& stats) = 0;
#     131                 :            : 
#     132                 :            :     //! Get ban map entries.
#     133                 :            :     virtual bool getBanned(banmap_t& banmap) = 0;
#     134                 :            : 
#     135                 :            :     //! Ban node.
#     136                 :            :     virtual bool ban(const CNetAddr& net_addr, int64_t ban_time_offset) = 0;
#     137                 :            : 
#     138                 :            :     //! Unban node.
#     139                 :            :     virtual bool unban(const CSubNet& ip) = 0;
#     140                 :            : 
#     141                 :            :     //! Disconnect node by address.
#     142                 :            :     virtual bool disconnectByAddress(const CNetAddr& net_addr) = 0;
#     143                 :            : 
#     144                 :            :     //! Disconnect node by id.
#     145                 :            :     virtual bool disconnectById(NodeId id) = 0;
#     146                 :            : 
#     147                 :            :     //! Return list of external signers (attached devices which can sign transactions).
#     148                 :            :     virtual std::vector<std::unique_ptr<ExternalSigner>> listExternalSigners() = 0;
#     149                 :            : 
#     150                 :            :     //! Get total bytes recv.
#     151                 :            :     virtual int64_t getTotalBytesRecv() = 0;
#     152                 :            : 
#     153                 :            :     //! Get total bytes sent.
#     154                 :            :     virtual int64_t getTotalBytesSent() = 0;
#     155                 :            : 
#     156                 :            :     //! Get mempool size.
#     157                 :            :     virtual size_t getMempoolSize() = 0;
#     158                 :            : 
#     159                 :            :     //! Get mempool dynamic usage.
#     160                 :            :     virtual size_t getMempoolDynamicUsage() = 0;
#     161                 :            : 
#     162                 :            :     //! Get header tip height and time.
#     163                 :            :     virtual bool getHeaderTip(int& height, int64_t& block_time) = 0;
#     164                 :            : 
#     165                 :            :     //! Get num blocks.
#     166                 :            :     virtual int getNumBlocks() = 0;
#     167                 :            : 
#     168                 :            :     //! Get best block hash.
#     169                 :            :     virtual uint256 getBestBlockHash() = 0;
#     170                 :            : 
#     171                 :            :     //! Get last block time.
#     172                 :            :     virtual int64_t getLastBlockTime() = 0;
#     173                 :            : 
#     174                 :            :     //! Get verification progress.
#     175                 :            :     virtual double getVerificationProgress() = 0;
#     176                 :            : 
#     177                 :            :     //! Is initial block download.
#     178                 :            :     virtual bool isInitialBlockDownload() = 0;
#     179                 :            : 
#     180                 :            :     //! Get reindex.
#     181                 :            :     virtual bool getReindex() = 0;
#     182                 :            : 
#     183                 :            :     //! Get importing.
#     184                 :            :     virtual bool getImporting() = 0;
#     185                 :            : 
#     186                 :            :     //! Set network active.
#     187                 :            :     virtual void setNetworkActive(bool active) = 0;
#     188                 :            : 
#     189                 :            :     //! Get network active.
#     190                 :            :     virtual bool getNetworkActive() = 0;
#     191                 :            : 
#     192                 :            :     //! Get dust relay fee.
#     193                 :            :     virtual CFeeRate getDustRelayFee() = 0;
#     194                 :            : 
#     195                 :            :     //! Execute rpc command.
#     196                 :            :     virtual UniValue executeRpc(const std::string& command, const UniValue& params, const std::string& uri) = 0;
#     197                 :            : 
#     198                 :            :     //! List rpc commands.
#     199                 :            :     virtual std::vector<std::string> listRpcCommands() = 0;
#     200                 :            : 
#     201                 :            :     //! Set RPC timer interface if unset.
#     202                 :            :     virtual void rpcSetTimerInterfaceIfUnset(RPCTimerInterface* iface) = 0;
#     203                 :            : 
#     204                 :            :     //! Unset RPC timer interface.
#     205                 :            :     virtual void rpcUnsetTimerInterface(RPCTimerInterface* iface) = 0;
#     206                 :            : 
#     207                 :            :     //! Get unspent outputs associated with a transaction.
#     208                 :            :     virtual bool getUnspentOutput(const COutPoint& output, Coin& coin) = 0;
#     209                 :            : 
#     210                 :            :     //! Broadcast transaction.
#     211                 :            :     virtual 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

Generated by: LCOV version 0-eol-96201-ge66f56f4af6a