From 0e63d1df4e5042af85d4a54a1061494b88f74d0b Mon Sep 17 00:00:00 2001 From: Samuel Dobson Date: Wed, 4 Nov 2020 14:42:54 +1300 Subject: [PATCH] Merge #20282: wallet: change upgradewallet return type to be an object 2ead31fb1b17c9b183a4b81f0ae4f48e5cf67d64 [wallet] Return object from upgradewallet RPC (Sishir Giri) Pull request description: Change the return type of upgradewallet to be an object for future extensibility. Also return any error string returned from the `UpgradeWallet()` function. ACKs for top commit: MarcoFalke: ACK 2ead31fb1b17c9b183a4b81f0ae4f48e5cf67d64 meshcollider: Tested ACK 2ead31fb1b17c9b183a4b81f0ae4f48e5cf67d64 Tree-SHA512: bcc7432d2f35093ec2463ea19e894fa885b698c0e8d8e4bd2f979bd4d722cbfed53ec589d6280968917893c64649dc9e40800b8d854273b0f9a1380f51afbdb1 --- 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 912d911a7bbd98..710a427a918349 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4175,7 +4175,12 @@ static UniValue upgradewallet(const JSONRPCRequest& request) { {"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", "120200") + HelpExampleRpc("upgradewallet", "120200") @@ -4198,7 +4203,11 @@ static UniValue upgradewallet(const JSONRPCRequest& request) if (!pwallet->UpgradeWallet(version, error)) { throw JSONRPCError(RPC_WALLET_ERROR, error.original); } - return error.original; + UniValue obj(UniValue::VOBJ); + if (!error.empty()) { + obj.pushKV("error", error.original); + } + return obj; } Span GetWalletRPCCommands() diff --git a/test/functional/wallet_upgradewallet.py b/test/functional/wallet_upgradewallet.py index b3e02003292d78..29f6ef4b51068c 100755 --- a/test/functional/wallet_upgradewallet.py +++ b/test/functional/wallet_upgradewallet.py @@ -108,7 +108,7 @@ def run_test(self): # 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) @@ -131,7 +131,7 @@ def run_test(self): 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)