diff --git a/src/Makefile.am b/src/Makefile.am index d063df76211..714a3531b36 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -145,7 +145,6 @@ DEFI_CORE_H = \ init.h \ interfaces/chain.h \ interfaces/handler.h \ - interfaces/node.h \ key.h \ key_io.h \ dbwrapper.h \ @@ -360,7 +359,6 @@ libdefi_server_a_SOURCES = \ index/blockfilterindex.cpp \ index/txindex.cpp \ interfaces/chain.cpp \ - interfaces/node.cpp \ init.cpp \ dbwrapper.cpp \ masternodes/accounts.cpp \ diff --git a/src/interfaces/README.md b/src/interfaces/README.md index 09346e08faf..436a9c41b7f 100644 --- a/src/interfaces/README.md +++ b/src/interfaces/README.md @@ -6,10 +6,6 @@ The following interfaces are defined here: * [`ChainClient`](chain.h) — used by node to start & stop `Chain` clients. Added in [#14437](https://github.com/bitcoin/bitcoin/pull/14437). -* [`Node`](node.h) — used by GUI to start & stop defi node. Added in [#10244](https://github.com/bitcoin/bitcoin/pull/10244). - -* [`Wallet`](wallet.h) — used by GUI to access wallets. Added in [#10244](https://github.com/bitcoin/bitcoin/pull/10244). - * [`Handler`](handler.h) — returned by `handleEvent` methods on interfaces above and used to manage lifetimes of event handlers. * [`Init`](init.h) — used by multiprocess code to access interfaces above on startup. Added in [#10102](https://github.com/bitcoin/bitcoin/pull/10102). diff --git a/src/interfaces/node.cpp b/src/interfaces/node.cpp deleted file mode 100644 index 112f403f1aa..00000000000 --- a/src/interfaces/node.cpp +++ /dev/null @@ -1,290 +0,0 @@ -// Copyright (c) 2018 The Bitcoin Core developers -// Distributed under the MIT software license, see the accompanying -// file LICENSE or http://www.opensource.org/licenses/mit-license.php. - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#if defined(HAVE_CONFIG_H) -#include -#endif - -#include -#include - -class CWallet; -fs::path GetWalletDir(); -std::vector ListWalletDir(); -std::vector> GetWallets(); -std::shared_ptr LoadWallet(interfaces::Chain& chain, const std::string& name, std::string& error, std::string& warning); - -namespace interfaces { - -class Wallet; - -namespace { - -class NodeImpl : public Node -{ -public: - NodeImpl() { m_interfaces.chain = MakeChain(); } - void initError(const std::string& message) override { InitError(message); } - bool parseParameters(int argc, const char* const argv[], std::string& error) override - { - return gArgs.ParseParameters(argc, argv, error); - } - bool readConfigFiles(std::string& error) override { return gArgs.ReadConfigFiles(error, true); } - bool softSetArg(const std::string& arg, const std::string& value) override { return gArgs.SoftSetArg(arg, value); } - bool softSetBoolArg(const std::string& arg, bool value) override { return gArgs.SoftSetBoolArg(arg, value); } - void selectParams(const std::string& network) override { SelectParams(network); } - uint64_t getAssumedBlockchainSize() override { return Params().AssumedBlockchainSize(); } - uint64_t getAssumedChainStateSize() override { return Params().AssumedChainStateSize(); } - std::string getNetwork() override { return Params().NetworkIDString(); } - void initLogging() override { InitLogging(); } - void initParameterInteraction() override { InitParameterInteraction(); } - std::string getWarnings(const std::string& type) override { return GetWarnings(type); } - uint32_t getLogCategories() override { return LogInstance().GetCategoryMask(); } - bool baseInitialize() override - { - return AppInitBasicSetup() && AppInitParameterInteraction() && AppInitSanityChecks() && - AppInitLockDataDirectory(); - } - bool appInitMain() override { return AppInitMain(m_interfaces); } - void appShutdown() override - { - Interrupt(); - Shutdown(m_interfaces); - } - void startShutdown() override { StartShutdown(); } - bool shutdownRequested() override { return ShutdownRequested(); } - void mapPort(bool use_upnp) override - { - if (use_upnp) { - StartMapPort(); - } else { - InterruptMapPort(); - StopMapPort(); - } - } - void setupServerArgs() override { return SetupServerArgs(); } - bool getProxy(Network net, proxyType& proxy_info) override { return GetProxy(net, proxy_info); } - size_t getNodeCount(CConnman::NumConnections flags) override - { - return g_connman ? g_connman->GetNodeCount(flags) : 0; - } - bool getNodesStats(NodesStats& stats) override - { - stats.clear(); - - if (g_connman) { - std::vector stats_temp; - g_connman->GetNodeStats(stats_temp); - - stats.reserve(stats_temp.size()); - for (auto& node_stats_temp : stats_temp) { - stats.emplace_back(std::move(node_stats_temp), false, CNodeStateStats()); - } - - // Try to retrieve the CNodeStateStats for each node. - TRY_LOCK(::cs_main, lockMain); - if (lockMain) { - for (auto& node_stats : stats) { - std::get<1>(node_stats) = - GetNodeStateStats(std::get<0>(node_stats).nodeid, std::get<2>(node_stats)); - } - } - return true; - } - return false; - } - bool getBanned(banmap_t& banmap) override - { - if (g_banman) { - g_banman->GetBanned(banmap); - return true; - } - return false; - } - bool ban(const CNetAddr& net_addr, BanReason reason, int64_t ban_time_offset) override - { - if (g_banman) { - g_banman->Ban(net_addr, reason, ban_time_offset); - return true; - } - return false; - } - bool unban(const CSubNet& ip) override - { - if (g_banman) { - g_banman->Unban(ip); - return true; - } - return false; - } - bool disconnect(const CNetAddr& net_addr) override - { - if (g_connman) { - return g_connman->DisconnectNode(net_addr); - } - return false; - } - bool disconnect(NodeId id) override - { - if (g_connman) { - return g_connman->DisconnectNode(id); - } - return false; - } - int64_t getTotalBytesRecv() override { return g_connman ? g_connman->GetTotalBytesRecv() : 0; } - int64_t getTotalBytesSent() override { return g_connman ? g_connman->GetTotalBytesSent() : 0; } - size_t getMempoolSize() override { return ::mempool.size(); } - size_t getMempoolDynamicUsage() override { return ::mempool.DynamicMemoryUsage(); } - bool getHeaderTip(int& height, int64_t& block_time) override - { - LOCK(::cs_main); - if (::pindexBestHeader) { - height = ::pindexBestHeader->nHeight; - block_time = ::pindexBestHeader->GetBlockTime(); - return true; - } - return false; - } - int getNumBlocks() override - { - LOCK(::cs_main); - return ::ChainActive().Height(); - } - int64_t getLastBlockTime() override - { - LOCK(::cs_main); - if (::ChainActive().Tip()) { - return ::ChainActive().Tip()->GetBlockTime(); - } - return Params().GenesisBlock().GetBlockTime(); // Genesis block's time of current network - } - double getVerificationProgress() override - { - const CBlockIndex* tip; - { - LOCK(::cs_main); - tip = ::ChainActive().Tip(); - } - return GuessVerificationProgress(Params().TxData(), tip); - } - bool isInitialBlockDownload() override { return ::ChainstateActive().IsInitialBlockDownload(); } - bool isAddressTypeSet() override { return !::gArgs.GetArg("-addresstype", "").empty(); } - bool getReindex() override { return ::fReindex; } - bool getImporting() override { return ::fImporting; } - void setNetworkActive(bool active) override - { - if (g_connman) { - g_connman->SetNetworkActive(active); - } - } - bool getNetworkActive() override { return g_connman && g_connman->GetNetworkActive(); } - CFeeRate estimateSmartFee(int num_blocks, bool conservative, int* returned_target = nullptr) override - { - FeeCalculation fee_calc; - CFeeRate result = ::feeEstimator.estimateSmartFee(num_blocks, &fee_calc, conservative); - if (returned_target) { - *returned_target = fee_calc.returnedTarget; - } - return result; - } - CFeeRate getDustRelayFee() override { return ::dustRelayFee; } - UniValue executeRpc(const std::string& command, const UniValue& params, const std::string& uri) override - { - JSONRPCRequest req; - req.params = params; - req.strMethod = command; - req.URI = uri; - return ::tableRPC.execute(req); - } - std::vector listRpcCommands() override { return ::tableRPC.listCommands(); } - void rpcSetTimerInterfaceIfUnset(RPCTimerInterface* iface) override { RPCSetTimerInterfaceIfUnset(iface); } - void rpcUnsetTimerInterface(RPCTimerInterface* iface) override { RPCUnsetTimerInterface(iface); } - bool getUnspentOutput(const COutPoint& output, Coin& coin) override - { - LOCK(::cs_main); - return ::ChainstateActive().CoinsTip().GetCoin(output, coin); - } - std::unique_ptr handleInitMessage(InitMessageFn fn) override - { - return MakeHandler(::uiInterface.InitMessage_connect(fn)); - } - std::unique_ptr handleMessageBox(MessageBoxFn fn) override - { - return MakeHandler(::uiInterface.ThreadSafeMessageBox_connect(fn)); - } - std::unique_ptr handleQuestion(QuestionFn fn) override - { - return MakeHandler(::uiInterface.ThreadSafeQuestion_connect(fn)); - } - std::unique_ptr handleShowProgress(ShowProgressFn fn) override - { - return MakeHandler(::uiInterface.ShowProgress_connect(fn)); - } - std::unique_ptr handleNotifyNumConnectionsChanged(NotifyNumConnectionsChangedFn fn) override - { - return MakeHandler(::uiInterface.NotifyNumConnectionsChanged_connect(fn)); - } - std::unique_ptr handleNotifyNetworkActiveChanged(NotifyNetworkActiveChangedFn fn) override - { - return MakeHandler(::uiInterface.NotifyNetworkActiveChanged_connect(fn)); - } - std::unique_ptr handleNotifyAlertChanged(NotifyAlertChangedFn fn) override - { - return MakeHandler(::uiInterface.NotifyAlertChanged_connect(fn)); - } - std::unique_ptr handleBannedListChanged(BannedListChangedFn fn) override - { - return MakeHandler(::uiInterface.BannedListChanged_connect(fn)); - } - std::unique_ptr handleNotifyBlockTip(NotifyBlockTipFn fn) override - { - return MakeHandler(::uiInterface.NotifyBlockTip_connect([fn](bool initial_download, const CBlockIndex* block) { - fn(initial_download, block->nHeight, block->GetBlockTime(), - GuessVerificationProgress(Params().TxData(), block)); - })); - } - std::unique_ptr handleNotifyHeaderTip(NotifyHeaderTipFn fn) override - { - return MakeHandler( - ::uiInterface.NotifyHeaderTip_connect([fn](bool initial_download, const CBlockIndex* block) { - fn(initial_download, block->nHeight, block->GetBlockTime(), - GuessVerificationProgress(Params().TxData(), block)); - })); - } - InitInterfaces m_interfaces; -}; - -} // namespace - -std::unique_ptr MakeNode() { return MakeUnique(); } - -} // namespace interfaces diff --git a/src/interfaces/node.h b/src/interfaces/node.h deleted file mode 100644 index 088deee0369..00000000000 --- a/src/interfaces/node.h +++ /dev/null @@ -1,241 +0,0 @@ -// Copyright (c) 2018 The Bitcoin Core developers -// Distributed under the MIT software license, see the accompanying -// file LICENSE or http://www.opensource.org/licenses/mit-license.php. - -#ifndef DEFI_INTERFACES_NODE_H -#define DEFI_INTERFACES_NODE_H - -#include // For banmap_t -#include // For CAmount -#include // For CConnman::NumConnections -#include // For Network - -#include -#include -#include -#include -#include -#include -#include - -class BanMan; -class CCoinControl; -class CFeeRate; -class CNodeStats; -class Coin; -class RPCTimerInterface; -class UniValue; -class proxyType; -struct CNodeStateStats; - -namespace interfaces { -class Handler; -class Wallet; - -//! Top-level interface for a DeFi Blockchain node (defid process). -class Node -{ -public: - virtual ~Node() {} - - //! Send init error. - virtual void initError(const std::string& message) = 0; - - //! Set command line arguments. - virtual bool parseParameters(int argc, const char* const argv[], std::string& error) = 0; - - //! Set a command line argument if it doesn't already have a value - virtual bool softSetArg(const std::string& arg, const std::string& value) = 0; - - //! Set a command line boolean argument if it doesn't already have a value - virtual bool softSetBoolArg(const std::string& arg, bool value) = 0; - - //! Load settings from configuration file. - virtual bool readConfigFiles(std::string& error) = 0; - - //! Choose network parameters. - virtual void selectParams(const std::string& network) = 0; - - //! Get the (assumed) blockchain size. - virtual uint64_t getAssumedBlockchainSize() = 0; - - //! Get the (assumed) chain state size. - virtual uint64_t getAssumedChainStateSize() = 0; - - //! Get network name. - virtual std::string getNetwork() = 0; - - //! Init logging. - virtual void initLogging() = 0; - - //! Init parameter interaction. - virtual void initParameterInteraction() = 0; - - //! Get warnings. - virtual std::string getWarnings(const std::string& type) = 0; - - // Get log flags. - virtual uint32_t getLogCategories() = 0; - - //! Initialize app dependencies. - virtual bool baseInitialize() = 0; - - //! Start node. - virtual bool appInitMain() = 0; - - //! Stop node. - virtual void appShutdown() = 0; - - //! Start shutdown. - virtual void startShutdown() = 0; - - //! Return whether shutdown was requested. - virtual bool shutdownRequested() = 0; - - //! Setup arguments - virtual void setupServerArgs() = 0; - - //! Map port. - virtual void mapPort(bool use_upnp) = 0; - - //! Get proxy. - virtual bool getProxy(Network net, proxyType& proxy_info) = 0; - - //! Get number of connections. - virtual size_t getNodeCount(CConnman::NumConnections flags) = 0; - - //! Get stats for connected nodes. - using NodesStats = std::vector>; - virtual bool getNodesStats(NodesStats& stats) = 0; - - //! Get ban map entries. - virtual bool getBanned(banmap_t& banmap) = 0; - - //! Ban node. - virtual bool ban(const CNetAddr& net_addr, BanReason reason, int64_t ban_time_offset) = 0; - - //! Unban node. - virtual bool unban(const CSubNet& ip) = 0; - - //! Disconnect node by address. - virtual bool disconnect(const CNetAddr& net_addr) = 0; - - //! Disconnect node by id. - virtual bool disconnect(NodeId id) = 0; - - //! Get total bytes recv. - virtual int64_t getTotalBytesRecv() = 0; - - //! Get total bytes sent. - virtual int64_t getTotalBytesSent() = 0; - - //! Get mempool size. - virtual size_t getMempoolSize() = 0; - - //! Get mempool dynamic usage. - virtual size_t getMempoolDynamicUsage() = 0; - - //! Get header tip height and time. - virtual bool getHeaderTip(int& height, int64_t& block_time) = 0; - - //! Get num blocks. - virtual int getNumBlocks() = 0; - - //! Get last block time. - virtual int64_t getLastBlockTime() = 0; - - //! Get verification progress. - virtual double getVerificationProgress() = 0; - - //! Is initial block download. - virtual bool isInitialBlockDownload() = 0; - - //! Is -addresstype set. - virtual bool isAddressTypeSet() = 0; - - //! Get reindex. - virtual bool getReindex() = 0; - - //! Get importing. - virtual bool getImporting() = 0; - - //! Set network active. - virtual void setNetworkActive(bool active) = 0; - - //! Get network active. - virtual bool getNetworkActive() = 0; - - //! Estimate smart fee. - virtual CFeeRate estimateSmartFee(int num_blocks, bool conservative, int* returned_target = nullptr) = 0; - - //! Get dust relay fee. - virtual CFeeRate getDustRelayFee() = 0; - - //! Execute rpc command. - virtual UniValue executeRpc(const std::string& command, const UniValue& params, const std::string& uri) = 0; - - //! List rpc commands. - virtual std::vector listRpcCommands() = 0; - - //! Set RPC timer interface if unset. - virtual void rpcSetTimerInterfaceIfUnset(RPCTimerInterface* iface) = 0; - - //! Unset RPC timer interface. - virtual void rpcUnsetTimerInterface(RPCTimerInterface* iface) = 0; - - //! Get unspent outputs associated with a transaction. - virtual bool getUnspentOutput(const COutPoint& output, Coin& coin) = 0; - - //! Register handler for init messages. - using InitMessageFn = std::function; - virtual std::unique_ptr handleInitMessage(InitMessageFn fn) = 0; - - //! Register handler for message box messages. - using MessageBoxFn = - std::function; - virtual std::unique_ptr handleMessageBox(MessageBoxFn fn) = 0; - - //! Register handler for question messages. - using QuestionFn = std::function; - virtual std::unique_ptr handleQuestion(QuestionFn fn) = 0; - - //! Register handler for progress messages. - using ShowProgressFn = std::function; - virtual std::unique_ptr handleShowProgress(ShowProgressFn fn) = 0; - - //! Register handler for number of connections changed messages. - using NotifyNumConnectionsChangedFn = std::function; - virtual std::unique_ptr handleNotifyNumConnectionsChanged(NotifyNumConnectionsChangedFn fn) = 0; - - //! Register handler for network active messages. - using NotifyNetworkActiveChangedFn = std::function; - virtual std::unique_ptr handleNotifyNetworkActiveChanged(NotifyNetworkActiveChangedFn fn) = 0; - - //! Register handler for notify alert messages. - using NotifyAlertChangedFn = std::function; - virtual std::unique_ptr handleNotifyAlertChanged(NotifyAlertChangedFn fn) = 0; - - //! Register handler for ban list messages. - using BannedListChangedFn = std::function; - virtual std::unique_ptr handleBannedListChanged(BannedListChangedFn fn) = 0; - - //! Register handler for block tip messages. - using NotifyBlockTipFn = - std::function; - virtual std::unique_ptr handleNotifyBlockTip(NotifyBlockTipFn fn) = 0; - - //! Register handler for header tip messages. - using NotifyHeaderTipFn = - std::function; - virtual std::unique_ptr handleNotifyHeaderTip(NotifyHeaderTipFn fn) = 0; -}; - -//! Return implementation of Node interface. -std::unique_ptr MakeNode(); - -} // namespace interfaces - -#endif // DEFI_INTERFACES_NODE_H diff --git a/src/logging.cpp b/src/logging.cpp index 56aa485112d..c09b8284bf0 100644 --- a/src/logging.cpp +++ b/src/logging.cpp @@ -148,7 +148,6 @@ const CLogCategoryDesc LogCategories[] = {BCLog::MEMPOOLREJ, "mempoolrej"}, {BCLog::LIBEVENT, "libevent"}, {BCLog::COINDB, "coindb"}, - {BCLog::QT, "qt"}, {BCLog::LEVELDB, "leveldb"}, {BCLog::STAKING, "staking"}, {BCLog::ANCHORING, "anchoring"}, diff --git a/src/logging.h b/src/logging.h index 946be4a006b..6f7ad986e27 100644 --- a/src/logging.h +++ b/src/logging.h @@ -52,7 +52,6 @@ namespace BCLog { MEMPOOLREJ = (1 << 16), LIBEVENT = (1 << 17), COINDB = (1 << 18), - QT = (1 << 19), LEVELDB = (1 << 20), STAKING = (1 << 21), ANCHORING = (1 << 22), diff --git a/test/functional/rpc_misc.py b/test/functional/rpc_misc.py index bca739fd127..d769117335e 100755 --- a/test/functional/rpc_misc.py +++ b/test/functional/rpc_misc.py @@ -47,11 +47,11 @@ def run_test(self): assert_raises_rpc_error(-8, "unknown mode foobar", node.getmemoryinfo, mode="foobar") self.log.info("test logging") - assert_equal(node.logging()['qt'], True) - node.logging(exclude=['qt']) - assert_equal(node.logging()['qt'], False) - node.logging(include=['qt']) - assert_equal(node.logging()['qt'], True) + assert_equal(node.logging()['anchoring'], True) + node.logging(exclude=['anchoring']) + assert_equal(node.logging()['anchoring'], False) + node.logging(include=['anchoring']) + assert_equal(node.logging()['anchoring'], True) if __name__ == '__main__':