Просмотр исходного кода

create node and blockchain features

ghassmo 4 лет назад
Родитель
Сommit
6e22b4ec9d

+ 26 - 14
Cargo.toml

@@ -16,12 +16,7 @@ git = "https://github.com/parazyd/halo2_gadgets.git"
 rev = "b45c527276bb2309f3b256eb5f45ccdcc5bd8c0f"
 features = ["dev-graph", "test-dependencies"]
 
-[dependencies.rocksdb]
-# TODO: Revert to upstream after bd966750ec861d687913d59a9939a1408ac53131 is merged.
-git = "https://github.com/parazyd/rust-rocksdb"
-rev = "bd966750ec861d687913d59a9939a1408ac53131"
-default-features = false
-features = ["zstd"]
+
 
 [dependencies]
 # Crypto
@@ -65,7 +60,7 @@ lazy_static = "1.4.0"
 log = "0.4.14"
 num_cpus = "1.13.0"
 signal-hook = "0.3.10"
-signal-hook-async-std = "0.2.1"
+
 subtle = "2.4.1"
 thiserror = "1.0.30"
 
@@ -73,25 +68,42 @@ thiserror = "1.0.30"
 async-tungstenite = "0.16.0"
 tungstenite = "0.16.0"
 
-# Used for wallet management.
-sqlx = {version = "0.5.10", features = ["runtime-async-std-native-tls", "sqlite"]}
-libsqlite3-sys = {version = "0.23.1", features = ["bundled-sqlcipher"]}
-
-# Used for gatewayd network transport.
-zeromq = {version = "0.3.1", default-features = false, features = ["async-std-runtime", "all-transport"]}
-
 #tui dependencies
 crossbeam-channel = { version = "0.5.1", optional = true}
 libc = { version = "0.2.112", optional = true}
 termion = { version = "1.5.6", optional = true}
 
+# node dependencies
+## Used for wallet management.
+sqlx = {version = "0.5.10", features = ["runtime-async-std-native-tls", "sqlite"], optional = true}
+libsqlite3-sys = {version = "0.23.1", features = ["bundled-sqlcipher"],  optional = true }
+## Used for gatewayd network transport.
+zeromq = {version = "0.3.1", default-features = false, features = ["async-std-runtime", "all-transport"],  optional = true }
+signal-hook-async-std = {version = "0.2.1", optional = true}
+
+# blockchain dependencies
+[dependencies.rocksdb]
+# TODO: Revert to upstream after bd966750ec861d687913d59a9939a1408ac53131 is merged.
+git = "https://github.com/parazyd/rust-rocksdb"
+rev = "bd966750ec861d687913d59a9939a1408ac53131"
+default-features = false
+features = ["zstd"]
+optional = true
+
+
 [features]
+blockchain = ["rocksdb"]
+node = ["sqlx", "libsqlite3-sys", "zeromq", "signal-hook-async-std"]
 tui = ["termion", "libc", "crossbeam-channel"]
 
 [[bin]]         
 name = "tui_ex"    
 required-features = ["tui"]
 
+[[bin]]         
+name = "tx"    
+required-features = ["node"]
+
 [[example]]
 name = "net"
 path = "example/net.rs"

+ 1 - 1
bin/cashier/Cargo.toml

@@ -6,7 +6,7 @@ edition = "2021"
 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
 
 [dependencies]
-darkfi = {path= "../../"}
+darkfi = {path= "../../", features = ["node", "blockchain"]}
 
 # Encoding and parsing
 serde_json = "1.0.72"

+ 1 - 1
bin/cashier/src/service/btc.rs

@@ -45,7 +45,7 @@ use darkfi::{
     crypto::keypair::PublicKey as DrkPublicKey,
     serial::{deserialize, serialize, Decodable, Encodable},
     util::{expand_path, generate_id2, load_keypair_to_str, NetworkName},
-    wallet::cashierdb::{CashierDb, TokenKey},
+    node::wallet::cashierdb::{CashierDb, TokenKey},
     Error, Result,
 };
 

+ 1 - 1
bin/cashier/src/service/eth.rs

@@ -18,7 +18,7 @@ use darkfi::{
     rpc::{jsonrpc, jsonrpc::JsonResult},
     serial::{deserialize, serialize, Decodable, Encodable},
     util::{generate_id2, parse::truncate, sleep, NetworkName},
-    wallet::cashierdb::{CashierDb, TokenKey},
+    node::wallet::cashierdb::{CashierDb, TokenKey},
     Error, Result,
 };
 

+ 1 - 1
bin/cashier/src/service/sol.rs

@@ -28,7 +28,7 @@ use darkfi::{
     rpc::{jsonrpc, jsonrpc::JsonResult, websockets, websockets::WsStream},
     serial::{deserialize, serialize, Decodable, Encodable},
     util::{expand_path, generate_id2, load_keypair_to_str, parse::truncate, sleep, NetworkName},
-    wallet::cashierdb::{CashierDb, TokenKey},
+    node::wallet::cashierdb::{CashierDb, TokenKey},
     Error, Result,
 };
 

+ 1 - 1
bin/darkfid/Cargo.toml

@@ -6,7 +6,7 @@ edition = "2021"
 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
 
 [dependencies]
-darkfi = {path= "../../"}
+darkfi = {path= "../../", features= ["node", "blockchain"] }
 
 # Encoding and parsing
 serde_json = "1.0.72"

+ 0 - 7
bin/drk/Cargo.toml

@@ -9,17 +9,10 @@ edition = "2021"
 darkfi = {path= "../../"}
 
 # Async
-async-std = "1.10.0"
-async-channel = "1.6.1"
-easy-parallel = "3.1.0"
 async-executor = "1.4.1"
 futures = "0.3.17"
 smol = "1.2.5"
 
 # Utilities
 clap = { version = "3.0.0", features = ["derive"] }
-log = "0.4.14"
-num_cpus = "1.13.0"
-simplelog = "0.11.1"
-thiserror = "1.0.30"
 prettytable-rs = "0.8.0"

+ 1 - 1
bin/gateway/Cargo.toml

@@ -6,7 +6,7 @@ edition = "2021"
 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
 
 [dependencies]
-darkfi = {path= "../../"}
+darkfi = {path= "../../", features= ["node", "blockchain"] }
 
 # Async
 async-std = "1.10.0"

+ 7 - 2
src/lib.rs

@@ -1,19 +1,24 @@
-pub mod blockchain;
 pub mod circuit;
 pub mod cli;
 pub mod crypto;
 pub mod net;
 pub mod rpc;
 pub mod system;
-pub mod tx;
 pub mod types;
 pub mod zk;
 
+#[cfg(feature = "node")]
 pub mod node;
 
+#[cfg(feature = "node")]
+pub mod tx;
+
 #[cfg(feature = "tui")]
 pub mod tui;
 
+#[cfg(feature = "blockchain")]
+pub mod blockchain;
+
 pub mod util;
 
 pub use util::{

+ 9 - 12
src/util/error.rs

@@ -1,5 +1,3 @@
-use crate::node::{client, state};
-
 pub type Result<T> = std::result::Result<T, Error>;
 
 #[derive(Debug, Clone, thiserror::Error)]
@@ -79,8 +77,10 @@ pub enum Error {
     PlonkError(String),
     #[error("Unable to decrypt mint note")]
     NoteDecryptionFailed,
+
+    #[cfg(feature = "node")]
     #[error(transparent)]
-    VerifyFailed(#[from] state::VerifyFailed),
+    VerifyFailed(#[from] crate::node::state::VerifyFailed),
     #[error("MerkleTree is full")]
     TreeFull,
 
@@ -164,18 +164,21 @@ pub enum Error {
     InvalidAddress,
 }
 
+#[cfg(feature = "node")]
 impl From<zeromq::ZmqError> for Error {
     fn from(err: zeromq::ZmqError) -> Error {
         Error::ZmqError(err.to_string())
     }
 }
 
+#[cfg(feature = "blockchain")]
 impl From<rocksdb::Error> for Error {
     fn from(err: rocksdb::Error) -> Error {
         Error::RocksdbError(err.to_string())
     }
 }
 
+#[cfg(feature = "node")]
 impl From<sqlx::error::Error> for Error {
     fn from(err: sqlx::error::Error) -> Error {
         Error::SqlxError(err.to_string())
@@ -212,8 +215,9 @@ impl From<url::ParseError> for Error {
     }
 }
 
-impl From<client::ClientFailed> for Error {
-    fn from(err: client::ClientFailed) -> Error {
+#[cfg(feature = "node")]
+impl From<crate::node::client::ClientFailed> for Error {
+    fn from(err: crate::node::client::ClientFailed) -> Error {
         Error::ClientFailed(err.to_string())
     }
 }
@@ -243,13 +247,6 @@ impl From<halo2::plonk::Error> for Error {
     }
 }
 
-#[cfg(feature = "darkpulse")]
-impl From<rusqlite::Error> for Error {
-    fn from(err: rusqlite::Error) -> Error {
-        Error::SqlxError(err.to_string())
-    }
-}
-
 impl From<Box<bincode::ErrorKind>> for Error {
     fn from(err: Box<bincode::ErrorKind>) -> Error {
         Error::BincodeError(err.to_string())