mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 15:09:59 +01:00
Merge #17070: wallet: Avoid showing GUI popups on RPC errors
facec1c643wallet: Avoid showing GUI popups on RPC errors (MarcoFalke) Pull request description: RPC errors and warnings are shown as popups in the GUI instead of being returned to the RPC caller. For example, ``` $ ./src/bitcoin-cli loadwallet $(pwd)/./test/functional/data/wallets/high_minversion/ error code: -4 error message: Wallet loading failed. ``` gives me a GUI popup and no reason why loading the wallet failed. After this pull request: ``` $ ./src/bitcoin-cli loadwallet $(pwd)/./test/functional/data/wallets/high_minversion/ error code: -4 error message: Wallet loading failed: Error loading /home/marco/workspace/btc_bitcoin_core/./test/functional/data/wallets/high_minversion/wallet.dat: Wallet requires newer version of Bitcoin Core ACKs for top commit: laanwj: Code review ACKfacec1c643Tree-SHA512: c8274bbb02cfcf71676eeec1e773e51fb3538cf93f82e7cb8536f4716d44ed819cdc162dfc039ac7386a4db381a734cdb27fd32567043a1180c02519fbcba194
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
#include <util/bip32.h>
|
||||
#include <util/fees.h>
|
||||
#include <util/moneystr.h>
|
||||
#include <util/string.h>
|
||||
#include <util/system.h>
|
||||
#include <util/url.h>
|
||||
#include <util/validation.h>
|
||||
@@ -2581,13 +2582,14 @@ static UniValue loadwallet(const JSONRPCRequest& request)
|
||||
}
|
||||
}
|
||||
|
||||
std::string error, warning;
|
||||
std::string error;
|
||||
std::vector<std::string> warning;
|
||||
std::shared_ptr<CWallet> const wallet = LoadWallet(*g_rpc_interfaces->chain, location, error, warning);
|
||||
if (!wallet) throw JSONRPCError(RPC_WALLET_ERROR, error);
|
||||
|
||||
UniValue obj(UniValue::VOBJ);
|
||||
obj.pushKV("name", wallet->GetName());
|
||||
obj.pushKV("warning", warning);
|
||||
obj.pushKV("warning", Join(warning, "\n"));
|
||||
|
||||
return obj;
|
||||
}
|
||||
@@ -2693,12 +2695,12 @@ static UniValue createwallet(const JSONRPCRequest& request)
|
||||
}
|
||||
SecureString passphrase;
|
||||
passphrase.reserve(100);
|
||||
std::string warning;
|
||||
std::vector<std::string> warnings;
|
||||
if (!request.params[3].isNull()) {
|
||||
passphrase = request.params[3].get_str().c_str();
|
||||
if (passphrase.empty()) {
|
||||
// Empty string means unencrypted
|
||||
warning = "Empty string given as passphrase, wallet will not be encrypted.";
|
||||
warnings.emplace_back("Empty string given as passphrase, wallet will not be encrypted.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2707,9 +2709,8 @@ static UniValue createwallet(const JSONRPCRequest& request)
|
||||
}
|
||||
|
||||
std::string error;
|
||||
std::string create_warning;
|
||||
std::shared_ptr<CWallet> wallet;
|
||||
WalletCreationStatus status = CreateWallet(*g_rpc_interfaces->chain, passphrase, flags, request.params[0].get_str(), error, create_warning, wallet);
|
||||
WalletCreationStatus status = CreateWallet(*g_rpc_interfaces->chain, passphrase, flags, request.params[0].get_str(), error, warnings, wallet);
|
||||
switch (status) {
|
||||
case WalletCreationStatus::CREATION_FAILED:
|
||||
throw JSONRPCError(RPC_WALLET_ERROR, error);
|
||||
@@ -2720,15 +2721,9 @@ static UniValue createwallet(const JSONRPCRequest& request)
|
||||
// no default case, so the compiler can warn about missing cases
|
||||
}
|
||||
|
||||
if (warning.empty()) {
|
||||
warning = create_warning;
|
||||
} else if (!warning.empty() && !create_warning.empty()){
|
||||
warning += "; " + create_warning;
|
||||
}
|
||||
|
||||
UniValue obj(UniValue::VOBJ);
|
||||
obj.pushKV("name", wallet->GetName());
|
||||
obj.pushKV("warning", warning);
|
||||
obj.pushKV("warning", Join(warnings, "\n"));
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user