aboutsummaryrefslogtreecommitdiff
path: root/src/wallet
diff options
context:
space:
mode:
authorBezdrighin <mbbezdri@3c22fbe8ae1b.ant.amazon.com>2021-01-03 01:45:25 +0100
committerBezdrighin <mbbezdri@3c22fbe8ae1b.ant.amazon.com>2021-01-24 02:44:53 +0100
commit8f0b64fb513e8c6cdd1f115856100a4ef5afe23e (patch)
tree25b5ca06023a3b6b633515962a952ebc94c538a0 /src/wallet
parent32b191fb66e644c690c94cbfdae6ddbc754769d7 (diff)
Better error messages for invalid addresses
This commit addresses #20809. We add an additional 'error' property in the result of 'validateaddress' in case the address is not valid that gives a short description of why the address in invalid. We also change the error message returned by 'getaddressinfo' in case the address is invalid.
Diffstat (limited to 'src/wallet')
-rw-r--r--src/wallet/rpcwallet.cpp12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp
index 9db327c913..b865130642 100644
--- a/src/wallet/rpcwallet.cpp
+++ b/src/wallet/rpcwallet.cpp
@@ -3820,13 +3820,19 @@ RPCHelpMan getaddressinfo()
LOCK(pwallet->cs_wallet);
- UniValue ret(UniValue::VOBJ);
- CTxDestination dest = DecodeDestination(request.params[0].get_str());
+ std::string error_msg;
+ CTxDestination dest = DecodeDestination(request.params[0].get_str(), error_msg);
+
// Make sure the destination is valid
if (!IsValidDestination(dest)) {
- throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid address");
+ // Set generic error message in case 'DecodeDestination' didn't set it
+ if (error_msg.empty()) error_msg = "Invalid address";
+
+ throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, error_msg);
}
+ UniValue ret(UniValue::VOBJ);
+
std::string currentAddress = EncodeDestination(dest);
ret.pushKV("address", currentAddress);