From 571b01b8537fcb59521e2bc24f3edf534ba5ca86 Mon Sep 17 00:00:00 2001 From: jpbogle Date: Fri, 27 May 2022 00:20:56 -0700 Subject: [PATCH] Clippy fix --- cli/hydra_cli/src/main.rs | 43 +++++++++---------- programs/hydra/src/error.rs | 6 +-- programs/hydra/src/processors/mod.rs | 2 + programs/hydra/src/utils/logic/calculation.rs | 2 +- .../hydra/src/utils/logic/distribution.rs | 3 +- programs/hydra/src/utils/mod.rs | 30 +++++++------ programs/hydra/src/utils/validation/mod.rs | 7 ++- 7 files changed, 47 insertions(+), 46 deletions(-) diff --git a/cli/hydra_cli/src/main.rs b/cli/hydra_cli/src/main.rs index 9ede77b..83f0455 100644 --- a/cli/hydra_cli/src/main.rs +++ b/cli/hydra_cli/src/main.rs @@ -22,7 +22,7 @@ mod cli_api; fn setup_connection(app: &ArgMatches) -> (RpcClient, Keypair) { let json = app .value_of("rpc") - .unwrap_or(&"wss://api.devnet.solana.com".to_owned()) + .unwrap_or("wss://api.devnet.solana.com") .to_owned(); let _wss = json.replace("https", "wss"); @@ -37,15 +37,15 @@ fn setup_connection(app: &ArgMatches) -> (RpcClient, Keypair) { #[derive(Debug)] struct HydraMint { - fanout_mint: FanoutMint, - address: Pubkey, + _fanout_mint: FanoutMint, + _address: Pubkey, } #[derive(Debug)] struct HydraObject { pub fanout: Fanout, pub address: Pubkey, - pub children: Option, + pub _children: Option, } fn main() { @@ -68,7 +68,7 @@ fn main() { let hpu = &hydra_pub; rpc.get_account_data(hpu) .map(|d| (hydra_pub, d)) - .map_err(|_| return hydra_not_found()) + .map_err(|_| hydra_not_found()) } }; @@ -92,16 +92,16 @@ fn main() { with_context: None, }, ) - .map_err(|e| hydra_mint_rpcs_error(e)) + .map_err(hydra_mint_rpcs_error) .map(|result| -> Vec { result .iter() - .map(|(addr, fanoutMintAccount)| HydraMint { - fanout_mint: FanoutMint::try_deserialize( - &mut fanoutMintAccount.data.as_slice(), + .map(|(addr, fanout_mint_account)| HydraMint { + _fanout_mint: FanoutMint::try_deserialize( + &mut fanout_mint_account.data.as_slice(), ) .unwrap(), - address: *addr, + _address: *addr, }) .collect() }) @@ -113,17 +113,17 @@ fn main() { .map(|f| HydraObject { address: input.0, fanout: f, - children: None, + _children: None, }) .map_err(|_| invalid_hydra_address()) }; match app.subcommand() { - (SHOW, Some(arg_matches)) => { - println!("Running {}", SHOW); + (show, Some(arg_matches)) => { + println!("Running {}", show); let hydra_pub = arg_matches .value_of("hydra_address") - .ok_or(missing_hydra_address()) + .ok_or_else(missing_hydra_address) .and_then(|hydra_address| { Pubkey::from_str(hydra_address).map_err(|_| invalid_hydra_address()) }); @@ -136,19 +136,16 @@ fn main() { println!("{:#?}", hy); get_mints(hy.address, hy.fanout) }) - .and_then(|mints| { + .map(|mints| { if mints.is_empty() { println!("No Hydra Children"); - return Ok(()); + } else { + mints.iter().for_each(|m| { + println!("\n\n{:#?}", m); + }); } - mints.iter().for_each(|m| { - println!("\n\n{:#?}", m); - }); - return Ok(()); - }) - .map_err(|e| { - println!("{:?}", e); }) + .map_err(|e| println!("{:?}", e)) .unwrap(); } _ => unreachable!(), diff --git a/programs/hydra/src/error.rs b/programs/hydra/src/error.rs index fc2c732..54e48cb 100644 --- a/programs/hydra/src/error.rs +++ b/programs/hydra/src/error.rs @@ -6,19 +6,19 @@ pub trait OrArithError { impl OrArithError for Option { fn or_arith_error(self) -> StdResult { - self.ok_or(HydraError::BadArtithmetic.into()) + self.ok_or_else(|| HydraError::BadArtithmetic.into()) } } impl OrArithError for Option { fn or_arith_error(self) -> StdResult { - self.ok_or(HydraError::BadArtithmetic.into()) + self.ok_or_else(|| HydraError::BadArtithmetic.into()) } } impl OrArithError for Option { fn or_arith_error(self) -> StdResult { - self.ok_or(HydraError::BadArtithmetic.into()) + self.ok_or_else(|| HydraError::BadArtithmetic.into()) } } diff --git a/programs/hydra/src/processors/mod.rs b/programs/hydra/src/processors/mod.rs index 904cb5c..41c6b98 100644 --- a/programs/hydra/src/processors/mod.rs +++ b/programs/hydra/src/processors/mod.rs @@ -1,9 +1,11 @@ pub mod add_member; pub mod distribute; pub mod init; +#[allow(clippy::module_inception)] pub mod remove_member; pub mod signing; pub mod stake; +#[allow(clippy::module_inception)] pub mod transfer_shares; pub use self::add_member::arg::*; diff --git a/programs/hydra/src/utils/logic/calculation.rs b/programs/hydra/src/utils/logic/calculation.rs index 0bb1add..725098c 100644 --- a/programs/hydra/src/utils/logic/calculation.rs +++ b/programs/hydra/src/utils/logic/calculation.rs @@ -126,5 +126,5 @@ pub fn current_lamports( let subtract_size = rent.minimum_balance(size).max(1); holding_account_lamports .checked_sub(subtract_size) - .ok_or(HydraError::NumericalOverflow.into()) + .ok_or_else(|| HydraError::NumericalOverflow.into()) } diff --git a/programs/hydra/src/utils/logic/distribution.rs b/programs/hydra/src/utils/logic/distribution.rs index 558e3bc..d13e476 100644 --- a/programs/hydra/src/utils/logic/distribution.rs +++ b/programs/hydra/src/utils/logic/distribution.rs @@ -38,6 +38,7 @@ pub fn distribute_native<'info>( ) } +#[allow(clippy::too_many_arguments)] pub fn distribute_mint<'info>( fanout_mint: Account<'info, Mint>, fanout_for_mint: &mut UncheckedAccount<'info>, @@ -59,7 +60,7 @@ pub fn distribute_mint<'info>( let fanout_mint_member_token_account_info = fanout_mint_member_token_account.to_account_info(); let fanout_for_mint = fanout_for_mint; let total_shares = fanout.total_shares as u64; - assert_owned_by(&fanout_for_mint, &crate::ID)?; + assert_owned_by(fanout_for_mint, &crate::ID)?; assert_owned_by(&fanout_mint_member_token_account_info, &Token::id())?; assert_owned_by(holding_account, &anchor_spl::token::Token::id())?; assert_ata( diff --git a/programs/hydra/src/utils/mod.rs b/programs/hydra/src/utils/mod.rs index 6982ede..ba72b5c 100644 --- a/programs/hydra/src/utils/mod.rs +++ b/programs/hydra/src/utils/mod.rs @@ -10,6 +10,7 @@ use anchor_lang::solana_program::system_instruction; use anchor_spl::token::TokenAccount; use std::convert::TryInto; +#[allow(clippy::too_many_arguments)] pub fn create_or_allocate_account_raw<'a>( program_id: Pubkey, new_account_info: &AccountInfo<'a>, @@ -26,16 +27,15 @@ pub fn create_or_allocate_account_raw<'a>( .max(1) .saturating_sub(new_account_info.lamports()); if required_lamports > 0 { - let seeds: &[&[&[u8]]]; let as_arr = [signer_seeds]; - if signer_seeds.len() > 0 { - seeds = &as_arr; + let seeds: &[&[&[u8]]] = if !signer_seeds.is_empty() { + &as_arr } else { - seeds = &[]; - } + &[] + }; invoke_signed( - &system_instruction::transfer(&payer_info.key, new_account_info.key, required_lamports), + &system_instruction::transfer(payer_info.key, new_account_info.key, required_lamports), &[ payer_info.clone(), new_account_info.clone(), @@ -43,21 +43,22 @@ pub fn create_or_allocate_account_raw<'a>( ], seeds, )?; - } + }; let accounts = &[new_account_info.clone(), system_program_info.clone()]; invoke_signed( &system_instruction::allocate(new_account_info.key, size.try_into().unwrap()), accounts, - &[&new_acct_seeds], + &[new_acct_seeds], )?; invoke_signed( &system_instruction::assign(new_account_info.key, &program_id), accounts, - &[&new_acct_seeds], + &[new_acct_seeds], )?; Ok(()) } +#[allow(clippy::useless_asref)] pub fn parse_fanout_mint( fanout_for_mint: &mut UncheckedAccount, fanout: &Pubkey, @@ -91,6 +92,7 @@ pub fn parse_token_account(account: &AccountInfo, owner: &Pubkey) -> Result( fanout_for_mint_membership_voucher: &mut UncheckedAccount<'info>, rent: &Sysvar<'info, anchor_lang::prelude::Rent>, @@ -120,15 +122,15 @@ pub fn parse_mint_membership_voucher<'info>( crate::ID, &account_info, &rent.to_account_info(), - &system_program, + system_program, payer, FANOUT_MINT_MEMBERSHIP_VOUCHER_SIZE, &[], &[ b"fanout-membership", - &fanout_for_mint.as_ref(), - &membership_key.as_ref(), - &fanout_mint.as_ref(), + fanout_for_mint.as_ref(), + membership_key.as_ref(), + fanout_mint.as_ref(), &[mint_membership_voucher_bump], ], )?; @@ -141,7 +143,7 @@ pub fn parse_mint_membership_voucher<'info>( } else { let mut membership_data: &[u8] = &fanout_for_mint_membership_voucher.try_borrow_mut_data()?; - assert_owned_by(&fanout_for_mint_membership_voucher, &crate::ID)?; + assert_owned_by(fanout_for_mint_membership_voucher, &crate::ID)?; let membership = FanoutMembershipMintVoucher::try_deserialize(&mut membership_data)?; if membership.bump_seed != mint_membership_voucher_bump { msg!("Mint Membership Bump Doesnt match"); diff --git a/programs/hydra/src/utils/validation/mod.rs b/programs/hydra/src/utils/validation/mod.rs index a45154b..a6231a3 100644 --- a/programs/hydra/src/utils/validation/mod.rs +++ b/programs/hydra/src/utils/validation/mod.rs @@ -11,12 +11,11 @@ pub fn assert_derivation( path: &[&[u8]], error: Option, ) -> Result { - let (key, bump) = Pubkey::find_program_address(&path, program_id); + let (key, bump) = Pubkey::find_program_address(path, program_id); if key != *account.key { - if error.is_some() { - let err = error.unwrap(); + if let Some(err) = error { msg!("Derivation {:?}", err); - return Err(err.into()); + return Err(err); } msg!("DerivedKeyInvalid"); return Err(HydraError::DerivedKeyInvalid.into());