Skip to content

Add Utility Function to Pull Relevant Data From Old BDK Database #361

@thunderbiscuit

Description

@thunderbiscuit

After discussing migrations from 0.X versions of BDK with users, I realize how hard it can appear to migrate from an old 0.X version of BDK to the new 2.X.

Our docs have a page on migrating but it does not describe a solution that's easy to implement, because it requires the application having access to 2 different versions of BDK at the same time, which very few apps in prod would/should ship with (uneccessary bloat).

After discussions over a dev call, @notmandatory suggested maybe adding a small utility method that would simply take an old BDK sqlite database and return the relevant data, which could then be used to ensure the new 2.X wallet reveals the correct addresses for example.

Old Schema

➜ sqlite3 bdk-wallet.sqlite ".tables"
checksums                sync_time                utxos
last_derivation_indices  transaction_details      version
script_pubkeys           transactions
➜ sqlite3 bdk-wallet.sqlite ".schema"
CREATE TABLE version (version INTEGER);
CREATE TABLE transactions (txid BLOB, raw_tx BLOB);
CREATE INDEX idx_txid ON transactions(txid);
CREATE TABLE last_derivation_indices (keychain TEXT, value INTEGER);
CREATE UNIQUE INDEX idx_indices_keychain ON last_derivation_indices(keychain);
CREATE TABLE checksums (keychain TEXT, checksum BLOB);
CREATE INDEX idx_checksums_keychain ON checksums(keychain);
CREATE TABLE sync_time (id INTEGER PRIMARY KEY, height INTEGER, timestamp INTEGER);
CREATE TABLE transaction_details (txid BLOB, timestamp INTEGER, received INTEGER, sent INTEGER, fee INTEGER, height INTEGER);
CREATE TABLE utxos (value INTEGER, keychain TEXT, vout INTEGER, txid BLOB, script BLOB, is_spent BOOLEAN DEFAULT 0);
CREATE UNIQUE INDEX idx_utxos_txid_vout ON utxos(txid, vout);
CREATE TABLE script_pubkeys (keychain TEXT, child INTEGER, script BLOB);
CREATE INDEX idx_keychain_child ON script_pubkeys(keychain, child);
CREATE INDEX idx_script ON script_pubkeys(script);
CREATE UNIQUE INDEX idx_script_pks_unique ON script_pubkeys(keychain, child);

Impact

  • Blocking production usage
  • Nice-to-have / UX improvement
  • Developer experience / maintainability

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions