Skip to content

feat: add one-liner wallet sync API with ElectrumSync#2094

Closed
ShigrafS wants to merge 4 commits intobitcoindevkit:masterfrom
ShigrafS:api
Closed

feat: add one-liner wallet sync API with ElectrumSync#2094
ShigrafS wants to merge 4 commits intobitcoindevkit:masterfrom
ShigrafS:api

Conversation

@ShigrafS
Copy link

Closes #1974

Description

This PR introduces a small, focused helper abstraction to reduce the boilerplate required to synchronize a wallet index with an Electrum server, addressing the usability concerns raised in #1974.

The main addition is the ElectrumSync helper and SyncOptions, which wrap existing SyncRequest and FullScanRequest flows into a single, ergonomic call while preserving the existing BdkElectrumClient cache and behavior.

Concretely, this PR:

  • Adds ElectrumSync, a lightweight helper for performing Electrum syncs using a shared BdkElectrumClient
  • Introduces SyncOptions to configure fast sync vs full scan, stop gap, batch size, and prevout fetching
  • Exports the helper from bdk_electrum for reuse
  • Adds an example demonstrating a “one-liner” full scan and fast sync using public Electrum servers

The helper is intentionally minimal and builds directly on top of existing BDK primitives without introducing a new builder API or altering wallet abstractions.


Notes to the reviewers

This PR is informed by the feedback and architectural concerns raised in #2059.

In particular:

  • The helper preserves the BdkElectrumClient and its cache across sync calls, avoiding the performance regressions discussed previously.
  • The API is intentionally small and avoids introducing a fluent/builder-style abstraction that would expand the public surface area.
  • The helper does not mutate wallet state; instead, it returns the existing chain and transaction updates so that application code remains in control of how updates are applied.

The goal of this PR is to provide a convenience layer that demonstrates a simplified sync flow while remaining close to existing abstractions.
Feedback on whether this belongs as a public helper or should instead live purely as an example is very welcome.


Changelog notice

  • Added ElectrumSync and SyncOptions helpers to simplify Electrum wallet synchronization
  • Added an example demonstrating one-liner Electrum sync usage

Checklists

All Submissions:

New Features:

  • I've added tests for the new feature
  • I've added docs for the new feature

Bugfixes:

Signed-off-by: ShigrafS <shigrafsalik@proton.me>
Signed-off-by: ShigrafS <shigrafsalik@proton.me>
@ShigrafS ShigrafS requested a review from evanlinjin January 17, 2026 17:42
@ShigrafS ShigrafS marked this pull request as ready for review January 18, 2026 03:52
@ShigrafS
Copy link
Author

The PR is ready for review.
The tests are passing locally.

@evanlinjin
Copy link
Member

Where exactly is the "small, focused helper abstraction"? You changed nothing of relevance in the bdk_electrum crate.

There is a whole lot of unrelated changes - I'm assuming this is an attempt at making thing run/compile on windows? This does not belong in this PR - feel free to create a new PR for these changes.

@ShigrafS
Copy link
Author

Fixed it.

@evanlinjin
Copy link
Member

@ShigrafS the "one liner helper" is currently an example and not part of the library.

@ShigrafS
Copy link
Author

@evanlinjin I was thinking this fits right within the scope of the issue with respect to the last PR.
If it makes sense to evolve it into a lightweight public API , should I proceed with that?

@thunderbiscuit
Copy link
Member

This PR doesn't add a 1-liner API to the bdk_electrum crate, nor does it make sense to add one IMO. I think the core issue is that we kept #1974 open when it should not be. Worse, we added a good-first-issue to it which draws in people when it's a fool's errand (sorry @ShigrafS! this is totally not your fault, I mean no offence at all). We're on the second PR on this, and honestly it just feels like it's wasting everyone's time.

My suggestion is to either:

  1. Close Provide a one liner to sync with electrum #1974 (preferred).
  2. If for whatever reason people feel strongly about this sort of thing which (in my opinion) belongs as code at the application-level not the library level, at most a single example could be added that would show how to do it. @ShigrafS your PR impacts 8 files when it should only create 1.

@ShigrafS
Copy link
Author

ShigrafS commented Feb 2, 2026

@evanlinjin @thunderbiscuit @luisschwab

Thanks for the feedback so far. Based on @evanlinjin’s comment [here]) and the discussion in this thread, I’ll be reducing the scope of this PR to an example-only implementation demonstrating a one-liner Electrum wallet sync. This keeps it safe, minimal, and in line with current BDK library constraints.

Given that this example fully demonstrates the intended functionality from #1974, I’d suggest we close the original issue, as adding it to the library API is beyond the scope of the repo at present.

I’ll update the PR accordingly to reflect the example-only version.

Thanks!

Reverts library API changes and consolidates one-liner sync logic into a single self-contained example in examples/example_electrum.

Changes:

- Revert public API additions in bdk_electrum

- Remove test_api_compatibility

- Remove separate example_one_liner crate

- Add ElectrumSync helper to examples/example_electrum/src/bin/one_liner_sync.rs

Signed-off-by: ShigrafS <shigrafsalik@proton.me>
… example

This commit also reverts accidental changes to crates/electrum/src/lib.rs and crates/electrum/Cargo.toml to ensure no library API changes are introduced.

Signed-off-by: ShigrafS <shigrafsalik@proton.me>
@evanlinjin
Copy link
Member

NACK

Thanks for trying to contribute, but I still don't see the value in this.

@ShigrafS
Copy link
Author

ShigrafS commented Feb 7, 2026

@evanlinjin
Thanks for the feedback and for taking the time to review this.

Given the consensus that this doesn’t belong in the BDK repo, I’ll close the PR.
Appreciate the guidance.

@ShigrafS ShigrafS closed this Feb 7, 2026
@github-project-automation github-project-automation bot moved this to Done in BDK Chain Feb 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Provide a one liner to sync with electrum

3 participants