MCPcopy Create free account
hub / github.com/ElementsProject/elements / upgradewallet

Function upgradewallet

src/wallet/rpc/wallet.cpp:523–585  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

521}
522
523static RPCHelpMan upgradewallet()
524{
525 return RPCHelpMan{"upgradewallet",
526 "\nUpgrade the wallet. Upgrades to the latest version if no version number is specified.\n"
527 "New keys may be generated and a new wallet backup will need to be made.",
528 {
529 {"version", RPCArg::Type::NUM, RPCArg::Default{FEATURE_LATEST}, "The version number to upgrade to. Default is the latest wallet version."}
530 },
531 RPCResult{
532 RPCResult::Type::OBJ, "", "",
533 {
534 {RPCResult::Type::STR, "wallet_name", "Name of wallet this operation was performed on"},
535 {RPCResult::Type::NUM, "previous_version", "Version of wallet before this operation"},
536 {RPCResult::Type::NUM, "current_version", "Version of wallet after this operation"},
537 {RPCResult::Type::STR, "result", /*optional=*/true, "Description of result, if no error"},
538 {RPCResult::Type::STR, "error", /*optional=*/true, "Error message (if there is one)"}
539 },
540 },
541 RPCExamples{
542 HelpExampleCli("upgradewallet", "169900")
543 + HelpExampleRpc("upgradewallet", "169900")
544 },
545 [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
546{
547 std::shared_ptr<CWallet> const pwallet = GetWalletForJSONRPCRequest(request);
548 if (!pwallet) return NullUniValue;
549
550 RPCTypeCheck(request.params, {UniValue::VNUM}, true);
551
552 EnsureWalletIsUnlocked(*pwallet);
553
554 int version = 0;
555 if (!request.params[0].isNull()) {
556 version = request.params[0].get_int();
557 }
558 bilingual_str error;
559 const int previous_version{pwallet->GetVersion()};
560 const bool wallet_upgraded{pwallet->UpgradeWallet(version, error)};
561 const int current_version{pwallet->GetVersion()};
562 std::string result;
563
564 if (wallet_upgraded) {
565 if (previous_version == current_version) {
566 result = "Already at latest version. Wallet version unchanged.";
567 } else {
568 result = strprintf("Wallet upgraded successfully from version %i to version %i.", previous_version, current_version);
569 }
570 }
571
572 UniValue obj(UniValue::VOBJ);
573 obj.pushKV("wallet_name", pwallet->GetName());
574 obj.pushKV("previous_version", previous_version);
575 obj.pushKV("current_version", current_version);
576 if (!result.empty()) {
577 obj.pushKV("result", result);
578 } else {
579 CHECK_NONFATAL(!error.empty());
580 obj.pushKV("error", error.original);

Callers

nothing calls this directly

Calls 12

HelpExampleCliFunction · 0.85
HelpExampleRpcFunction · 0.85
RPCTypeCheckFunction · 0.85
EnsureWalletIsUnlockedFunction · 0.85
get_intMethod · 0.80
UpgradeWalletMethod · 0.80
isNullMethod · 0.45
GetVersionMethod · 0.45
pushKVMethod · 0.45
GetNameMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected