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 May 31, 2024
1 parent 9cbf0de commit e5a10f7
Show file tree
Hide file tree
Showing 24 changed files with 392 additions and 701 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
7 changes: 5 additions & 2 deletions crates/chain/src/persist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
use crate::{indexed_tx_graph, keychain, local_chain, Anchor, Append};
use bitcoin::Network;
use core::convert::Infallible;
use core::default::Default;
use core::fmt::{Debug, Display};
use std::convert::Infallible;
use std::mem;
use core::mem;

/// A changeset containing [`crate`] structures typically persisted together.
#[derive(Debug, Clone, PartialEq)]
Expand Down Expand Up @@ -214,6 +214,7 @@ mod test {

use crate::persist::{Persist, StagedPersist};
use crate::Append;
use std::error::Error;
use std::fmt::{self, Display, Formatter};
use std::prelude::rust_2015::{String, ToString};
use TestError::FailedWrite;
Expand All @@ -234,6 +235,8 @@ mod test {
}
}

impl Error for TestError {}

#[derive(Clone, Default)]
struct TestChangeSet(Option<String>);

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
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
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"
Loading

0 comments on commit e5a10f7

Please sign in to comment.