feat: minimal sweep WIF QR implementation#355
feat: minimal sweep WIF QR implementation#355otaliptus wants to merge 6 commits intobitcoindevkit:mainfrom
Conversation
|
Will review this, added myself. But if @r1b2ns or @Aniket-pd or anyone else wants to review feel free. |
| continue | ||
| } | ||
|
|
||
| let psbt = try TxBuilder() |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
Aniket-pd
left a comment
There was a problem hiding this comment.
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)" |
There was a problem hiding this comment.
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.
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:
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:
.swift-formatfileNew Features: