Skip to content

docs(wallet): add sync operation to bdk_wallet examples #274

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

tvpeter
Copy link
Contributor

@tvpeter tvpeter commented Jun 30, 2025

Description

This PR adds sync operation to bdk_wallet examples for electrum and esplora clients.

Fixes #253

Checklists

All Submissions:

@tvpeter tvpeter changed the title docs(wallet): add sync operation to bdk_wallet examples for electrum and esplora docs(wallet): add sync operation to bdk_wallet examples Jun 30, 2025
@coveralls
Copy link

coveralls commented Jun 30, 2025

Pull Request Test Coverage Report for Build 16172743430

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 84.733%

Totals Coverage Status
Change from base Build 16052072493: 0.0%
Covered Lines: 6577
Relevant Lines: 7762

💛 - Coveralls

@notmandatory notmandatory added the documentation Improvements or additions to documentation label Jul 1, 2025
@notmandatory notmandatory moved this to Needs Review in BDK Wallet Jul 1, 2025
@notmandatory notmandatory added this to the Wallet 2.1.0 milestone Jul 1, 2025
Copy link
Contributor

@oleonardolima oleonardolima left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cACK 8e1a6ef

I left a few comments that I think are applicable. Also, I was unable to test the electrum example locally (I guess it's a local problem on my end).

I think it's a good opportunity to also add a forced eviction, and show that to the user. WDYT?

Any reason to not add the sync usage to blocking esplora example ?

client.populate_tx_cache(wallet.tx_graph().full_txs().map(|tx_node| tx_node.tx));

let sync_update = client.sync(sync_request, BATCH_SIZE, false)?;
wallet.apply_update(sync_update)?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's a good idea to also persist here. wdyt ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yes, I will do that. Thank you!

.inspect(|sync_item, sync_progress| {
let progress_percent =
(100 * sync_progress.consumed()) as f32 / sync_progress.total() as f32;
eprintln!("[ SCANNING {:03.0}%] {}", progress_percent, sync_item)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good! I personally think this approach is good, but I'm wondering if it's too verbose.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay

@@ -92,5 +97,29 @@ fn main() -> Result<(), anyhow::Error> {
client.transaction_broadcast(&tx)?;
println!("Tx broadcasted! Txid: {}", tx.compute_txid());

println!("=== Performing Partial Sync ===");
std::io::stdout().flush().expect("must flush");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this strictly needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do think so because the progress update may appear before the performing partial sync message if it is not flushed (when using eprintln). I will update this, so it is consistent.

@tvpeter
Copy link
Contributor Author

tvpeter commented Jul 2, 2025

I think it's a good opportunity to also add a forced eviction, and show that to the user. WDYT?

Alright, I will do that.

Any reason to not add the sync usage to blocking esplora example ?

No reason, I will also add that.

Thank you for the review. I will make updates.

@tvpeter tvpeter force-pushed the doc/wallet-sync-example branch 3 times, most recently from 98cb6b9 to 4130f46 Compare July 4, 2025 11:15
@tvpeter
Copy link
Contributor Author

tvpeter commented Jul 4, 2025

I think it's a good opportunity to also add a forced eviction, and show that to the user. WDYT?

Alright, I will do that.

I have added the eviction logic that identifies transactions that were unconfirmed before a partial sync but are no longer canonical after the sync.

Any reason to not add the sync usage to blocking esplora example ?

No reason, I will also add that.

I have also added the sync to the esplora blocking example.

Another thing I considered was reducing the output of the full scan by a multiple of say 5 or 10 as it is getting lengthy.

@tvpeter tvpeter requested a review from oleonardolima July 4, 2025 11:37
tvpeter added 2 commits July 9, 2025 15:53
- add partial syncing to electrum, esplora_async
and esplora_blocking examples
- add applying evicted txns to wallet in electrum,
esplora_async and esplora_blocking examples
@tvpeter tvpeter force-pushed the doc/wallet-sync-example branch from 4130f46 to 50dacbf Compare July 9, 2025 14:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
Status: Needs Review
Development

Successfully merging this pull request may close these issues.

Missing bdk_wallet examples with sync
4 participants