Skip to content

Import exportwatchonly wallet #539

Description

@110CodingP

Describe the enhancement

BDK Wallet should be able to import (watch-only) wallet created by the new exportwatchonly rpc.

Use case

Applications using bdk_wallet would be able to easily and efficiently import a Bitcoin Core Wallet.

Impact

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

Are you using BDK in a production project?

  • Yes
  • No
  • Not yet, but planning to

Which backend(s) are relevant (if any)?

  • Electrum
  • Esplora
  • Bitcoin Core RPC
  • None / not backend-related (e.g. bdk_chain, bdk_core)
  • Other (please specify): ____

Project or organization (optional)

Additional context

The exported wallet has the same format as a regular Bitcoin Core Wallet just without private keys (and hence WALLET_FLAG_DISABLE_PRIVATE_KEYS flag enabled). Therefore it consists of
a Sqlite table (called main) with two columns (key and value). Both the columns have the
BLOB type.

PRAGMA Value Corresponding BDK Structure
"application_id" Network Magic as string Network
"user_version" Sqlite Schema Version (0) KeyRing(?) (Required for Round Trip)

Sqlite Table:

Key Value Corresponding BDK Structure
"version" Bitcoin Core Client Version (u32) KeyRing(?) (Required for Round Trip)
"flags" Wallet Flags Bitmask (u64) KeyRing(?) (Required for Round Trip)
("walletdescriptor", descriptorid) WalletDescriptor Keyring
("activeexternalspk", output_type) descriptorid KeyRing/Wallet
("activeinternalspk", output_type) descriptorid KeyRing/Wallet
(("walletdescriptorcache", descriptorid), expression_index) CExtPubKey N/A (Construct for round trip)
(("walletdescriptorcache", descriptorid), (expression_index, der_index)) CExtPubKey N/A (Construct for round trip)
(("walletdescriptorlhcache", descriptorid), expression_index ) CExtPubKey N/A(Contruct for round trip)
("tx", txid) CWalletTx Tx_graph
("wtxvariant",(txid, wtxid)) CTransaction Tx_graph
("lockedutxo" , (txid, vout)) 0x31 Currently no structure/Locked Outpoints in Wallet finally?
"bestblock_nomerkle" CBlockLocator LocalChain
"bestblock" CBlockLocator(Empty) N/A (Construct for round trip)
"orderposnext" u64 ?
("purpose", address-string) Purpose-string Need Labels
("name", address-string) Label-string Need Labels
("destdata",(address-string, "rr"+ id-string)) Bip21-request-string Need Labels
("destdata", (address-string, "used")) 0x31 Need Labels

Points to note:

  • Strings are serialized with a CompactSize length prefix.
  • Tuples and Pairs (e.g., std::make_pair(A, B)) are serialized simply by serializing A immediately followed by B.
  • descriptorid is a u256
  • output_type is a u8
  • The descriptor cache has 3 variants:
    • m_parent_xpubs: Cache of XPubs just before the wildcard level (if the wildcard is not hardened).
    • m_last_hardened_xpubs: Cache of XPubs at the last hardened level (if the wildcard is not hardened and if there is any hardened level).
    • m_derived_xpubs: Cache of XPubs at the wildcard level in case the wildcard is hardened.
  • expression_index is the position of the key in the descriptor.
  • der_index is needed when
  • txid and wtxid are u256
  • CWalletTx also contains the blockhash the tx is anchored at, the position of the tx in the block and the time at which the tx was received by node (could be the first_seen).
  • wtxvariant are the (currently) non-canonical versions of the Tx which have different wtxid.
  • vout is a u32.
  • How do we remember the nOrderPos corresponding to each transaction?
  • id-string is the Bitcoin Wallet's internal enumeration of the Bip21 requests for the address.

This needs #524 and #168 .

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    new featureNew feature or request

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions