Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: show example migration from bdk to bdk_wallet #1648

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ValuedMammal
Copy link
Contributor

@ValuedMammal ValuedMammal commented Oct 15, 2024

I created a migration workflow in the form of a runnable example that does everything in one go. In the example we

  1. Open an existing sqlite db
  2. Get the last revealed addresses
  3. Create a new bdk_wallet::Wallet with new database
  4. Restore previously revealed addresses
  5. Sync with electrum

*UPDATED example code to use sqlite instead of sled, but it's waiting for a release with the changes from #1651

fixes #1606

Changelog notice

Checklists

All Submissions:

  • I've signed all my commits
  • I followed the contribution guidelines
  • I ran cargo fmt and cargo clippy before committing

@notmandatory
Copy link
Member

Looks good, simpler and safer than dealing directly with database or intermediate text files as I'd originally proposed. A few suggestions:

  1. would read better with more descriptive variable names, ie. old_wallet, new_wallet
  2. should add sanity check asserts after sync for things like balances, indexes; maybe also utxos and tx ids.
  3. need to update PR description with sqlite instead of sled
  4. make it clearer in code comments that you're opening an "old" (will be) 0.30 wallet and a "new" 1.0 wallet

@ValuedMammal ValuedMammal marked this pull request as draft October 22, 2024 20:04
@ValuedMammal
Copy link
Contributor Author

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

@notmandatory
Copy link
Member

Yes I agree it might make a better book section with companion code to take snippets from.

@notmandatory notmandatory removed this from the 1.0.0-beta milestone Nov 21, 2024
@notmandatory
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

Create wallet data migration process
2 participants