Skip to content

Commit

Permalink
Clippy fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jpbogle committed May 27, 2022
1 parent bac6c60 commit 80de850
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 46 deletions.
43 changes: 20 additions & 23 deletions cli/hydra_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand All @@ -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<HydraMint>,
pub _children: Option<HydraMint>,
}

fn main() {
Expand All @@ -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())
}
};

Expand All @@ -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<HydraMint> {
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()
})
Expand All @@ -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())
});
Expand All @@ -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!(),
Expand Down
6 changes: 3 additions & 3 deletions programs/hydra/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ pub trait OrArithError<T> {

impl OrArithError<u64> for Option<u64> {
fn or_arith_error(self) -> StdResult<u64, error::Error> {
self.ok_or(HydraError::BadArtithmetic.into())
self.ok_or_else(|| HydraError::BadArtithmetic.into())
}
}

impl OrArithError<u32> for Option<u32> {
fn or_arith_error(self) -> StdResult<u32, error::Error> {
self.ok_or(HydraError::BadArtithmetic.into())
self.ok_or_else(|| HydraError::BadArtithmetic.into())
}
}

impl OrArithError<u128> for Option<u128> {
fn or_arith_error(self) -> StdResult<u128, error::Error> {
self.ok_or(HydraError::BadArtithmetic.into())
self.ok_or_else(|| HydraError::BadArtithmetic.into())
}
}

Expand Down
2 changes: 2 additions & 0 deletions programs/hydra/src/processors/mod.rs
Original file line number Diff line number Diff line change
@@ -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::*;
Expand Down
2 changes: 1 addition & 1 deletion programs/hydra/src/utils/logic/calculation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
3 changes: 2 additions & 1 deletion programs/hydra/src/utils/logic/distribution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand All @@ -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(
Expand Down
30 changes: 16 additions & 14 deletions programs/hydra/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand All @@ -26,38 +27,38 @@ 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(),
system_program_info.clone(),
],
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,
Expand Down Expand Up @@ -91,6 +92,7 @@ pub fn parse_token_account(account: &AccountInfo, owner: &Pubkey) -> Result<Toke
Ok(account_object)
}

#[allow(clippy::too_many_arguments)]
pub fn parse_mint_membership_voucher<'info>(
fanout_for_mint_membership_voucher: &mut UncheckedAccount<'info>,
rent: &Sysvar<'info, anchor_lang::prelude::Rent>,
Expand Down Expand Up @@ -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],
],
)?;
Expand All @@ -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");
Expand Down
7 changes: 3 additions & 4 deletions programs/hydra/src/utils/validation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ pub fn assert_derivation(
path: &[&[u8]],
error: Option<error::Error>,
) -> Result<u8> {
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());
Expand Down

0 comments on commit 80de850

Please sign in to comment.