diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -499,6 +499,8 @@ if(BUILD_BITCOIN_WALLET) add_subdirectory(wallet) target_link_libraries(server wallet) +else() + target_sources(server PRIVATE dummywallet.cpp) endif() # ZeroMQ diff --git a/src/Makefile.am b/src/Makefile.am --- a/src/Makefile.am +++ b/src/Makefile.am @@ -302,6 +302,10 @@ validationinterface.cpp \ $(BITCOIN_CORE_H) +if !ENABLE_WALLET +libbitcoin_server_a_SOURCES += dummywallet.cpp +endif + if ENABLE_ZMQ libbitcoin_zmq_a_CPPFLAGS = $(BITCOIN_INCLUDES) $(ZMQ_CFLAGS) libbitcoin_zmq_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) diff --git a/src/dummywallet.cpp b/src/dummywallet.cpp new file mode 100644 --- /dev/null +++ b/src/dummywallet.cpp @@ -0,0 +1,38 @@ +// Copyright (c) 2018 The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include +#include +#include + +class DummyWalletInit : public WalletInitInterface { +public: + bool HasWalletSupport() const override { return false; } + void AddWalletOptions() const override; + bool ParameterInteraction() const override { return true; } + void RegisterRPC(CRPCTable &) const override {} + bool Verify(const CChainParams &chainParams) const override { return true; } + bool Open(const CChainParams &chainParams) const override { + LogPrintf("No wallet support compiled in!\n"); + return true; + } + void Start(CScheduler &scheduler) const override {} + void Flush() const override {} + void Stop() const override {} + void Close() const override {} +}; + +void DummyWalletInit::AddWalletOptions() const { + std::vector opts = { + "-avoidpartialspends", "-disablewallet", "-fallbackfee=", + "-keypool=", "-maxtxfee=", "-mintxfee=", "-paytxfee=", + "-rescan", "-salvagewallet", "-spendzeroconfchange", "-upgradewallet", + "-wallet=", "-walletbroadcast", "-walletdir=", + "-walletnotify=", "-zapwallettxes=", + // Wallet debug options + "-dblogsize=", "-flushwallet", "-privdb", "-walletrejectlongchains"}; + gArgs.AddHiddenArgs(opts); +} + +const WalletInitInterface &g_wallet_init_interface = DummyWalletInit(); diff --git a/src/httprpc.cpp b/src/httprpc.cpp --- a/src/httprpc.cpp +++ b/src/httprpc.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include // boost::trim @@ -388,11 +389,9 @@ std::bind(&HTTPRPCRequestProcessor::DelegateHTTPRequest, &httpRPCRequestProcessor, std::placeholders::_2); RegisterHTTPHandler("/", true, rpcFunction); -#ifdef ENABLE_WALLET - // ifdef can be removed once we switch to better endpoint support and API - // versioning - RegisterHTTPHandler("/wallet/", false, rpcFunction); -#endif + if (g_wallet_init_interface.HasWalletSupport()) { + RegisterHTTPHandler("/wallet/", false, rpcFunction); + } struct event_base *eventBase = EventBase(); assert(eventBase); httpRPCTimerInterface = std::make_unique(eventBase); @@ -407,9 +406,9 @@ void StopHTTPRPC() { LogPrint(BCLog::RPC, "Stopping HTTP RPC server\n"); UnregisterHTTPHandler("/", true); -#ifdef ENABLE_WALLET - UnregisterHTTPHandler("/wallet/", false); -#endif + if (g_wallet_init_interface.HasWalletSupport()) { + UnregisterHTTPHandler("/wallet/", false); + } if (httpRPCTimerInterface) { RPCUnsetTimerInterface(httpRPCTimerInterface.get()); httpRPCTimerInterface.reset(); diff --git a/src/init.h b/src/init.h --- a/src/init.h +++ b/src/init.h @@ -18,9 +18,6 @@ class HTTPRPCRequestProcessor; class RPCServer; -class WalletInitInterface; -extern const WalletInitInterface &g_wallet_init_interface; - namespace boost { class thread_group; } // namespace boost diff --git a/src/init.cpp b/src/init.cpp --- a/src/init.cpp +++ b/src/init.cpp @@ -78,38 +78,6 @@ std::unique_ptr peerLogic; std::unique_ptr g_banman; -#if !(ENABLE_WALLET) -class DummyWalletInit : public WalletInitInterface { -public: - void AddWalletOptions() const override; - bool ParameterInteraction() const override { return true; } - void RegisterRPC(CRPCTable &) const override {} - bool Verify(const CChainParams &chainParams) const override { return true; } - bool Open(const CChainParams &chainParams) const override { - LogPrintf("No wallet support compiled in!\n"); - return true; - } - void Start(CScheduler &scheduler) const override {} - void Flush() const override {} - void Stop() const override {} - void Close() const override {} -}; - -void DummyWalletInit::AddWalletOptions() const { - std::vector opts = { - "-avoidpartialspends", "-disablewallet", "-fallbackfee=", - "-keypool=", "-maxtxfee=", "-mintxfee=", "-paytxfee=", - "-rescan", "-salvagewallet", "-spendzeroconfchange", "-upgradewallet", - "-wallet=", "-walletbroadcast", "-walletdir=", - "-walletnotify=", "-zapwallettxes=", - // Wallet debug options - "-dblogsize=", "-flushwallet", "-privdb", "-walletrejectlongchains"}; - gArgs.AddHiddenArgs(opts); -} - -const WalletInitInterface &g_wallet_init_interface = DummyWalletInit(); -#endif - #ifdef WIN32 // Win32 LevelDB doesn't use filedescriptors, and the ones used for accessing // block files don't count towards the fd_set size limit anyway. diff --git a/src/wallet/init.cpp b/src/wallet/init.cpp --- a/src/wallet/init.cpp +++ b/src/wallet/init.cpp @@ -19,6 +19,9 @@ class WalletInit : public WalletInitInterface { public: + //! Was the wallet component compiled in. + bool HasWalletSupport() const override { return true; } + //! Return the wallets help message. void AddWalletOptions() const override; diff --git a/src/walletinitinterface.h b/src/walletinitinterface.h --- a/src/walletinitinterface.h +++ b/src/walletinitinterface.h @@ -14,6 +14,8 @@ class WalletInitInterface { public: + /** Is the wallet component enabled */ + virtual bool HasWalletSupport() const = 0; /** Get wallet help string */ virtual void AddWalletOptions() const = 0; /** Check wallet parameter interaction */ @@ -36,4 +38,6 @@ virtual ~WalletInitInterface() {} }; +extern const WalletInitInterface &g_wallet_init_interface; + #endif // BITCOIN_WALLETINITINTERFACE_H