forked from bitcoindevkit/bdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add bdk_sqlite_store crate implementing PersistBackend backed b…
…y a SQLite database
- Loading branch information
1 parent
f95506b
commit 6603c60
Showing
6 changed files
with
412 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
[package] | ||
name = "bdk_sqlite_store" | ||
version = "0.2.0" | ||
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 SQLite based implementation of Persist for Bitcoin Dev Kit." | ||
keywords = ["bitcoin", "persist", "persistence", "bdk", "sqlite"] | ||
authors = ["Bitcoin Dev Kit Developers"] | ||
readme = "README.md" | ||
|
||
[dependencies] | ||
bdk_chain = { path = "../chain", version = "0.5.0", features = [ "serde", "miniscript" ] } | ||
rusqlite = { version = "0.29.0", features = ["bundled"]} | ||
serde = { version = "1", features = ["derive"] } | ||
log = { version = "0.4", features = [] } | ||
serde_json = "1.0.107" | ||
|
||
[dev-dependencies] | ||
tempfile = "3" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# BDK SQLite Store | ||
|
||
This is a simple append-only [SQLite] database backed implementation of | ||
[`Persist`](`bdk_chain::Persist`). | ||
|
||
The main structure is [`Store`](`crate::Store`), which can be used with [`bdk`]'s | ||
`Wallet` to persist wallet data into a SQLite database file. | ||
|
||
[`bdk`]: https://docs.rs/bdk/latest | ||
[`bdk_chain`]: https://docs.rs/bdk_chain/latest | ||
[SQLite]: https://www.sqlite.org/index.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#![doc = include_str!("../README.md")] | ||
|
||
mod store; | ||
|
||
pub use store::*; | ||
|
||
/// Error that occurs while appending new change sets to the DB. | ||
#[derive(Debug)] | ||
pub enum AppendError { | ||
/// JSON encoding error. | ||
Json(serde_json::Error), | ||
/// SQLite error. | ||
Sqlite(rusqlite::Error), | ||
} | ||
|
||
impl<'a> core::fmt::Display for AppendError { | ||
Check failure on line 16 in crates/sqlite_store/src/lib.rs GitHub Actions / clippythis lifetime isn't used in the impl
|
||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { | ||
match self { | ||
Self::Json(e) => write!(f, "json error trying to append change set: {}", e), | ||
Self::Sqlite(e) => write!(f, "sqlite error trying to append change set: {}", e), | ||
} | ||
} | ||
} | ||
|
||
impl<'a> From<serde_json::Error> for AppendError { | ||
Check failure on line 25 in crates/sqlite_store/src/lib.rs GitHub Actions / clippythis lifetime isn't used in the impl
|
||
fn from(error: serde_json::Error) -> Self { | ||
Self::Json(error) | ||
} | ||
} | ||
|
||
impl<'a> std::error::Error for AppendError {} | ||
Check failure on line 31 in crates/sqlite_store/src/lib.rs GitHub Actions / clippythis lifetime isn't used in the impl
|
||
|
||
/// Error the occurs while iterating stored change sets from the DB. | ||
#[derive(Debug)] | ||
pub enum IterError { | ||
/// Json decoding | ||
Json { | ||
rowid: usize, | ||
err: serde_json::Error, | ||
}, | ||
/// Sqlite error | ||
Sqlite(rusqlite::Error), | ||
/// FromSql error | ||
FromSql(rusqlite::types::FromSqlError), | ||
} | ||
|
||
impl core::fmt::Display for IterError { | ||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { | ||
match self { | ||
IterError::Json { rowid, err } => write!( | ||
f, | ||
"json error trying to decode change set {}, {}", | ||
rowid, err | ||
), | ||
IterError::Sqlite(err) => write!(f, "Sqlite error {}", err), | ||
IterError::FromSql(err) => write!(f, "FromSql error {}", err), | ||
} | ||
} | ||
} |
Oops, something went wrong.