2023-10-17 11:00:05 +02:00
|
|
|
//! Contains the [`IndexedTxGraph`] and associated types. Refer to the
|
|
|
|
|
//! [`IndexedTxGraph`] documentation for more.
|
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-11 04:49:01 +00:00
|
|
|
use core::fmt::Debug;
|
|
|
|
|
|
2023-04-21 13:29:44 +08:00
|
|
|
use alloc::vec::Vec;
|
2023-10-06 11:07:00 +08:00
|
|
|
use bitcoin::{Block, OutPoint, Transaction, TxOut, Txid};
|
2023-03-27 14:21:10 +08:00
|
|
|
|
|
|
|
|
use crate::{
|
2023-08-07 17:43:17 +02:00
|
|
|
tx_graph::{self, TxGraph},
|
2024-07-04 22:09:04 +08:00
|
|
|
Anchor, AnchorFromBlockPosition, BlockId, Indexer, Merge,
|
2023-03-27 14:21:10 +08:00
|
|
|
};
|
|
|
|
|
|
2023-10-17 11:00:05 +02:00
|
|
|
/// The [`IndexedTxGraph`] combines a [`TxGraph`] and an [`Indexer`] implementation.
|
2023-04-17 23:25:57 +08:00
|
|
|
///
|
2023-10-17 11:00:05 +02:00
|
|
|
/// It ensures that [`TxGraph`] and [`Indexer`] are updated atomically.
|
2023-05-03 15:20:49 +08:00
|
|
|
#[derive(Debug)]
|
2023-03-27 14:21:10 +08:00
|
|
|
pub struct IndexedTxGraph<A, I> {
|
2023-03-31 22:42:47 +08:00
|
|
|
/// Transaction index.
|
|
|
|
|
pub index: I,
|
2023-03-27 14:21:10 +08:00
|
|
|
graph: TxGraph<A>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<A, I: Default> Default for IndexedTxGraph<A, I> {
|
|
|
|
|
fn default() -> Self {
|
|
|
|
|
Self {
|
|
|
|
|
graph: Default::default(),
|
|
|
|
|
index: Default::default(),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-03 15:20:49 +08:00
|
|
|
impl<A, I> IndexedTxGraph<A, I> {
|
2023-05-10 14:14:29 +08:00
|
|
|
/// Construct a new [`IndexedTxGraph`] with a given `index`.
|
|
|
|
|
pub fn new(index: I) -> Self {
|
|
|
|
|
Self {
|
|
|
|
|
index,
|
|
|
|
|
graph: TxGraph::default(),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-27 14:21:10 +08:00
|
|
|
/// Get a reference of the internal transaction graph.
|
|
|
|
|
pub fn graph(&self) -> &TxGraph<A> {
|
|
|
|
|
&self.graph
|
|
|
|
|
}
|
2023-05-03 15:20:49 +08:00
|
|
|
}
|
2023-03-27 14:21:10 +08:00
|
|
|
|
2023-05-03 15:20:49 +08:00
|
|
|
impl<A: Anchor, I: Indexer> IndexedTxGraph<A, I> {
|
2023-08-07 17:43:17 +02:00
|
|
|
/// Applies the [`ChangeSet`] to the [`IndexedTxGraph`].
|
|
|
|
|
pub fn apply_changeset(&mut self, changeset: ChangeSet<A, I::ChangeSet>) {
|
|
|
|
|
self.index.apply_changeset(changeset.indexer);
|
2023-03-27 21:51:11 +08:00
|
|
|
|
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-11 04:49:01 +00:00
|
|
|
for tx in &changeset.tx_graph.txs {
|
2023-03-27 21:51:11 +08:00
|
|
|
self.index.index_tx(tx);
|
|
|
|
|
}
|
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-11 04:49:01 +00:00
|
|
|
for (&outpoint, txout) in &changeset.tx_graph.txouts {
|
2023-03-27 21:51:11 +08:00
|
|
|
self.index.index_txout(outpoint, txout);
|
|
|
|
|
}
|
|
|
|
|
|
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-11 04:49:01 +00:00
|
|
|
self.graph.apply_changeset(changeset.tx_graph);
|
2023-03-27 15:36:37 +08:00
|
|
|
}
|
2023-08-16 17:39:35 +02:00
|
|
|
|
|
|
|
|
/// Determines the [`ChangeSet`] between `self` and an empty [`IndexedTxGraph`].
|
|
|
|
|
pub fn initial_changeset(&self) -> ChangeSet<A, I::ChangeSet> {
|
|
|
|
|
let graph = self.graph.initial_changeset();
|
|
|
|
|
let indexer = self.index.initial_changeset();
|
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-11 04:49:01 +00:00
|
|
|
ChangeSet {
|
|
|
|
|
tx_graph: graph,
|
|
|
|
|
indexer,
|
|
|
|
|
}
|
2023-08-16 17:39:35 +02:00
|
|
|
}
|
2023-04-17 23:25:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<A: Anchor, I: Indexer> IndexedTxGraph<A, I>
|
|
|
|
|
where
|
2024-07-04 22:09:04 +08:00
|
|
|
I::ChangeSet: Default + Merge,
|
2023-04-17 23:25:57 +08:00
|
|
|
{
|
2023-10-06 02:05:31 +08:00
|
|
|
fn index_tx_graph_changeset(
|
|
|
|
|
&mut self,
|
|
|
|
|
tx_graph_changeset: &tx_graph::ChangeSet<A>,
|
|
|
|
|
) -> I::ChangeSet {
|
|
|
|
|
let mut changeset = I::ChangeSet::default();
|
|
|
|
|
for added_tx in &tx_graph_changeset.txs {
|
2024-07-04 22:09:04 +08:00
|
|
|
changeset.merge(self.index.index_tx(added_tx));
|
2023-10-06 02:05:31 +08:00
|
|
|
}
|
|
|
|
|
for (&added_outpoint, added_txout) in &tx_graph_changeset.txouts {
|
2024-07-04 22:09:04 +08:00
|
|
|
changeset.merge(self.index.index_txout(added_outpoint, added_txout));
|
2023-10-06 02:05:31 +08:00
|
|
|
}
|
|
|
|
|
changeset
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-17 23:25:57 +08:00
|
|
|
/// Apply an `update` directly.
|
|
|
|
|
///
|
2023-08-07 17:43:17 +02:00
|
|
|
/// `update` is a [`TxGraph<A>`] and the resultant changes is returned as [`ChangeSet`].
|
|
|
|
|
pub fn apply_update(&mut self, update: TxGraph<A>) -> ChangeSet<A, I::ChangeSet> {
|
|
|
|
|
let graph = self.graph.apply_update(update);
|
2023-10-06 02:05:31 +08:00
|
|
|
let indexer = self.index_tx_graph_changeset(&graph);
|
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-11 04:49:01 +00:00
|
|
|
ChangeSet {
|
|
|
|
|
tx_graph: graph,
|
|
|
|
|
indexer,
|
|
|
|
|
}
|
2023-04-17 23:25:57 +08:00
|
|
|
}
|
2023-03-27 15:36:37 +08:00
|
|
|
|
2023-04-17 23:25:57 +08:00
|
|
|
/// Insert a floating `txout` of given `outpoint`.
|
2023-10-06 02:05:31 +08:00
|
|
|
pub fn insert_txout(&mut self, outpoint: OutPoint, txout: TxOut) -> ChangeSet<A, I::ChangeSet> {
|
|
|
|
|
let graph = self.graph.insert_txout(outpoint, txout);
|
|
|
|
|
let indexer = self.index_tx_graph_changeset(&graph);
|
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-11 04:49:01 +00:00
|
|
|
ChangeSet {
|
|
|
|
|
tx_graph: graph,
|
|
|
|
|
indexer,
|
|
|
|
|
}
|
2023-03-27 14:21:10 +08:00
|
|
|
}
|
|
|
|
|
|
2023-04-17 23:25:57 +08:00
|
|
|
/// Insert and index a transaction into the graph.
|
2023-10-06 11:07:00 +08:00
|
|
|
pub fn insert_tx(&mut self, tx: Transaction) -> ChangeSet<A, I::ChangeSet> {
|
|
|
|
|
let graph = self.graph.insert_tx(tx);
|
2023-10-06 02:05:31 +08:00
|
|
|
let indexer = self.index_tx_graph_changeset(&graph);
|
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-11 04:49:01 +00:00
|
|
|
ChangeSet {
|
|
|
|
|
tx_graph: graph,
|
|
|
|
|
indexer,
|
|
|
|
|
}
|
2023-03-27 14:21:10 +08:00
|
|
|
}
|
|
|
|
|
|
2023-10-06 11:07:00 +08:00
|
|
|
/// Insert an `anchor` for a given transaction.
|
|
|
|
|
pub fn insert_anchor(&mut self, txid: Txid, anchor: A) -> ChangeSet<A, I::ChangeSet> {
|
|
|
|
|
self.graph.insert_anchor(txid, anchor).into()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Insert a unix timestamp of when a transaction is seen in the mempool.
|
|
|
|
|
///
|
|
|
|
|
/// This is used for transaction conflict resolution in [`TxGraph`] where the transaction with
|
|
|
|
|
/// the later last-seen is prioritized.
|
|
|
|
|
pub fn insert_seen_at(&mut self, txid: Txid, seen_at: u64) -> ChangeSet<A, I::ChangeSet> {
|
|
|
|
|
self.graph.insert_seen_at(txid, seen_at).into()
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-04 17:10:46 +08:00
|
|
|
/// Batch insert transactions, filtering out those that are irrelevant.
|
2023-04-17 23:25:57 +08:00
|
|
|
///
|
|
|
|
|
/// Relevancy is determined by the [`Indexer::is_tx_relevant`] implementation of `I`. Irrelevant
|
2023-04-23 00:12:41 +08:00
|
|
|
/// transactions in `txs` will be ignored. `txs` do not need to be in topological order.
|
2023-10-04 17:10:46 +08:00
|
|
|
pub fn batch_insert_relevant<'t>(
|
2023-03-27 14:21:10 +08:00
|
|
|
&mut self,
|
2023-10-06 02:05:31 +08:00
|
|
|
txs: impl IntoIterator<Item = (&'t Transaction, impl IntoIterator<Item = A>)>,
|
2023-08-07 17:43:17 +02:00
|
|
|
) -> ChangeSet<A, I::ChangeSet> {
|
2023-04-22 22:56:51 +08:00
|
|
|
// The algorithm below allows for non-topologically ordered transactions by using two loops.
|
|
|
|
|
// This is achieved by:
|
2023-04-21 13:29:44 +08:00
|
|
|
// 1. insert all txs into the index. If they are irrelevant then that's fine it will just
|
|
|
|
|
// not store anything about them.
|
|
|
|
|
// 2. decide whether to insert them into the graph depending on whether `is_tx_relevant`
|
|
|
|
|
// returns true or not. (in a second loop).
|
2023-10-06 02:05:31 +08:00
|
|
|
let txs = txs.into_iter().collect::<Vec<_>>();
|
2023-10-04 17:10:46 +08:00
|
|
|
|
2023-10-06 02:05:31 +08:00
|
|
|
let mut indexer = I::ChangeSet::default();
|
|
|
|
|
for (tx, _) in &txs {
|
2024-07-04 22:09:04 +08:00
|
|
|
indexer.merge(self.index.index_tx(tx));
|
2023-10-06 02:05:31 +08:00
|
|
|
}
|
2023-10-04 17:10:46 +08:00
|
|
|
|
2023-10-06 02:05:31 +08:00
|
|
|
let mut graph = tx_graph::ChangeSet::default();
|
|
|
|
|
for (tx, anchors) in txs {
|
2023-10-04 17:10:46 +08:00
|
|
|
if self.index.is_tx_relevant(tx) {
|
deps(bdk): bump `bitcoin` to `0.32.0`, miniscript to `12.0.0`
deps(chain): bump `bitcoin` to `0.32.0`, miniscript to `12.0.0`
fix(chain): use `minimal_non_dust()` instead of `dust_value()`
fix(chain): use `compute_txid()` instead of `txid`
deps(testenv): bump `electrsd` to `0.28.0`
deps(electrum): bump `electrum-client` to `0.20.0`
fix(electrum): use `compute_txid()` instead of `txid`
deps(esplora): bump `esplora-client` to `0.8.0`
deps(bitcoind_rpc): bump `bitcoin` to `0.32.0`, `bitcoincore-rpc` to
`0.19.0`
fix(bitcoind_rpc): use `compute_txid()` instead of `txid`
fix(nursery/tmp_plan): use proper `sighash` errors, and fix the expected
`Signature` fields
fix(sqlite): use `compute_txid()` instead of `txid`
deps(hwi): bump `hwi` to `0.9.0`
deps(wallet): bump `bitcoin` to `0.32.0`, miniscript to `12.0.0`
fix(wallet): use `compute_txid()` and `minimal_non_dust()`
- update to use `compute_txid()` instead of deprecated `txid()`
- update to use `minimal_non_dust()` instead of `dust_value()`
- remove unused `bitcoin::hex::FromHex`.
fix(wallet): uses `.into` conversion on `Network` for `NetworkKind`
- uses `.into()` when appropriate, otherwise use the explicit
`NetworkKind`, and it's `.is_mainnet()` method.
fix(wallet): add P2wpkh, Taproot, InputsIndex errors to `SignerError`
fix(wallet): fields on taproot, and ecdsa `Signature` structure
fix(wallet/wallet): convert `Weight` to `usize` for now
- converts the `bitcoin-units::Weight` type to `usize` with help of
`to_wu()` method.
- it should be updated/refactored in the future to handle the `Weight`
type throughout the code instead of current `usize`, only converting
it for now.
- allows the usage of deprecated `is_provably_unspendable()`, needs
further discussion if suggested `is_op_return` is suitable.
- update the expect field to `signature`, as it was renamed from `sig`.
fix(wallet/wallet): use `is_op_return` instead of
`is_provably_unspendable`
fix(wallet/wallet): use `relative::Locktime` instead of `Sequence`
fix(wallet/descriptor): use `ParsePublicKeyError`
fix(wallet/descriptor): use `.into()` to convert from `AbsLockTime` and
`RelLockTime` to `absolute::LockTime` and `relative::LockTime`
fix(wallet/wallet): use `Message::from_digest()` instead of relying on
deprecated `ThirtyTwoByteHash` trait.
fix(wallet/descriptor+wallet): expect `Threshold` type, and handle it
internally
fix(wallet/wallet): remove `0x` prefix from expected `TxId` display
fix(examples): use `compute_txid()` instead of `txid`
fix(ci): remove usage of `bitcoin/no-std` feature
- remove comment: `# The `no-std` feature it's implied when the `std` feature is disabled.`
2024-05-22 18:34:30 -03:00
|
|
|
let txid = tx.compute_txid();
|
2024-07-04 22:09:04 +08:00
|
|
|
graph.merge(self.graph.insert_tx(tx.clone()));
|
2023-10-06 02:05:31 +08:00
|
|
|
for anchor in anchors {
|
2024-07-04 22:09:04 +08:00
|
|
|
graph.merge(self.graph.insert_anchor(txid, anchor));
|
2023-10-06 02:05:31 +08:00
|
|
|
}
|
2023-10-04 17:10:46 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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-11 04:49:01 +00:00
|
|
|
ChangeSet {
|
|
|
|
|
tx_graph: graph,
|
|
|
|
|
indexer,
|
|
|
|
|
}
|
2023-03-27 14:21:10 +08:00
|
|
|
}
|
2023-10-04 17:10:46 +08:00
|
|
|
|
|
|
|
|
/// Batch insert unconfirmed transactions, filtering out those that are irrelevant.
|
|
|
|
|
///
|
|
|
|
|
/// Relevancy is determined by the internal [`Indexer::is_tx_relevant`] implementation of `I`.
|
2023-10-20 17:37:28 -03:00
|
|
|
/// Irrelevant transactions in `txs` will be ignored.
|
2023-10-04 17:10:46 +08:00
|
|
|
///
|
2023-10-06 02:05:31 +08:00
|
|
|
/// Items of `txs` are tuples containing the transaction and a *last seen* timestamp. The
|
|
|
|
|
/// *last seen* communicates when the transaction is last seen in the mempool which is used for
|
|
|
|
|
/// conflict-resolution in [`TxGraph`] (refer to [`TxGraph::insert_seen_at`] for details).
|
2023-10-04 17:10:46 +08:00
|
|
|
pub fn batch_insert_relevant_unconfirmed<'t>(
|
|
|
|
|
&mut self,
|
2023-10-06 02:05:31 +08:00
|
|
|
unconfirmed_txs: impl IntoIterator<Item = (&'t Transaction, u64)>,
|
2023-10-04 17:10:46 +08:00
|
|
|
) -> ChangeSet<A, I::ChangeSet> {
|
2023-10-06 02:05:31 +08:00
|
|
|
// The algorithm below allows for non-topologically ordered transactions by using two loops.
|
|
|
|
|
// This is achieved by:
|
|
|
|
|
// 1. insert all txs into the index. If they are irrelevant then that's fine it will just
|
|
|
|
|
// not store anything about them.
|
|
|
|
|
// 2. decide whether to insert them into the graph depending on whether `is_tx_relevant`
|
|
|
|
|
// returns true or not. (in a second loop).
|
|
|
|
|
let txs = unconfirmed_txs.into_iter().collect::<Vec<_>>();
|
|
|
|
|
|
|
|
|
|
let mut indexer = I::ChangeSet::default();
|
|
|
|
|
for (tx, _) in &txs {
|
2024-07-04 22:09:04 +08:00
|
|
|
indexer.merge(self.index.index_tx(tx));
|
2023-10-06 02:05:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let graph = self.graph.batch_insert_unconfirmed(
|
|
|
|
|
txs.into_iter()
|
|
|
|
|
.filter(|(tx, _)| self.index.is_tx_relevant(tx))
|
|
|
|
|
.map(|(tx, seen_at)| (tx.clone(), seen_at)),
|
|
|
|
|
);
|
|
|
|
|
|
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-11 04:49:01 +00:00
|
|
|
ChangeSet {
|
|
|
|
|
tx_graph: graph,
|
|
|
|
|
indexer,
|
|
|
|
|
}
|
2023-10-04 17:10:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Batch insert unconfirmed transactions.
|
|
|
|
|
///
|
2023-10-06 02:05:31 +08:00
|
|
|
/// Items of `txs` are tuples containing the transaction and a *last seen* timestamp. The
|
|
|
|
|
/// *last seen* communicates when the transaction is last seen in the mempool which is used for
|
|
|
|
|
/// conflict-resolution in [`TxGraph`] (refer to [`TxGraph::insert_seen_at`] for details).
|
2023-10-04 17:10:46 +08:00
|
|
|
///
|
|
|
|
|
/// To filter out irrelevant transactions, use [`batch_insert_relevant_unconfirmed`] instead.
|
|
|
|
|
///
|
|
|
|
|
/// [`batch_insert_relevant_unconfirmed`]: IndexedTxGraph::batch_insert_relevant_unconfirmed
|
2023-10-06 02:05:31 +08:00
|
|
|
pub fn batch_insert_unconfirmed(
|
2023-10-04 17:10:46 +08:00
|
|
|
&mut self,
|
2023-10-06 02:05:31 +08:00
|
|
|
txs: impl IntoIterator<Item = (Transaction, u64)>,
|
2023-10-04 17:10:46 +08:00
|
|
|
) -> ChangeSet<A, I::ChangeSet> {
|
2023-10-06 02:05:31 +08:00
|
|
|
let graph = self.graph.batch_insert_unconfirmed(txs);
|
|
|
|
|
let indexer = self.index_tx_graph_changeset(&graph);
|
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-11 04:49:01 +00:00
|
|
|
ChangeSet {
|
|
|
|
|
tx_graph: graph,
|
|
|
|
|
indexer,
|
|
|
|
|
}
|
2023-10-04 17:10:46 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Methods are available if the anchor (`A`) implements [`AnchorFromBlockPosition`].
|
|
|
|
|
impl<A: Anchor, I: Indexer> IndexedTxGraph<A, I>
|
|
|
|
|
where
|
2024-07-04 22:09:04 +08:00
|
|
|
I::ChangeSet: Default + Merge,
|
2023-10-04 17:10:46 +08:00
|
|
|
A: AnchorFromBlockPosition,
|
|
|
|
|
{
|
|
|
|
|
/// Batch insert all transactions of the given `block` of `height`, filtering out those that are
|
|
|
|
|
/// irrelevant.
|
|
|
|
|
///
|
|
|
|
|
/// Each inserted transaction's anchor will be constructed from
|
|
|
|
|
/// [`AnchorFromBlockPosition::from_block_position`].
|
|
|
|
|
///
|
|
|
|
|
/// Relevancy is determined by the internal [`Indexer::is_tx_relevant`] implementation of `I`.
|
2023-10-20 17:37:28 -03:00
|
|
|
/// Irrelevant transactions in `txs` will be ignored.
|
2023-10-04 17:10:46 +08:00
|
|
|
pub fn apply_block_relevant(
|
|
|
|
|
&mut self,
|
2024-01-02 17:31:34 +08:00
|
|
|
block: &Block,
|
2023-10-04 17:10:46 +08:00
|
|
|
height: u32,
|
|
|
|
|
) -> ChangeSet<A, I::ChangeSet> {
|
|
|
|
|
let block_id = BlockId {
|
|
|
|
|
hash: block.block_hash(),
|
|
|
|
|
height,
|
|
|
|
|
};
|
2024-01-02 17:31:34 +08:00
|
|
|
let mut changeset = ChangeSet::<A, I::ChangeSet>::default();
|
|
|
|
|
for (tx_pos, tx) in block.txdata.iter().enumerate() {
|
2024-07-04 22:09:04 +08:00
|
|
|
changeset.indexer.merge(self.index.index_tx(tx));
|
2024-01-02 17:31:34 +08:00
|
|
|
if self.index.is_tx_relevant(tx) {
|
deps(bdk): bump `bitcoin` to `0.32.0`, miniscript to `12.0.0`
deps(chain): bump `bitcoin` to `0.32.0`, miniscript to `12.0.0`
fix(chain): use `minimal_non_dust()` instead of `dust_value()`
fix(chain): use `compute_txid()` instead of `txid`
deps(testenv): bump `electrsd` to `0.28.0`
deps(electrum): bump `electrum-client` to `0.20.0`
fix(electrum): use `compute_txid()` instead of `txid`
deps(esplora): bump `esplora-client` to `0.8.0`
deps(bitcoind_rpc): bump `bitcoin` to `0.32.0`, `bitcoincore-rpc` to
`0.19.0`
fix(bitcoind_rpc): use `compute_txid()` instead of `txid`
fix(nursery/tmp_plan): use proper `sighash` errors, and fix the expected
`Signature` fields
fix(sqlite): use `compute_txid()` instead of `txid`
deps(hwi): bump `hwi` to `0.9.0`
deps(wallet): bump `bitcoin` to `0.32.0`, miniscript to `12.0.0`
fix(wallet): use `compute_txid()` and `minimal_non_dust()`
- update to use `compute_txid()` instead of deprecated `txid()`
- update to use `minimal_non_dust()` instead of `dust_value()`
- remove unused `bitcoin::hex::FromHex`.
fix(wallet): uses `.into` conversion on `Network` for `NetworkKind`
- uses `.into()` when appropriate, otherwise use the explicit
`NetworkKind`, and it's `.is_mainnet()` method.
fix(wallet): add P2wpkh, Taproot, InputsIndex errors to `SignerError`
fix(wallet): fields on taproot, and ecdsa `Signature` structure
fix(wallet/wallet): convert `Weight` to `usize` for now
- converts the `bitcoin-units::Weight` type to `usize` with help of
`to_wu()` method.
- it should be updated/refactored in the future to handle the `Weight`
type throughout the code instead of current `usize`, only converting
it for now.
- allows the usage of deprecated `is_provably_unspendable()`, needs
further discussion if suggested `is_op_return` is suitable.
- update the expect field to `signature`, as it was renamed from `sig`.
fix(wallet/wallet): use `is_op_return` instead of
`is_provably_unspendable`
fix(wallet/wallet): use `relative::Locktime` instead of `Sequence`
fix(wallet/descriptor): use `ParsePublicKeyError`
fix(wallet/descriptor): use `.into()` to convert from `AbsLockTime` and
`RelLockTime` to `absolute::LockTime` and `relative::LockTime`
fix(wallet/wallet): use `Message::from_digest()` instead of relying on
deprecated `ThirtyTwoByteHash` trait.
fix(wallet/descriptor+wallet): expect `Threshold` type, and handle it
internally
fix(wallet/wallet): remove `0x` prefix from expected `TxId` display
fix(examples): use `compute_txid()` instead of `txid`
fix(ci): remove usage of `bitcoin/no-std` feature
- remove comment: `# The `no-std` feature it's implied when the `std` feature is disabled.`
2024-05-22 18:34:30 -03:00
|
|
|
let txid = tx.compute_txid();
|
2024-01-02 17:31:34 +08:00
|
|
|
let anchor = A::from_block_position(block, block_id, tx_pos);
|
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-11 04:49:01 +00:00
|
|
|
changeset.tx_graph.merge(self.graph.insert_tx(tx.clone()));
|
2024-01-02 17:31:34 +08:00
|
|
|
changeset
|
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-11 04:49:01 +00:00
|
|
|
.tx_graph
|
2024-07-04 22:09:04 +08:00
|
|
|
.merge(self.graph.insert_anchor(txid, anchor));
|
2024-01-02 17:31:34 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
changeset
|
2023-10-04 17:10:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Batch insert all transactions of the given `block` of `height`.
|
|
|
|
|
///
|
|
|
|
|
/// Each inserted transaction's anchor will be constructed from
|
|
|
|
|
/// [`AnchorFromBlockPosition::from_block_position`].
|
|
|
|
|
///
|
|
|
|
|
/// To only insert relevant transactions, use [`apply_block_relevant`] instead.
|
|
|
|
|
///
|
|
|
|
|
/// [`apply_block_relevant`]: IndexedTxGraph::apply_block_relevant
|
|
|
|
|
pub fn apply_block(&mut self, block: Block, height: u32) -> ChangeSet<A, I::ChangeSet> {
|
|
|
|
|
let block_id = BlockId {
|
|
|
|
|
hash: block.block_hash(),
|
|
|
|
|
height,
|
|
|
|
|
};
|
2023-10-06 02:05:31 +08:00
|
|
|
let mut graph = tx_graph::ChangeSet::default();
|
|
|
|
|
for (tx_pos, tx) in block.txdata.iter().enumerate() {
|
|
|
|
|
let anchor = A::from_block_position(&block, block_id, tx_pos);
|
2024-07-04 22:09:04 +08:00
|
|
|
graph.merge(self.graph.insert_anchor(tx.compute_txid(), anchor));
|
|
|
|
|
graph.merge(self.graph.insert_tx(tx.clone()));
|
2023-10-06 02:05:31 +08:00
|
|
|
}
|
|
|
|
|
let indexer = self.index_tx_graph_changeset(&graph);
|
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-11 04:49:01 +00:00
|
|
|
ChangeSet {
|
|
|
|
|
tx_graph: graph,
|
|
|
|
|
indexer,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<A, I> AsRef<TxGraph<A>> for IndexedTxGraph<A, I> {
|
|
|
|
|
fn as_ref(&self) -> &TxGraph<A> {
|
|
|
|
|
&self.graph
|
2023-10-04 17:10:46 +08:00
|
|
|
}
|
2023-04-17 23:25:57 +08:00
|
|
|
}
|
2023-03-27 14:21:10 +08:00
|
|
|
|
2023-10-17 11:00:05 +02:00
|
|
|
/// Represents changes to an [`IndexedTxGraph`].
|
2023-04-12 11:24:05 +08:00
|
|
|
#[derive(Clone, Debug, PartialEq)]
|
|
|
|
|
#[cfg_attr(
|
|
|
|
|
feature = "serde",
|
|
|
|
|
derive(serde::Deserialize, serde::Serialize),
|
|
|
|
|
serde(
|
|
|
|
|
crate = "serde_crate",
|
|
|
|
|
bound(
|
|
|
|
|
deserialize = "A: Ord + serde::Deserialize<'de>, IA: serde::Deserialize<'de>",
|
|
|
|
|
serialize = "A: Ord + serde::Serialize, IA: serde::Serialize"
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
)]
|
|
|
|
|
#[must_use]
|
2023-08-07 17:43:17 +02:00
|
|
|
pub struct ChangeSet<A, IA> {
|
|
|
|
|
/// [`TxGraph`] changeset.
|
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-11 04:49:01 +00:00
|
|
|
pub tx_graph: tx_graph::ChangeSet<A>,
|
2023-08-07 17:43:17 +02:00
|
|
|
/// [`Indexer`] changeset.
|
|
|
|
|
pub indexer: IA,
|
2023-04-12 11:24:05 +08:00
|
|
|
}
|
|
|
|
|
|
2023-08-07 17:43:17 +02:00
|
|
|
impl<A, IA: Default> Default for ChangeSet<A, IA> {
|
2023-04-12 11:24:05 +08:00
|
|
|
fn default() -> Self {
|
|
|
|
|
Self {
|
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-11 04:49:01 +00:00
|
|
|
tx_graph: Default::default(),
|
2023-08-07 17:43:17 +02:00
|
|
|
indexer: Default::default(),
|
2023-04-12 11:24:05 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-04 22:09:04 +08:00
|
|
|
impl<A: Anchor, IA: Merge> Merge for ChangeSet<A, IA> {
|
|
|
|
|
fn merge(&mut self, other: Self) {
|
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-11 04:49:01 +00:00
|
|
|
self.tx_graph.merge(other.tx_graph);
|
2024-07-04 22:09:04 +08:00
|
|
|
self.indexer.merge(other.indexer);
|
2023-04-12 11:24:05 +08:00
|
|
|
}
|
2023-05-09 09:59:42 +08:00
|
|
|
|
|
|
|
|
fn is_empty(&self) -> bool {
|
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-11 04:49:01 +00:00
|
|
|
self.tx_graph.is_empty() && self.indexer.is_empty()
|
2023-05-09 09:59:42 +08:00
|
|
|
}
|
2023-04-12 11:24:05 +08:00
|
|
|
}
|
|
|
|
|
|
2023-08-07 17:43:17 +02:00
|
|
|
impl<A, IA: Default> From<tx_graph::ChangeSet<A>> for ChangeSet<A, IA> {
|
|
|
|
|
fn from(graph: tx_graph::ChangeSet<A>) -> Self {
|
2023-05-12 16:17:17 +08:00
|
|
|
Self {
|
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-11 04:49:01 +00:00
|
|
|
tx_graph: graph,
|
2023-05-12 16:17:17 +08:00
|
|
|
..Default::default()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-12 00:03:18 +08:00
|
|
|
#[cfg(feature = "miniscript")]
|
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-11 04:49:01 +00:00
|
|
|
impl<A> From<crate::keychain_txout::ChangeSet> for ChangeSet<A, crate::keychain_txout::ChangeSet> {
|
|
|
|
|
fn from(indexer: crate::keychain_txout::ChangeSet) -> Self {
|
2023-05-13 23:28:03 +08:00
|
|
|
Self {
|
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-11 04:49:01 +00:00
|
|
|
tx_graph: Default::default(),
|
2023-08-07 17:43:17 +02:00
|
|
|
indexer,
|
2023-05-13 23:28:03 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|