Skip to content

Commit 3a9e9be

Browse files
committed
Add migratewallet method and test
Add the struct, client macro, reexports and test. No model is required, change the types table to `version`, update verify and remove TODO.
1 parent 976bb9e commit 3a9e9be

File tree

21 files changed

+78
-18
lines changed

21 files changed

+78
-18
lines changed

client/src/client_sync/v24/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ crate::impl_client_v18__list_wallet_dir!();
171171
crate::impl_client_v17__list_wallets!();
172172
crate::impl_client_v22__load_wallet!();
173173
crate::impl_client_v17__lock_unspent!();
174+
crate::impl_client_v24__migrate_wallet!();
174175
crate::impl_client_v23__new_keypool!();
175176
crate::impl_client_v21__psbt_bump_fee!();
176177
crate::impl_client_v17__remove_pruned_funds!();

client/src/client_sync/v24/wallet.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,18 @@
99
//!
1010
//! See or use the `define_jsonrpc_minreq_client!` macro to define a `Client`.
1111
12+
/// Implements Bitcoin Core JSON-RPC API method `migratewallet`.
13+
#[macro_export]
14+
macro_rules! impl_client_v24__migrate_wallet {
15+
() => {
16+
impl Client {
17+
pub fn migrate_wallet(&self, wallet_name: &str) -> Result<MigrateWallet> {
18+
self.call("migratewallet", &[wallet_name.into()])
19+
}
20+
}
21+
};
22+
}
23+
1224
/// Implements Bitcoin Core JSON-RPC API method `sendall`.
1325
#[macro_export]
1426
macro_rules! impl_client_v24__send_all {

client/src/client_sync/v25/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ crate::impl_client_v18__list_wallet_dir!();
170170
crate::impl_client_v17__list_wallets!();
171171
crate::impl_client_v22__load_wallet!();
172172
crate::impl_client_v17__lock_unspent!();
173+
crate::impl_client_v24__migrate_wallet!();
173174
crate::impl_client_v23__new_keypool!();
174175
crate::impl_client_v21__psbt_bump_fee!();
175176
crate::impl_client_v17__remove_pruned_funds!();

client/src/client_sync/v26/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ crate::impl_client_v18__list_wallet_dir!();
174174
crate::impl_client_v17__list_wallets!();
175175
crate::impl_client_v22__load_wallet!();
176176
crate::impl_client_v17__lock_unspent!();
177+
crate::impl_client_v24__migrate_wallet!();
177178
crate::impl_client_v23__new_keypool!();
178179
crate::impl_client_v21__psbt_bump_fee!();
179180
crate::impl_client_v17__remove_pruned_funds!();

client/src/client_sync/v27/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ crate::impl_client_v18__list_wallet_dir!();
170170
crate::impl_client_v17__list_wallets!();
171171
crate::impl_client_v22__load_wallet!();
172172
crate::impl_client_v17__lock_unspent!();
173+
crate::impl_client_v24__migrate_wallet!();
173174
crate::impl_client_v23__new_keypool!();
174175
crate::impl_client_v21__psbt_bump_fee!();
175176
crate::impl_client_v17__remove_pruned_funds!();

client/src/client_sync/v28/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ crate::impl_client_v18__list_wallet_dir!();
172172
crate::impl_client_v17__list_wallets!();
173173
crate::impl_client_v22__load_wallet!();
174174
crate::impl_client_v17__lock_unspent!();
175+
crate::impl_client_v24__migrate_wallet!();
175176
crate::impl_client_v23__new_keypool!();
176177
crate::impl_client_v21__psbt_bump_fee!();
177178
crate::impl_client_v17__remove_pruned_funds!();

client/src/client_sync/v29/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ crate::impl_client_v18__list_wallet_dir!();
172172
crate::impl_client_v17__list_wallets!();
173173
crate::impl_client_v22__load_wallet!();
174174
crate::impl_client_v17__lock_unspent!();
175+
crate::impl_client_v24__migrate_wallet!();
175176
crate::impl_client_v23__new_keypool!();
176177
crate::impl_client_v21__psbt_bump_fee!();
177178
crate::impl_client_v17__remove_pruned_funds!();

integration_test/tests/wallet.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,18 @@ fn wallet__lock_unspent() {
573573
assert!(json.0);
574574
}
575575

576+
#[cfg(not(feature = "v23_and_below"))]
577+
#[test]
578+
fn wallet__migrate_wallet() {
579+
let node = Node::with_wallet(Wallet::None, &["-deprecatedrpc=create_bdb"]);
580+
let wallet_name = "legacy_wallet";
581+
node.client.create_legacy_wallet(wallet_name).expect("createlegacywallet");
582+
583+
let json: MigrateWallet = node.client.migrate_wallet(wallet_name).expect("migratewallet");
584+
585+
assert_eq!(json.wallet_name, wallet_name);
586+
}
587+
576588
#[cfg(not(feature = "v22_and_below"))]
577589
#[test]
578590
fn wallet__new_keypool() {

types/src/v24/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@
193193
//! | listdescriptors | version | |
194194
//! | listlabels | version + model | UNTESTED |
195195
//! | listlockunspent | version + model | UNTESTED |
196-
//! | migratewallet | version + model | TODO |
196+
//! | migratewallet | version | |
197197
//! | newkeypool | returns nothing | |
198198
//! | psbtbumpfee | version + model | |
199199
//! | listreceivedbyaddress | version + model | UNTESTED |
@@ -258,7 +258,7 @@ pub use self::{
258258
},
259259
wallet::{
260260
GetTransaction, GetTransactionDetail, GetTransactionError, ListUnspent, ListUnspentItem,
261-
SendAll, SendAllError,
261+
MigrateWallet, SendAll, SendAllError,
262262
},
263263
};
264264
#[doc(inline)]

types/src/v24/wallet/mod.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,36 @@ pub struct ListUnspentItem {
167167
pub parent_descriptors: Option<Vec<String>>,
168168
}
169169

170+
/// Result of JSON-RPC method `migratewallet`.
171+
///
172+
/// > migratewallet ( "wallet_name" "passphrase" )
173+
/// >
174+
/// > EXPERIMENTAL warning: This call may not work as expected and may be changed in future releases
175+
/// >
176+
/// > Migrate the wallet to a descriptor wallet.
177+
/// > A new wallet backup will need to be made.
178+
/// >
179+
/// > The migration process will create a backup of the wallet before migrating. This backup
180+
/// > file will be named {wallet name}-{timestamp}.legacy.bak and can be found in the directory
181+
/// > for this wallet. In the event of an incorrect migration, the backup can be restored using restorewallet.
182+
/// > Encrypted wallets must have the passphrase provided as an argument to this call.
183+
/// >
184+
/// > Arguments:
185+
/// > 1. wallet_name (string, optional, default=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.
186+
/// > 2. passphrase (string) The wallet passphrase
187+
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
188+
#[serde(deny_unknown_fields)]
189+
pub struct MigrateWallet {
190+
/// The name of the primary migrated wallet
191+
pub wallet_name: String,
192+
/// The name of the migrated wallet containing the watchonly scripts
193+
pub watchonly_name: Option<String>,
194+
/// The name of the migrated wallet containing solvable but not watched scripts
195+
pub solvables_name: Option<String>,
196+
/// The location of the backup of the original wallet
197+
pub backup_path: String,
198+
}
199+
170200
/// Result of JSON-RPC method `sendall`.
171201
///
172202
/// > sendall ["address",{"address":amount,...},...] ( conf_target "estimate_mode" fee_rate options )

0 commit comments

Comments
 (0)