From f4863c6314904ddd5da586fed0abb8f04ccee396 Mon Sep 17 00:00:00 2001 From: thunderbiscuit Date: Tue, 19 Dec 2023 16:05:01 -0500 Subject: [PATCH] fix(wallet): apply loaded changeset to indexed_graph --- crates/bdk/src/wallet/mod.rs | 4 +++- crates/bdk/tests/wallet.rs | 19 +++++++++++++------ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/crates/bdk/src/wallet/mod.rs b/crates/bdk/src/wallet/mod.rs index e945484dd..873af72b2 100644 --- a/crates/bdk/src/wallet/mod.rs +++ b/crates/bdk/src/wallet/mod.rs @@ -517,7 +517,9 @@ impl Wallet { create_signers(&mut index, &secp, descriptor, change_descriptor, network) .map_err(LoadError::Descriptor)?; - let indexed_graph = IndexedTxGraph::new(index); + let mut indexed_graph = IndexedTxGraph::new(index); + indexed_graph.apply_changeset(changeset.indexed_tx_graph); + let persist = Persist::new(db); Ok(Wallet { diff --git a/crates/bdk/tests/wallet.rs b/crates/bdk/tests/wallet.rs index 4fa399d86..6efb0d791 100644 --- a/crates/bdk/tests/wallet.rs +++ b/crates/bdk/tests/wallet.rs @@ -71,19 +71,26 @@ fn load_recovers_wallet() { let file_path = temp_dir.path().join("store.db"); // create new wallet - let wallet_keychains = { + let wallet_spk_index = { let db = bdk_file_store::Store::create_new(DB_MAGIC, &file_path).expect("must create db"); - let wallet = - Wallet::new(get_test_wpkh(), None, db, Network::Testnet).expect("must init wallet"); - wallet.keychains().clone() + let mut wallet = Wallet::new(get_test_tr_single_sig_xprv(), None, db, Network::Testnet) + .expect("must init wallet"); + + wallet.try_get_address(New).unwrap(); + wallet.spk_index().clone() }; // recover wallet { let db = bdk_file_store::Store::open(DB_MAGIC, &file_path).expect("must recover db"); - let wallet = Wallet::load(get_test_wpkh(), None, db).expect("must recover wallet"); + let wallet = + Wallet::load(get_test_tr_single_sig_xprv(), None, db).expect("must recover wallet"); assert_eq!(wallet.network(), Network::Testnet); - assert_eq!(wallet.spk_index().keychains(), &wallet_keychains); + assert_eq!(wallet.spk_index().keychains(), wallet_spk_index.keychains()); + assert_eq!( + wallet.spk_index().last_revealed_indices(), + wallet_spk_index.last_revealed_indices() + ); } }