LCOV - code coverage report
Current view: top level - src/interfaces - node.h (source / functions) Hit Total Coverage
Test: total_coverage.info Lines: 2 4 50.0 %
Date: 2020-09-26 01:30:44 Functions: 2 6 33.3 %

          Line data    Source code
       1             : // Copyright (c) 2018-2019 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 CAmount
       9             : #include <net.h>        // For CConnman::NumConnections
      10             : #include <net_types.h>  // For banmap_t
      11             : #include <netaddress.h> // For Network
      12             : #include <support/allocators/secure.h> // For SecureString
      13             : #include <util/translation.h>
      14             : 
      15             : #include <functional>
      16             : #include <memory>
      17             : #include <stddef.h>
      18             : #include <stdint.h>
      19             : #include <string>
      20             : #include <tuple>
      21             : #include <vector>
      22             : 
      23             : class BanMan;
      24             : class CCoinControl;
      25             : class CFeeRate;
      26             : class CNodeStats;
      27             : class Coin;
      28             : class RPCTimerInterface;
      29             : class UniValue;
      30             : class proxyType;
      31             : enum class SynchronizationState;
      32             : struct CNodeStateStats;
      33             : struct NodeContext;
      34             : struct bilingual_str;
      35             : 
      36             : namespace interfaces {
      37             : class Handler;
      38             : class WalletClient;
      39             : struct BlockTip;
      40             : 
      41             : //! Block and header tip information
      42             : struct BlockAndHeaderTipInfo
      43             : {
      44             :     int block_height;
      45             :     int64_t block_time;
      46             :     int header_height;
      47             :     int64_t header_time;
      48             :     double verification_progress;
      49             : };
      50             : 
      51             : //! Top-level interface for a bitcoin node (bitcoind process).
      52           1 : class Node
      53             : {
      54             : public:
      55           1 :     virtual ~Node() {}
      56             : 
      57             :     //! Init logging.
      58             :     virtual void initLogging() = 0;
      59             : 
      60             :     //! Init parameter interaction.
      61             :     virtual void initParameterInteraction() = 0;
      62             : 
      63             :     //! Get warnings.
      64             :     virtual bilingual_str getWarnings() = 0;
      65             : 
      66             :     // Get log flags.
      67             :     virtual uint32_t getLogCategories() = 0;
      68             : 
      69             :     //! Initialize app dependencies.
      70             :     virtual bool baseInitialize() = 0;
      71             : 
      72             :     //! Start node.
      73             :     virtual bool appInitMain(interfaces::BlockAndHeaderTipInfo* tip_info = nullptr) = 0;
      74             : 
      75             :     //! Stop node.
      76             :     virtual void appShutdown() = 0;
      77             : 
      78             :     //! Start shutdown.
      79             :     virtual void startShutdown() = 0;
      80             : 
      81             :     //! Return whether shutdown was requested.
      82             :     virtual bool shutdownRequested() = 0;
      83             : 
      84             :     //! Map port.
      85             :     virtual void mapPort(bool use_upnp) = 0;
      86             : 
      87             :     //! Get proxy.
      88             :     virtual bool getProxy(Network net, proxyType& proxy_info) = 0;
      89             : 
      90             :     //! Get number of connections.
      91             :     virtual size_t getNodeCount(CConnman::NumConnections flags) = 0;
      92             : 
      93             :     //! Get stats for connected nodes.
      94             :     using NodesStats = std::vector<std::tuple<CNodeStats, bool, CNodeStateStats>>;
      95             :     virtual bool getNodesStats(NodesStats& stats) = 0;
      96             : 
      97             :     //! Get ban map entries.
      98             :     virtual bool getBanned(banmap_t& banmap) = 0;
      99             : 
     100             :     //! Ban node.
     101             :     virtual bool ban(const CNetAddr& net_addr, int64_t ban_time_offset) = 0;
     102             : 
     103             :     //! Unban node.
     104             :     virtual bool unban(const CSubNet& ip) = 0;
     105             : 
     106             :     //! Disconnect node by address.
     107             :     virtual bool disconnectByAddress(const CNetAddr& net_addr) = 0;
     108             : 
     109             :     //! Disconnect node by id.
     110             :     virtual bool disconnectById(NodeId id) = 0;
     111             : 
     112             :     //! Get total bytes recv.
     113             :     virtual int64_t getTotalBytesRecv() = 0;
     114             : 
     115             :     //! Get total bytes sent.
     116             :     virtual int64_t getTotalBytesSent() = 0;
     117             : 
     118             :     //! Get mempool size.
     119             :     virtual size_t getMempoolSize() = 0;
     120             : 
     121             :     //! Get mempool dynamic usage.
     122             :     virtual size_t getMempoolDynamicUsage() = 0;
     123             : 
     124             :     //! Get header tip height and time.
     125             :     virtual bool getHeaderTip(int& height, int64_t& block_time) = 0;
     126             : 
     127             :     //! Get num blocks.
     128             :     virtual int getNumBlocks() = 0;
     129             : 
     130             :     //! Get best block hash.
     131             :     virtual uint256 getBestBlockHash() = 0;
     132             : 
     133             :     //! Get last block time.
     134             :     virtual int64_t getLastBlockTime() = 0;
     135             : 
     136             :     //! Get verification progress.
     137             :     virtual double getVerificationProgress() = 0;
     138             : 
     139             :     //! Is initial block download.
     140             :     virtual bool isInitialBlockDownload() = 0;
     141             : 
     142             :     //! Get reindex.
     143             :     virtual bool getReindex() = 0;
     144             : 
     145             :     //! Get importing.
     146             :     virtual bool getImporting() = 0;
     147             : 
     148             :     //! Set network active.
     149             :     virtual void setNetworkActive(bool active) = 0;
     150             : 
     151             :     //! Get network active.
     152             :     virtual bool getNetworkActive() = 0;
     153             : 
     154             :     //! Estimate smart fee.
     155             :     virtual CFeeRate estimateSmartFee(int num_blocks, bool conservative, int* returned_target = nullptr) = 0;
     156             : 
     157             :     //! Get dust relay fee.
     158             :     virtual CFeeRate getDustRelayFee() = 0;
     159             : 
     160             :     //! Execute rpc command.
     161             :     virtual UniValue executeRpc(const std::string& command, const UniValue& params, const std::string& uri) = 0;
     162             : 
     163             :     //! List rpc commands.
     164             :     virtual std::vector<std::string> listRpcCommands() = 0;
     165             : 
     166             :     //! Set RPC timer interface if unset.
     167             :     virtual void rpcSetTimerInterfaceIfUnset(RPCTimerInterface* iface) = 0;
     168             : 
     169             :     //! Unset RPC timer interface.
     170             :     virtual void rpcUnsetTimerInterface(RPCTimerInterface* iface) = 0;
     171             : 
     172             :     //! Get unspent outputs associated with a transaction.
     173             :     virtual bool getUnspentOutput(const COutPoint& output, Coin& coin) = 0;
     174             : 
     175             :     //! Get wallet client.
     176             :     virtual WalletClient& walletClient() = 0;
     177             : 
     178             :     //! Register handler for init messages.
     179             :     using InitMessageFn = std::function<void(const std::string& message)>;
     180             :     virtual std::unique_ptr<Handler> handleInitMessage(InitMessageFn fn) = 0;
     181             : 
     182             :     //! Register handler for message box messages.
     183             :     using MessageBoxFn =
     184             :         std::function<bool(const bilingual_str& message, const std::string& caption, unsigned int style)>;
     185             :     virtual std::unique_ptr<Handler> handleMessageBox(MessageBoxFn fn) = 0;
     186             : 
     187             :     //! Register handler for question messages.
     188             :     using QuestionFn = std::function<bool(const bilingual_str& message,
     189             :         const std::string& non_interactive_message,
     190             :         const std::string& caption,
     191             :         unsigned int style)>;
     192             :     virtual std::unique_ptr<Handler> handleQuestion(QuestionFn fn) = 0;
     193             : 
     194             :     //! Register handler for progress messages.
     195             :     using ShowProgressFn = std::function<void(const std::string& title, int progress, bool resume_possible)>;
     196             :     virtual std::unique_ptr<Handler> handleShowProgress(ShowProgressFn fn) = 0;
     197             : 
     198             :     //! Register handler for number of connections changed messages.
     199             :     using NotifyNumConnectionsChangedFn = std::function<void(int new_num_connections)>;
     200             :     virtual std::unique_ptr<Handler> handleNotifyNumConnectionsChanged(NotifyNumConnectionsChangedFn fn) = 0;
     201             : 
     202             :     //! Register handler for network active messages.
     203             :     using NotifyNetworkActiveChangedFn = std::function<void(bool network_active)>;
     204             :     virtual std::unique_ptr<Handler> handleNotifyNetworkActiveChanged(NotifyNetworkActiveChangedFn fn) = 0;
     205             : 
     206             :     //! Register handler for notify alert messages.
     207             :     using NotifyAlertChangedFn = std::function<void()>;
     208             :     virtual std::unique_ptr<Handler> handleNotifyAlertChanged(NotifyAlertChangedFn fn) = 0;
     209             : 
     210             :     //! Register handler for ban list messages.
     211             :     using BannedListChangedFn = std::function<void()>;
     212             :     virtual std::unique_ptr<Handler> handleBannedListChanged(BannedListChangedFn fn) = 0;
     213             : 
     214             :     //! Register handler for block tip messages.
     215             :     using NotifyBlockTipFn =
     216             :         std::function<void(SynchronizationState, interfaces::BlockTip tip, double verification_progress)>;
     217             :     virtual std::unique_ptr<Handler> handleNotifyBlockTip(NotifyBlockTipFn fn) = 0;
     218             : 
     219             :     //! Register handler for header tip messages.
     220             :     using NotifyHeaderTipFn =
     221             :         std::function<void(SynchronizationState, interfaces::BlockTip tip, double verification_progress)>;
     222             :     virtual std::unique_ptr<Handler> handleNotifyHeaderTip(NotifyHeaderTipFn fn) = 0;
     223             : 
     224             :     //! Get and set internal node context. Useful for testing, but not
     225             :     //! accessible across processes.
     226           0 :     virtual NodeContext* context() { return nullptr; }
     227           0 :     virtual void setContext(NodeContext* context) { }
     228             : };
     229             : 
     230             : //! Return implementation of Node interface.
     231             : std::unique_ptr<Node> MakeNode(NodeContext* context = nullptr);
     232             : 
     233             : //! Block tip (could be a header or not, depends on the subscribed signal).
     234             : struct BlockTip {
     235             :     int block_height;
     236             :     int64_t block_time;
     237             :     uint256 block_hash;
     238             : };
     239             : 
     240             : } // namespace interfaces
     241             : 
     242             : #endif // BITCOIN_INTERFACES_NODE_H

Generated by: LCOV version 1.15