志宇 6b43001951
feat!: Rework sqlite, changesets, persistence and wallet-construction
Rework sqlite: Instead of only supported one schema (defined in
`bdk_sqlite`), we have a schema per changeset type for more flexiblity.

* rm `bdk_sqlite` crate (as we don't need `bdk_sqlite::Store` anymore).
* add `sqlite` feature on `bdk_chain` which adds methods on each
  changeset type for initializing tables, loading the changeset and
  writing.

Rework changesets: Some callers may want to use `KeychainTxOutIndex`
where `K` may change per descriptor on every run. So we only want to
persist the last revealed indices by `DescriptorId` (which uniquely-ish
identifies the descriptor).

* rm `keychain_added` field from `keychain_txout`'s changeset.
* Add `keychain_added` to `CombinedChangeSet` (which is renamed to
  `WalletChangeSet`).

Rework persistence: add back some safety and convenience when persisting
our types. Working with changeset directly (as we were doing before) can
be cumbersome.

* Intoduce `struct Persisted<T>` which wraps a type `T` which stores
  staged changes to it. This adds safety when creating and or loading
  `T` from db.
* `struct Persisted<T>` methods, `create`, `load` and `persist`, are
  avaliable if `trait PersistWith<Db>` is implemented for `T`. `Db`
  represents the database connection and `PersistWith` should be
  implemented per database-type.
* For async, we have `trait PersistedAsyncWith<Db>`.
* `Wallet` has impls of `PersistedWith<rusqlite::Connection>`,
  `PersistedWith<rusqlite::Transaction>` and
  `PersistedWith<bdk_file_store::Store>` by default.

Rework wallet-construction: Before, we had multiple methods for loading
and creating with different input-counts so it would be unwieldly to add
more parameters in the future. This also makes it difficult to impl
`PersistWith` (which has a single method for `load` that takes in
`PersistWith::LoadParams` and a single method for `create` that takes in
`PersistWith::CreateParams`).

* Introduce a builder pattern when constructing a `Wallet`. For loading
  from persistence or `ChangeSet`, we have `LoadParams`. For creating a
  new wallet, we have `CreateParams`.
2024-07-18 03:25:41 +00:00
..

Wallet RPC Example

$ cargo run --bin wallet_rpc -- --help

wallet_rpc 0.1.0
Bitcoind RPC example using `bdk_wallet::Wallet`

USAGE:
    wallet_rpc [OPTIONS] <DESCRIPTOR> [CHANGE_DESCRIPTOR]

ARGS:
    <DESCRIPTOR>           Wallet descriptor [env: DESCRIPTOR=]
    <CHANGE_DESCRIPTOR>    Wallet change descriptor [env: CHANGE_DESCRIPTOR=]

OPTIONS:
        --db-path <DB_PATH>
            Where to store wallet data [env: BDK_DB_PATH=] [default: .bdk_wallet_rpc_example.db]

    -h, --help
            Print help information

        --network <NETWORK>
            Bitcoin network to connect to [env: BITCOIN_NETWORK=] [default: testnet]

        --rpc-cookie <RPC_COOKIE>
            RPC auth cookie file [env: RPC_COOKIE=]

        --rpc-pass <RPC_PASS>
            RPC auth password [env: RPC_PASS=]

        --rpc-user <RPC_USER>
            RPC auth username [env: RPC_USER=]

        --start-height <START_HEIGHT>
            Earliest block height to start sync from [env: START_HEIGHT=] [default: 481824]

        --url <URL>
            RPC URL [env: RPC_URL=] [default: 127.0.0.1:8332]

    -V, --version
            Print version information