mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-22 15:04:44 +01:00
rpc: Allow users to specify wallet name for migratewallet
This commit is contained in:
parent
dbfa345403
commit
6bdbc5ff59
1 changed files with 17 additions and 8 deletions
|
@ -722,7 +722,9 @@ static RPCHelpMan migratewallet()
|
||||||
"file will be named <wallet name>-<timestamp>.legacy.bak and can be found in the directory\n"
|
"file will be named <wallet name>-<timestamp>.legacy.bak and can be found in the directory\n"
|
||||||
"for this wallet. In the event of an incorrect migration, the backup can be restored using restorewallet." +
|
"for this wallet. In the event of an incorrect migration, the backup can be restored using restorewallet." +
|
||||||
HELP_REQUIRING_PASSPHRASE,
|
HELP_REQUIRING_PASSPHRASE,
|
||||||
{},
|
{
|
||||||
|
{"wallet_name", RPCArg::Type::STR, RPCArg::DefaultHint{"the wallet name from the RPC endpoint"}, "The name of the wallet to migrate. If provided both here and in the RPC endpoint, the two must be identical."},
|
||||||
|
},
|
||||||
RPCResult{
|
RPCResult{
|
||||||
RPCResult::Type::OBJ, "", "",
|
RPCResult::Type::OBJ, "", "",
|
||||||
{
|
{
|
||||||
|
@ -739,17 +741,24 @@ static RPCHelpMan migratewallet()
|
||||||
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
|
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
|
||||||
{
|
{
|
||||||
std::string wallet_name;
|
std::string wallet_name;
|
||||||
{
|
if (GetWalletNameFromJSONRPCRequest(request, wallet_name)) {
|
||||||
std::shared_ptr<CWallet> wallet = GetWalletForJSONRPCRequest(request);
|
if (!(request.params[0].isNull() || request.params[0].get_str() == wallet_name)) {
|
||||||
if (!wallet) return NullUniValue;
|
throw JSONRPCError(RPC_INVALID_PARAMETER, "RPC endpoint wallet and wallet_name parameter specify different wallets");
|
||||||
|
|
||||||
if (wallet->IsCrypted()) {
|
|
||||||
throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, "Error: migratewallet on encrypted wallets is currently unsupported.");
|
|
||||||
}
|
}
|
||||||
wallet_name = wallet->GetName();
|
} else {
|
||||||
|
if (request.params[0].isNull()) {
|
||||||
|
throw JSONRPCError(RPC_INVALID_PARAMETER, "Either RPC endpoint wallet or wallet_name parameter must be provided");
|
||||||
|
}
|
||||||
|
wallet_name = request.params[0].get_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
WalletContext& context = EnsureWalletContext(request.context);
|
WalletContext& context = EnsureWalletContext(request.context);
|
||||||
|
{
|
||||||
|
std::shared_ptr<CWallet> wallet = GetWallet(context, wallet_name);
|
||||||
|
if (wallet && wallet->IsCrypted()) {
|
||||||
|
throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, "Error: migratewallet on encrypted wallets is currently unsupported.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
util::Result<MigrationResult> res = MigrateLegacyToDescriptor(wallet_name, context);
|
util::Result<MigrationResult> res = MigrateLegacyToDescriptor(wallet_name, context);
|
||||||
if (!res) {
|
if (!res) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue