Sfoglia il codice sorgente

Add "net" feature.

parazyd 4 anni fa
parent
commit
f3045f80e5
8 ha cambiato i file con 48 aggiunte e 39 eliminazioni
  1. 7 3
      Cargo.toml
  2. 1 0
      src/crypto/mod.rs
  3. 0 0
      src/crypto/types.rs
  4. 23 21
      src/error.rs
  5. 8 11
      src/lib.rs
  6. 2 2
      src/net/message_subscriber.rs
  7. 2 2
      src/net/messages.rs
  8. 5 0
      src/util/mod.rs

+ 7 - 3
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"

+ 1 - 0
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;

+ 0 - 0
src/types.rs → src/crypto/types.rs


+ 23 - 21
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,
-
-    // /// Util
-    // #[error("No config file detected. Please create one.")]
-    // ConfigNotFound,
+    #[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,
+
     #[cfg(feature = "util")]
     #[error("No keypair file detected.")]
     KeypairPathNotFound,

+ 8 - 11
src/lib.rs

@@ -1,29 +1,26 @@
 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 = "node")]
+pub mod node;
 
-#[cfg(feature = "chain")]
-pub mod chain;
+#[cfg(feature = "node")]
+pub mod tx;
 
 #[cfg(feature = "net")]
 pub mod net;
 
-#[cfg(feature = "node")]
-pub mod node;
+#[cfg(feature = "cli")]
+pub mod cli;
 
-#[cfg(feature = "node")]
-pub mod tx;
+#[cfg(feature = "chain")]
+pub mod chain;
 
 #[cfg(feature = "system")]
 pub mod system;

+ 2 - 2
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.

+ 2 - 2
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];

+ 5 - 0
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};