Skip to content

Commit

Permalink
fix: use sync instead of scan in migrate-version
Browse files Browse the repository at this point in the history
  • Loading branch information
ValuedMammal committed Dec 8, 2024
1 parent 750eaaa commit 5cee1e6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
6 changes: 3 additions & 3 deletions docs/getting-started/migrating.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ This is important because without that metadata the new wallet may end up reusin
1. Create new wallet
1. Restore revealed addresses
1. Write to new database
1. Rescan (recommended)
1. Sync

<!-- overview -->
```rust title="examples/rust/migrate-version/src/main.rs"
Expand Down Expand Up @@ -74,8 +74,8 @@ If the given descriptors contain secret keys, then the wallet will be able to si
```

<!-- sync -->
Now that we have a new database and have properly restored our addresses, you'll likely want to rescan the blockchain to recover the wallet's transactions.
Below is an example of doing a `full_scan` using `bdk_esplora` but the exact method of syncing will depend on your application.
Now that we have a new database and have properly restored our addresses, you will want to sync with the blockchain to recover the wallet's transactions.
Below is an example of doing a `sync` using `bdk_esplora` but the exact method of syncing will depend on your application.
Happy migrating and see you on [v1.0][1]!

```rust title="examples/rust/migrate-version/src/main.rs"
Expand Down
21 changes: 10 additions & 11 deletions examples/rust/migrate-version/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,18 @@ use bdk_esplora::{esplora_client, EsploraExt};
let client = esplora_client::Builder::new(ESPLORA_URL).build_blocking();
let request = wallet.start_full_scan().inspect({
let mut stdout = std::io::stdout();
let mut once = BTreeSet::<KeychainKind>::new();
move |keychain, spk_i, _| {
if once.insert(keychain) {
print!("\nScanning keychain [{:?}] ", keychain);
let request = wallet
.start_sync_with_revealed_spks()
.inspect(|item, prog| {
if let SyncItem::Spk(index, script) = item {
let address = Address::from_script(script, NETWORK).unwrap();
let progress = prog.consumed() as f32 / prog.total() as f32;
eprintln!("[ SYNCING {:.2}% ] {:?} {}", 100.0 * progress, index, address);
std::io::stdout().flush().unwrap();
}
print!(" {:<3}", spk_i);
stdout.flush().unwrap();
}
});
});
let update = client.full_scan(request, STOP_GAP, PARALLEL_REQUESTS)?;
let update = client.sync(request, PARALLEL_REQUESTS)?;
wallet.apply_update(update)?;
wallet.persist(&mut db)?;
Expand Down

0 comments on commit 5cee1e6

Please sign in to comment.