فهرست منبع

Remove some unnecessary dependencies.

parazyd 3 سال پیش
والد
کامیت
a654341ea4
4فایلهای تغییر یافته به همراه48 افزوده شده و 54 حذف شده
  1. 0 20
      Cargo.lock
  2. 0 12
      Cargo.toml
  3. 0 16
      src/error.rs
  4. 48 6
      src/zkas/parser.rs

+ 0 - 20
Cargo.lock

@@ -1579,11 +1579,7 @@ dependencies = [
  "futures",
  "halo2_gadgets",
  "halo2_proofs",
- "hex",
- "indexmap 1.9.3",
  "indicatif",
- "ipnet",
- "iprange",
  "itertools 0.10.5",
  "lazy_static",
  "libc",
@@ -1593,7 +1589,6 @@ dependencies = [
  "prettytable-rs",
  "rand 0.8.5",
  "rcgen",
- "ripemd",
  "rusqlite",
  "rustls-pemfile",
  "semver 1.0.17",
@@ -3405,21 +3400,6 @@ dependencies = [
  "windows-sys 0.48.0",
 ]
 
-[[package]]
-name = "ipnet"
-version = "2.8.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "28b29a3cd74f0f4598934efe3aeba42bae0eb4680554128851ebbecb02af14e6"
-
-[[package]]
-name = "iprange"
-version = "0.6.7"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "37209be0ad225457e63814401415e748e2453a5297f9b637338f5fb8afa4ec00"
-dependencies = [
- "ipnet",
-]
-
 [[package]]
 name = "is-terminal"
 version = "0.4.8"

+ 0 - 12
Cargo.toml

@@ -70,14 +70,11 @@ smol = {version = "1.3.0", optional = true}
 
 # Networking
 async-rustls = {version = "0.4.0", features = ["dangerous_configuration"], optional = true}
-iprange = {version = "0.6.7", optional = true}
-ipnet = {version = "2.7.2", optional = true}
 socket2 = {version = "0.5.3", optional = true, features = ["all"]}
 
 # Pluggable Transports
 arti-client = {version = "0.9.2", default-features = false, features = ["async-std", "rustls", "onion-service-client"], optional = true}
 tor-hscrypto = {version = "0.3.0", optional = true}
-# TODO: nym ( Read this to figure out impl https://github.com/ChainSafe/rust-libp2p-nym )
 
 # TLS cert utilities
 ed25519-compact = {version = "2.0.4", optional = true}
@@ -87,7 +84,6 @@ x509-parser = {version = "0.15.0", features = ["validate", "verify"], optional =
 
 # Encoding
 bs58 = {version = "0.5.0", optional = true}
-hex = {version = "0.4.3", optional = true}
 serde_json = {version = "1.0.96", optional = true}
 serde = {version = "1.0.164", features = ["derive"], optional = true}
 semver = {version = "1.0.17", optional = true}
@@ -103,7 +99,6 @@ chrono = {version = "0.4.26", optional = true}
 darkfi-serial = {path = "src/serial", optional = true}
 darkfi-derive = {path = "src/serial/derive", optional = true}
 darkfi-derive-internal = {path = "src/serial/derive-internal", optional = true}
-indexmap = {version = "1.9.3", optional = true}
 itertools = {version = "0.10.5", optional = true}
 lazy_static = {version = "1.4.0", optional = true}
 # TODO: Test without serde
@@ -113,7 +108,6 @@ url = {version = "2.4.0", features = ["serde"], optional = true}
 # TODO: Implement something simple and kill these deps
 indicatif = {version = "0.17.5", optional = true}
 simplelog = {version = "0.12.1", optional = true}
-ripemd = {version = "0.1.3", optional = true}
 
 # Crypto
 rand = {version = "0.8.5", optional = true}
@@ -199,7 +193,6 @@ dht = [
 event-graph = [
     "blake3",
     "chrono",
-    "hex",
     "rand",
 
     "async-runtime",
@@ -210,9 +203,6 @@ event-graph = [
 net = [
     "ed25519-compact",
     "async-rustls",
-    "hex",
-    "iprange",
-    "ipnet",
     "structopt",
     "structopt-toml",
     "rand",
@@ -249,7 +239,6 @@ raft = [
 ]
 
 rpc = [
-    "hex",
     "rand",
     "serde",
     "serde_json",
@@ -315,7 +304,6 @@ zk = [
 ]
 
 zkas = [
-    "indexmap",
     "itertools",
 
     "darkfi-serial",

+ 0 - 16
src/error.rs

@@ -94,10 +94,6 @@ pub enum Error {
     #[error(transparent)]
     Bs58DecodeError(#[from] bs58::decode::Error),
 
-    #[cfg(feature = "hex")]
-    #[error(transparent)]
-    HexDecodeError(#[from] hex::FromHexError),
-
     #[error("Bad operation type byte")]
     BadOperationType,
 
@@ -221,18 +217,6 @@ pub enum Error {
     // =======================
     // Protocol-related errors
     // =======================
-    #[error("Unsupported chain")]
-    UnsupportedChain,
-
-    #[error("Unsupported token")]
-    UnsupportedToken,
-
-    #[error("Unsupported coin network")]
-    UnsupportedCoinNetwork,
-
-    #[error("Raft error: {0}")]
-    RaftError(String),
-
     #[error("JSON-RPC error: {0}")]
     JsonRpcError(String),
 

+ 48 - 6
src/zkas/parser.rs

@@ -16,9 +16,8 @@
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
 
-use std::{iter::Peekable, str::Chars};
+use std::{borrow::Borrow, collections::HashMap, hash::Hash, iter::Peekable, str::Chars};
 
-use indexmap::IndexMap;
 use itertools::Itertools;
 
 use super::{
@@ -44,6 +43,49 @@ const VALID_ECFIXEDPOINTSHORT: [&str; 1] = ["VALUE_COMMIT_VALUE"];
 /// Valid EcFixedPointBase constant names supported by the VM.
 const VALID_ECFIXEDPOINTBASE: [&str; 1] = ["NULLIFIER_K"];
 
+#[derive(Clone)]
+struct IndexMap<K, V> {
+    pub order: Vec<K>,
+    pub map: HashMap<K, V>,
+}
+
+impl<K, V> IndexMap<K, V> {
+    fn new() -> Self {
+        Self { order: vec![], map: HashMap::new() }
+    }
+}
+
+impl<K, V> IndexMap<K, V>
+where
+    K: Eq + Hash + Send + Sync + Clone + 'static,
+    V: Send + Sync + Clone + 'static,
+{
+    fn contains_key<Q: ?Sized>(&self, k: &Q) -> bool
+    where
+        K: Borrow<Q>,
+        Q: Hash + Eq,
+    {
+        self.map.contains_key(k)
+    }
+
+    fn get<Q: ?Sized>(&self, k: &Q) -> Option<&V>
+    where
+        K: Borrow<Q>,
+        Q: Hash + Eq,
+    {
+        self.map.get(k)
+    }
+
+    fn insert(&mut self, k: K, v: V) -> Option<V> {
+        self.order.push(k.clone());
+        self.map.insert(k, v)
+    }
+
+    fn scam_iter(&self) -> Vec<(K, V)> {
+        self.order.iter().map(|k| (k.clone(), self.get(k).unwrap().clone())).collect()
+    }
+}
+
 pub struct Parser {
     tokens: Vec<Token>,
     error: ErrorEmitter,
@@ -373,8 +415,8 @@ impl Parser {
 
         // k = name
         // v = (name, type)
-        for (k, v) in ast {
-            if &v.0.token != k {
+        for (k, v) in ast.scam_iter() {
+            if v.0.token != k {
                 self.error.abort(
                     &format!("Constant name `{}` doesn't match token `{}`.", v.0.token, k),
                     v.0.line,
@@ -482,8 +524,8 @@ impl Parser {
 
         // k = name
         // v = (name, type)
-        for (k, v) in ast {
-            if &v.0.token != k {
+        for (k, v) in ast.scam_iter() {
+            if v.0.token != k {
                 self.error.abort(
                     &format!("Witness name `{}` doesn't match token `{}`.", v.0.token, k),
                     v.0.line,