Skip to content

Commit

Permalink
refactor(persist): update file_store, sqlite, wallet to use bdk_chain…
Browse files Browse the repository at this point in the history
…::persist

Also update examples and remove bdk_persist crate.
  • Loading branch information
notmandatory committed Jun 1, 2024
1 parent 1e8dbda commit 6b047ea
Show file tree
Hide file tree
Showing 32 changed files with 516 additions and 775 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ members = [
"crates/esplora",
"crates/bitcoind_rpc",
"crates/hwi",
"crates/persist",
"crates/testenv",
"example-crates/example_cli",
"example-crates/example_electrum",
Expand Down
2 changes: 0 additions & 2 deletions crates/file_store/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ authors = ["Bitcoin Dev Kit Developers"]
readme = "README.md"

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

Expand Down
2 changes: 1 addition & 1 deletion crates/file_store/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# BDK File Store

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

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

Expand Down
15 changes: 8 additions & 7 deletions crates/file_store/src/store.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::{bincode_options, EntryIter, FileError, IterError};
use anyhow::anyhow;
use bdk_chain::persist::Persist;
use bdk_chain::Append;
use bdk_persist::PersistBackend;
use bincode::Options;
use std::{
fmt::{self, Debug},
Expand All @@ -22,22 +21,24 @@ where
marker: PhantomData<C>,
}

impl<C> PersistBackend<C> for Store<C>
impl<C> Persist<C> for Store<C>
where
C: Append
+ Debug
+ serde::Serialize
+ serde::de::DeserializeOwned
+ core::marker::Send
+ core::marker::Sync,
{
fn write_changes(&mut self, changeset: &C) -> anyhow::Result<()> {
type WriteError = io::Error;
type LoadError = AggregateChangesetsError<C>;

fn write_changes(&mut self, changeset: &C) -> Result<(), Self::WriteError> {
self.append_changeset(changeset)
.map_err(|e| anyhow!(e).context("failed to write changes to persistence backend"))
}

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

Expand Down
2 changes: 1 addition & 1 deletion crates/hwi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
//! let first_device = devices.remove(0)?;
//! let custom_signer = HWISigner::from_device(&first_device, Network::Testnet.into())?;
//!
//! # let mut wallet = Wallet::new_no_persist(
//! # let mut wallet = Wallet::new(
//! # "",
//! # None,
//! # Network::Testnet,
Expand Down
22 changes: 0 additions & 22 deletions crates/persist/Cargo.toml

This file was deleted.

5 changes: 0 additions & 5 deletions crates/persist/README.md

This file was deleted.

73 changes: 0 additions & 73 deletions crates/persist/src/changeset.rs

This file was deleted.

8 changes: 0 additions & 8 deletions crates/persist/src/lib.rs

This file was deleted.

106 changes: 0 additions & 106 deletions crates/persist/src/persist.rs

This file was deleted.

2 changes: 0 additions & 2 deletions crates/sqlite/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ authors = ["Bitcoin Dev Kit Developers"]
readme = "README.md"

[dependencies]
anyhow = { version = "1", default-features = false }
bdk_chain = { path = "../chain", version = "0.15.0", features = ["serde", "miniscript"] }
bdk_persist = { path = "../persist", version = "0.3.0", features = ["serde"] }
rusqlite = { version = "0.31.0", features = ["bundled"] }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
6 changes: 3 additions & 3 deletions crates/sqlite/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# BDK SQLite

This is a simple [SQLite] relational database schema backed implementation of [`PersistBackend`](bdk_persist::PersistBackend).
This is a simple [SQLite] relational database schema backed implementation of `Persist`.

The main structure is `Store` which persists [`bdk_persist`] `CombinedChangeSet` data into a SQLite database file.
The main structure is `Store` which persists `CombinedChangeSet` data into a SQLite database file.

[`bdk_persist`]:https://docs.rs/bdk_persist/latest/bdk_persist/
<!-- [`Persist`]: bdk_chain::persist::PersistBackend -->
[SQLite]: https://www.sqlite.org/index.html
Loading

0 comments on commit 6b047ea

Please sign in to comment.