Skip to content

feat: minimal sweep WIF QR implementation#355

Open
otaliptus wants to merge 6 commits intobitcoindevkit:mainfrom
otaliptus:feat/wif-sweep-qr-minimal
Open

feat: minimal sweep WIF QR implementation#355
otaliptus wants to merge 6 commits intobitcoindevkit:mainfrom
otaliptus:feat/wif-sweep-qr-minimal

Conversation

@otaliptus
Copy link

@otaliptus otaliptus commented Feb 26, 2026

Description

This PR adds an example WIF sweep with a QR code (or copy-paste a raw WIF string). Given this is an example wallet app, I tried to keep the changes & functionality minimal.

The basic flow is as follows:

  1. Using a regular wallet address A, go to Send part (i.e. QR scan)
  2. Scan a WIF QR for B
  3. It detects all sweepable funds at B and broadcasts a transaction that sweeps the funds to A

Best way to test it is generating a WIF/address and sending some funds there, and sweeping it. Some example transactions on testnet4 can be seen here.

I can also send the WIF of some addresses to Discord, in case you want to try.

Notes to the reviewers

I've tried to work clean here but let me know if you have an alternative implementation/flow in mind please. Also tried to use as much as existing features from BDK & FFI, but open to suggestions.

Checklists

All Submissions:

New Features:

  • I've added tests for the new feature
  • I've added docs for the new feature
  • UI changes tested on small, medium, and large devices to ensure layout consistency

@reez reez self-requested a review February 26, 2026 14:56
@otaliptus otaliptus marked this pull request as ready for review February 26, 2026 16:33
@reez
Copy link
Collaborator

reez commented Feb 26, 2026

Will review this, added myself.

But if @r1b2ns or @Aniket-pd or anyone else wants to review feel free.

continue
}

let psbt = try TxBuilder()

Choose a reason for hiding this comment

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

sweepWif intentionally probes several descriptor candidates, but once one candidate has balance, any failure in finish, sign, or broadcast throws out of the whole method and prevents trying the remaining candidates. Since this is a heuristic multi-descriptor sweep, per-candidate failures should probably be isolated and skipped; otherwise one unspendable or unbroadcastable candidate can block sweeping funds from the actual matching descriptor shape.


Task {
do {
if self.looksLikeWif(self.words) {

Choose a reason for hiding this comment

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

This guard only checks whether the raw trimmed input itself looks like a WIF. In this same PR, the send flow accepts additional formats like wif:... and URI query params (?wif=...), so those values would still fall through wallet creation here instead of showing the sweep guidance. It would be safer to reuse the same parsing or normalization logic before calling looksLikeWif.

Copy link

@Aniket-pd Aniket-pd left a comment

Choose a reason for hiding this comment

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

Flagging three issues that look worth addressing before merge. I added inline comments for each one.

let txidText = txids.map { "\($0)" }.joined(separator: ", ")

await MainActor.run {
alertMessage = "Sweep broadcasted: \(txidText)"

Choose a reason for hiding this comment

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

This success branch sets "Sweep broadcasted: ...", but the alert shown above is still hard-coded to the title "Error". That means a successful sweep is presented as an error dialog. We should either restore a dynamic title or use a separate success presentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants