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

contract/dao: cleaned unused stuff

skoupidi 1 год назад
Родитель
Сommit
5e79d8519b

+ 0 - 12
bin/drk/src/dao.rs

@@ -2310,14 +2310,6 @@ impl Drk {
         transfer_params.encode_async(&mut data).await?;
         let transfer_call = ContractCall { contract_id: *MONEY_CONTRACT_ID, data };
 
-        // Now we need to extract the exec call parameters
-        let mut input_value = 0;
-        let mut input_value_blind = Blind::ZERO;
-        for (input, blind) in spent_coins.iter().zip(transfer_secrets.input_value_blinds.iter()) {
-            input_value += input.note.value;
-            input_value_blind += *blind;
-        }
-
         // Create the exec call
         let exec_signature_secret = SecretKey::random(&mut OsRng);
         let exec_builder = DaoExecCall {
@@ -2327,10 +2319,6 @@ impl Drk {
             all_vote_value,
             yes_vote_blind,
             all_vote_blind,
-            input_value,
-            input_value_blind,
-            input_user_data_blind,
-            hook_dao_exec: DAO_CONTRACT_ID.inner(),
             signature_secret: exec_signature_secret,
         };
         let (exec_params, exec_proofs) = exec_builder.make(&dao_exec_zkbin, &dao_exec_pk)?;

+ 1 - 7
src/contract/dao/src/client/exec.rs

@@ -17,9 +17,7 @@
  */
 
 use darkfi_sdk::{
-    crypto::{
-        pasta_prelude::*, pedersen_commitment_u64, BaseBlind, PublicKey, ScalarBlind, SecretKey,
-    },
+    crypto::{pasta_prelude::*, pedersen_commitment_u64, PublicKey, ScalarBlind, SecretKey},
     pasta::pallas,
 };
 
@@ -44,10 +42,6 @@ pub struct DaoExecCall {
     pub all_vote_value: u64,
     pub yes_vote_blind: ScalarBlind,
     pub all_vote_blind: ScalarBlind,
-    pub input_value: u64,
-    pub input_value_blind: ScalarBlind,
-    pub input_user_data_blind: BaseBlind,
-    pub hook_dao_exec: pallas::Base,
     pub signature_secret: SecretKey,
 }
 

+ 1 - 17
src/contract/dao/src/client/mint.rs

@@ -21,28 +21,12 @@ use darkfi::{
     zkas::ZkBinary,
     Result,
 };
-use darkfi_sdk::{
-    crypto::{PublicKey, SecretKey},
-    pasta::pallas,
-};
+use darkfi_sdk::{crypto::SecretKey, pasta::pallas};
 use log::debug;
 use rand::rngs::OsRng;
 
-use darkfi_money_contract::model::TokenId;
-
 use crate::model::{Dao, DaoMintParams};
 
-#[derive(Clone)]
-pub struct DaoInfo {
-    pub proposer_limit: u64,
-    pub quorum: u64,
-    pub approval_ratio_quot: u64,
-    pub approval_ratio_base: u64,
-    pub gov_token_id: TokenId,
-    pub public_key: PublicKey,
-    pub bulla_blind: pallas::Base,
-}
-
 pub fn make_mint_call(
     dao: &Dao,
     dao_secret_key: &SecretKey,

+ 1 - 1
src/contract/dao/src/client/mod.rs

@@ -17,7 +17,7 @@
  */
 
 pub mod mint;
-pub use mint::{make_mint_call, DaoInfo};
+pub use mint::make_mint_call;
 
 /// Provides core structs for DAO::propose()
 ///

+ 4 - 33
src/contract/dao/tests/integration.rs

@@ -295,14 +295,7 @@ fn integration_test() -> Result<()> {
         let user_data = pallas::Base::ZERO;
 
         let (propose_tx, (propose_params, fee_params), propose_info) = th
-            .dao_propose(
-                &Holder::Alice,
-                &proposal_coinattrs,
-                user_data,
-                &dao,
-                &dao_mint_params.dao_bulla,
-                current_block_height,
-            )
+            .dao_propose(&Holder::Alice, &proposal_coinattrs, user_data, &dao, current_block_height)
             .await?;
 
         for holder in &HOLDERS {
@@ -330,28 +323,12 @@ fn integration_test() -> Result<()> {
 
         info!("[Alice] Building vote tx (yes)");
         let (alice_vote_tx, alice_vote_params, alice_vote_fee_params) = th
-            .dao_vote(
-                &Holder::Alice,
-                true,
-                &dao,
-                &dao_keypair,
-                &propose_info,
-                &propose_params.proposal_bulla,
-                current_block_height,
-            )
+            .dao_vote(&Holder::Alice, true, &dao, &dao_keypair, &propose_info, current_block_height)
             .await?;
 
         info!("[Bob] Building vote tx (no)");
         let (bob_vote_tx, bob_vote_params, bob_vote_fee_params) = th
-            .dao_vote(
-                &Holder::Bob,
-                false,
-                &dao,
-                &dao_keypair,
-                &propose_info,
-                &propose_params.proposal_bulla,
-                current_block_height,
-            )
+            .dao_vote(&Holder::Bob, false, &dao, &dao_keypair, &propose_info, current_block_height)
             .await?;
 
         info!("[Charlie] Building vote tx (yes)");
@@ -362,7 +339,6 @@ fn integration_test() -> Result<()> {
                 &dao,
                 &dao_keypair,
                 &propose_info,
-                &propose_params.proposal_bulla,
                 current_block_height,
             )
             .await?;
@@ -372,7 +348,6 @@ fn integration_test() -> Result<()> {
             th.execute_dao_vote_tx(
                 holder,
                 alice_vote_tx.clone(),
-                &alice_vote_params,
                 &alice_vote_fee_params,
                 current_block_height,
                 true,
@@ -383,7 +358,6 @@ fn integration_test() -> Result<()> {
             th.execute_dao_vote_tx(
                 holder,
                 bob_vote_tx.clone(),
-                &bob_vote_params,
                 &bob_vote_fee_params,
                 current_block_height,
                 true,
@@ -394,7 +368,6 @@ fn integration_test() -> Result<()> {
             th.execute_dao_vote_tx(
                 holder,
                 charlie_vote_tx.clone(),
-                &charlie_vote_params,
                 &charlie_vote_fee_params,
                 current_block_height,
                 true,
@@ -478,11 +451,10 @@ fn integration_test() -> Result<()> {
         info!("Stage 6. Execute the vote");
 
         info!("[Dao] Building Dao::Exec tx");
-        let (exec_tx, xfer_params, exec_params, exec_fee_params) = th
+        let (exec_tx, xfer_params, exec_fee_params) = th
             .dao_exec(
                 &Holder::Alice,
                 &dao,
-                &dao_mint_params.dao_bulla,
                 &propose_info,
                 proposal_coinattrs,
                 total_yes_vote_value,
@@ -499,7 +471,6 @@ fn integration_test() -> Result<()> {
                 holder,
                 exec_tx.clone(),
                 &xfer_params,
-                &exec_params,
                 &exec_fee_params,
                 current_block_height,
                 true,

+ 4 - 11
src/contract/test-harness/src/dao_exec.rs

@@ -22,7 +22,7 @@ use darkfi::{
 };
 use darkfi_dao_contract::{
     client::{DaoAuthMoneyTransferCall, DaoExecCall},
-    model::{Dao, DaoBulla, DaoExecParams, DaoProposal},
+    model::{Dao, DaoProposal},
     DaoFunction, DAO_CONTRACT_ZKAS_DAO_AUTH_MONEY_TRANSFER_ENC_COIN_NS,
     DAO_CONTRACT_ZKAS_DAO_AUTH_MONEY_TRANSFER_NS, DAO_CONTRACT_ZKAS_DAO_EXEC_NS,
 };
@@ -52,7 +52,6 @@ impl TestHarness {
         &mut self,
         holder: &Holder,
         dao: &Dao,
-        dao_bulla: &DaoBulla,
         proposal: &DaoProposal,
         proposal_coinattrs: Vec<CoinAttributes>,
         yes_vote_value: u64,
@@ -60,7 +59,7 @@ impl TestHarness {
         yes_vote_blind: ScalarBlind,
         all_vote_blind: ScalarBlind,
         block_height: u32,
-    ) -> Result<(Transaction, MoneyTransferParamsV1, DaoExecParams, Option<MoneyFeeParamsV1>)> {
+    ) -> Result<(Transaction, MoneyTransferParamsV1, Option<MoneyFeeParamsV1>)> {
         let dao_wallet = self.holders.get(&Holder::Dao).unwrap();
 
         let (mint_pk, mint_zkbin) = self.proving_keys.get(MONEY_CONTRACT_ZKAS_MINT_NS_V1).unwrap();
@@ -114,7 +113,7 @@ impl TestHarness {
             value: change_value,
             token_id: proposal_token_id,
             spend_hook,
-            user_data: dao_bulla.inner(),
+            user_data: dao.to_bulla().inner(),
             blind: Blind::random(&mut OsRng),
         };
         outputs.push(dao_coin_attrs.clone());
@@ -154,10 +153,6 @@ impl TestHarness {
             all_vote_value,
             yes_vote_blind,
             all_vote_blind,
-            input_value,
-            input_value_blind,
-            input_user_data_blind,
-            hook_dao_exec: DAO_CONTRACT_ID.inner(),
             signature_secret: exec_signature_secret,
         };
 
@@ -240,19 +235,17 @@ impl TestHarness {
             tx.signatures.push(sigs);
         }
 
-        Ok((tx, xfer_params, exec_params, fee_params))
+        Ok((tx, xfer_params, fee_params))
     }
 
     /// Execute the transaction made by `dao_exec()` for a given [`Holder`].
     ///
     /// Returns any found [`OwnCoin`]s.
-    #[allow(clippy::too_many_arguments)]
     pub async fn execute_dao_exec_tx(
         &mut self,
         holder: &Holder,
         tx: Transaction,
         xfer_params: &MoneyTransferParamsV1,
-        _exec_params: &DaoExecParams,
         fee_params: &Option<MoneyFeeParamsV1>,
         block_height: u32,
         append: bool,

+ 2 - 3
src/contract/test-harness/src/dao_mint.rs

@@ -46,7 +46,7 @@ impl TestHarness {
     pub async fn dao_mint(
         &mut self,
         holder: &Holder,
-        dao_info: &Dao,
+        dao: &Dao,
         dao_kp: &Keypair,
         block_height: u32,
     ) -> Result<(Transaction, DaoMintParams, Option<MoneyFeeParamsV1>)> {
@@ -54,8 +54,7 @@ impl TestHarness {
             self.proving_keys.get(DAO_CONTRACT_ZKAS_DAO_MINT_NS).unwrap();
 
         // Create the call
-        let (params, proofs) =
-            make_mint_call(dao_info, &dao_kp.secret, dao_mint_zkbin, dao_mint_pk)?;
+        let (params, proofs) = make_mint_call(dao, &dao_kp.secret, dao_mint_zkbin, dao_mint_pk)?;
 
         // Encode the call
         let mut data = vec![DaoFunction::Mint as u8];

+ 4 - 4
src/contract/test-harness/src/dao_propose.rs

@@ -23,7 +23,7 @@ use darkfi::{
 use darkfi_dao_contract::{
     blockwindow,
     client::{DaoProposeCall, DaoProposeStakeInput},
-    model::{Dao, DaoAuthCall, DaoBulla, DaoProposal, DaoProposeParams},
+    model::{Dao, DaoAuthCall, DaoProposal, DaoProposeParams},
     DaoFunction, DAO_CONTRACT_ZKAS_DAO_PROPOSE_INPUT_NS, DAO_CONTRACT_ZKAS_DAO_PROPOSE_MAIN_NS,
 };
 use darkfi_money_contract::{
@@ -53,7 +53,6 @@ impl TestHarness {
         proposal_coinattrs: &[CoinAttributes],
         user_data: pallas::Base,
         dao: &Dao,
-        dao_bulla: &DaoBulla,
         block_height: u32,
     ) -> Result<(Transaction, (DaoProposeParams, Option<MoneyFeeParamsV1>), DaoProposal)> {
         let wallet = self.holders.get(proposer).unwrap();
@@ -129,16 +128,17 @@ impl TestHarness {
         };
 
         let signature_secret = SecretKey::random(&mut OsRng);
+        let dao_bulla = dao.to_bulla();
 
         let call = DaoProposeCall {
             money_null_smt: &wallet.money_null_smt,
             inputs: vec![input],
             proposal: proposal.clone(),
             dao: dao.clone(),
-            dao_leaf_position: *wallet.dao_leafs.get(dao_bulla).unwrap(),
+            dao_leaf_position: *wallet.dao_leafs.get(&dao_bulla).unwrap(),
             dao_merkle_path: wallet
                 .dao_merkle_tree
-                .witness(*wallet.dao_leafs.get(dao_bulla).unwrap(), 0)
+                .witness(*wallet.dao_leafs.get(&dao_bulla).unwrap(), 0)
                 .unwrap(),
             dao_merkle_root: wallet.dao_merkle_tree.root(0).unwrap(),
             signature_secret,

+ 3 - 6
src/contract/test-harness/src/dao_vote.rs

@@ -23,7 +23,7 @@ use darkfi::{
 use darkfi_dao_contract::{
     blockwindow,
     client::{DaoVoteCall, DaoVoteInput},
-    model::{Dao, DaoProposal, DaoProposalBulla, DaoVoteParams},
+    model::{Dao, DaoProposal, DaoVoteParams},
     DaoFunction, DAO_CONTRACT_ZKAS_DAO_VOTE_INPUT_NS, DAO_CONTRACT_ZKAS_DAO_VOTE_MAIN_NS,
 };
 use darkfi_money_contract::{
@@ -42,7 +42,6 @@ use super::{Holder, TestHarness};
 
 impl TestHarness {
     /// Create a `Dao::Vote` transaction.
-    #[allow(clippy::too_many_arguments)]
     pub async fn dao_vote(
         &mut self,
         voter: &Holder,
@@ -50,7 +49,6 @@ impl TestHarness {
         dao: &Dao,
         dao_keypair: &Keypair,
         proposal: &DaoProposal,
-        proposal_bulla: &DaoProposalBulla,
         block_height: u32,
     ) -> Result<(Transaction, DaoVoteParams, Option<MoneyFeeParamsV1>)> {
         let wallet = self.holders.get(voter).unwrap();
@@ -61,8 +59,8 @@ impl TestHarness {
         let (dao_vote_main_pk, dao_vote_main_zkbin) =
             self.proving_keys.get(DAO_CONTRACT_ZKAS_DAO_VOTE_MAIN_NS).unwrap();
 
-        let (_proposal_leaf_pos, snapshot_money_merkle_tree) =
-            wallet.dao_prop_leafs.get(proposal_bulla).unwrap();
+        let (_, snapshot_money_merkle_tree) =
+            wallet.dao_prop_leafs.get(&proposal.to_bulla()).unwrap();
 
         let vote_owncoin: OwnCoin = wallet
             .unspent_money_coins
@@ -142,7 +140,6 @@ impl TestHarness {
         &mut self,
         holder: &Holder,
         tx: Transaction,
-        _params: &DaoVoteParams,
         fee_params: &Option<MoneyFeeParamsV1>,
         block_height: u32,
         append: bool,