mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-28 23:08:52 +01:00
Merge #15761: Replace -upgradewallet startup option with upgradewallet RPC
0d32d66148Remove -upgradewallet startup option (Andrew Chow)92263cce5bAdd upgradewallet RPC (Andrew Chow)1e48796c99Make UpgradeWallet a member function of CWallet (Andrew Chow)c988f27937Have UpgradeWallet take the version to upgrade to and an error message out parameter (Andrew Chow)1833237123Only run UpgradeWallet if the wallet needs to be upgraded (Andrew Chow)9c16b1735fMove wallet upgrading to its own function (Andrew Chow) Pull request description: `-upgradewallet` is largely incompatible with many recent wallet features and versions. For example, it was disabled if multiple wallets were used and would not work with encrypted wallets that were being upgraded to HD. This PR does away with the old method of upgrading upon startup and instead allows users to upgrade their wallets via an `upgradewallet` RPC. This does largely the same thing as the old `-upgradewallet` option but because the wallet is loaded, it can be unlocked to upgrade to HD. Furthermore it is compatible with multiwallet as it works on the individual wallet that is specified by the RPC. ACKs for top commit: meshcollider: Code review ACK0d32d66148darosior: ACK0d32d66148MarcoFalke: ACK0d32d66148🚵 Tree-SHA512: b425bf6f5d605e26506889d63c780895482f07cbc086193218e031e8504d3072d41e90d65cd41bcc98ee4c1eb048954bc5d4ac85435f7394892373aac89a3b0a
This commit is contained in:
@@ -2591,7 +2591,7 @@ static UniValue loadwallet(const JSONRPCRequest& request)
|
||||
RPCHelpMan{"loadwallet",
|
||||
"\nLoads a wallet from a wallet file or directory."
|
||||
"\nNote that all wallet command-line options used when starting bitcoind will be"
|
||||
"\napplied to the new wallet (eg -zapwallettxes, upgradewallet, rescan, etc).\n",
|
||||
"\napplied to the new wallet (eg -zapwallettxes, rescan, etc).\n",
|
||||
{
|
||||
{"filename", RPCArg::Type::STR, RPCArg::Optional::NO, "The wallet directory or .dat file."},
|
||||
},
|
||||
@@ -4017,7 +4017,7 @@ UniValue sethdseed(const JSONRPCRequest& request)
|
||||
|
||||
// Do not do anything to non-HD wallets
|
||||
if (!pwallet->CanSupportFeature(FEATURE_HD)) {
|
||||
throw JSONRPCError(RPC_WALLET_ERROR, "Cannot set a HD seed on a non-HD wallet. Start with -upgradewallet in order to upgrade a non-HD wallet to HD");
|
||||
throw JSONRPCError(RPC_WALLET_ERROR, "Cannot set a HD seed on a non-HD wallet. Use the upgradewallet RPC in order to upgrade a non-HD wallet to HD");
|
||||
}
|
||||
|
||||
EnsureWalletIsUnlocked(pwallet);
|
||||
@@ -4241,6 +4241,45 @@ UniValue walletcreatefundedpsbt(const JSONRPCRequest& request)
|
||||
return result;
|
||||
}
|
||||
|
||||
static UniValue upgradewallet(const JSONRPCRequest& request)
|
||||
{
|
||||
std::shared_ptr<CWallet> 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", "169900")
|
||||
+ HelpExampleRpc("upgradewallet", "169900")
|
||||
}
|
||||
}.Check(request);
|
||||
|
||||
RPCTypeCheck(request.params, {UniValue::VNUM}, true);
|
||||
|
||||
EnsureWalletIsUnlocked(pwallet);
|
||||
|
||||
int version = 0;
|
||||
if (!request.params[0].isNull()) {
|
||||
version = request.params[0].get_int();
|
||||
}
|
||||
|
||||
std::string error;
|
||||
std::vector<std::string> warnings;
|
||||
if (!pwallet->UpgradeWallet(version, error, warnings)) {
|
||||
throw JSONRPCError(RPC_WALLET_ERROR, error);
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
UniValue abortrescan(const JSONRPCRequest& request); // in rpcdump.cpp
|
||||
UniValue dumpprivkey(const JSONRPCRequest& request); // in rpcdump.cpp
|
||||
UniValue importprivkey(const JSONRPCRequest& request);
|
||||
@@ -4309,6 +4348,7 @@ static const CRPCCommand commands[] =
|
||||
{ "wallet", "signmessage", &signmessage, {"address","message"} },
|
||||
{ "wallet", "signrawtransactionwithwallet", &signrawtransactionwithwallet, {"hexstring","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"} },
|
||||
|
||||
Reference in New Issue
Block a user