From 06f41f35860ffb255c195b1d9a542b6f0a8392fa Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Wed, 21 Sep 2016 12:27:47 +0200 Subject: [PATCH] Merge #8768: init: Get rid of fDisableWallet fa58edb [wallet] Introduce DEFAULT_DISABLE_WALLET (MarcoFalke) fab9107 init: Get rid of fDisableWallet (MarcoFalke) --- src/init.cpp | 53 ++++++++++++++++------------------------ src/qt/bitcoingui.cpp | 2 +- src/wallet/rpcwallet.cpp | 3 +++ src/wallet/wallet.cpp | 12 +++++++++ src/wallet/wallet.h | 1 + 5 files changed, 38 insertions(+), 33 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index 3cd589c9a..696490a2a 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1103,9 +1103,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) RegisterAllCoreRPCCommands(tableRPC); #ifdef ENABLE_WALLET - bool fDisableWallet = GetBoolArg("-disablewallet", false); - if (!fDisableWallet) - RegisterWalletRPCCommands(tableRPC); + RegisterWalletRPCCommands(tableRPC); #endif nConnectTimeout = GetArg("-timeout", DEFAULT_CONNECT_TIMEOUT); @@ -1133,7 +1131,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) nBytesPerSigOp = GetArg("-bytespersigop", nBytesPerSigOp); #ifdef ENABLE_WALLET - if (!fDisableWallet && !CWallet::ParameterInteraction()) + if (!CWallet::ParameterInteraction()) return false; #endif // ENABLE_WALLET @@ -1243,29 +1241,26 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) // ********************************************************* Step 5: Backup wallet and verify wallet database integrity #ifdef ENABLE_WALLET - if (!fDisableWallet) { - std::string strWarning; - std::string strError; + std::string strWarning; + std::string strError; - nWalletBackups = GetArg("-createwalletbackups", 10); - nWalletBackups = std::max(0, std::min(10, nWalletBackups)); + nWalletBackups = GetArg("-createwalletbackups", 10); + nWalletBackups = std::max(0, std::min(10, nWalletBackups)); - std::string strWalletFile = GetArg("-wallet", DEFAULT_WALLET_DAT); + std::string strWalletFile = GetArg("-wallet", DEFAULT_WALLET_DAT); - if(!AutoBackupWallet(NULL, strWalletFile, strWarning, strError)) { - if (!strWarning.empty()) - InitWarning(strWarning); - if (!strError.empty()) - return InitError(strError); - } + if(!AutoBackupWallet(NULL, strWalletFile, strWarning, strError)) { + if (!strWarning.empty()) + InitWarning(strWarning); + if (!strError.empty()) + return InitError(strError); + } - if (!CWallet::Verify()) - return false; + if (!CWallet::Verify()) + return false; - // Initialize KeePass Integration - keePassInt.init(); - - } // (!fDisableWallet) + // Initialize KeePass Integration + keePassInt.init(); #endif // ENABLE_WALLET // ********************************************************* Step 6: network initialization // Note that we absolutely cannot open any actual connections @@ -1613,17 +1608,11 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) // ********************************************************* Step 8: load wallet #ifdef ENABLE_WALLET - if (fDisableWallet) { - pwalletMain = NULL; - LogPrintf("Wallet disabled!\n"); - } else { - CWallet::InitLoadWallet(); - if (!pwalletMain) - return false; - } -#else // ENABLE_WALLET + if (!CWallet::InitLoadWallet()) + return false; +#else LogPrintf("No wallet support compiled in!\n"); -#endif // !ENABLE_WALLET +#endif // ********************************************************* Step 9: data directory maintenance diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index cc5d2ed38..7f5bbbc1b 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -134,7 +134,7 @@ BitcoinGUI::BitcoinGUI(const PlatformStyle *platformStyle, const NetworkStyle *n QString windowTitle = tr(PACKAGE_NAME) + " - "; #ifdef ENABLE_WALLET /* if compiled with wallet support, -disablewallet can still disable the wallet */ - enableWallet = !GetBoolArg("-disablewallet", false); + enableWallet = !GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET); #else enableWallet = false; #endif // ENABLE_WALLET diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 039d0398e..689f16c8b 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -2762,6 +2762,9 @@ static const CRPCCommand commands[] = void RegisterWalletRPCCommands(CRPCTable &t) { + if (GetBoolArg("-disablewallet", false)) + return; + for (unsigned int vcidx = 0; vcidx < ARRAYLEN(commands); vcidx++) t.appendCommand(commands[vcidx].name, &commands[vcidx]); } diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index def0300a6..0adf83706 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -596,6 +596,9 @@ void CWallet::Flush(bool shutdown) bool CWallet::Verify() { + if (GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET)) + return true; + LogPrintf("Using BerkeleyDB version %s\n", DbEnv::version(0, 0, 0)); std::string walletFile = GetArg("-wallet", DEFAULT_WALLET_DAT); @@ -4561,6 +4564,12 @@ std::string CWallet::GetWalletHelpString(bool showDebug) bool CWallet::InitLoadWallet() { + if (GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET)) { + pwalletMain = NULL; + LogPrintf("Wallet disabled!\n"); + return true; + } + std::string walletFile = GetArg("-wallet", DEFAULT_WALLET_DAT); // needed to restore wallet transaction meta data after -zapwallettxes @@ -4758,6 +4767,9 @@ bool CWallet::InitLoadWallet() bool CWallet::ParameterInteraction() { + if (GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET)) + return true; + if (GetBoolArg("-blocksonly", DEFAULT_BLOCKSONLY) && SoftSetBoolArg("-walletbroadcast", false)) { LogPrintf("%s: parameter interaction: -blocksonly=1 -> setting -walletbroadcast=0\n", __func__); } diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 1252693ac..9b78f2301 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -61,6 +61,7 @@ static const unsigned int DEFAULT_TX_CONFIRM_TARGET = 2; //! Largest (in bytes) free transaction we're willing to create static const unsigned int MAX_FREE_TRANSACTION_CREATE_SIZE = 1000; static const bool DEFAULT_WALLETBROADCAST = true; +static const bool DEFAULT_DISABLE_WALLET = false; extern const char * DEFAULT_WALLET_DAT;