aboutsummaryrefslogtreecommitdiff
path: root/src/wallet/rpcwallet.cpp
diff options
context:
space:
mode:
authorMarcoFalke <falke.marco@gmail.com>2019-08-19 18:12:35 -0400
committerMarcoFalke <falke.marco@gmail.com>2020-05-01 07:39:00 -0400
commitfae51a5c6f4270a1088e6295b10a8cc45988ae46 (patch)
tree1367e0780ab7e2fda2cb1cd46174029515d098f2 /src/wallet/rpcwallet.cpp
parent608359b071dac82a9cf33a6c9e01f87abfcb90eb (diff)
downloadbitcoin-fae51a5c6f4270a1088e6295b10a8cc45988ae46.tar.xz
wallet: Avoid translating RPC errors when loading wallets
Common errors and warnings should be translated when displayed in the GUI, but not translated when displayed elsewhere. The wallet method CreateWalletFromFile does not know its caller, so this commit changes it to return a bilingual_str to the caller.
Diffstat (limited to 'src/wallet/rpcwallet.cpp')
-rw-r--r--src/wallet/rpcwallet.cpp31
1 files changed, 16 insertions, 15 deletions
diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp
index 91162d575d..8343ae3360 100644
--- a/src/wallet/rpcwallet.cpp
+++ b/src/wallet/rpcwallet.cpp
@@ -23,6 +23,7 @@
#include <util/moneystr.h>
#include <util/string.h>
#include <util/system.h>
+#include <util/translation.h>
#include <util/url.h>
#include <util/vector.h>
#include <wallet/coincontrol.h>
@@ -2589,14 +2590,14 @@ static UniValue loadwallet(const JSONRPCRequest& request)
}
}
- std::string error;
- std::vector<std::string> warning;
- std::shared_ptr<CWallet> const wallet = LoadWallet(*g_rpc_chain, location, error, warning);
- if (!wallet) throw JSONRPCError(RPC_WALLET_ERROR, error);
+ bilingual_str error;
+ std::vector<bilingual_str> warnings;
+ std::shared_ptr<CWallet> const wallet = LoadWallet(*g_rpc_chain, location, error, warnings);
+ if (!wallet) throw JSONRPCError(RPC_WALLET_ERROR, error.original);
UniValue obj(UniValue::VOBJ);
obj.pushKV("name", wallet->GetName());
- obj.pushKV("warning", Join(warning, "\n"));
+ obj.pushKV("warning", Join(warnings, "\n", OpOriginal));
return obj;
}
@@ -2705,12 +2706,12 @@ static UniValue createwallet(const JSONRPCRequest& request)
}
SecureString passphrase;
passphrase.reserve(100);
- std::vector<std::string> warnings;
+ std::vector<bilingual_str> warnings;
if (!request.params[3].isNull()) {
passphrase = request.params[3].get_str().c_str();
if (passphrase.empty()) {
// Empty string means unencrypted
- warnings.emplace_back("Empty string given as passphrase, wallet will not be encrypted.");
+ warnings.emplace_back(Untranslated("Empty string given as passphrase, wallet will not be encrypted."));
}
}
@@ -2721,14 +2722,14 @@ static UniValue createwallet(const JSONRPCRequest& request)
flags |= WALLET_FLAG_DESCRIPTORS;
}
- std::string error;
+ bilingual_str error;
std::shared_ptr<CWallet> wallet;
WalletCreationStatus status = CreateWallet(*g_rpc_chain, passphrase, flags, request.params[0].get_str(), error, warnings, wallet);
switch (status) {
case WalletCreationStatus::CREATION_FAILED:
- throw JSONRPCError(RPC_WALLET_ERROR, error);
+ throw JSONRPCError(RPC_WALLET_ERROR, error.original);
case WalletCreationStatus::ENCRYPTION_FAILED:
- throw JSONRPCError(RPC_WALLET_ENCRYPTION_FAILED, error);
+ throw JSONRPCError(RPC_WALLET_ENCRYPTION_FAILED, error.original);
case WalletCreationStatus::SUCCESS:
break;
// no default case, so the compiler can warn about missing cases
@@ -2736,7 +2737,7 @@ static UniValue createwallet(const JSONRPCRequest& request)
UniValue obj(UniValue::VOBJ);
obj.pushKV("name", wallet->GetName());
- obj.pushKV("warning", Join(warnings, "\n"));
+ obj.pushKV("warning", Join(warnings, "\n", OpOriginal));
return obj;
}
@@ -4239,12 +4240,12 @@ static UniValue upgradewallet(const JSONRPCRequest& request)
version = request.params[0].get_int();
}
- std::string error;
- std::vector<std::string> warnings;
+ bilingual_str error;
+ std::vector<bilingual_str> warnings;
if (!pwallet->UpgradeWallet(version, error, warnings)) {
- throw JSONRPCError(RPC_WALLET_ERROR, error);
+ throw JSONRPCError(RPC_WALLET_ERROR, error.original);
}
- return error;
+ return error.original;
}
UniValue abortrescan(const JSONRPCRequest& request); // in rpcdump.cpp