diff --git a/Cargo.toml b/Cargo.toml index 3db8fa203..898efd332 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,10 +30,12 @@ native-tls = {version = "0.2.8", optional = true} # Encoding hex = {version = "0.4.3", optional = true} +toml = {version = "0.5.8", optional = true} serde = {version = "1.0.133", features = ["derive"], optional = true} serde_json = {version = "1.0.74", optional = true} # Utilities +clap = {version = "3.0.7", features = ["derive"], optional = true} dirs = {version = "4.0.0", optional = true} url = {version = "2.2.2", optional = true} @@ -58,11 +60,13 @@ optional = true async-runtime = ["async-std", "async-channel", "async-executor", "async-trait", "futures", "smol"] async-net = ["async-native-tls", "native-tls"] websockets = ["tungstenite", "async-tungstenite"] -util = ["async-runtime", "hex", "serde", "serde_json", "dirs", "num-bigint"] -rpc = ["async-net", "util", "websockets", "url"] -chain = ["rocksdb", "util"] +util = ["hex", "serde", "serde_json", "dirs", "num-bigint"] +rpc = ["async-runtime", "async-net", "util", "websockets", "url"] +chain = ["async-runtime", "rocksdb", "util"] tui = ["async-std", "termion"] system = ["async-runtime"] +cli = ["toml", "serde", "clap", "util"] +net = ["async-runtime", "util", "system"] # [dependencies.halo2_gadgets] # git = "https://github.com/parazyd/halo2_gadgets.git" diff --git a/src/crypto/mod.rs b/src/crypto/mod.rs index 7373ce1f8..b47d22296 100644 --- a/src/crypto/mod.rs +++ b/src/crypto/mod.rs @@ -10,6 +10,7 @@ pub mod nullifier; pub mod proof; pub mod schnorr; pub mod spend_proof; +pub mod types; pub mod util; pub(crate) use mint_proof::MintRevealedValues; diff --git a/src/types.rs b/src/crypto/types.rs similarity index 100% rename from src/types.rs rename to src/crypto/types.rs diff --git a/src/error.rs b/src/error.rs index 86da744f0..89c1fbbe3 100644 --- a/src/error.rs +++ b/src/error.rs @@ -38,8 +38,6 @@ pub enum Error { #[error("No url found")] NoUrlFound, - // #[error("Malformed packet")] - // MalformedPacket, // #[error(transparent)] // AddrParseError(#[from] std::net::AddrParseError), // #[error(transparent)] @@ -61,8 +59,11 @@ pub enum Error { #[cfg(feature = "util")] #[error("Json serialization error: `{0}`")] SerdeJsonError(String), - // #[error(transparent)] - // TomlDeserializeError(#[from] toml::de::Error), + + #[cfg(feature = "cli")] + #[error(transparent)] + TomlDeserializeError(#[from] toml::de::Error), + // #[error(transparent)] // TomlSerializeError(#[from] toml::ser::Error), // #[error("Bincode serialization error: `{0}`")] @@ -83,8 +84,6 @@ pub enum Error { // MissingParams, // #[error("Contract is poorly defined")] // BadContract, - // #[error("Operation failed")] - // OperationFailed, // #[error("PLONK error: `{0}`")] // PlonkError(String), // #[error("Unable to decrypt mint note")] @@ -135,21 +134,24 @@ pub enum Error { #[error("TungsteniteError: `{0}`")] TungsteniteError(String), - // /// Network - // #[error("Connection failed")] - // ConnectFailed, - // #[error("Connection timed out")] - // ConnectTimeout, - // #[error("Channel stopped")] - // ChannelStopped, - // #[error("Channel timed out")] - // ChannelTimeout, - // #[error("Service stopped")] - // ServiceStopped, + #[error("Connection failed")] + ConnectFailed, + #[error("Connection timed out")] + ConnectTimeout, + #[error("Channel stopped")] + ChannelStopped, + #[error("Channel timed out")] + ChannelTimeout, + #[error("Service stopped")] + ServiceStopped, + #[error("Operation failed")] + OperationFailed, + #[error("Malformed packet")] + MalformedPacket, + + #[error("No config file detected. Please create one.")] + ConfigNotFound, - // /// Util - // #[error("No config file detected. Please create one.")] - // ConfigNotFound, #[cfg(feature = "util")] #[error("No keypair file detected.")] KeypairPathNotFound, diff --git a/src/lib.rs b/src/lib.rs index cd56d5720..3431e0180 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,30 +1,27 @@ pub mod error; pub use error::{Error, Result}; -#[cfg(feature = "cli")] -pub mod cli; - #[cfg(feature = "crypto")] pub mod crypto; #[cfg(feature = "crypto")] pub mod zk; -#[cfg(feature = "crypto")] -pub mod types; - -#[cfg(feature = "chain")] -pub mod chain; - -#[cfg(feature = "net")] -pub mod net; - #[cfg(feature = "node")] pub mod node; #[cfg(feature = "node")] pub mod tx; +#[cfg(feature = "net")] +pub mod net; + +#[cfg(feature = "cli")] +pub mod cli; + +#[cfg(feature = "chain")] +pub mod chain; + #[cfg(feature = "system")] pub mod system; diff --git a/src/net/message_subscriber.rs b/src/net/message_subscriber.rs index bbb5b87a9..b14356348 100644 --- a/src/net/message_subscriber.rs +++ b/src/net/message_subscriber.rs @@ -5,9 +5,9 @@ use rand::Rng; use std::{any::Any, collections::HashMap, io, io::Cursor, sync::Arc}; use crate::{ - error::{Error, Result}, net::messages::Message, - serial::{Decodable, Encodable}, + util::serial::{Decodable, Encodable}, + Error, Result, }; /// 64bit identifier for message subscription. diff --git a/src/net/messages.rs b/src/net/messages.rs index bdaf2188b..1c42a7abb 100644 --- a/src/net/messages.rs +++ b/src/net/messages.rs @@ -3,8 +3,8 @@ use log::*; use std::{io, net::SocketAddr}; use crate::{ - error::{Error, Result}, - serial::{Decodable, Encodable, VarInt}, + util::serial::{Decodable, Encodable, VarInt}, + Error, Result, }; const MAGIC_BYTES: [u8; 4] = [0xd9, 0xef, 0xb6, 0x7d]; diff --git a/src/util/mod.rs b/src/util/mod.rs index b19a07340..a3fe71640 100644 --- a/src/util/mod.rs +++ b/src/util/mod.rs @@ -1,12 +1,17 @@ +#[cfg(feature = "async-runtime")] pub mod async_serial; +#[cfg(feature = "async-runtime")] pub mod async_util; + pub mod endian; pub mod net_name; pub mod parse; pub mod path; pub mod serial; +#[cfg(feature = "async-runtime")] pub use async_util::sleep; + pub use net_name::NetworkName; pub use parse::{decode_base10, encode_base10}; pub use path::{expand_path, join_config_path, load_keypair_to_str};