Skip to content

Commit

Permalink
Merge bitcoin#20282: wallet: change upgradewallet return type to be a…
Browse files Browse the repository at this point in the history
…n object

2ead31f [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 2ead31f
  meshcollider:
    Tested ACK 2ead31f

Tree-SHA512: bcc7432d2f35093ec2463ea19e894fa885b698c0e8d8e4bd2f979bd4d722cbfed53ec589d6280968917893c64649dc9e40800b8d854273b0f9a1380f51afbdb1
  • Loading branch information
meshcollider authored and knst committed Jan 14, 2024
1 parent f72650d commit 0e63d1d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
13 changes: 11 additions & 2 deletions src/wallet/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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<const CRPCCommand> GetWalletRPCCommands()
Expand Down
4 changes: 2 additions & 2 deletions test/functional/wallet_upgradewallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 0e63d1d

Please sign in to comment.