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

example/dao: remove unused imports

Dastan-glitch 3 лет назад
Родитель
Сommit
d001ebf28a
3 измененных файлов с 67 добавлено и 85 удалено
  1. 14 31
      example/dao/src/dao.rs
  2. 41 41
      example/dao/src/error.rs
  3. 12 13
      example/dao/src/util.rs

+ 14 - 31
example/dao/src/dao.rs

@@ -1,21 +1,10 @@
-use async_std::sync::{Arc, Mutex};
-use std::{
-    any::{Any, TypeId},
-    collections::HashMap,
-    hash::Hasher,
-    io,
-    time::Instant,
-};
+use std::{any::TypeId, time::Instant};
 
-use darkfi_serial::Encodable;
 use incrementalmerkletree::Tree;
-use log::{debug, info};
+use log::debug;
 use pasta_curves::{
     arithmetic::CurveAffine,
-    group::{
-        ff::{Field, PrimeField},
-        Curve, Group,
-    },
+    group::{ff::Field, Curve, Group},
     pallas,
 };
 use rand::rngs::OsRng;
@@ -24,16 +13,10 @@ use darkfi::{
     crypto::{
         keypair::{Keypair, PublicKey, SecretKey},
         proof::{ProvingKey, VerifyingKey},
-        schnorr::{SchnorrPublic, SchnorrSecret, Signature},
-        types::{DrkCircuitField, DrkSpendHook, DrkUserData, DrkValue},
+        types::{DrkSpendHook, DrkUserData, DrkValue},
         util::{pedersen_commitment_u64, poseidon_hash},
-        Proof,
-    },
-    zk::{
-        circuit::{BurnContract, MintContract},
-        vm::ZkCircuit,
-        vm_stack::empty_witnesses,
     },
+    zk::circuit::{BurnContract, MintContract},
     zkas::decoder::ZkBinary,
 };
 
@@ -106,7 +89,7 @@ pub async fn example() -> Result<()> {
         update.apply(&mut states);
     }
 
-    tx.zk_verify(&zk_bins);
+    tx.zk_verify(&zk_bins).unwrap();
     tx.verify_sigs();
 
     Ok(())
@@ -249,7 +232,7 @@ async fn main() -> Result<()> {
         update.apply(&mut states);
     }
 
-    tx.zk_verify(&zk_bins);
+    tx.zk_verify(&zk_bins).unwrap();
     tx.verify_sigs();
 
     // Wallet stuff
@@ -346,7 +329,7 @@ async fn main() -> Result<()> {
         update.apply(&mut states);
     }
 
-    tx.zk_verify(&zk_bins);
+    tx.zk_verify(&zk_bins).unwrap();
     tx.verify_sigs();
 
     //// Wallet
@@ -473,7 +456,7 @@ async fn main() -> Result<()> {
         update.apply(&mut states);
     }
 
-    tx.zk_verify(&zk_bins);
+    tx.zk_verify(&zk_bins).unwrap();
     tx.verify_sigs();
 
     //// Wallet
@@ -619,7 +602,7 @@ async fn main() -> Result<()> {
         update.apply(&mut states);
     }
 
-    tx.zk_verify(&zk_bins);
+    tx.zk_verify(&zk_bins).unwrap();
     tx.verify_sigs();
 
     //// Wallet
@@ -740,7 +723,7 @@ async fn main() -> Result<()> {
         update.apply(&mut states);
     }
 
-    tx.zk_verify(&zk_bins);
+    tx.zk_verify(&zk_bins).unwrap();
     tx.verify_sigs();
 
     //// Wallet
@@ -826,7 +809,7 @@ async fn main() -> Result<()> {
         update.apply(&mut states);
     }
 
-    tx.zk_verify(&zk_bins);
+    tx.zk_verify(&zk_bins).unwrap();
     tx.verify_sigs();
 
     //// Wallet
@@ -912,7 +895,7 @@ async fn main() -> Result<()> {
         update.apply(&mut states);
     }
 
-    tx.zk_verify(&zk_bins);
+    tx.zk_verify(&zk_bins).unwrap();
     tx.verify_sigs();
 
     //// Wallet
@@ -1130,7 +1113,7 @@ async fn main() -> Result<()> {
     }
 
     // Other stuff
-    tx.zk_verify(&zk_bins);
+    tx.zk_verify(&zk_bins).unwrap();
     tx.verify_sigs();
 
     //// Wallet

+ 41 - 41
example/dao/src/error.rs

@@ -1,19 +1,19 @@
-use serde_json::Value;
+// use serde_json::Value;
 
-use darkfi::rpc::jsonrpc::{ErrorCode::ServerError, JsonError, JsonResult};
+// use darkfi::rpc::jsonrpc::{ErrorCode::ServerError, JsonError, JsonResult};
 
 #[derive(Debug, thiserror::Error)]
 pub enum DaoError {
-    #[error("No Proposals found")]
-    NoProposals,
-    #[error("No DAO params found")]
-    DaoNotConfigured,
-    #[error("State transition failed: '{0}'")]
-    StateTransitionFailed(String),
-    #[error("Wallet does not exist")]
-    NoWalletFound,
-    #[error("State not found")]
-    StateNotFound,
+    // #[error("No Proposals found")]
+    // NoProposals,
+    // #[error("No DAO params found")]
+    // DaoNotConfigured,
+    // #[error("State transition failed: '{0}'")]
+    // StateTransitionFailed(String),
+    // #[error("Wallet does not exist")]
+    // NoWalletFound,
+    // #[error("State not found")]
+    // StateNotFound,
     #[error("InternalError")]
     Darkfi(#[from] darkfi::error::Error),
     #[error("Verify proof failed: '{0}', '{0}'")]
@@ -22,35 +22,35 @@ pub enum DaoError {
 
 pub type DaoResult<T> = std::result::Result<T, DaoError>;
 
-pub enum RpcError {
-    Vote = -32101,
-    Propose = -32102,
-    Exec = -32103,
-    Airdrop = -32104,
-    Mint = -32105,
-    Keygen = -32106,
-    Create = -32107,
-    Parse = -32108,
-    Balance = -32109,
-}
+// pub enum RpcError {
+//     Vote = -32101,
+//     Propose = -32102,
+//     Exec = -32103,
+//     Airdrop = -32104,
+//     Mint = -32105,
+//     Keygen = -32106,
+//     Create = -32107,
+//     Parse = -32108,
+//     Balance = -32109,
+// }
 
-fn to_tuple(e: RpcError) -> (i64, String) {
-    let msg = match e {
-        RpcError::Vote => "Failed to cast a Vote",
-        RpcError::Propose => "Failed to generate a Proposal",
-        RpcError::Airdrop => "Failed to transfer an airdrop",
-        RpcError::Keygen => "Failed to generate keypair",
-        RpcError::Create => "Failed to create DAO",
-        RpcError::Exec => "Failed to execute Proposal",
-        RpcError::Mint => "Failed to mint DAO treasury",
-        RpcError::Parse => "Generic parsing error",
-        RpcError::Balance => "Failed to get balance",
-    };
+// fn to_tuple(e: RpcError) -> (i64, String) {
+//     let msg = match e {
+//         RpcError::Vote => "Failed to cast a Vote",
+//         RpcError::Propose => "Failed to generate a Proposal",
+//         RpcError::Airdrop => "Failed to transfer an airdrop",
+//         RpcError::Keygen => "Failed to generate keypair",
+//         RpcError::Create => "Failed to create DAO",
+//         RpcError::Exec => "Failed to execute Proposal",
+//         RpcError::Mint => "Failed to mint DAO treasury",
+//         RpcError::Parse => "Generic parsing error",
+//         RpcError::Balance => "Failed to get balance",
+//     };
 
-    (e as i64, msg.to_string())
-}
+//     (e as i64, msg.to_string())
+// }
 
-pub fn server_error(e: RpcError, id: Value) -> JsonResult {
-    let (code, msg) = to_tuple(e);
-    JsonError::new(ServerError(code), Some(msg), id).into()
-}
+// pub fn server_error(e: RpcError, id: Value) -> JsonResult {
+//     let (code, msg) = to_tuple(e);
+//     JsonError::new(ServerError(code), Some(msg), id).into()
+// }

+ 12 - 13
example/dao/src/util.rs

@@ -18,26 +18,25 @@ use darkfi::{
     },
     zk::{vm::ZkCircuit, vm_stack::empty_witnesses},
     zkas::decoder::ZkBinary,
-    Error,
 };
 use darkfi_serial::Encodable;
 
 use crate::error::{DaoError, DaoResult};
 
-/// Parse pallas::Base from a base58-encoded string
-pub fn parse_b58(s: &str) -> std::result::Result<pallas::Base, darkfi::Error> {
-    let bytes = bs58::decode(s).into_vec()?;
-    if bytes.len() != 32 {
-        return Err(Error::ParseFailed("Failed parsing DrkTokenId from base58 string"))
-    }
+// /// Parse pallas::Base from a base58-encoded string
+// pub fn parse_b58(s: &str) -> std::result::Result<pallas::Base, darkfi::Error> {
+//     let bytes = bs58::decode(s).into_vec()?;
+//     if bytes.len() != 32 {
+//         return Err(Error::ParseFailed("Failed parsing DrkTokenId from base58 string"))
+//     }
 
-    let ret = pallas::Base::from_repr(bytes.try_into().unwrap());
-    if ret.is_some().unwrap_u8() == 1 {
-        return Ok(ret.unwrap())
-    }
+//     let ret = pallas::Base::from_repr(bytes.try_into().unwrap());
+//     if ret.is_some().unwrap_u8() == 1 {
+//         return Ok(ret.unwrap())
+//     }
 
-    Err(Error::ParseFailed("Failed parsing DrkTokenId from base58 string"))
-}
+//     Err(Error::ParseFailed("Failed parsing DrkTokenId from base58 string"))
+// }
 
 // The token of the DAO treasury.
 lazy_static! {