LCOV - code coverage report
Current view: top level - src/interfaces - node.h (source / functions) Hit Total Coverage
Test: fuzz_coverage.info Lines: 0 4 0.0 %
Date: 2023-11-10 23:46:46 Functions: 0 5 0.0 %
Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : // Copyright (c) 2018-2022 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>          // For CAmount
      10                 :            : #include <net.h>                       // For NodeId
      11                 :            : #include <net_types.h>                 // For banmap_t
      12                 :            : #include <netaddress.h>                // For Network
      13                 :            : #include <netbase.h>                   // For ConnectionDirection
      14                 :            : #include <support/allocators/secure.h> // For SecureString
      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                 :            :     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                 :          0 : class Node
      70                 :            : {
      71                 :            : public:
      72                 :          0 :     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 exit status.
      84                 :            :     virtual int getExitStatus() = 0;
      85                 :            : 
      86                 :            :     // Get log flags.
      87                 :            :     virtual uint32_t 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 use_upnp, bool use_natpmp) = 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 header tip height and time.
     166                 :            :     virtual bool getHeaderTip(int& height, int64_t& block_time) = 0;
     167                 :            : 
     168                 :            :     //! Get num blocks.
     169                 :            :     virtual int getNumBlocks() = 0;
     170                 :            : 
     171                 :            :     //! Get best block hash.
     172                 :            :     virtual uint256 getBestBlockHash() = 0;
     173                 :            : 
     174                 :            :     //! Get last block time.
     175                 :            :     virtual int64_t getLastBlockTime() = 0;
     176                 :            : 
     177                 :            :     //! Get verification progress.
     178                 :            :     virtual double getVerificationProgress() = 0;
     179                 :            : 
     180                 :            :     //! Is initial block download.
     181                 :            :     virtual bool isInitialBlockDownload() = 0;
     182                 :            : 
     183                 :            :     //! Is loading blocks.
     184                 :            :     virtual bool isLoadingBlocks() = 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 1.14