Add get_pre_1_wallet_keychains migration helper#364
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #364 +/- ##
==========================================
+ Coverage 86.75% 86.78% +0.02%
==========================================
Files 25 26 +1
Lines 8479 8551 +72
==========================================
+ Hits 7356 7421 +65
- Misses 1123 1130 +7
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
4751fac to
366ca7a
Compare
|
Part of this PR (rather a sidequest to this PR) could include updating the Migrating from 0.X page on the book of bdk, since this approach is simpler and requires less code, and I think it could simply supercede what we have there (or at least be added as a secondary section/option). Also would be great to add a small feature page on the Release Guide when we do push the 2.4 section of the Release Guide. I keep track of the features I think should be highlighted here. |
|
Two things I'd like to clarify maybe:
|
The only sqlite tables this function uses is
Unfortunately pre-1.0 we did not persist the descriptor string in the sqlite db, all wallet constructors required you pass in your descriptor(s), see: pre-1.0 Wallet docs. All we have in the pre-1.0 sqlite db are the descriptor checksums. |
| // Create pre-1.0 bdk sqlite schema | ||
| conn.execute_batch( | ||
| "CREATE TABLE last_derivation_indices (keychain TEXT, value INTEGER); | ||
| CREATE UNIQUE INDEX idx_indices_keychain ON last_derivation_indices(keychain); |
There was a problem hiding this comment.
Just a nit, feel free to ignore:
Do we need to create an index on the keychain column?
There was a problem hiding this comment.
Agreed probably don't need it for this test, but I'll leave it since it's copy/paste from pre-1.0 schema sqlite.
|
TACK 366ca7a Tested by running the following in use bdk_wallet::rusqlite::{self, Connection};
fn main() -> rusqlite::Result<()> {
let mut conn = Connection::open("/home/codingp110/pre-1_wallet/.bdk_db.sqlite")?;
let external_checksum = "1cead456".as_bytes();
let internal_checksum = "1cead454".as_bytes();
let result = bdk_wallet::migration::get_pre_1_wallet_keychains(&mut conn)?;
assert_eq!(result.len(), 2);
assert_eq!(result[0].keychain, "External");
assert_eq!(result[0].last_derivation_index, 1337);
assert_eq!(result[0].checksum, external_checksum);
assert_eq!(result[1].keychain, "Internal");
assert_eq!(result[1].last_derivation_index, 68);
assert_eq!(result[1].checksum, internal_checksum);
println!("Successful");
Ok(())
}and use bdk::database::SqliteDatabase;
use bdk::database::{BatchOperations, Database};
use bdk::KeychainKind;
fn main() {
let mut db = SqliteDatabase::new(String::from("./.bdk_db.sqlite"));
db.set_last_index(KeychainKind::External, 1337).unwrap();
db.set_last_index(KeychainKind::Internal, 68).unwrap();
db.check_descriptor_checksum(KeychainKind::External, "1cead456".as_bytes());
db.check_descriptor_checksum(KeychainKind::Internal, "1cead454".as_bytes());
} |
366ca7a to
80276fc
Compare
|
Rebased on |
|
Code review ACK |
f19c6fb feat[rusqlite]: add get_pre_1_wallet_keychains migration helper (Steve Myers) Pull request description: ### Description Add `wallet/migration` module and `get_pre_1_wallet_keychains()` to help migrate users from a pre-1.0 bdk sqlite database. This new function returns the last revealed index and checksum value for each keychain it finds. ### Notes to the reviewers This is a backport to the `release/2.x` branch of #364. ### Changelog notice * Add `get_pre_1_wallet_keychains` to assist migration from pre-1.0 bdk wallets. (back ported from 3.x) ### Checklists #### All Submissions: * [x] I've signed all my commits * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md) * [x] I ran `just p` before pushing #### New Features: * [x] I've added tests for the new feature * [x] I've added docs for the new feature ACKs for top commit: thunderbiscuit: Tested ACK f19c6fb. 110CodingP: ACK [f19c6fb](f19c6fb) Tree-SHA512: 48ec320871361bc041020efdbdcfbdf7acd9d80700c5b35c933868424edb3fef8bae3a39491c722f619aeefe36456b42ac78626a758847ff9de566baae2456b4
Description
Add
wallet/migrationmodule andget_pre_1_wallet_keychains()to help migrate users from a pre-1.0 bdk sqlite database. This new function returns the last revealed index and checksum value for each keychain it finds.Notes to the reviewers
This PR replaces bitcoindevkit/bdk#2090 since make more sense to put it in the wallet where it will be easier to export the bindings.
Changelog notice
get_pre_1_wallet_keychainsto assist migration from pre-1.0 bdk wallets.Checklists
All Submissions:
just pbefore pushingNew Features: