diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp --- a/src/bitcoind.cpp +++ b/src/bitcoind.cpp @@ -137,7 +137,7 @@ // up on console return false; } - if (!AppInitParameterInteraction(config, rpcServer)) { + if (!AppInitParameterInteraction(config)) { // InitError will have been called with detailed error, which ends // up on console return false; @@ -178,7 +178,7 @@ // If locking the data directory failed, exit immediately return false; } - fRet = AppInitMain(config, httpRPCRequestProcessor); + fRet = AppInitMain(config, rpcServer, httpRPCRequestProcessor); } catch (const std::exception &e) { PrintExceptionContinue(&e, "AppInit()"); } catch (...) { diff --git a/src/init.h b/src/init.h --- a/src/init.h +++ b/src/init.h @@ -47,7 +47,7 @@ * @pre Parameters should be parsed and config file should be read, * AppInitBasicSetup should have been called. */ -bool AppInitParameterInteraction(Config &config, RPCServer &rpcServer); +bool AppInitParameterInteraction(Config &config); /** * Initialization sanity checks: ecc init, sanity checks, dir lock. * @note This can be done before daemonization. @@ -70,7 +70,7 @@ * @pre Parameters should be parsed and config file should be read, * AppInitLockDataDirectory should have been called. */ -bool AppInitMain(Config &config, +bool AppInitMain(Config &config, RPCServer &rpcServer, HTTPRPCRequestProcessor &httpRPCRequestProcessor); /** The help message mode determines what help message to show */ diff --git a/src/init.cpp b/src/init.cpp --- a/src/init.cpp +++ b/src/init.cpp @@ -1359,7 +1359,7 @@ return true; } -bool AppInitParameterInteraction(Config &config, RPCServer &rpcServer) { +bool AppInitParameterInteraction(Config &config) { const CChainParams &chainparams = config.GetChainParams(); // Step 2: parameter interactions @@ -1598,9 +1598,6 @@ fPruneMode = true; } - RegisterAllRPCCommands(config, rpcServer, tableRPC); - g_wallet_init_interface->RegisterRPC(tableRPC); - nConnectTimeout = gArgs.GetArg("-timeout", DEFAULT_CONNECT_TIMEOUT); if (nConnectTimeout <= 0) { nConnectTimeout = DEFAULT_CONNECT_TIMEOUT; @@ -1745,7 +1742,7 @@ return true; } -bool AppInitMain(Config &config, +bool AppInitMain(Config &config, RPCServer &rpcServer, HTTPRPCRequestProcessor &httpRPCRequestProcessor) { // Step 4a: application initialization const CChainParams &chainparams = config.GetChainParams(); @@ -1815,6 +1812,13 @@ GetMainSignals().RegisterBackgroundSignalScheduler(scheduler); GetMainSignals().RegisterWithMempoolSignals(g_mempool); + /** + * 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); + g_wallet_init_interface->RegisterRPC(tableRPC); + /** * Start the RPC server. It will be started in "warmup" mode and not * process calls yet (but it will verify that the server is there and will diff --git a/src/interfaces/node.h b/src/interfaces/node.h --- a/src/interfaces/node.h +++ b/src/interfaces/node.h @@ -70,11 +70,11 @@ virtual std::string getWarnings(const std::string &type) = 0; //! Initialize app dependencies. - virtual bool baseInitialize(Config &config, RPCServer &rpcServer) = 0; + virtual bool baseInitialize(Config &config) = 0; //! Start node. virtual bool - appInitMain(Config &config, + appInitMain(Config &config, RPCServer &rpcServer, HTTPRPCRequestProcessor &httpRPCRequestProcessor) = 0; //! Stop node. diff --git a/src/interfaces/node.cpp b/src/interfaces/node.cpp --- a/src/interfaces/node.cpp +++ b/src/interfaces/node.cpp @@ -73,15 +73,14 @@ std::string getWarnings(const std::string &type) override { return GetWarnings(type); } - bool baseInitialize(Config &config, RPCServer &rpcServer) override { - return AppInitBasicSetup() && - AppInitParameterInteraction(config, rpcServer) && + bool baseInitialize(Config &config) override { + return AppInitBasicSetup() && AppInitParameterInteraction(config) && AppInitSanityChecks() && AppInitLockDataDirectory(); } bool - appInitMain(Config &config, + appInitMain(Config &config, RPCServer &rpcServer, HTTPRPCRequestProcessor &httpRPCRequestProcessor) override { - return AppInitMain(config, httpRPCRequestProcessor); + return AppInitMain(config, rpcServer, httpRPCRequestProcessor); } void appShutdown() override { Interrupt(); diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp --- a/src/qt/bitcoin.cpp +++ b/src/qt/bitcoin.cpp @@ -172,7 +172,7 @@ explicit BitcoinABC(interfaces::Node &node); public Q_SLOTS: - void initialize(Config *config, + void initialize(Config *config, RPCServer *rpcServer, HTTPRPCRequestProcessor *httpRPCRequestProcessor); void shutdown(); @@ -209,7 +209,7 @@ void createSplashScreen(const NetworkStyle *networkStyle); /// Request core initialization - void requestInitialize(Config &config, + void requestInitialize(Config &config, RPCServer &rpcServer, HTTPRPCRequestProcessor &httpRPCRequestProcessor); /// Request core shutdown void requestShutdown(Config &config); @@ -228,7 +228,7 @@ void handleRunawayException(const QString &message); Q_SIGNALS: - void requestedInitialize(Config *config, + void requestedInitialize(Config *config, RPCServer *rpcServer, HTTPRPCRequestProcessor *httpRPCRequestProcessor); void requestedShutdown(); void stopThread(); @@ -261,12 +261,12 @@ Q_EMIT runawayException(QString::fromStdString(m_node.getWarnings("gui"))); } -void BitcoinABC::initialize(Config *cfg, +void BitcoinABC::initialize(Config *config, RPCServer *rpcServer, HTTPRPCRequestProcessor *httpRPCRequestProcessor) { - Config &config(*cfg); try { qDebug() << __func__ << ": Running initialization in thread"; - bool rv = m_node.appInitMain(config, *httpRPCRequestProcessor); + bool rv = + m_node.appInitMain(*config, *rpcServer, *httpRPCRequestProcessor); Q_EMIT initializeResult(rv); } catch (const std::exception &e) { handleRunawayException(&e); @@ -391,8 +391,10 @@ // crash because initialize() gets executed in another thread at some // unspecified time (after) requestedInitialize() is emitted! connect(this, - SIGNAL(requestedInitialize(Config *, HTTPRPCRequestProcessor *)), - executor, SLOT(initialize(Config *, HTTPRPCRequestProcessor *))); + SIGNAL(requestedInitialize(Config *, RPCServer *, + HTTPRPCRequestProcessor *)), + executor, + SLOT(initialize(Config *, RPCServer *, HTTPRPCRequestProcessor *))); connect(this, SIGNAL(requestedShutdown()), executor, SLOT(shutdown())); /* make sure executor object is deleted in its own thread */ @@ -408,13 +410,14 @@ } void BitcoinApplication::requestInitialize( - Config &config, HTTPRPCRequestProcessor &httpRPCRequestProcessor) { + Config &config, RPCServer &rpcServer, + HTTPRPCRequestProcessor &httpRPCRequestProcessor) { qDebug() << __func__ << ": Requesting initialize"; startThread(); // IMPORTANT: config must NOT be a reference to a temporary because below // signal may be connected to a slot that will be executed as a queued // connection in another thread! - Q_EMIT requestedInitialize(&config, &httpRPCRequestProcessor); + Q_EMIT requestedInitialize(&config, &rpcServer, &httpRPCRequestProcessor); } void BitcoinApplication::requestShutdown(Config &config) { @@ -767,11 +770,11 @@ // initialization/shutdown thread. This is acceptable because this // function only contains steps that are quick to execute, so the GUI // thread won't be held up. - if (!node->baseInitialize(config, rpcServer)) { + if (!node->baseInitialize(config)) { // A dialog with detailed error will have been shown by InitError() return EXIT_FAILURE; } - app.requestInitialize(config, httpRPCRequestProcessor); + app.requestInitialize(config, rpcServer, httpRPCRequestProcessor); #if defined(Q_OS_WIN) WinShutdownMonitor::registerShutdownBlockReason( QObject::tr("%1 didn't yet exit safely...")