docs: show example migration from bdk to bdk_wallet
I created a migration workflow in the form of a runnable example that does everything in one go. In the example we
- Open an existing sled db
- Get the last revealed addresses
- Create a new
bdk_wallet::Walletwith new database - Restore previously revealed addresses
- Sync with electrum
I also provide commentary around special considerations including how signers can be transferred and why it's necessary to do a full scan. One scenario that might be difficult to show with this example is how to migrate from an old sqlite-backed wallet to a new wallet that also uses sqlite due to conflicting versions of libsqlite3-sys in the same crate
*UPDATED example code to use sqlite instead of sled, but it's waiting for a release with the changes from #1651
candidate for solving #1606
Changelog notice
Checklists
All Submissions:
- [x] I've signed all my commits
- [x] I followed the contribution guidelines
- [x] I ran
cargo fmtandcargo clippybefore committing
Looks good, simpler and safer than dealing directly with database or intermediate text files as I'd originally proposed. A few suggestions:
- would read better with more descriptive variable names, ie.
old_wallet,new_wallet - should add sanity check asserts after sync for things like balances, indexes; maybe also utxos and tx ids.
- need to update PR description with sqlite instead of sled
- make it clearer in code comments that you're opening an "old" (will be) 0.30 wallet and a "new" 1.0 wallet
I tested this by first syncing a bdk wallet using electrum_backend.rs, adapted to use this tprv
tprv8ZgxMBicQKsPdy6LMhUtFHAgpocR8GC6QmwMSFpZs7h6Eziw3SpThFfczTDh5rW2krkqffa11UpX3XkeTTB2FvzZKWXqPY54Y6Rq4AQ5R8L
and persisted with sqlite. Then I ran the example in this PR, initializing BDK_DB_PATH to the old db path.
should add sanity check asserts after sync for things like balances, indexes; maybe also utxos and tx ids
I added assertions for utxos, balance, and revealed addresses. Just to note: this assumes the old database is up to date and no new information is presented as a result of syncing the new wallet.
I'm wondering whether example-crates/ is the best place for this compared to maybe a page in Book of BDK - I guess either is fine
Yes I agree it might make a better book section with companion code to take snippets from.
Maintenance version v0.30.0 of bdk crate with upgrade to rusqlite 0.31 is now published:
https://crates.io/crates/bdk/0.30.0
Overall looks great, short and too the point. I have a couple suggestions but otherwise this looks ready to go.
As discussed on call today, this can be closed in favor of bitcoindevkit/book-of-bdk#81. That PR is already using sync instead of full_scan and I understand and agree it's best to use AddressIndex::LastUnused.