فهرست منبع

Apply some linting cleanups.

parazyd 4 سال پیش
والد
کامیت
81f95745f3
12فایلهای تغییر یافته به همراه38 افزوده شده و 46 حذف شده
  1. 2 0
      src/crypto/merkle.rs
  2. 6 9
      src/crypto/merkle_node2.rs
  3. 1 1
      src/crypto/mint_proof.rs
  4. 4 7
      src/crypto/schnorr.rs
  5. 4 2
      src/rpc/websockets.rs
  6. 3 3
      src/service/eth.rs
  7. 1 2
      src/state.rs
  8. 1 4
      src/tx/mod.rs
  9. 1 1
      src/tx/partial.rs
  10. 1 3
      src/util/address.rs
  11. 13 13
      src/vm.rs
  12. 1 1
      src/wallet/walletdb.rs

+ 2 - 0
src/crypto/merkle.rs

@@ -42,9 +42,11 @@ impl MerkleHash {
         MerkleHash(value.inner())
         MerkleHash(value.inner())
     }
     }
 
 
+    /*
     pub(crate) fn inner(&self) -> pallas::Base {
     pub(crate) fn inner(&self) -> pallas::Base {
         self.0
         self.0
     }
     }
+    */
 
 
     pub fn to_bytes(&self) -> [u8; 32] {
     pub fn to_bytes(&self) -> [u8; 32] {
         self.0.to_bytes()
         self.0.to_bytes()

+ 6 - 9
src/crypto/merkle_node2.rs

@@ -1,12 +1,9 @@
-use halo2_gadgets::{primitives::sinsemilla::HashDomain, utilities::Var};
+use std::{io, iter};
+
+use halo2_gadgets::primitives::sinsemilla::HashDomain;
 use incrementalmerkletree::{Altitude, Hashable};
 use incrementalmerkletree::{Altitude, Hashable};
 use lazy_static::lazy_static;
 use lazy_static::lazy_static;
-use pasta_curves::{
-    arithmetic::{Field, FieldExt},
-    group::ff::PrimeFieldBits,
-    pallas,
-};
-use std::{io, iter};
+use pasta_curves::{arithmetic::FieldExt, group::ff::PrimeFieldBits, pallas};
 use subtle::ConstantTimeEq;
 use subtle::ConstantTimeEq;
 
 
 use crate::{
 use crate::{
@@ -49,7 +46,7 @@ impl std::hash::Hash for MerkleNode {
 
 
 impl Hashable for MerkleNode {
 impl Hashable for MerkleNode {
     fn empty_leaf() -> Self {
     fn empty_leaf() -> Self {
-        MerkleNode(UNCOMMITTED_ORCHARD.clone())
+        MerkleNode(*UNCOMMITTED_ORCHARD)
     }
     }
 
 
     /// Implements `MerkleCRH^Orchard` as defined in
     /// Implements `MerkleCRH^Orchard` as defined in
@@ -85,7 +82,7 @@ impl Hashable for MerkleNode {
 
 
 impl Encodable for MerkleNode {
 impl Encodable for MerkleNode {
     fn encode<S: io::Write>(&self, mut s: S) -> Result<usize> {
     fn encode<S: io::Write>(&self, mut s: S) -> Result<usize> {
-        Ok(self.0.encode(&mut s)?)
+        self.0.encode(&mut s)
     }
     }
 }
 }
 
 

+ 1 - 1
src/crypto/mint_proof.rs

@@ -65,7 +65,7 @@ impl MintRevealedValues {
 
 
         vec![
         vec![
             //DrkCircuitField::from_bytes(&self.coin).unwrap(),
             //DrkCircuitField::from_bytes(&self.coin).unwrap(),
-            self.coin.clone(),
+            self.coin,
             *value_coords.x(),
             *value_coords.x(),
             *value_coords.y(),
             *value_coords.y(),
             *token_coords.x(),
             *token_coords.x(),

+ 4 - 7
src/crypto/schnorr.rs

@@ -6,15 +6,12 @@ use rand::rngs::OsRng;
 
 
 use super::{
 use super::{
     constants::{OrchardFixedBases, DRK_SCHNORR_DOMAIN},
     constants::{OrchardFixedBases, DRK_SCHNORR_DOMAIN},
-    util::{hash_to_scalar, mod_r_p},
+    util::hash_to_scalar,
 };
 };
 use crate::{
 use crate::{
     error::Result,
     error::Result,
     serial::{Decodable, Encodable},
     serial::{Decodable, Encodable},
-    types::{
-        derive_public_key, DrkCoinBlind, DrkPublicKey, DrkSecretKey, DrkSerial, DrkTokenId,
-        DrkValueBlind, DrkValueCommit,
-    },
+    types::{DrkPublicKey, DrkValueBlind, DrkValueCommit},
 };
 };
 
 
 #[derive(Clone)]
 #[derive(Clone)]
@@ -73,8 +70,8 @@ impl PublicKey {
 }
 }
 
 
 impl Encodable for PublicKey {
 impl Encodable for PublicKey {
-    fn encode<S: io::Write>(&self, mut s: S) -> Result<usize> {
-        Ok(self.0.encode(s)?)
+    fn encode<S: io::Write>(&self, s: S) -> Result<usize> {
+        self.0.encode(s)
     }
     }
 }
 }
 
 

+ 4 - 2
src/rpc/websockets.rs

@@ -64,8 +64,10 @@ impl Stream for WsStream {
 /// Connects to a WebSocket address (optionally secured by TLS).
 /// Connects to a WebSocket address (optionally secured by TLS).
 pub async fn connect(addr: &str, tls: TlsConnector) -> DrkResult<(WsStream, Response)> {
 pub async fn connect(addr: &str, tls: TlsConnector) -> DrkResult<(WsStream, Response)> {
     let url = Url::parse(addr)?;
     let url = Url::parse(addr)?;
-    let host =
-        url.host_str().ok_or(Error::UrlParseError(format!("Missing Host in {}", url)))?.to_string();
+    let host = url
+        .host_str()
+        .ok_or_else(|| Error::UrlParseError(format!("Missing host in {}", url)))?
+        .to_string();
     let port = url
     let port = url
         .port_or_known_default()
         .port_or_known_default()
         .ok_or_else(|| Error::UrlParseError(format!("Missing port in {}", url)))?;
         .ok_or_else(|| Error::UrlParseError(format!("Missing port in {}", url)))?;

+ 3 - 3
src/service/eth.rs

@@ -14,7 +14,7 @@ use serde_json::{json, Value};
 use super::bridge::{NetworkClient, TokenNotification, TokenSubscribtion};
 use super::bridge::{NetworkClient, TokenNotification, TokenSubscribtion};
 use crate::{
 use crate::{
     rpc::{jsonrpc, jsonrpc::JsonResult},
     rpc::{jsonrpc, jsonrpc::JsonResult},
-    serial::{deserialize, serialize, Decodable, Encodable},
+    serial::{deserialize, serialize},
     types::*,
     types::*,
     util::{generate_id, parse::truncate, NetworkName},
     util::{generate_id, parse::truncate, NetworkName},
     Error, Result,
     Error, Result,
@@ -265,7 +265,7 @@ impl EthClient {
         Ok(())
         Ok(())
     }
     }
 
 
-    async fn unsubscribe(&self, pubkey: &String) {
+    async fn unsubscribe(&self, pubkey: &str) {
         let mut subscriptions = self.subscriptions.lock().await;
         let mut subscriptions = self.subscriptions.lock().await;
         let index = subscriptions.iter().position(|p| p == pubkey);
         let index = subscriptions.iter().position(|p| p == pubkey);
         if let Some(ind) = index {
         if let Some(ind) = index {
@@ -336,7 +336,7 @@ impl EthClient {
         let block = block.as_str().unwrap();
         let block = block.as_str().unwrap();
 
 
         // Native ETH balance
         // Native ETH balance
-        let hexbalance = self.get_eth_balance(&acc, block).await?;
+        let hexbalance = self.get_eth_balance(acc, block).await?;
         let hexbalance = hexbalance.as_str().unwrap().trim_start_matches("0x");
         let hexbalance = hexbalance.as_str().unwrap().trim_start_matches("0x");
         let balance = BigUint::parse_bytes(hexbalance.as_bytes(), 16).unwrap();
         let balance = BigUint::parse_bytes(hexbalance.as_bytes(), 16).unwrap();
 
 

+ 1 - 2
src/state.rs

@@ -6,7 +6,6 @@ use crate::{
         proof::VerifyingKey, schnorr,
         proof::VerifyingKey, schnorr,
     },
     },
     tx::Transaction,
     tx::Transaction,
-    types::{DrkCoinBlind, DrkPublicKey, DrkSecretKey, DrkSerial, DrkTokenId, DrkValueBlind},
 };
 };
 
 
 pub trait ProgramState {
 pub trait ProgramState {
@@ -97,7 +96,7 @@ pub fn state_transition<S: ProgramState>(state: &S, tx: Transaction) -> VerifyRe
     let mut enc_notes = vec![];
     let mut enc_notes = vec![];
     for output in tx.outputs {
     for output in tx.outputs {
         // Gather all the coins
         // Gather all the coins
-        coins.push(Coin(output.revealed.coin.clone()));
+        coins.push(Coin(output.revealed.coin));
         enc_notes.push(output.enc_note);
         enc_notes.push(output.enc_note);
     }
     }
 
 

+ 1 - 4
src/tx/mod.rs

@@ -19,10 +19,7 @@ use crate::{
     impl_vec,
     impl_vec,
     serial::{Decodable, Encodable, VarInt},
     serial::{Decodable, Encodable, VarInt},
     state,
     state,
-    types::{
-        DrkCoinBlind, DrkPublicKey, DrkSecretKey, DrkSerial, DrkTokenId, DrkValue, DrkValueBlind,
-        DrkValueCommit,
-    },
+    types::{DrkTokenId, DrkValueBlind, DrkValueCommit},
 };
 };
 
 
 pub use self::builder::{
 pub use self::builder::{

+ 1 - 1
src/tx/partial.rs

@@ -6,7 +6,7 @@ use crate::{
     error::Result,
     error::Result,
     impl_vec,
     impl_vec,
     serial::{Decodable, Encodable, VarInt},
     serial::{Decodable, Encodable, VarInt},
-    types::{DrkCoinBlind, DrkPublicKey, DrkSecretKey, DrkSerial, DrkTokenId, DrkValueBlind},
+    types::{DrkTokenId, DrkValueBlind},
 };
 };
 
 
 pub struct PartialTransaction {
 pub struct PartialTransaction {

+ 1 - 3
src/util/address.rs

@@ -31,10 +31,8 @@ impl Address {
     pub fn pkh_address(raw: &DrkPublicKey) -> String {
     pub fn pkh_address(raw: &DrkPublicKey) -> String {
         let mut hash = Self::get_hash(raw);
         let mut hash = Self::get_hash(raw);
 
 
-        let mut payload = vec![];
-
         // add version
         // add version
-        payload.push(0x00 as u8);
+        let mut payload = vec![0x00_u8];
 
 
         // add public key hash
         // add public key hash
         payload.append(&mut hash);
         payload.append(&mut hash);

+ 13 - 13
src/vm.rs

@@ -32,7 +32,7 @@ use crate::{
     crypto::{
     crypto::{
         arith_chip::{ArithmeticChip, ArithmeticChipConfig},
         arith_chip::{ArithmeticChip, ArithmeticChipConfig},
         constants::{
         constants::{
-            sinsemilla::{OrchardCommitDomains, OrchardHashDomains, MERKLE_CRH_PERSONALIZATION},
+            sinsemilla::{OrchardCommitDomains, OrchardHashDomains},
             OrchardFixedBases,
             OrchardFixedBases,
         },
         },
     },
     },
@@ -122,7 +122,7 @@ impl MintConfig {
 #[derive(Clone, Debug)]
 #[derive(Clone, Debug)]
 pub struct ZkCircuit<'a> {
 pub struct ZkCircuit<'a> {
     pub const_fixed_points: HashMap<String, OrchardFixedBases>,
     pub const_fixed_points: HashMap<String, OrchardFixedBases>,
-    pub constants: &'a Vec<(String, ZkType)>,
+    pub constants: &'a [(String, ZkType)],
     pub contract: &'a ZkContract,
     pub contract: &'a ZkContract,
     // For each type create a separate stack
     // For each type create a separate stack
     pub witness_base: HashMap<String, Option<pallas::Base>>,
     pub witness_base: HashMap<String, Option<pallas::Base>>,
@@ -133,7 +133,7 @@ pub struct ZkCircuit<'a> {
 impl<'a> ZkCircuit<'a> {
 impl<'a> ZkCircuit<'a> {
     pub fn new(
     pub fn new(
         const_fixed_points: HashMap<String, OrchardFixedBases>,
         const_fixed_points: HashMap<String, OrchardFixedBases>,
-        constants: &'a Vec<(String, ZkType)>,
+        constants: &'a [(String, ZkType)],
         contract: &'a ZkContract,
         contract: &'a ZkContract,
     ) -> Self {
     ) -> Self {
         let mut witness_base = HashMap::new();
         let mut witness_base = HashMap::new();
@@ -177,7 +177,7 @@ impl<'a> ZkCircuit<'a> {
             *self.witness_base.get_mut(name).unwrap() = Some(value);
             *self.witness_base.get_mut(name).unwrap() = Some(value);
             return Ok(())
             return Ok(())
         }
         }
-        return Err(Error::InvalidParamName)
+        Err(Error::InvalidParamName)
     }
     }
 
 
     pub fn witness_scalar(&mut self, name: &str, value: pallas::Scalar) -> Result<()> {
     pub fn witness_scalar(&mut self, name: &str, value: pallas::Scalar) -> Result<()> {
@@ -191,7 +191,7 @@ impl<'a> ZkCircuit<'a> {
             *self.witness_scalar.get_mut(name).unwrap() = Some(value);
             *self.witness_scalar.get_mut(name).unwrap() = Some(value);
             return Ok(())
             return Ok(())
         }
         }
-        return Err(Error::InvalidParamName)
+        Err(Error::InvalidParamName)
     }
     }
 
 
     pub fn witness_merkle_path(
     pub fn witness_merkle_path(
@@ -210,7 +210,7 @@ impl<'a> ZkCircuit<'a> {
             *self.witness_merkle_path.get_mut(name).unwrap() = (Some(leaf_pos), Some(path));
             *self.witness_merkle_path.get_mut(name).unwrap() = (Some(leaf_pos), Some(path));
             return Ok(())
             return Ok(())
         }
         }
-        return Err(Error::InvalidParamName)
+        Err(Error::InvalidParamName)
     }
     }
 }
 }
 
 
@@ -226,7 +226,7 @@ impl<'a> Circuit<pallas::Base> for ZkCircuit<'a> {
         Self {
         Self {
             const_fixed_points: self.const_fixed_points.clone(),
             const_fixed_points: self.const_fixed_points.clone(),
             constants: self.constants,
             constants: self.constants,
-            contract: &self.contract,
+            contract: self.contract,
             witness_base: self.witness_base.keys().map(|key| (key.clone(), None)).collect(),
             witness_base: self.witness_base.keys().map(|key| (key.clone(), None)).collect(),
             witness_scalar: self.witness_scalar.keys().map(|key| (key.clone(), None)).collect(),
             witness_scalar: self.witness_scalar.keys().map(|key| (key.clone(), None)).collect(),
             witness_merkle_path: self
             witness_merkle_path: self
@@ -400,11 +400,11 @@ impl<'a> Circuit<pallas::Base> for ZkCircuit<'a> {
                         config.advices[0],
                         config.advices[0],
                         *value,
                         *value,
                     )?;
                     )?;
-                    stack_base.push(value.clone());
+                    stack_base.push(value);
                 }
                 }
                 ZkType::Scalar => {
                 ZkType::Scalar => {
                     let value = self.witness_scalar.get(variable).expect("witness base set");
                     let value = self.witness_scalar.get(variable).expect("witness base set");
-                    stack_scalar.push(value.clone());
+                    stack_scalar.push(*value);
                 }
                 }
                 ZkType::EcPoint => {
                 ZkType::EcPoint => {
                     unimplemented!();
                     unimplemented!();
@@ -415,7 +415,7 @@ impl<'a> Circuit<pallas::Base> for ZkCircuit<'a> {
                 ZkType::MerklePath => {
                 ZkType::MerklePath => {
                     let value =
                     let value =
                         self.witness_merkle_path.get(variable).expect("witness merkle path set");
                         self.witness_merkle_path.get(variable).expect("witness merkle path set");
-                    stack_merkle_path.push(value.clone());
+                    stack_merkle_path.push(*value);
                 }
                 }
             }
             }
         }
         }
@@ -550,12 +550,12 @@ impl<'a> Circuit<pallas::Base> for ZkCircuit<'a> {
                         chip_1: config.merkle_chip_1(),
                         chip_1: config.merkle_chip_1(),
                         chip_2: config.merkle_chip_2(),
                         chip_2: config.merkle_chip_2(),
                         domain: OrchardHashDomains::MerkleCrh,
                         domain: OrchardHashDomains::MerkleCrh,
-                        leaf_pos: leaf_pos.clone(),
-                        path: path.clone(),
+                        leaf_pos: *leaf_pos,
+                        path: *path,
                     };
                     };
 
 
                     let root =
                     let root =
-                        path.calculate_root(layouter.namespace(|| "calculate root"), leaf.clone())?;
+                        path.calculate_root(layouter.namespace(|| "calculate root"), *leaf)?;
                     stack_base.push(root);
                     stack_base.push(root);
                 }
                 }
             }
             }

+ 1 - 1
src/wallet/walletdb.rs

@@ -1,4 +1,4 @@
-use std::{collections::HashMap, path::Path, sync::Arc};
+use std::{path::Path, sync::Arc};
 
 
 use log::{debug, error, info};
 use log::{debug, error, info};
 use pasta_curves::arithmetic::Field;
 use pasta_curves::arithmetic::Field;