refactor(persist): update file_store, sqlite, wallet to use bdk_chain::persist

Also update examples and remove bdk_persist crate.
This commit is contained in:
Steve Myers
2024-06-01 00:06:20 -05:00
parent 54b0c11cbe
commit 9e97ac0330
39 changed files with 542 additions and 1086 deletions

View File

@@ -5,15 +5,13 @@ edition = "2021"
license = "MIT OR Apache-2.0"
repository = "https://github.com/bitcoindevkit/bdk"
documentation = "https://docs.rs/bdk_file_store"
description = "A simple append-only flat file implementation of Persist for Bitcoin Dev Kit."
description = "A simple append-only flat file implementation of PersistBackend for Bitcoin Dev Kit."
keywords = ["bitcoin", "persist", "persistence", "bdk", "file"]
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"] }

View File

@@ -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 [`PersistBackend`](bdk_chain::persist::PersistBackend).
The main structure is [`Store`] which works with any [`bdk_chain`] based changesets to persist data into a flat file.

View File

@@ -1,7 +1,6 @@
use crate::{bincode_options, EntryIter, FileError, IterError};
use anyhow::anyhow;
use bdk_chain::persist::PersistBackend;
use bdk_chain::Append;
use bdk_persist::PersistBackend;
use bincode::Options;
use std::{
fmt::{self, Debug},
@@ -25,19 +24,21 @@ where
impl<C> PersistBackend<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"))
}
}