From 3734b649acf553dfbff30a3e3ea38ae770d62c93 Mon Sep 17 00:00:00 2001 From: Semen Medvedev Date: Fri, 1 Apr 2022 11:44:01 +0700 Subject: [PATCH] Fix clippy warnings #17 --- addin-fixed-weights/program/src/processor.rs | 2 +- addin-vesting/program/src/instruction.rs | 1 + governance-lib/src/addin_fixed_weights.rs | 4 +-- governance-lib/src/client.rs | 4 +-- governance-lib/src/realm.rs | 6 ++-- governance-test-scripts/src/main.rs | 36 ++++++++++---------- 6 files changed, 27 insertions(+), 26 deletions(-) diff --git a/addin-fixed-weights/program/src/processor.rs b/addin-fixed-weights/program/src/processor.rs index b2223d0..093e557 100644 --- a/addin-fixed-weights/program/src/processor.rs +++ b/addin-fixed-weights/program/src/processor.rs @@ -142,5 +142,5 @@ fn get_voter_weight_fixed(token_owner: &Pubkey) -> Result { .iter() .find(|&&item| item.0 == *token_owner ) .map(|item| item.1 ) - .ok_or(VoterWeightAddinError::WrongTokenOwner.into()) + .ok_or_else(|| VoterWeightAddinError::WrongTokenOwner.into()) } diff --git a/addin-vesting/program/src/instruction.rs b/addin-vesting/program/src/instruction.rs index ec99a3b..8dc7bd5 100644 --- a/addin-vesting/program/src/instruction.rs +++ b/addin-vesting/program/src/instruction.rs @@ -362,6 +362,7 @@ pub fn create_voter_weight_record( } /// Creates a `ChangeVotePercentage` instruction with realm +#[allow(clippy::too_many_arguments)] pub fn set_vote_percentage_with_realm( program_id: &Pubkey, seeds: [u8; 32], diff --git a/governance-lib/src/addin_fixed_weights.rs b/governance-lib/src/addin_fixed_weights.rs index 65be2ed..7d70e6b 100644 --- a/governance-lib/src/addin_fixed_weights.rs +++ b/governance-lib/src/addin_fixed_weights.rs @@ -65,7 +65,7 @@ impl<'a> AddinFixedWeights<'a> { &self.program_id, &realm.address, &realm.community_mint, - &token_owner); + token_owner); if !self.interactor.account_exists(&voter_weight_record_pubkey) { let setup_voter_weight_record_instruction: Instruction = @@ -73,7 +73,7 @@ impl<'a> AddinFixedWeights<'a> { &self.program_id, &realm.address, &realm.data.community_mint, - &token_owner, + token_owner, &self.interactor.payer.pubkey(), ); diff --git a/governance-lib/src/client.rs b/governance-lib/src/client.rs index 603cdcd..79f94e1 100644 --- a/governance-lib/src/client.rs +++ b/governance-lib/src/client.rs @@ -48,13 +48,13 @@ impl<'a> SplGovernanceInteractor<'a> { SplGovernanceInteractor { url: url.to_string(), solana_client: RpcClient::new_with_commitment(url.to_string(),CommitmentConfig::confirmed()), - payer: payer, + payer, spl_governance_program_address: program_address, spl_governance_voter_weight_addin_address: addin_address, } } pub fn account_exists(&self, address: &Pubkey) -> bool { - self.solana_client.get_account(&address).is_ok() + self.solana_client.get_account(address).is_ok() } pub fn get_realm_address(&self, name: &str) -> Pubkey { get_realm_address(&self.spl_governance_program_address, name) diff --git a/governance-lib/src/realm.rs b/governance-lib/src/realm.rs index 7c30fc0..514c25f 100644 --- a/governance-lib/src/realm.rs +++ b/governance-lib/src/realm.rs @@ -57,7 +57,7 @@ impl<'a> Realm<'a> { } pub fn create_token_owner_record<'b:'a>(&'b self, token_owner: &Pubkey) -> Result,ClientError> { - let token_owner_record_address: Pubkey = self.get_token_owner_record_address(&token_owner); + let token_owner_record_address: Pubkey = self.get_token_owner_record_address(token_owner); if !self.interactor.account_exists(&token_owner_record_address) { let create_token_owner_record_instruction: Instruction = @@ -87,8 +87,8 @@ impl<'a> Realm<'a> { TokenOwner { realm: self, //authority: token_owner_keypair, - token_owner_record_address: token_owner_record_address, - token_owner_record: self.get_token_owner_record_v2(&token_owner), + token_owner_record_address, + token_owner_record: self.get_token_owner_record_v2(token_owner), // voter_weight_record_authority: None, voter_weight_record_address: None, // voter_weight_record: None, diff --git a/governance-test-scripts/src/main.rs b/governance-test-scripts/src/main.rs index 88357b6..475534f 100644 --- a/governance-test-scripts/src/main.rs +++ b/governance-test-scripts/src/main.rs @@ -37,11 +37,11 @@ use governance_lib::{ addin_fixed_weights::AddinFixedWeights, }; -const GOVERNANCE_KEY_FILE_PATH: &'static str = "solana-program-library/target/deploy/spl_governance-keypair.json"; -const VOTER_WEIGHT_ADDIN_KEY_FILE_PATH: &'static str = "target/deploy/spl_governance_addin_fixed_weights-keypair.json"; -const COMMUTINY_MINT_KEY_FILE_PATH: &'static str = "governance-test-scripts/community_mint.keypair"; -const GOVERNED_MINT_KEY_FILE_PATH: &'static str = "governance-test-scripts/governance.keypair"; -const PAYER_KEY_FILE_PATH: &'static str = "artifacts/payer.keypair"; +const GOVERNANCE_KEY_FILE_PATH: &str = "solana-program-library/target/deploy/spl_governance-keypair.json"; +const VOTER_WEIGHT_ADDIN_KEY_FILE_PATH: &str = "target/deploy/spl_governance_addin_fixed_weights-keypair.json"; +const COMMUTINY_MINT_KEY_FILE_PATH: &str = "governance-test-scripts/community_mint.keypair"; +const GOVERNED_MINT_KEY_FILE_PATH: &str = "governance-test-scripts/governance.keypair"; +const PAYER_KEY_FILE_PATH: &str = "artifacts/payer.keypair"; const VOTERS_KEY_FILE_PATH: [&str;5] = [ "artifacts/voter1.keypair", @@ -51,11 +51,11 @@ const VOTERS_KEY_FILE_PATH: [&str;5] = [ "artifacts/voter5.keypair", ]; -// const REALM_NAME: &'static str = "Test Realm"; -const REALM_NAME: &'static str = "Test_Realm_4"; -// const REALM_NAME: &'static str = "Test Realm 6"; -const PROPOSAL_NAME: &'static str = "Proposal To Vote"; -const PROPOSAL_DESCRIPTION: &'static str = "proposal_description"; +// const REALM_NAME: &str = "Test Realm"; +const REALM_NAME: &str = "Test_Realm_4"; +// const REALM_NAME: &str = "Test Realm 6"; +const PROPOSAL_NAME: &str = "Proposal To Vote"; +const PROPOSAL_DESCRIPTION: &str = "proposal_description"; fn main() { @@ -130,13 +130,13 @@ fn main() { gov_config).unwrap(); println!("{:?}", governance); - let proposal_number: u32 = - if governance.get_proposal_count() > 0 { - // governance.get_proposal_count() - 0 - } else { - 0 - }; + let proposal_number: u32 = 0; +// if governance.get_proposal_count() > 0 { +// // governance.get_proposal_count() +// 0 +// } else { +// 0 +// }; let proposal: Proposal = governance.create_proposal( &voter_keypairs[0], &token_owners[0], @@ -158,7 +158,7 @@ fn main() { let yes = i == 0 || i == 3 || i == 4; let result = proposal.cast_vote( &voter_keypairs[i], - &owner, yes); + owner, yes); println!("CastVote {} {:?}", i, result); } }