Skip to content
This repository was archived by the owner on Dec 9, 2023. It is now read-only.

Commit 0842f0e

Browse files
committed
Making SQL and NoSQL storage engines optional
1 parent f403605 commit 0842f0e

File tree

10 files changed

+48
-38
lines changed

10 files changed

+48
-38
lines changed

Diff for: .gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@
1010
# Temporary directory for debug data storage
1111
/data
1212
# /sample
13+
14+
test/data

Diff for: Cargo.toml

+5-2
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ electrum-client = { version = "0.5.0-beta.1", optional = true, git = "https://gi
4747
lazy_static = "1.4"
4848
nix = { version = "0.19", optional = true }
4949
chrono = "0.4"
50-
diesel = { version = "1.4", features = ["sqlite", "uuid", "numeric", "chrono"] }
51-
hammersbald = "2.4"
50+
diesel = { version = "1.4", optional = true, features = ["sqlite", "uuid", "numeric", "chrono"] }
51+
hammersbald = { version = "2.4", optional = true }
5252
# Serialization & parsing
5353
serde_crate = { package = "serde", version = "1", features = ["derive"], optional = true }
5454
serde_with = { version = "1.5", optional = true }
@@ -75,6 +75,7 @@ shellexpand = { version = "2.0", optional = true }
7575
# 5. Simple cli utility app: `shell`
7676
[features]
7777
default = ["client", "fungibles"]
78+
all = ["server", "cli", "serde", "tor", "sql", "nosql", "vendored_openssl", "fungibles", "collectibles", "identities", "auditlogs"]
7879

7980
# Server is a standalone application that runs daemon
8081
server = ["node", "shell", "nix", "microservices/server"]
@@ -110,6 +111,8 @@ serde = ["serde_crate", "serde_with", "serde_yaml", "serde_json", "toml",
110111
"amplify/serde", "lnpbp/serde", "internet2/serde", "microservices/serde",
111112
"chrono/serde", "bitcoin/serde", "rgb20/serde"]
112113
tor = ["microservices/tor", "internet2/tor"]
114+
sql = ["diesel"]
115+
nosql = ["hammersbald"]
113116
vendored_openssl = ["microservices/vendored_openssl", "internet2/vendored_openssl"]
114117

115118
# Schema-specific components exposed as features:

Diff for: src/error.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub enum BootstrapError {
3939

4040
#[cfg(feature = "fungibles")]
4141
#[from(crate::fungibled::FileCacheError)]
42-
#[from(crate::fungibled::SqlCacheError)]
42+
#[cfg_attr(feature = "sql", from(crate::fungibled::SqlCacheError))]
4343
CacheError,
4444

4545
Other,
@@ -90,7 +90,7 @@ pub enum ServiceErrorDomain {
9090

9191
#[cfg(feature = "fungibles")]
9292
#[from(crate::fungibled::FileCacheError)]
93-
#[from(crate::fungibled::SqlCacheError)]
93+
#[cfg_attr(feature = "sql", from(crate::fungibled::SqlCacheError))]
9494
Cache,
9595

9696
Multithreading,

Diff for: src/fungibled/cache/cache.rs

-28
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use rgb::prelude::*;
1515
use rgb20::Asset;
1616
use std::collections::BTreeMap;
1717

18-
use super::sql::SqlCacheError;
1918
use super::FileCacheError;
2019
use crate::error::{BootstrapError, ServiceErrorDomain};
2120
use crate::util::file::FileMode;
@@ -102,30 +101,3 @@ impl From<FileCacheError> for CacheError {
102101
}
103102
}
104103
}
105-
106-
impl From<SqlCacheError> for CacheError {
107-
fn from(err: SqlCacheError) -> Self {
108-
match err {
109-
SqlCacheError::Io(e) => Self::Io(format!("{:?}", e)),
110-
SqlCacheError::Sqlite(e) => {
111-
Self::Sqlite(format!("Error from sqlite asset cache {}", e.to_string()))
112-
}
113-
SqlCacheError::HexDecoding(_) => Self::DataIntegrityError(format!(
114-
"Wrong hex encoded data in sqlite asset cache table"
115-
)),
116-
SqlCacheError::Generic(e) => Self::DataIntegrityError(e),
117-
SqlCacheError::WrongChainData(e) => Self::DataIntegrityError(format!(
118-
"Wrong Chain data in sqlite asset cache table: {}",
119-
e
120-
)),
121-
SqlCacheError::NotFound => {
122-
Self::DataIntegrityError(format!("Asset cache sqlite database file not found"))
123-
}
124-
SqlCacheError::BlindKey(e) => Self::DataIntegrityError(format!(
125-
"Wrong amount blinding factor in asset cache sqlite database: {}",
126-
e
127-
)),
128-
SqlCacheError::Bech32(e) => Self::DataIntegrityError(e.to_string()),
129-
}
130-
}
131-
}

Diff for: src/fungibled/cache/file.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ impl Cache for FileCache {
264264
}
265265
}
266266

267-
#[cfg(test)]
267+
#[cfg(all(test, feature = "sql"))]
268268
mod test {
269269
use super::super::sql::{SqlCache, SqlCacheConfig};
270270
use super::*;

Diff for: src/fungibled/cache/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313

1414
mod cache;
1515
mod file;
16+
#[cfg(feature = "sql")]
1617
mod sql;
1718

1819
pub use cache::{Cache, CacheError};
1920
pub use file::{FileCache, FileCacheConfig, FileCacheError};
21+
#[cfg(feature = "sql")]
2022
pub use sql::{SqlCache, SqlCacheConfig, SqlCacheError};

Diff for: src/fungibled/cache/sql.rs

+27
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,33 @@ pub enum SqlCacheError {
6161
NotFound,
6262
}
6363

64+
impl From<SqlCacheError> for CacheError {
65+
fn from(err: SqlCacheError) -> Self {
66+
match err {
67+
SqlCacheError::Io(e) => Self::Io(format!("{:?}", e)),
68+
SqlCacheError::Sqlite(e) => {
69+
Self::Sqlite(format!("Error from sqlite asset cache {}", e.to_string()))
70+
}
71+
SqlCacheError::HexDecoding(_) => Self::DataIntegrityError(format!(
72+
"Wrong hex encoded data in sqlite asset cache table"
73+
)),
74+
SqlCacheError::Generic(e) => Self::DataIntegrityError(e),
75+
SqlCacheError::WrongChainData(e) => Self::DataIntegrityError(format!(
76+
"Wrong Chain data in sqlite asset cache table: {}",
77+
e
78+
)),
79+
SqlCacheError::NotFound => {
80+
Self::DataIntegrityError(format!("Asset cache sqlite database file not found"))
81+
}
82+
SqlCacheError::BlindKey(e) => Self::DataIntegrityError(format!(
83+
"Wrong amount blinding factor in asset cache sqlite database: {}",
84+
e
85+
)),
86+
SqlCacheError::Bech32(e) => Self::DataIntegrityError(e.to_string()),
87+
}
88+
}
89+
}
90+
6491
#[derive(Clone, PartialEq, Eq, Hash, Debug, Display)]
6592
#[display(Debug)]
6693
pub struct SqlCacheConfig {

Diff for: src/fungibled/mod.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,14 @@
1313

1414
mod config;
1515
mod runtime;
16+
#[cfg(feature = "sql")]
1617
pub(self) mod sql;
1718

1819
pub(self) mod cache;
1920

2021
pub use config::{Config, Opts};
2122
pub use runtime::{main_with_config, Runtime};
2223

23-
pub use cache::{CacheError, FileCacheError, SqlCacheError};
24+
#[cfg(feature = "sql")]
25+
pub use cache::SqlCacheError;
26+
pub use cache::{CacheError, FileCacheError};

Diff for: src/lib.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,9 @@ extern crate serde_crate as serde;
3434
#[macro_use]
3535
extern crate serde_with;
3636

37-
#[cfg_attr(feature = "fungibles", macro_use)]
38-
pub extern crate diesel;
39-
40-
extern crate hammersbald;
37+
#[cfg(all(feature = "fungibles", feature = "sql"))]
38+
#[macro_use]
39+
extern crate diesel;
4140

4241
#[cfg(feature = "cli")]
4342
pub mod cli;

Diff for: src/stashd/storage/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@
1212
// If not, see <https://opensource.org/licenses/MIT>.
1313

1414
mod disk;
15+
#[cfg(feature = "hammersbald")]
1516
mod hammersbald;
1617
mod store;
1718

19+
#[cfg(feature = "hammersbald")]
1820
pub use self::hammersbald::HammersbaldStorage;
1921
pub use disk::{DiskStorage, DiskStorageConfig, DiskStorageError};
2022
pub use store::Store;

0 commit comments

Comments
 (0)