From 6ab29fcec5bf318d4d57f54b6f89cd791ed1c92e Mon Sep 17 00:00:00 2001 From: Alekos Filini Date: Wed, 5 Feb 2020 11:59:02 +0100 Subject: [PATCH] Add a generalized database trait and a Sled-based implementation --- core/lib/Cargo.toml | 7 + core/lib/src/database/keyvalue.rs | 390 ++++++++++++++++++++++++++++++ core/lib/src/database/mod.rs | 71 ++++++ core/lib/src/error.rs | 12 + core/lib/src/lib.rs | 6 + core/lib/src/types.rs | 47 ++++ 6 files changed, 533 insertions(+) create mode 100644 core/lib/src/database/keyvalue.rs create mode 100644 core/lib/src/database/mod.rs create mode 100644 core/lib/src/types.rs diff --git a/core/lib/Cargo.toml b/core/lib/Cargo.toml index 6894d5e9..1f0b2c2d 100644 --- a/core/lib/Cargo.toml +++ b/core/lib/Cargo.toml @@ -10,3 +10,10 @@ miniscript = { version = "0.12" } serde = { version = "^1.0", features = ["derive"] } serde_json = { version = "^1.0" } base64 = "^0.11" + +# Optional dependencies +sled = { version = "0.31.0", optional = true } + +[features] +default = ["sled"] +key-value-db = ["sled"] diff --git a/core/lib/src/database/keyvalue.rs b/core/lib/src/database/keyvalue.rs new file mode 100644 index 00000000..f04e9fbd --- /dev/null +++ b/core/lib/src/database/keyvalue.rs @@ -0,0 +1,390 @@ +use std::borrow::Borrow; +use std::convert::{From, TryInto}; + +use sled::{Batch, Db, IVec, Tree}; + +use bitcoin::consensus::encode::{deserialize, serialize}; +use bitcoin::hash_types::Txid; +use bitcoin::util::bip32::{ChildNumber, DerivationPath}; +use bitcoin::{OutPoint, Script, Transaction, TxOut}; + +use crate::database::{BatchDatabase, BatchOperations, Database}; +use crate::error::Error; +use crate::types::*; + +// TODO: rename mod to Sled? + +// path -> script p{i,e} -> script +// script -> path s