aboutsummaryrefslogtreecommitdiff
path: root/src/wallet/rpcwallet.cpp
diff options
context:
space:
mode:
authorJonas Schnelli <dev@jonasschnelli.ch>2020-09-03 18:24:23 +0200
committerJonas Schnelli <dev@jonasschnelli.ch>2020-09-03 18:24:32 +0200
commita0a422c34cfd6514d0cc445bd784d3ee1a2d1749 (patch)
tree75eeca979b74c28af06eec94d0986a3f00626339 /src/wallet/rpcwallet.cpp
parentbd60a9a8edd4a3fe2f4f605b77cdae34969eaaf2 (diff)
parentf1ee37319a7a211e5fb325406d62db5b61dbd30e (diff)
downloadbitcoin-a0a422c34cfd6514d0cc445bd784d3ee1a2d1749.tar.xz
Merge #19754: wallet, gui: Reload previously loaded wallets on startup
f1ee37319a7a211e5fb325406d62db5b61dbd30e wallet: Reload previously loaded wallets on GUI startup (Andrew Chow) Pull request description: Enable the GUI to also use the load_on_startup feature. Wallets loaded in the GUI always have load_on_startup=true. When they are unloaded from the GUI, load_on_startup=false. To facilitate this change, UpdateWalletSetting is moved into the wallet module and called from within LoadWallet, RemoveWallet, and Createwallet. This change does not actually touch the GUI code but rather the wallet functions that are shared between the GUI and RPC. ACKs for top commit: jonasschnelli: Tested ACK f1ee37319a7a211e5fb325406d62db5b61dbd30e - works as expected. Wallets loaded via bitcoin-cli (in `-server` mode) or through the RPC console won't be loaded on startup but wallets loaded via the GUI menu will. kristapsk: ACK f1ee37319a7a211e5fb325406d62db5b61dbd30e, I have tested the code. Tree-SHA512: f5b44aa763cf761d919015c5fbc0600b72434aa71e3b57007fd7530a29c3da1a9a0c98c4f22cb6cdffba61150a31170056a7d4737625e7b76f6958f3d584da8c
Diffstat (limited to 'src/wallet/rpcwallet.cpp')
-rw-r--r--src/wallet/rpcwallet.cpp30
1 files changed, 7 insertions, 23 deletions
diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp
index 7ef0b2129b..887c5b632b 100644
--- a/src/wallet/rpcwallet.cpp
+++ b/src/wallet/rpcwallet.cpp
@@ -230,18 +230,6 @@ static void SetFeeEstimateMode(const CWallet* pwallet, CCoinControl& cc, const U
}
}
-static void UpdateWalletSetting(interfaces::Chain& chain,
- const std::string& wallet_name,
- const UniValue& load_on_startup,
- std::vector<bilingual_str>& warnings)
-{
- if (load_on_startup.isTrue() && !AddWalletSetting(chain, wallet_name)) {
- warnings.emplace_back(Untranslated("Wallet load on startup setting could not be updated, so wallet may not be loaded next node startup."));
- } else if (load_on_startup.isFalse() && !RemoveWalletSetting(chain, wallet_name)) {
- warnings.emplace_back(Untranslated("Wallet load on startup setting could not be updated, so wallet may still be loaded next node startup."));
- }
-}
-
static UniValue getnewaddress(const JSONRPCRequest& request)
{
RPCHelpMan{"getnewaddress",
@@ -2528,11 +2516,10 @@ static UniValue loadwallet(const JSONRPCRequest& request)
bilingual_str error;
std::vector<bilingual_str> warnings;
- std::shared_ptr<CWallet> const wallet = LoadWallet(*context.chain, location, error, warnings);
+ Optional<bool> load_on_start = request.params[1].isNull() ? nullopt : Optional<bool>(request.params[1].get_bool());
+ std::shared_ptr<CWallet> const wallet = LoadWallet(*context.chain, location, load_on_start, error, warnings);
if (!wallet) throw JSONRPCError(RPC_WALLET_ERROR, error.original);
- UpdateWalletSetting(*context.chain, location.GetName(), request.params[1], warnings);
-
UniValue obj(UniValue::VOBJ);
obj.pushKV("name", wallet->GetName());
obj.pushKV("warning", Join(warnings, Untranslated("\n")).original);
@@ -2662,7 +2649,8 @@ static UniValue createwallet(const JSONRPCRequest& request)
bilingual_str error;
std::shared_ptr<CWallet> wallet;
- WalletCreationStatus status = CreateWallet(*context.chain, passphrase, flags, request.params[0].get_str(), error, warnings, wallet);
+ Optional<bool> load_on_start = request.params[6].isNull() ? nullopt : Optional<bool>(request.params[6].get_bool());
+ WalletCreationStatus status = CreateWallet(*context.chain, passphrase, flags, request.params[0].get_str(), load_on_start, error, warnings, wallet);
switch (status) {
case WalletCreationStatus::CREATION_FAILED:
throw JSONRPCError(RPC_WALLET_ERROR, error.original);
@@ -2673,8 +2661,6 @@ static UniValue createwallet(const JSONRPCRequest& request)
// no default case, so the compiler can warn about missing cases
}
- UpdateWalletSetting(*context.chain, request.params[0].get_str(), request.params[6], warnings);
-
UniValue obj(UniValue::VOBJ);
obj.pushKV("name", wallet->GetName());
obj.pushKV("warning", Join(warnings, Untranslated("\n")).original);
@@ -2717,15 +2703,13 @@ static UniValue unloadwallet(const JSONRPCRequest& request)
// Release the "main" shared pointer and prevent further notifications.
// Note that any attempt to load the same wallet would fail until the wallet
// is destroyed (see CheckUniqueFileid).
- if (!RemoveWallet(wallet)) {
+ std::vector<bilingual_str> warnings;
+ Optional<bool> load_on_start = request.params[1].isNull() ? nullopt : Optional<bool>(request.params[1].get_bool());
+ if (!RemoveWallet(wallet, load_on_start, warnings)) {
throw JSONRPCError(RPC_MISC_ERROR, "Requested wallet already unloaded");
}
- interfaces::Chain& chain = wallet->chain();
- std::vector<bilingual_str> warnings;
-
UnloadWallet(std::move(wallet));
- UpdateWalletSetting(chain, wallet_name, request.params[1], warnings);
UniValue result(UniValue::VOBJ);
result.pushKV("warning", Join(warnings, Untranslated("\n")).original);