Explorar el Código

bin/dao: remove warnings

Dastan-glitch hace 3 años
padre
commit
3cc6098ed7

+ 0 - 2
bin/dao/daod/src/contract/dao_contract/exec/validate.rs

@@ -17,8 +17,6 @@ use crate::{
     util::{CallDataBase, HashableBase, StateRegistry, Transaction, UpdateBase},
 };
 
-use log::debug;
-
 type Result<T> = std::result::Result<T, Error>;
 
 #[derive(Debug, Clone, thiserror::Error)]

+ 0 - 2
bin/dao/daod/src/contract/dao_contract/vote/validate.rs

@@ -22,8 +22,6 @@ use crate::{
     util::{CallDataBase, StateRegistry, Transaction, UpdateBase},
 };
 
-use log::debug;
-
 #[derive(Debug, Clone, thiserror::Error)]
 pub enum Error {
     #[error("Invalid proposal")]

+ 22 - 23
bin/dao/daod/src/contract/example_contract/foo/validate.rs

@@ -6,20 +6,19 @@ use darkfi::{
     Error as DarkFiError,
 };
 
-use std::any::{Any, TypeId};
+use std::any::Any;
 
 use crate::{
     contract::example_contract::{state::State, CONTRACT_ID},
-    util::{CallDataBase, StateRegistry, Transaction, UpdateBase},
+    util::{CallDataBase, StateRegistry, UpdateBase},
 };
 
-type Result<T> = std::result::Result<T, Error>;
+// type Result<T> = std::result::Result<T, Error>;
 
 #[derive(Debug, Clone, thiserror::Error)]
 pub enum Error {
-    #[error("ValueExists")]
-    ValueExists,
-
+    // #[error("ValueExists")]
+    // ValueExists,
     #[error("DarkFi error: {0}")]
     DarkFiError(String),
 }
@@ -57,28 +56,28 @@ impl CallDataBase for CallData {
     }
 }
 
-pub fn state_transition(
-    states: &StateRegistry,
-    func_call_index: usize,
-    parent_tx: &Transaction,
-) -> Result<Box<dyn UpdateBase + Send>> {
-    let func_call = &parent_tx.func_calls[func_call_index];
-    let call_data = func_call.call_data.as_any();
+// pub fn state_transition(
+//     states: &StateRegistry,
+//     func_call_index: usize,
+//     parent_tx: &Transaction,
+// ) -> Result<Box<dyn UpdateBase + Send>> {
+//     let func_call = &parent_tx.func_calls[func_call_index];
+//     let call_data = func_call.call_data.as_any();
 
-    assert_eq!((&*call_data).type_id(), TypeId::of::<CallData>());
-    let call_data = call_data.downcast_ref::<CallData>();
+//     assert_eq!((&*call_data).type_id(), TypeId::of::<CallData>());
+//     let call_data = call_data.downcast_ref::<CallData>();
 
-    // This will be inside wasm so unwrap is fine.
-    let call_data = call_data.unwrap();
+//     // This will be inside wasm so unwrap is fine.
+//     let call_data = call_data.unwrap();
 
-    let example_state = states.lookup::<State>(*CONTRACT_ID).unwrap();
+//     let example_state = states.lookup::<State>(*CONTRACT_ID).unwrap();
 
-    if example_state.public_exists(&call_data.public_value) {
-        return Err(Error::ValueExists)
-    }
+//     if example_state.public_exists(&call_data.public_value) {
+//         return Err(Error::ValueExists)
+//     }
 
-    Ok(Box::new(Update { public_value: call_data.public_value }))
-}
+//     Ok(Box::new(Update { public_value: call_data.public_value }))
+// }
 
 #[derive(Clone)]
 pub struct Update {

+ 74 - 74
bin/dao/daod/src/contract/example_contract/foo/wallet.rs

@@ -1,74 +1,74 @@
-use log::debug;
-use rand::rngs::OsRng;
-
-use halo2_proofs::circuit::Value;
-use pasta_curves::pallas;
-
-use darkfi::{
-    crypto::{
-        keypair::{PublicKey, SecretKey},
-        Proof,
-    },
-    zk::vm::{Witness, ZkCircuit},
-};
-
-use crate::{
-    contract::example_contract::{foo::validate::CallData, CONTRACT_ID},
-    util::{FuncCall, ZkContractInfo, ZkContractTable},
-};
-
-pub struct Foo {
-    pub a: u64,
-    pub b: u64,
-}
-
-pub struct Builder {
-    pub foo: Foo,
-    pub signature_secret: SecretKey,
-}
-
-impl Builder {
-    pub fn build(self, zk_bins: &ZkContractTable) -> FuncCall {
-        debug!(target: "example_contract::foo::wallet::Builder", "build()");
-        let mut proofs = vec![];
-
-        let zk_info = zk_bins.lookup(&"example-foo".to_string()).unwrap();
-        let zk_info = if let ZkContractInfo::Binary(info) = zk_info {
-            info
-        } else {
-            panic!("Not binary info")
-        };
-
-        let zk_bin = zk_info.bincode.clone();
-
-        let prover_witnesses = vec![
-            Witness::Base(Value::known(pallas::Base::from(self.foo.a))),
-            Witness::Base(Value::known(pallas::Base::from(self.foo.b))),
-        ];
-
-        let a = pallas::Base::from(self.foo.a);
-        let b = pallas::Base::from(self.foo.b);
-
-        let c = a + b;
-
-        let public_inputs = vec![c];
-
-        let circuit = ZkCircuit::new(prover_witnesses, zk_bin);
-        debug!(target: "example_contract::foo::wallet::Builder", "input_proof Proof::create()");
-        let proving_key = &zk_info.proving_key;
-        let input_proof = Proof::create(proving_key, &[circuit], &public_inputs, &mut OsRng)
-            .expect("Example::foo() proving error!)");
-        proofs.push(input_proof);
-
-        let signature_public = PublicKey::from_secret(self.signature_secret);
-
-        let call_data = CallData { public_value: c, signature_public };
-
-        FuncCall {
-            contract_id: *CONTRACT_ID,
-            func_id: *super::FUNC_ID,
-            call_data: Box::new(call_data),
-            proofs,
-        }
-    }
-}
+// use log::debug;
+// use rand::rngs::OsRng;
+
+// use halo2_proofs::circuit::Value;
+// use pasta_curves::pallas;
+
+// use darkfi::{
+//     crypto::{
+//         keypair::{PublicKey, SecretKey},
+//         Proof,
+//     },
+//     zk::vm::{Witness, ZkCircuit},
+// };
+
+// use crate::{
+//     contract::example_contract::{foo::validate::CallData, CONTRACT_ID},
+//     util::{FuncCall, ZkContractInfo, ZkContractTable},
+// };
+
+// pub struct Foo {
+//     pub a: u64,
+//     pub b: u64,
+// }
+
+// pub struct Builder {
+//     pub foo: Foo,
+//     pub signature_secret: SecretKey,
+// }
+
+// impl Builder {
+//     pub fn build(self, zk_bins: &ZkContractTable) -> FuncCall {
+//         debug!(target: "example_contract::foo::wallet::Builder", "build()");
+//         let mut proofs = vec![];
+
+//         let zk_info = zk_bins.lookup(&"example-foo".to_string()).unwrap();
+//         let zk_info = if let ZkContractInfo::Binary(info) = zk_info {
+//             info
+//         } else {
+//             panic!("Not binary info")
+//         };
+
+//         let zk_bin = zk_info.bincode.clone();
+
+//         let prover_witnesses = vec![
+//             Witness::Base(Value::known(pallas::Base::from(self.foo.a))),
+//             Witness::Base(Value::known(pallas::Base::from(self.foo.b))),
+//         ];
+
+//         let a = pallas::Base::from(self.foo.a);
+//         let b = pallas::Base::from(self.foo.b);
+
+//         let c = a + b;
+
+//         let public_inputs = vec![c];
+
+//         let circuit = ZkCircuit::new(prover_witnesses, zk_bin);
+//         debug!(target: "example_contract::foo::wallet::Builder", "input_proof Proof::create()");
+//         let proving_key = &zk_info.proving_key;
+//         let input_proof = Proof::create(proving_key, &[circuit], &public_inputs, &mut OsRng)
+//             .expect("Example::foo() proving error!)");
+//         proofs.push(input_proof);
+
+//         let signature_public = PublicKey::from_secret(self.signature_secret);
+
+//         let call_data = CallData { public_value: c, signature_public };
+
+//         FuncCall {
+//             contract_id: *CONTRACT_ID,
+//             func_id: *super::FUNC_ID,
+//             call_data: Box::new(call_data),
+//             proofs,
+//         }
+//     }
+// }

+ 7 - 7
bin/dao/daod/src/contract/example_contract/state.rs

@@ -1,4 +1,4 @@
-use std::any::Any;
+// use std::any::Any;
 
 use pasta_curves::pallas;
 
@@ -7,15 +7,15 @@ pub struct State {
 }
 
 impl State {
-    pub fn new() -> Box<dyn Any> {
-        Box::new(Self { public_values: Vec::new() })
-    }
+    // pub fn new() -> Box<dyn Any> {
+    //     Box::new(Self { public_values: Vec::new() })
+    // }
 
     pub fn add_public_value(&mut self, public_value: pallas::Base) {
         self.public_values.push(public_value)
     }
 
-    pub fn public_exists(&self, public_value: &pallas::Base) -> bool {
-        self.public_values.iter().any(|v| v == public_value)
-    }
+    // pub fn public_exists(&self, public_value: &pallas::Base) -> bool {
+    //     self.public_values.iter().any(|v| v == public_value)
+    // }
 }

+ 1 - 7
bin/dao/daod/src/contract/money_contract/transfer/wallet.rs

@@ -1,8 +1,4 @@
-use pasta_curves::{
-    arithmetic::CurveAffine,
-    group::{ff::Field, Curve},
-    pallas,
-};
+use pasta_curves::group::ff::Field;
 use rand::rngs::OsRng;
 
 use darkfi::{
@@ -29,8 +25,6 @@ use crate::{
     util::{FuncCall, ZkContractInfo, ZkContractTable},
 };
 
-use log::debug;
-
 #[derive(Clone, SerialEncodable, SerialDecodable)]
 pub struct Note {
     pub serial: DrkSerial,

+ 28 - 30
bin/dao/daod/src/main.rs

@@ -1,13 +1,12 @@
-use std::{any::TypeId, collections::HashMap, sync::Arc, time::Instant};
+use std::{sync::Arc, time::Instant};
 
 use fxhash::FxHashMap;
-use group::ff::PrimeField;
 use incrementalmerkletree::{Position, Tree};
 use log::debug;
 use pasta_curves::{
     arithmetic::CurveAffine,
     group::{ff::Field, Curve, Group},
-    pallas, Fp, Fq,
+    pallas,
 };
 use rand::rngs::OsRng;
 use simplelog::{ColorChoice, LevelFilter, TermLogger, TerminalMode};
@@ -35,12 +34,10 @@ mod util;
 use crate::{
     contract::{
         dao_contract::{self, mint::wallet::DaoParams, propose::wallet::Proposal, DaoBulla},
-        money_contract::{self, state::OwnCoin, transfer::Note},
+        money_contract::{self, state::OwnCoin},
     },
     rpc::JsonRpcInterface,
-    util::{
-        sign, FuncCall, HashableBase, StateRegistry, Transaction, ZkContractTable, DRK_ID, GOV_ID,
-    },
+    util::{sign, StateRegistry, Transaction, ZkContractTable, DRK_ID},
 };
 
 //////////////////////////////////////////////////////////////////////////
@@ -178,10 +175,10 @@ impl Client {
         let cashier_wallet = CashierWallet::new();
 
         // Lookup table for smart contract states
-        let mut states = StateRegistry::new();
+        let states = StateRegistry::new();
 
         // Initialize ZK binary table
-        let mut zk_bins = ZkContractTable::new();
+        let zk_bins = ZkContractTable::new();
 
         Self { dao_wallet, money_wallets, cashier_wallet, states, zk_bins }
     }
@@ -305,11 +302,11 @@ impl Client {
         token_supply: u64,
         recipient: PublicKey,
     ) -> Result<()> {
-        self.dao_wallet.track(&mut self.states);
+        self.dao_wallet.track(&mut self.states)?;
 
         let tx = self
             .cashier_wallet
-            .mint(*DRK_ID, token_supply, self.dao_wallet.bullas[0].0, recipient, &self.zk_bins)
+            .mint(token_id, token_supply, self.dao_wallet.bullas[0].0, recipient, &self.zk_bins)
             .unwrap();
 
         self.validate(&tx).unwrap();
@@ -384,7 +381,7 @@ impl Client {
         let state =
             self.states.lookup_mut::<money_contract::State>(*money_contract::CONTRACT_ID).unwrap();
 
-        let mut dao_coins = state.wallet_cache.get_received(&self.dao_wallet.keypair.secret);
+        let dao_coins = state.wallet_cache.get_received(&self.dao_wallet.keypair.secret);
         for coin in dao_coins {
             let note = coin.note.clone();
             let coords = self.dao_wallet.keypair.public.0.to_affine().coordinates().unwrap();
@@ -408,8 +405,8 @@ impl Client {
             debug!("DAO received a coin worth {} xDRK", note.value);
         }
 
-        for (key, wallet) in &mut self.money_wallets {
-            let mut coins = state.wallet_cache.get_received(&wallet.keypair.secret);
+        for (_key, wallet) in &mut self.money_wallets {
+            let coins = state.wallet_cache.get_received(&wallet.keypair.secret);
             for coin in coins {
                 let note = coin.note.clone();
                 let coords = wallet.keypair.public.0.to_affine().coordinates().unwrap();
@@ -447,7 +444,7 @@ impl Client {
         // To be able to make a proposal, we must prove we have ownership
         // of governance tokens, and that the quantity of governance
         // tokens is within the accepted proposer limit.
-        let mut sender_wallet = self.money_wallets.get_mut(&sender).unwrap();
+        let sender_wallet = self.money_wallets.get_mut(&sender).unwrap();
 
         let tx = sender_wallet.propose_tx(
             params.clone(),
@@ -478,7 +475,7 @@ impl Client {
         let dao_params = self.dao_wallet.params[0].clone();
         let dao_keypair = self.dao_wallet.keypair;
 
-        let mut voter_wallet = self.money_wallets.get_mut(&pubkey).unwrap();
+        let voter_wallet = self.money_wallets.get_mut(&pubkey).unwrap();
 
         let tx = voter_wallet
             .vote_tx(
@@ -582,7 +579,7 @@ impl DaoWallet {
             dao_quorum,
             dao_approval_ratio_quot,
             dao_approval_ratio_base,
-            gov_token_id: *GOV_ID,
+            gov_token_id: token_id,
             dao_pubkey: self.keypair.public,
             dao_bulla_blind: self.bulla_blind,
             _signature_secret: self.signature_secret,
@@ -691,7 +688,7 @@ impl DaoWallet {
     fn exec_tx(
         &self,
         proposal: Proposal,
-        proposal_bulla: pallas::Base,
+        _proposal_bulla: pallas::Base,
         dao_params: DaoParams,
         zk_bins: &ZkContractTable,
         states: &mut StateRegistry,
@@ -844,13 +841,13 @@ struct MoneyWallet {
 }
 
 impl MoneyWallet {
-    fn signature_public(&self) -> PublicKey {
-        PublicKey::from_secret(self.signature_secret)
-    }
+    // fn signature_public(&self) -> PublicKey {
+    //     PublicKey::from_secret(self.signature_secret)
+    // }
 
-    fn get_public_key(&self) -> PublicKey {
-        self.keypair.public
-    }
+    // fn get_public_key(&self) -> PublicKey {
+    //     self.keypair.public
+    // }
 
     fn track(&self, states: &mut StateRegistry) -> Result<()> {
         let state =
@@ -958,7 +955,7 @@ impl MoneyWallet {
     fn vote_tx(
         &mut self,
         vote_option: bool,
-        dao_key: Keypair,
+        _dao_key: Keypair,
         proposal: Proposal,
         dao_params: DaoParams,
         dao_keypair: Keypair,
@@ -968,7 +965,7 @@ impl MoneyWallet {
         let mut inputs = Vec::new();
 
         // We must prove we have sufficient governance tokens in order to vote.
-        for (coin, is_spent) in &self.own_coins {
+        for (coin, _is_spent) in &self.own_coins {
             let (money_leaf_position, money_merkle_path) = self.get_path(states, &coin).unwrap();
 
             let input = {
@@ -1019,15 +1016,16 @@ async fn start_rpc(client: Client) -> Result<()> {
 // Mint authority that mints the DAO treasury and airdrops governance tokens.
 #[derive(Clone)]
 struct CashierWallet {
-    keypair: Keypair,
+    // keypair: Keypair,
     signature_secret: SecretKey,
 }
 
 impl CashierWallet {
     fn new() -> Self {
-        let keypair = Keypair::random(&mut OsRng);
+        // let keypair = Keypair::random(&mut OsRng);
         let signature_secret = SecretKey::random(&mut OsRng);
-        Self { keypair, signature_secret }
+        // Self { keypair, signature_secret }
+        Self { signature_secret }
     }
 
     fn signature_public(&self) -> PublicKey {
@@ -1116,7 +1114,7 @@ async fn main() -> Result<()> {
     .unwrap();
 
     let mut client = Client::new();
-    client.init();
+    client.init()?;
 
     start_rpc(client).await.unwrap();
 

+ 14 - 15
bin/dao/daod/src/rpc.rs

@@ -2,7 +2,6 @@ use std::sync::Arc;
 
 use async_std::sync::Mutex;
 use async_trait::async_trait;
-use fxhash::FxHashMap;
 use log::debug;
 use pasta_curves::{group::ff::PrimeField, pallas};
 use rand::rngs::OsRng;
@@ -90,8 +89,8 @@ impl JsonRpcInterface {
 
     // --> {"method": "get_dao_addr", "params": []}
     // <-- {"result": "getting dao public addr..."}
-    async fn get_dao_addr(&self, id: Value, params: &[Value]) -> JsonResult {
-        let mut client = self.client.lock().await;
+    async fn get_dao_addr(&self, id: Value, _params: &[Value]) -> JsonResult {
+        let client = self.client.lock().await;
         let pubkey = client.dao_wallet.get_public_key();
         let addr: String = bs58::encode(pubkey.to_bytes()).into_string();
         JsonResponse::new(json!(addr), id).into()
@@ -99,8 +98,8 @@ impl JsonRpcInterface {
 
     // --> {"method": "get_dao_addr", "params": []}
     // <-- {"result": "getting dao public addr..."}
-    async fn get_votes(&self, id: Value, params: &[Value]) -> JsonResult {
-        let mut client = self.client.lock().await;
+    async fn get_votes(&self, id: Value, _params: &[Value]) -> JsonResult {
+        let client = self.client.lock().await;
         let vote_notes = client.dao_wallet.get_votes();
         let mut vote_data = vec![];
 
@@ -115,8 +114,8 @@ impl JsonRpcInterface {
 
     // --> {"method": "get_dao_addr", "params": []}
     // <-- {"result": "getting dao public addr..."}
-    async fn get_proposals(&self, id: Value, params: &[Value]) -> JsonResult {
-        let mut client = self.client.lock().await;
+    async fn get_proposals(&self, id: Value, _params: &[Value]) -> JsonResult {
+        let client = self.client.lock().await;
         let proposals = client.dao_wallet.get_proposals();
         let mut proposal_data = vec![];
 
@@ -131,14 +130,14 @@ impl JsonRpcInterface {
         JsonResponse::new(json!(proposal_data), id).into()
     }
 
-    async fn dao_balance(&self, id: Value, params: &[Value]) -> JsonResult {
-        let mut client = self.client.lock().await;
+    async fn dao_balance(&self, id: Value, _params: &[Value]) -> JsonResult {
+        let client = self.client.lock().await;
         let balance = client.dao_wallet.balances().unwrap();
         JsonResponse::new(json!(balance), id).into()
     }
 
-    async fn dao_bulla(&self, id: Value, params: &[Value]) -> JsonResult {
-        let mut client = self.client.lock().await;
+    async fn dao_bulla(&self, id: Value, _params: &[Value]) -> JsonResult {
+        let client = self.client.lock().await;
         let dao_bullas = client.dao_wallet.bullas.clone();
         let mut bulla_vec = Vec::new();
 
@@ -151,7 +150,7 @@ impl JsonRpcInterface {
     }
 
     async fn user_balance(&self, id: Value, params: &[Value]) -> JsonResult {
-        let mut client = self.client.lock().await;
+        let client = self.client.lock().await;
         let nym = params[0].as_str().unwrap();
 
         let pubkey = PublicKey::from_str(nym).unwrap();
@@ -183,7 +182,7 @@ impl JsonRpcInterface {
         let signature_secret = SecretKey::random(&mut OsRng);
         let own_coins: Vec<(OwnCoin, bool)> = Vec::new();
         let money_wallet = MoneyWallet { keypair, signature_secret, own_coins };
-        money_wallet.track(&mut client.states);
+        money_wallet.track(&mut client.states).unwrap();
 
         client.money_wallets.insert(keypair.public, money_wallet);
 
@@ -198,7 +197,7 @@ impl JsonRpcInterface {
     // <-- {"result": "airdropping tokens..."}
     async fn airdrop_tokens(&self, id: Value, params: &[Value]) -> JsonResult {
         let mut client = self.client.lock().await;
-        let zk_bins = &client.zk_bins;
+        // let zk_bins = &client.zk_bins;
 
         let addr = PublicKey::from_str(params[0].as_str().unwrap()).unwrap();
         let value = params[1].as_u64().unwrap();
@@ -254,7 +253,7 @@ impl JsonRpcInterface {
         let bulla_str = params[0].as_str().unwrap();
         let bulla: pallas::Base = parse_b58(bulla_str).unwrap();
 
-        client.exec_proposal(bulla);
+        client.exec_proposal(bulla).unwrap();
 
         JsonResponse::new(json!("Proposal executed successfully."), id).into()
     }