diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp --- a/src/bitcoind.cpp +++ b/src/bitcoind.cpp @@ -70,8 +70,8 @@ RPCServer rpcServer; HTTPRPCRequestProcessor httpRPCRequestProcessor(config, rpcServer); - InitInterfaces interfaces; - interfaces.chain = interfaces::MakeChain(); + NodeContext node; + node.chain = interfaces::MakeChain(); bool fRet = false; @@ -195,8 +195,7 @@ // If locking the data directory failed, exit immediately return false; } - fRet = - AppInitMain(config, rpcServer, httpRPCRequestProcessor, interfaces); + fRet = AppInitMain(config, rpcServer, httpRPCRequestProcessor, node); } catch (const std::exception &e) { PrintExceptionContinue(&e, "AppInit()"); } catch (...) { @@ -208,7 +207,7 @@ } else { WaitForShutdown(); } - Shutdown(interfaces); + Shutdown(node); return fRet; } diff --git a/src/dummywallet.cpp b/src/dummywallet.cpp --- a/src/dummywallet.cpp +++ b/src/dummywallet.cpp @@ -18,7 +18,7 @@ bool HasWalletSupport() const override { return false; } void AddWalletOptions() const override; bool ParameterInteraction() const override { return true; } - void Construct(InitInterfaces &interfaces) const override { + void Construct(NodeContext &node) const override { LogPrintf("No wallet support compiled in!\n"); } }; diff --git a/src/init.h b/src/init.h --- a/src/init.h +++ b/src/init.h @@ -24,7 +24,7 @@ } // namespace interfaces //! Pointers to interfaces used during init and destroyed on shutdown. -struct InitInterfaces { +struct NodeContext { std::unique_ptr chain; std::vector> chain_clients; }; @@ -35,7 +35,7 @@ /** Interrupt threads */ void Interrupt(); -void Shutdown(InitInterfaces &interfaces); +void Shutdown(NodeContext &node); //! Initialize the logging infrastructure void InitLogging(); //! Parameter interaction: change current parameters depending on various rules @@ -80,7 +80,7 @@ */ bool AppInitMain(Config &config, RPCServer &rpcServer, HTTPRPCRequestProcessor &httpRPCRequestProcessor, - InitInterfaces &interfaces); + NodeContext &node); /** * Setup the arguments for gArgs. diff --git a/src/init.cpp b/src/init.cpp --- a/src/init.cpp +++ b/src/init.cpp @@ -200,7 +200,7 @@ } } -void Shutdown(InitInterfaces &interfaces) { +void Shutdown(NodeContext &node) { LogPrintf("%s: In progress...\n", __func__); static RecursiveMutex cs_Shutdown; TRY_LOCK(cs_Shutdown, lockShutdown); @@ -219,7 +219,7 @@ StopREST(); StopRPC(); StopHTTPServer(); - for (const auto &client : interfaces.chain_clients) { + for (const auto &client : node.chain_clients) { client->flush(); } StopMapPort(); @@ -294,7 +294,7 @@ pcoinsdbview.reset(); pblocktree.reset(); } - for (const auto &client : interfaces.chain_clients) { + for (const auto &client : node.chain_clients) { client->stop(); } @@ -315,7 +315,7 @@ LogPrintf("%s: Unable to remove PID file: %s\n", __func__, fsbridge::get_filesystem_error_message(e)); } - interfaces.chain_clients.clear(); + node.chain_clients.clear(); UnregisterAllValidationInterfaces(); GetMainSignals().UnregisterBackgroundSignalScheduler(); GetMainSignals().UnregisterWithMempoolSignals(g_mempool); @@ -1973,7 +1973,7 @@ bool AppInitMain(Config &config, RPCServer &rpcServer, HTTPRPCRequestProcessor &httpRPCRequestProcessor, - InitInterfaces &interfaces) { + NodeContext &node) { // Step 4a: application initialization const CChainParams &chainparams = config.GetChainParams(); @@ -2064,17 +2064,17 @@ // according to -wallet and -disablewallet options. This only constructs // the interfaces, it doesn't load wallet data. Wallets actually get loaded // when load() and start() interface methods are called below. - g_wallet_init_interface.Construct(interfaces); + g_wallet_init_interface.Construct(node); /** * Register RPC commands regardless of -server setting so they will be * available in the GUI RPC console even if external calls are disabled. */ RegisterAllRPCCommands(config, rpcServer, tableRPC); - for (const auto &client : interfaces.chain_clients) { + for (const auto &client : node.chain_clients) { client->registerRpcs(); } - g_rpc_interfaces = &interfaces; + g_rpc_node = &node; #if ENABLE_ZMQ RegisterZMQRPCCommands(tableRPC); #endif @@ -2095,7 +2095,7 @@ } // Step 5: verify wallet database integrity - for (const auto &client : interfaces.chain_clients) { + for (const auto &client : node.chain_clients) { if (!client->verify(chainparams)) { return false; } @@ -2514,7 +2514,7 @@ } // Step 9: load wallet - for (const auto &client : interfaces.chain_clients) { + for (const auto &client : node.chain_clients) { if (!client->load(chainparams)) { return false; } @@ -2671,7 +2671,7 @@ SetRPCWarmupFinished(); uiInterface.InitMessage(_("Done loading").translated); - for (const auto &client : interfaces.chain_clients) { + for (const auto &client : node.chain_clients) { client->start(scheduler); } diff --git a/src/interfaces/node.cpp b/src/interfaces/node.cpp --- a/src/interfaces/node.cpp +++ b/src/interfaces/node.cpp @@ -54,7 +54,7 @@ class NodeImpl : public Node { public: - NodeImpl() { m_interfaces.chain = MakeChain(); } + NodeImpl() { m_context.chain = MakeChain(); } void initError(const std::string &message) override { InitError(message); } @@ -95,11 +95,11 @@ appInitMain(Config &config, RPCServer &rpcServer, HTTPRPCRequestProcessor &httpRPCRequestProcessor) override { return AppInitMain(config, rpcServer, httpRPCRequestProcessor, - m_interfaces); + m_context); } void appShutdown() override { Interrupt(); - Shutdown(m_interfaces); + Shutdown(m_context); } void startShutdown() override { StartShutdown(); } bool shutdownRequested() override { return ShutdownRequested(); } @@ -323,7 +323,7 @@ GuessVerificationProgress(Params().TxData(), block)); })); } - InitInterfaces m_interfaces; + NodeContext m_context; }; } // namespace diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -908,7 +908,7 @@ keystore.AddKey(key); } - return SignTransaction(*g_rpc_interfaces->chain, mtx, request.params[2], + return SignTransaction(*g_rpc_node->chain, mtx, request.params[2], &keystore, true, request.params[3]); } diff --git a/src/rpc/util.h b/src/rpc/util.h --- a/src/rpc/util.h +++ b/src/rpc/util.h @@ -18,13 +18,13 @@ class CKeyStore; class CPubKey; class CScript; -struct InitInterfaces; +struct NodeContext; class UniValue; //! Pointers to interfaces that need to be accessible from RPC methods. Due to //! limitations of the RPC framework, there's currently no direct way to pass in //! state to RPC method implementations. -extern InitInterfaces *g_rpc_interfaces; +extern NodeContext *g_rpc_node; /** * Wrapper for UniValue::VType, which includes typeAny: used to denote don't diff --git a/src/rpc/util.cpp b/src/rpc/util.cpp --- a/src/rpc/util.cpp +++ b/src/rpc/util.cpp @@ -14,7 +14,7 @@ #include -InitInterfaces *g_rpc_interfaces = nullptr; +NodeContext *g_rpc_node = nullptr; void RPCTypeCheck(const UniValue ¶ms, const std::list &typesExpected, diff --git a/src/test/rpc_tests.cpp b/src/test/rpc_tests.cpp --- a/src/test/rpc_tests.cpp +++ b/src/test/rpc_tests.cpp @@ -138,16 +138,16 @@ "\"KzsXybp9jX64P5ekX1KUxRQ79Jht9uzW7LorgwE65i5rWACL6LQe\""; std::string privkey2 = "\"Kyhdf5LuKTRx4ge69ybABsiUAWjVRK4XGxAKk2FQLp2HjGMy87Z4\""; - InitInterfaces interfaces; - interfaces.chain = interfaces::MakeChain(); - g_rpc_interfaces = &interfaces; + NodeContext node; + node.chain = interfaces::MakeChain(); + g_rpc_node = &node; r = CallRPC(std::string("signrawtransactionwithkey ") + notsigned + " [] " + prevout); BOOST_CHECK(find_value(r.get_obj(), "complete").get_bool() == false); r = CallRPC(std::string("signrawtransactionwithkey ") + notsigned + " [" + privkey1 + "," + privkey2 + "] " + prevout); BOOST_CHECK(find_value(r.get_obj(), "complete").get_bool() == true); - g_rpc_interfaces = nullptr; + g_rpc_node = nullptr; } BOOST_AUTO_TEST_CASE(rpc_rawsign_missing_amount) { @@ -178,9 +178,9 @@ bool exceptionThrownDueToMissingAmount = false, errorWasMissingAmount = false; - InitInterfaces interfaces; - interfaces.chain = interfaces::MakeChain(); - g_rpc_interfaces = &interfaces; + NodeContext node; + node.chain = interfaces::MakeChain(); + g_rpc_node = &node; try { r = CallRPC(std::string("signrawtransactionwithkey ") + notsigned + @@ -194,7 +194,7 @@ BOOST_CHECK(exceptionThrownDueToMissingAmount == true); BOOST_CHECK(errorWasMissingAmount == true); - g_rpc_interfaces = nullptr; + g_rpc_node = nullptr; } BOOST_AUTO_TEST_CASE(rpc_createraw_op_return) { diff --git a/src/wallet/init.cpp b/src/wallet/init.cpp --- a/src/wallet/init.cpp +++ b/src/wallet/init.cpp @@ -31,8 +31,8 @@ //! Wallets parameter interaction bool ParameterInteraction() const override; - //! Add wallets that should be opened to list of init interfaces. - void Construct(InitInterfaces &interfaces) const override; + //! Add wallets that should be opened to list of chain clients. + void Construct(NodeContext &node) const override; }; const WalletInitInterface &g_wallet_init_interface = WalletInit(); @@ -257,12 +257,12 @@ return true; } -void WalletInit::Construct(InitInterfaces &interfaces) const { +void WalletInit::Construct(NodeContext &node) const { if (gArgs.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET)) { LogPrintf("Wallet disabled!\n"); return; } gArgs.SoftSetArg("-wallet", ""); - interfaces.chain_clients.emplace_back(interfaces::MakeWalletClient( - *interfaces.chain, gArgs.GetArgs("-wallet"))); + node.chain_clients.emplace_back( + interfaces::MakeWalletClient(*node.chain, gArgs.GetArgs("-wallet"))); } diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -3132,8 +3132,8 @@ } std::string error, warning; - std::shared_ptr const wallet = LoadWallet( - chainParams, *g_rpc_interfaces->chain, location, error, warning); + std::shared_ptr const wallet = + LoadWallet(chainParams, *g_rpc_node->chain, location, error, warning); if (!wallet) { throw JSONRPCError(RPC_WALLET_ERROR, error); } @@ -3202,14 +3202,14 @@ // Wallet::Verify will check if we're trying to create a wallet with a // duplicate name. - if (!CWallet::Verify(chainParams, *g_rpc_interfaces->chain, location, false, + if (!CWallet::Verify(chainParams, *g_rpc_node->chain, location, false, error, warning)) { throw JSONRPCError(RPC_WALLET_ERROR, "Wallet file verification failed: " + error); } std::shared_ptr const wallet = CWallet::CreateWalletFromFile( - chainParams, *g_rpc_interfaces->chain, location, flags); + chainParams, *g_rpc_node->chain, location, flags); if (!wallet) { throw JSONRPCError(RPC_WALLET_ERROR, "Wallet creation failed."); } diff --git a/src/walletinitinterface.h b/src/walletinitinterface.h --- a/src/walletinitinterface.h +++ b/src/walletinitinterface.h @@ -5,7 +5,7 @@ #ifndef BITCOIN_WALLETINITINTERFACE_H #define BITCOIN_WALLETINITINTERFACE_H -struct InitInterfaces; +struct NodeContext; class WalletInitInterface { public: @@ -15,8 +15,8 @@ virtual void AddWalletOptions() const = 0; /** Check wallet parameter interaction */ virtual bool ParameterInteraction() const = 0; - /** Add wallets that should be opened to list of init interfaces. */ - virtual void Construct(InitInterfaces &interfaces) const = 0; + /** Add wallets that should be opened to list of chain clients. */ + virtual void Construct(NodeContext &node) const = 0; virtual ~WalletInitInterface() {} };