From 9c76ba18cdfe01fe9266e0dcf6714dbe0abbb837 Mon Sep 17 00:00:00 2001 From: John Newbery Date: Tue, 29 Aug 2017 11:48:25 -0400 Subject: [PATCH 1/8] [wallet] Rename InitLoadWallet() to OpenWallets() Rationale: - this init function can now open multiple wallets (hence Wallet->Wallets) - This is named as the antonym to CloseWallets(), which carries out the opposite action. --- src/init.cpp | 2 +- src/wallet/init.cpp | 2 +- src/wallet/init.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index 7c99dc74e..387bd2e2f 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1567,7 +1567,7 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler) // ********************************************************* Step 8: load wallet #ifdef ENABLE_WALLET - if (!InitLoadWallet()) + if (!OpenWallets()) return false; #else LogPrintf("No wallet support compiled in!\n"); diff --git a/src/wallet/init.cpp b/src/wallet/init.cpp index 18365b1b7..95b188b62 100644 --- a/src/wallet/init.cpp +++ b/src/wallet/init.cpp @@ -228,7 +228,7 @@ bool WalletVerify() return true; } -bool InitLoadWallet() +bool OpenWallets() { if (gArgs.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET)) { LogPrintf("Wallet disabled!\n"); diff --git a/src/wallet/init.h b/src/wallet/init.h index fa2251506..1821e5e70 100644 --- a/src/wallet/init.h +++ b/src/wallet/init.h @@ -20,6 +20,6 @@ bool WalletParameterInteraction(); bool WalletVerify(); //! Load wallet databases. -bool InitLoadWallet(); +bool OpenWallets(); #endif // BITCOIN_WALLET_INIT_H From 1b9cee66e1c50cb6f110793ec5dc4c6a291cce36 Mon Sep 17 00:00:00 2001 From: John Newbery Date: Tue, 29 Aug 2017 11:51:02 -0400 Subject: [PATCH 2/8] [wallet] Rename WalletVerify() to VerifyWallets() This function can now verify multiple wallets. --- src/init.cpp | 2 +- src/wallet/init.cpp | 2 +- src/wallet/init.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index 387bd2e2f..ce368a6bb 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1246,7 +1246,7 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler) // ********************************************************* Step 5: verify wallet database integrity #ifdef ENABLE_WALLET - if (!WalletVerify()) + if (!VerifyWallets()) return false; #endif // ********************************************************* Step 6: network initialization diff --git a/src/wallet/init.cpp b/src/wallet/init.cpp index 95b188b62..f39201e79 100644 --- a/src/wallet/init.cpp +++ b/src/wallet/init.cpp @@ -171,7 +171,7 @@ bool WalletParameterInteraction() return true; } -bool WalletVerify() +bool VerifyWallets() { if (gArgs.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET)) return true; diff --git a/src/wallet/init.h b/src/wallet/init.h index 1821e5e70..a66b35943 100644 --- a/src/wallet/init.h +++ b/src/wallet/init.h @@ -17,7 +17,7 @@ bool WalletParameterInteraction(); //! Responsible for reading and validating the -wallet arguments and verifying the wallet database. // This function will perform salvage on the wallet if requested, as long as only one wallet is // being loaded (CWallet::ParameterInteraction forbids -salvagewallet, -zapwallettxes or -upgradewallet with multiwallet). -bool WalletVerify(); +bool VerifyWallets(); //! Load wallet databases. bool OpenWallets(); From 2da5eafa47cdf81107bd3e71a709d404ebb6dcdb Mon Sep 17 00:00:00 2001 From: John Newbery Date: Mon, 28 Aug 2017 12:31:53 -0400 Subject: [PATCH 3/8] [wallet] Add FlushWallets() function to wallet/init.cpp --- src/init.cpp | 8 ++------ src/wallet/init.cpp | 6 ++++++ src/wallet/init.h | 3 +++ 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index ce368a6bb..6d250a25c 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -189,9 +189,7 @@ void Shutdown() StopRPC(); StopHTTPServer(); #ifdef ENABLE_WALLET - for (CWalletRef pwallet : vpwallets) { - pwallet->Flush(false); - } + FlushWallets(false); #endif MapPort(false); UnregisterValidationInterface(peerLogic.get()); @@ -246,9 +244,7 @@ void Shutdown() pblocktree = nullptr; } #ifdef ENABLE_WALLET - for (CWalletRef pwallet : vpwallets) { - pwallet->Flush(true); - } + FlushWallets(true); #endif #if ENABLE_ZMQ diff --git a/src/wallet/init.cpp b/src/wallet/init.cpp index f39201e79..f58f3bc54 100644 --- a/src/wallet/init.cpp +++ b/src/wallet/init.cpp @@ -245,3 +245,9 @@ bool OpenWallets() return true; } + +void FlushWallets(bool shutdown) { + for (CWalletRef pwallet : vpwallets) { + pwallet->Flush(shutdown); + } +} diff --git a/src/wallet/init.h b/src/wallet/init.h index a66b35943..5445c72d1 100644 --- a/src/wallet/init.h +++ b/src/wallet/init.h @@ -22,4 +22,7 @@ bool VerifyWallets(); //! Load wallet databases. bool OpenWallets(); +//! Flush all wallets in preparation for shutdown. +//! Call with shutdown = true to actually shutdown the wallet. +void FlushWallets(bool shutdown); #endif // BITCOIN_WALLET_INIT_H From 77fe07c1591395b4279f9f2ff3c36c6bde11fbb7 Mon Sep 17 00:00:00 2001 From: John Newbery Date: Mon, 28 Aug 2017 12:53:56 -0400 Subject: [PATCH 4/8] [wallet] Add StopWallets() function to wallet/init.cpp --- src/init.cpp | 4 ++-- src/wallet/init.cpp | 10 ++++++++-- src/wallet/init.h | 6 ++++-- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index 6d250a25c..d1ffe126d 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -189,7 +189,7 @@ void Shutdown() StopRPC(); StopHTTPServer(); #ifdef ENABLE_WALLET - FlushWallets(false); + FlushWallets(); #endif MapPort(false); UnregisterValidationInterface(peerLogic.get()); @@ -244,7 +244,7 @@ void Shutdown() pblocktree = nullptr; } #ifdef ENABLE_WALLET - FlushWallets(true); + StopWallets(); #endif #if ENABLE_ZMQ diff --git a/src/wallet/init.cpp b/src/wallet/init.cpp index f58f3bc54..2b5c6b173 100644 --- a/src/wallet/init.cpp +++ b/src/wallet/init.cpp @@ -246,8 +246,14 @@ bool OpenWallets() return true; } -void FlushWallets(bool shutdown) { +void FlushWallets() { for (CWalletRef pwallet : vpwallets) { - pwallet->Flush(shutdown); + pwallet->Flush(false); + } +} + +void StopWallets() { + for (CWalletRef pwallet : vpwallets) { + pwallet->Flush(true); } } diff --git a/src/wallet/init.h b/src/wallet/init.h index 5445c72d1..c06b05847 100644 --- a/src/wallet/init.h +++ b/src/wallet/init.h @@ -23,6 +23,8 @@ bool VerifyWallets(); bool OpenWallets(); //! Flush all wallets in preparation for shutdown. -//! Call with shutdown = true to actually shutdown the wallet. -void FlushWallets(bool shutdown); +void FlushWallets(); + +//! Stop all wallets. Wallets will be flushed first. +void StopWallets(); #endif // BITCOIN_WALLET_INIT_H From 062d63102eb1e90168d28589de8bf182e9a6a7d3 Mon Sep 17 00:00:00 2001 From: John Newbery Date: Mon, 28 Aug 2017 12:41:33 -0400 Subject: [PATCH 5/8] [wallet] Add CloseWallets() function to wallet/init.cpp --- src/init.cpp | 5 +---- src/wallet/init.cpp | 7 +++++++ src/wallet/init.h | 4 ++++ 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index d1ffe126d..3f528a1f5 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -265,10 +265,7 @@ void Shutdown() UnregisterAllValidationInterfaces(); GetMainSignals().UnregisterBackgroundSignalScheduler(); #ifdef ENABLE_WALLET - for (CWalletRef pwallet : vpwallets) { - delete pwallet; - } - vpwallets.clear(); + CloseWallets(); #endif globalVerifyHandle.reset(); ECC_Stop(); diff --git a/src/wallet/init.cpp b/src/wallet/init.cpp index 2b5c6b173..84318eac0 100644 --- a/src/wallet/init.cpp +++ b/src/wallet/init.cpp @@ -257,3 +257,10 @@ void StopWallets() { pwallet->Flush(true); } } + +void CloseWallets() { + for (CWalletRef pwallet : vpwallets) { + delete pwallet; + } + vpwallets.clear(); +} diff --git a/src/wallet/init.h b/src/wallet/init.h index c06b05847..1be2ef927 100644 --- a/src/wallet/init.h +++ b/src/wallet/init.h @@ -27,4 +27,8 @@ void FlushWallets(); //! Stop all wallets. Wallets will be flushed first. void StopWallets(); + +//! Close all wallets. +void CloseWallets(); + #endif // BITCOIN_WALLET_INIT_H From 290f3c56d9dd8a519920939a4fc440da832c1c63 Mon Sep 17 00:00:00 2001 From: John Newbery Date: Mon, 28 Aug 2017 13:33:59 -0400 Subject: [PATCH 6/8] [wallet] Add RegisterWalletRPC() function to wallet/init.cpp --- src/init.cpp | 2 +- src/wallet/init.cpp | 8 ++++++++ src/wallet/init.h | 5 +++++ src/wallet/rpcwallet.cpp | 3 --- src/wallet/rpcwallet.h | 3 +++ 5 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index 3f528a1f5..9022b4a4c 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1017,7 +1017,7 @@ bool AppInitParameterInteraction() RegisterAllCoreRPCCommands(tableRPC); #ifdef ENABLE_WALLET - RegisterWalletRPCCommands(tableRPC); + RegisterWalletRPC(tableRPC); #endif nConnectTimeout = gArgs.GetArg("-timeout", DEFAULT_CONNECT_TIMEOUT); diff --git a/src/wallet/init.cpp b/src/wallet/init.cpp index 84318eac0..9fd038150 100644 --- a/src/wallet/init.cpp +++ b/src/wallet/init.cpp @@ -10,6 +10,7 @@ #include "utilmoneystr.h" #include "validation.h" #include "wallet/wallet.h" +#include "wallet/rpcwallet.h" std::string GetWalletHelpString(bool showDebug) { @@ -171,6 +172,13 @@ bool WalletParameterInteraction() return true; } +void RegisterWalletRPC(CRPCTable &t) +{ + if (gArgs.GetBoolArg("-disablewallet", false)) return; + + RegisterWalletRPCCommands(t); +} + bool VerifyWallets() { if (gArgs.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET)) diff --git a/src/wallet/init.h b/src/wallet/init.h index 1be2ef927..588357119 100644 --- a/src/wallet/init.h +++ b/src/wallet/init.h @@ -8,12 +8,17 @@ #include +class CRPCTable; + //! Return the wallets help message. std::string GetWalletHelpString(bool showDebug); //! Wallets parameter interaction bool WalletParameterInteraction(); +//! Register wallet RPCs. +void RegisterWalletRPC(CRPCTable &tableRPC); + //! Responsible for reading and validating the -wallet arguments and verifying the wallet database. // This function will perform salvage on the wallet if requested, as long as only one wallet is // being loaded (CWallet::ParameterInteraction forbids -salvagewallet, -zapwallettxes or -upgradewallet with multiwallet). diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 4ea53c413..6ef3599a1 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -3217,9 +3217,6 @@ static const CRPCCommand commands[] = void RegisterWalletRPCCommands(CRPCTable &t) { - if (gArgs.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/rpcwallet.h b/src/wallet/rpcwallet.h index db0808b93..14e51610d 100644 --- a/src/wallet/rpcwallet.h +++ b/src/wallet/rpcwallet.h @@ -5,7 +5,10 @@ #ifndef BITCOIN_WALLET_RPCWALLET_H #define BITCOIN_WALLET_RPCWALLET_H +#include + class CRPCTable; +class CWallet; class JSONRPCRequest; void RegisterWalletRPCCommands(CRPCTable &t); From 43b0e81d0f8f5d235e1cdaa2ee128b67259f7109 Mon Sep 17 00:00:00 2001 From: John Newbery Date: Tue, 29 Aug 2017 11:47:06 -0400 Subject: [PATCH 7/8] [wallet] Add StartWallets() function to wallet/init.cpp --- src/init.cpp | 5 +---- src/wallet/init.cpp | 6 ++++++ src/wallet/init.h | 4 ++++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index 9022b4a4c..fc31d3d4d 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -44,7 +44,6 @@ #include "validationinterface.h" #ifdef ENABLE_WALLET #include "wallet/init.h" -#include "wallet/wallet.h" #endif #include "warnings.h" #include @@ -1691,9 +1690,7 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler) uiInterface.InitMessage(_("Done loading")); #ifdef ENABLE_WALLET - for (CWalletRef pwallet : vpwallets) { - pwallet->postInitProcess(scheduler); - } + StartWallets(scheduler); #endif return !fRequestShutdown; diff --git a/src/wallet/init.cpp b/src/wallet/init.cpp index 9fd038150..1e00735ed 100644 --- a/src/wallet/init.cpp +++ b/src/wallet/init.cpp @@ -254,6 +254,12 @@ bool OpenWallets() return true; } +void StartWallets(CScheduler& scheduler) { + for (CWalletRef pwallet : vpwallets) { + pwallet->postInitProcess(scheduler); + } +} + void FlushWallets() { for (CWalletRef pwallet : vpwallets) { pwallet->Flush(false); diff --git a/src/wallet/init.h b/src/wallet/init.h index 588357119..0d5e5f0cd 100644 --- a/src/wallet/init.h +++ b/src/wallet/init.h @@ -9,6 +9,7 @@ #include class CRPCTable; +class CScheduler; //! Return the wallets help message. std::string GetWalletHelpString(bool showDebug); @@ -27,6 +28,9 @@ bool VerifyWallets(); //! Load wallet databases. bool OpenWallets(); +//! Complete startup of wallets. +void StartWallets(CScheduler& scheduler); + //! Flush all wallets in preparation for shutdown. void FlushWallets(); From 5d2a3995e7035b3607a11660a2c8330a548f733d Mon Sep 17 00:00:00 2001 From: John Newbery Date: Thu, 7 Sep 2017 16:22:11 -0700 Subject: [PATCH 8/8] [trivial] fixup comment for VerifyWallets() --- src/wallet/init.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/init.h b/src/wallet/init.h index 0d5e5f0cd..0b3ee2dda 100644 --- a/src/wallet/init.h +++ b/src/wallet/init.h @@ -22,7 +22,7 @@ void RegisterWalletRPC(CRPCTable &tableRPC); //! Responsible for reading and validating the -wallet arguments and verifying the wallet database. // This function will perform salvage on the wallet if requested, as long as only one wallet is -// being loaded (CWallet::ParameterInteraction forbids -salvagewallet, -zapwallettxes or -upgradewallet with multiwallet). +// being loaded (WalletParameterInteraction forbids -salvagewallet, -zapwallettxes or -upgradewallet with multiwallet). bool VerifyWallets(); //! Load wallet databases.