feat: minimal sweep WIF QR-code implementation#53
Conversation
|
@psychemist Hi thanks for the PR. Not quite sure we want to add a WIF feature for the sample app. IMO adding WIF is a big jump from where the wallet is atm. @thunderbiscuit might have a different opinion. Don't mind me asking, what was your rationale the for adding WIF ? are you use in your projects somewhere? |
|
have a contributor who added it for BDK iOS bitcoindevkit/BDKSwiftExampleWallet#355 so let me know if we're doing anything different from ya'll here if you do add it |
|
@ItoroD i saw the contribution on the iOS repo so i thought it would be a nice addition here. unfortunately, i thought about raising the issue AFTER i was done building |
Ahhh I see! Thanks for the input. |
No worries! When I saw camera permissions and QR scanning I had to look a little harder. I know IOS has been using those for a while already. I think we do not even have camera scanning for QR anywhere yet not even for scanning addresses. Probably good to start now. I will run the test and do a proper review. |
| DwLogger.log(INFO, "Sweep started for WIF $shortWif (length=${wif.length}) on ${wallet.network()}") | ||
| DwLogger.log(INFO, "Esplora endpoint: ${getClientEndpoint()}") | ||
|
|
||
| val candidates = listOf( |
There was a problem hiding this comment.
Currently, errors are rightfully thrown when we pass an uncompressed key because uncompressed will only work for legacy pkh script. Maybe we want to determine if the key is compressed or uncompressed and that will help us determine what to put as the candidates. pkh for uncompressed then the rest if compressed.
Maybe a helper function in WifParser can help tell us if isCompressed here.
thunderbiscuit
left a comment
There was a problem hiding this comment.
My only comment on this PR is that it's a bit outside the scope of what this wallet is about IMO (you need to create a completely new wallet for the sweep, etc.). Don't get me wrong, it's a pretty cool feature, but also it's something you'd like in a real wallet, and maybe not as useful here. I don't know a lot of users who go through that workflow of scanning and emptying WIFs, and it's adding a bit more bloat in places where I would rather keep the app clean.
Mind you I know this is super arbitrary and we are merging other stuff that might look just as off the beaten path I'm not sure (maybe depends on where you stand), but to me this one is a bit more work to maintain than is worth.
|
@thunderbiscuit i built this because i had a valid use case while building a related project: consolidating test faucet coins littered around many random addresses into one wallet. i also thought it was in line with the project's README: showcasing advanced BDK APIs for developers. the sweep demonstrates single-key WIF descriptors, ephemeral wallets, and drainWallet/drainTo re: bloat, i limited all changes to only corresponding code sections, created separate modules for the scanner, etc. and wrote isolated test files. i can also pull the sweep logic out of Wallet.kt into an independent WifSweeper so the core wallet stays clean |
Description
This PR adds the ability to sweep funds from an external WIF private key into the user's wallet by scanning a QR code or copy-pasting the raw WIF string.
What This Does
raw WIF,wif: prefix, andbitcoin:?wif= URIformatsFlow
Testing
Unit tests (JVM, no device needed)
./gradlew :app:testDebugUnitTestInstall on device/emulator
./gradlew installDebugManual: send testnet4 coins to the wpkh address derived from a test WIF then sweep. Check in-app logs for balance details per descriptor.
Check out test sweep transaction on testnet4 here:
Screenshots