]> Untitled Git - bdk/commit
feat!: Rework sqlite, changesets, persistence and wallet-construction
author志宇 <hello@evanlinjin.me>
Thu, 11 Jul 2024 04:49:01 +0000 (04:49 +0000)
committer志宇 <hello@evanlinjin.me>
Thu, 18 Jul 2024 03:25:41 +0000 (03:25 +0000)
commit6b43001951db7738f788bcdbb46c8c1cd3e24a66
tree6594408308cc8f0a533fc5ff08aade6cb2b2eb60
parentd99b3ef4b449a5c7b8facf04db3cb9be829a0ac1
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`.
49 files changed:
Cargo.toml
crates/bitcoind_rpc/tests/test_emitter.rs
crates/chain/Cargo.toml
crates/chain/src/changeset.rs
crates/chain/src/indexed_tx_graph.rs
crates/chain/src/indexer/keychain_txout.rs
crates/chain/src/indexer/spk_txout.rs
crates/chain/src/lib.rs
crates/chain/src/local_chain.rs
crates/chain/src/persist.rs [new file with mode: 0644]
crates/chain/src/sqlite.rs [new file with mode: 0644]
crates/chain/src/tx_graph.rs
crates/chain/tests/common/tx_template.rs
crates/chain/tests/test_indexed_tx_graph.rs
crates/chain/tests/test_keychain_txout_index.rs
crates/chain/tests/test_spk_txout_index.rs
crates/electrum/tests/test_electrum.rs
crates/hwi/src/lib.rs
crates/sqlite/Cargo.toml [deleted file]
crates/sqlite/README.md [deleted file]
crates/sqlite/schema/schema_0.sql [deleted file]
crates/sqlite/src/lib.rs [deleted file]
crates/sqlite/src/schema.rs [deleted file]
crates/sqlite/src/store.rs [deleted file]
crates/wallet/Cargo.toml
crates/wallet/README.md
crates/wallet/examples/compiler.rs
crates/wallet/src/descriptor/mod.rs
crates/wallet/src/descriptor/template.rs
crates/wallet/src/lib.rs
crates/wallet/src/wallet/export.rs
crates/wallet/src/wallet/hardwaresigner.rs
crates/wallet/src/wallet/mod.rs
crates/wallet/src/wallet/params.rs [new file with mode: 0644]
crates/wallet/src/wallet/persisted.rs [new file with mode: 0644]
crates/wallet/src/wallet/signer.rs
crates/wallet/tests/common.rs
crates/wallet/tests/wallet.rs
example-crates/example_bitcoind_rpc_polling/src/main.rs
example-crates/example_cli/src/lib.rs
example-crates/example_electrum/src/main.rs
example-crates/example_esplora/src/main.rs
example-crates/wallet_electrum/Cargo.toml
example-crates/wallet_electrum/src/main.rs
example-crates/wallet_esplora_async/Cargo.toml
example-crates/wallet_esplora_async/src/main.rs
example-crates/wallet_esplora_blocking/src/main.rs
example-crates/wallet_rpc/Cargo.toml
example-crates/wallet_rpc/src/main.rs