Skip to content

Commit e5c73ec

Browse files
committed
refactor(persist): update file_store, sqlite, wallet to use bdk_chain::persist
Also update examples and remove bdk_persist crate.
1 parent 9cbf0de commit e5c73ec

27 files changed

Lines changed: 488 additions & 738 deletions

File tree

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ members = [
99
"crates/esplora",
1010
"crates/bitcoind_rpc",
1111
"crates/hwi",
12-
"crates/persist",
1312
"crates/testenv",
1413
"example-crates/example_cli",
1514
"example-crates/example_electrum",

crates/chain/src/persist.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
//! This module is home to the [`Persist`] trait which defines the behavior of a data store
22
//! required to persist changes made to BDK data structures.
33
//!
4-
//! The [`Stage`] type provides a convenient wrapper around implementations of [`Persist`] that
4+
//! The [`StagedPersist`] type provides a convenient wrapper around implementations of [`Persist`] that
55
//! allows changes to be staged before committing them.
66
//!
77
//! The [`CombinedChangeSet`] type encapsulates a combination of [`crate`] structures that are
88
//! typically persisted together.
99
1010
use crate::{indexed_tx_graph, keychain, local_chain, Anchor, Append};
1111
use bitcoin::Network;
12+
use core::convert::Infallible;
1213
use core::default::Default;
1314
use core::fmt::{Debug, Display};
14-
use std::convert::Infallible;
15-
use std::mem;
15+
use core::mem;
1616

1717
/// A changeset containing [`crate`] structures typically persisted together.
1818
#[derive(Debug, Clone, PartialEq)]
@@ -151,7 +151,7 @@ where
151151
P: Persist<C>,
152152
{
153153
/// Create a new [`StagedPersist`] adding staging to an inner data store that implements
154-
/// [`Persit`].
154+
/// [`Persist`].
155155
pub fn new(persist: P) -> Self {
156156
Self {
157157
inner: persist,
@@ -214,6 +214,7 @@ mod test {
214214

215215
use crate::persist::{Persist, StagedPersist};
216216
use crate::Append;
217+
use std::error::Error;
217218
use std::fmt::{self, Display, Formatter};
218219
use std::prelude::rust_2015::{String, ToString};
219220
use TestError::FailedWrite;
@@ -234,6 +235,8 @@ mod test {
234235
}
235236
}
236237

238+
impl Error for TestError {}
239+
237240
#[derive(Clone, Default)]
238241
struct TestChangeSet(Option<String>);
239242

crates/file_store/Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ authors = ["Bitcoin Dev Kit Developers"]
1111
readme = "README.md"
1212

1313
[dependencies]
14-
anyhow = { version = "1", default-features = false }
1514
bdk_chain = { path = "../chain", version = "0.15.0", features = [ "serde", "miniscript" ] }
16-
bdk_persist = { path = "../persist", version = "0.3.0"}
1715
bincode = { version = "1" }
1816
serde = { version = "1", features = ["derive"] }
1917

crates/file_store/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# BDK File Store
22

3-
This is a simple append-only flat file implementation of [`PersistBackend`](bdk_persist::PersistBackend).
3+
This is a simple append-only flat file implementation of [`Persist`](bdk_chain::persist::Persist).
44

55
The main structure is [`Store`] which works with any [`bdk_chain`] based changesets to persist data into a flat file.
66

crates/file_store/src/store.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use crate::{bincode_options, EntryIter, FileError, IterError};
2-
use anyhow::anyhow;
2+
use bdk_chain::persist::Persist;
33
use bdk_chain::Append;
4-
use bdk_persist::PersistBackend;
54
use bincode::Options;
65
use std::{
76
fmt::{self, Debug},
@@ -22,22 +21,24 @@ where
2221
marker: PhantomData<C>,
2322
}
2423

25-
impl<C> PersistBackend<C> for Store<C>
24+
impl<C> Persist<C> for Store<C>
2625
where
2726
C: Append
27+
+ Debug
2828
+ serde::Serialize
2929
+ serde::de::DeserializeOwned
3030
+ core::marker::Send
3131
+ core::marker::Sync,
3232
{
33-
fn write_changes(&mut self, changeset: &C) -> anyhow::Result<()> {
33+
type WriteError = io::Error;
34+
type LoadError = AggregateChangesetsError<C>;
35+
36+
fn write_changes(&mut self, changeset: &C) -> Result<(), Self::WriteError> {
3437
self.append_changeset(changeset)
35-
.map_err(|e| anyhow!(e).context("failed to write changes to persistence backend"))
3638
}
3739

38-
fn load_from_persistence(&mut self) -> anyhow::Result<Option<C>> {
40+
fn load_changes(&mut self) -> Result<Option<C>, Self::LoadError> {
3941
self.aggregate_changesets()
40-
.map_err(|e| anyhow!(e.iter_error).context("error loading from persistence backend"))
4142
}
4243
}
4344

crates/persist/Cargo.toml

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

crates/persist/README.md

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

crates/persist/src/changeset.rs

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

crates/persist/src/lib.rs

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

crates/persist/src/persist.rs

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

0 commit comments

Comments
 (0)