Skip to content

Commit 1eca568

Browse files
committed
feat!: rm persist submodule
Remove `PersistBackend`, `PersistBackendAsync`, `StageExt` and `StageExtAsync`. Remove `async` feature flag and dependency. Update examples and wallet.
1 parent 782eb56 commit 1eca568

File tree

18 files changed

+239
-469
lines changed

18 files changed

+239
-469
lines changed

crates/chain/Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ serde_crate = { package = "serde", version = "1", optional = true, features = ["
1919
# Use hashbrown as a feature flag to have HashSet and HashMap from it.
2020
hashbrown = { version = "0.9.1", optional = true, features = ["serde"] }
2121
miniscript = { version = "12.0.0", optional = true, default-features = false }
22-
async-trait = { version = "0.1.80", optional = true }
2322

2423
[dev-dependencies]
2524
rand = "0.8"
@@ -29,4 +28,3 @@ proptest = "1.2.0"
2928
default = ["std", "miniscript"]
3029
std = ["bitcoin/std", "miniscript?/std"]
3130
serde = ["serde_crate", "bitcoin/serde", "miniscript?/serde"]
32-
async = ["async-trait"]

crates/chain/src/changeset.rs

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
//! This module is home to the [`PersistBackend`] trait which defines the behavior of a data store
2+
//! required to persist changes made to BDK data structures.
3+
//!
4+
//! The [`CombinedChangeSet`] type encapsulates a combination of [`crate`] structures that are
5+
//! typically persisted together.
6+
7+
/// A changeset containing [`crate`] structures typically persisted together.
8+
#[cfg(feature = "miniscript")]
9+
#[derive(Debug, Clone, PartialEq)]
10+
#[cfg_attr(
11+
feature = "serde",
12+
derive(crate::serde::Deserialize, crate::serde::Serialize),
13+
serde(
14+
crate = "crate::serde",
15+
bound(
16+
deserialize = "A: Ord + crate::serde::Deserialize<'de>, K: Ord + crate::serde::Deserialize<'de>",
17+
serialize = "A: Ord + crate::serde::Serialize, K: Ord + crate::serde::Serialize",
18+
),
19+
)
20+
)]
21+
pub struct CombinedChangeSet<K, A> {
22+
/// Changes to the [`LocalChain`](crate::local_chain::LocalChain).
23+
pub chain: crate::local_chain::ChangeSet,
24+
/// Changes to [`IndexedTxGraph`](crate::indexed_tx_graph::IndexedTxGraph).
25+
pub indexed_tx_graph: crate::indexed_tx_graph::ChangeSet<A, crate::keychain::ChangeSet<K>>,
26+
/// Stores the network type of the transaction data.
27+
pub network: Option<bitcoin::Network>,
28+
}
29+
30+
#[cfg(feature = "miniscript")]
31+
impl<K, A> core::default::Default for CombinedChangeSet<K, A> {
32+
fn default() -> Self {
33+
Self {
34+
chain: core::default::Default::default(),
35+
indexed_tx_graph: core::default::Default::default(),
36+
network: None,
37+
}
38+
}
39+
}
40+
41+
#[cfg(feature = "miniscript")]
42+
impl<K: Ord, A: crate::Anchor> crate::Append for CombinedChangeSet<K, A> {
43+
fn append(&mut self, other: Self) {
44+
crate::Append::append(&mut self.chain, other.chain);
45+
crate::Append::append(&mut self.indexed_tx_graph, other.indexed_tx_graph);
46+
if other.network.is_some() {
47+
debug_assert!(
48+
self.network.is_none() || self.network == other.network,
49+
"network type must either be just introduced or remain the same"
50+
);
51+
self.network = other.network;
52+
}
53+
}
54+
55+
fn is_empty(&self) -> bool {
56+
self.chain.is_empty() && self.indexed_tx_graph.is_empty() && self.network.is_none()
57+
}
58+
}
59+
60+
#[cfg(feature = "miniscript")]
61+
impl<K, A> From<crate::local_chain::ChangeSet> for CombinedChangeSet<K, A> {
62+
fn from(chain: crate::local_chain::ChangeSet) -> Self {
63+
Self {
64+
chain,
65+
..Default::default()
66+
}
67+
}
68+
}
69+
70+
#[cfg(feature = "miniscript")]
71+
impl<K, A> From<crate::indexed_tx_graph::ChangeSet<A, crate::keychain::ChangeSet<K>>>
72+
for CombinedChangeSet<K, A>
73+
{
74+
fn from(
75+
indexed_tx_graph: crate::indexed_tx_graph::ChangeSet<A, crate::keychain::ChangeSet<K>>,
76+
) -> Self {
77+
Self {
78+
indexed_tx_graph,
79+
..Default::default()
80+
}
81+
}
82+
}
83+
84+
#[cfg(feature = "miniscript")]
85+
impl<K, A> From<crate::keychain::ChangeSet<K>> for CombinedChangeSet<K, A> {
86+
fn from(indexer: crate::keychain::ChangeSet<K>) -> Self {
87+
Self {
88+
indexed_tx_graph: crate::indexed_tx_graph::ChangeSet {
89+
indexer,
90+
..Default::default()
91+
},
92+
..Default::default()
93+
}
94+
}
95+
}

crates/chain/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ pub use descriptor_ext::{DescriptorExt, DescriptorId};
5050
mod spk_iter;
5151
#[cfg(feature = "miniscript")]
5252
pub use spk_iter::*;
53-
pub mod persist;
53+
mod changeset;
54+
pub use changeset::*;
5455
pub mod spk_client;
5556

5657
#[allow(unused_imports)]

crates/chain/src/persist.rs

Lines changed: 0 additions & 279 deletions
This file was deleted.

0 commit comments

Comments
 (0)