From 2ead31fb1b17c9b183a4b81f0ae4f48e5cf67d64 Mon Sep 17 00:00:00 2001 From: Sishir Giri Date: Sun, 18 Oct 2020 18:01:42 -0700 Subject: [wallet] Return object from upgradewallet RPC --- src/wallet/rpcwallet.cpp | 13 +++++++++++-- test/functional/wallet_upgradewallet.py | 4 ++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 086ffa1272..8aaa03e0c9 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4443,7 +4443,12 @@ static RPCHelpMan upgradewallet() { {"version", RPCArg::Type::NUM, /* default */ strprintf("%d", FEATURE_LATEST), "The version number to upgrade to. Default is the latest wallet version"} }, - RPCResults{}, + RPCResult{ + RPCResult::Type::OBJ, "", "", + { + {RPCResult::Type::STR, "error", /* optional */ true, "Error message (if there is one)"} + }, + }, RPCExamples{ HelpExampleCli("upgradewallet", "169900") + HelpExampleRpc("upgradewallet", "169900") @@ -4468,7 +4473,11 @@ static RPCHelpMan upgradewallet() if (!pwallet->UpgradeWallet(version, error, warnings)) { throw JSONRPCError(RPC_WALLET_ERROR, error.original); } - return error.original; + UniValue obj(UniValue::VOBJ); + if (!error.empty()) { + obj.pushKV("error", error.original); + } + return obj; }, }; } diff --git a/test/functional/wallet_upgradewallet.py b/test/functional/wallet_upgradewallet.py index 446a601aee..15d9b109c5 100755 --- a/test/functional/wallet_upgradewallet.py +++ b/test/functional/wallet_upgradewallet.py @@ -107,7 +107,7 @@ class UpgradeWalletTest(BitcoinTestFramework): # calling upgradewallet without version arguments # should return nothing if successful - assert_equal(wallet.upgradewallet(), "") + assert_equal(wallet.upgradewallet(), {}) new_version = wallet.getwalletinfo()["walletversion"] # upgraded wallet version should be greater than older one assert_greater_than(new_version, old_version) @@ -130,7 +130,7 @@ class UpgradeWalletTest(BitcoinTestFramework): assert_equal('hdseedid' in wallet.getwalletinfo(), False) # calling upgradewallet with explicit version number # should return nothing if successful - assert_equal(wallet.upgradewallet(169900), "") + assert_equal(wallet.upgradewallet(169900), {}) new_version = wallet.getwalletinfo()["walletversion"] # upgraded wallet should have version 169900 assert_equal(new_version, 169900) -- cgit v1.2.3