aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Chow <github@achow101.com>2022-11-28 17:03:35 -0500
committerfanquake <fanquake@gmail.com>2023-02-27 14:13:46 +0000
commit50dd8b13dfc070b550680617e76eff1c09af3a58 (patch)
treee2ae29b91ec12e63f77fcb3177e28c0b2d6e24a9
parent648b06256da65b4513977e351aabf3e5c06ce060 (diff)
downloadbitcoin-50dd8b13dfc070b550680617e76eff1c09af3a58.tar.xz
rpc: Allow users to specify wallet name for migratewallet
Github-Pull: #26595 Rebased-From: 6bdbc5ff590de18dfb47c31190baad879f68fef7
-rw-r--r--src/wallet/rpc/wallet.cpp25
1 files changed, 17 insertions, 8 deletions
diff --git a/src/wallet/rpc/wallet.cpp b/src/wallet/rpc/wallet.cpp
index a8896f5f93..2773a7ed59 100644
--- a/src/wallet/rpc/wallet.cpp
+++ b/src/wallet/rpc/wallet.cpp
@@ -711,7 +711,9 @@ static RPCHelpMan migratewallet()
"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." +
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::Type::OBJ, "", "",
{
@@ -728,17 +730,24 @@ static RPCHelpMan migratewallet()
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
{
std::string wallet_name;
- {
- std::shared_ptr<CWallet> wallet = GetWalletForJSONRPCRequest(request);
- if (!wallet) return NullUniValue;
-
- if (wallet->IsCrypted()) {
- throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, "Error: migratewallet on encrypted wallets is currently unsupported.");
+ if (GetWalletNameFromJSONRPCRequest(request, wallet_name)) {
+ if (!(request.params[0].isNull() || request.params[0].get_str() == wallet_name)) {
+ throw JSONRPCError(RPC_INVALID_PARAMETER, "RPC endpoint wallet and wallet_name parameter specify different wallets");
}
- 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);
+ {
+ 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);
if (!res) {