diff --git a/src/rpc/client.cpp b/src/rpc/client.cpp --- a/src/rpc/client.cpp +++ b/src/rpc/client.cpp @@ -137,6 +137,7 @@ {"disconnectnode", 1, "nodeid"}, {"logging", 0, "include"}, {"logging", 1, "exclude"}, + {"upgradewallet", 0, "version"}, // Echo with conversion (For testing only) {"echojson", 0, "arg0"}, {"echojson", 1, "arg1"}, diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4834,6 +4834,46 @@ return result; } +static UniValue upgradewallet(const Config &config, + const JSONRPCRequest &request) { + std::shared_ptr const wallet = GetWalletForJSONRPCRequest(request); + CWallet *const pwallet = wallet.get(); + + if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { + return NullUniValue; + } + + RPCHelpMan{"upgradewallet", + "\nUpgrade the wallet. Upgrades to the latest version if no " + "version number is specified\n" + "New keys may be generated and a new wallet backup will need to " + "be made.", + {{"version", RPCArg::Type::NUM, + /* default */ strprintf("%d", FEATURE_LATEST), + "The version number to upgrade to. Default is the latest " + "wallet version"}}, + RPCResults{}, + RPCExamples{HelpExampleCli("upgradewallet", "200300") + + HelpExampleRpc("upgradewallet", "200300")}} + .Check(request); + + RPCTypeCheck(request.params, {UniValue::VNUM}, true); + + EnsureWalletIsUnlocked(pwallet); + + int version = 0; + if (!request.params[0].isNull()) { + version = request.params[0].get_int(); + } + + bilingual_str error; + std::vector warnings; + if (!pwallet->UpgradeWallet(version, error, warnings)) { + throw JSONRPCError(RPC_WALLET_ERROR, error.original); + } + return error.original; +} + // clang-format off static const CRPCCommand commands[] = { // category name actor (function) argNames @@ -4878,6 +4918,7 @@ { "wallet", "signmessage", signmessage, {"address","message"} }, { "wallet", "signrawtransactionwithwallet", signrawtransactionwithwallet, {"hextring","prevtxs","sighashtype"} }, { "wallet", "unloadwallet", unloadwallet, {"wallet_name"} }, + { "wallet", "upgradewallet", upgradewallet, {"version"} }, { "wallet", "walletcreatefundedpsbt", walletcreatefundedpsbt, {"inputs","outputs","locktime","options","bip32derivs"} }, { "wallet", "walletlock", walletlock, {} }, { "wallet", "walletpassphrase", walletpassphrase, {"passphrase","timeout"} },