More clippy

This commit is contained in:
Michael Vines 2019-10-02 18:33:01 -07:00
parent 9fe8c98047
commit f9f5bc2eb5
No known key found for this signature in database
GPG Key ID: 33F4FDEC4E0E88BD
21 changed files with 97 additions and 90 deletions

View File

@ -91,9 +91,10 @@ pub fn parse_args(matches: &ArgMatches<'_>) -> Result<WalletConfig, Box<dyn erro
} else {
let default = WalletConfig::default();
if !std::path::Path::new(&default.keypair_path).exists() {
Err(WalletError::KeypairFileNotFound(
return Err(WalletError::KeypairFileNotFound(
"Generate a new keypair with `solana-keygen new`".to_string(),
))?;
)
.into());
}
default.keypair_path
};

View File

@ -371,10 +371,11 @@ pub fn process_create_stake_account(
rpc_client.get_minimum_balance_for_rent_exemption(std::mem::size_of::<StakeState>())?;
if lamports < minimum_balance {
Err(WalletError::BadParameter(format!(
return Err(WalletError::BadParameter(format!(
"need atleast {} lamports for stake account to be rent exempt, provided lamports: {}",
minimum_balance, lamports
)))?;
))
.into());
}
let ixs = stake_instruction::create_stake_account_with_lockup(
@ -486,9 +487,10 @@ pub fn process_show_stake_account(
) -> ProcessResult {
let stake_account = rpc_client.get_account(stake_account_pubkey)?;
if stake_account.owner != solana_stake_api::id() {
Err(WalletError::RpcRequestError(
return Err(WalletError::RpcRequestError(
format!("{:?} is not a stake account", stake_account_pubkey).to_string(),
))?;
)
.into());
}
fn show_authorized(authorized: &Authorized) {
println!("authorized staker: {}", authorized.staker);
@ -537,7 +539,8 @@ pub fn process_show_stake_account(
Err(err) => Err(WalletError::RpcRequestError(format!(
"Account data could not be deserialized to stake state: {:?}",
err
)))?,
))
.into()),
}
}

View File

@ -92,13 +92,14 @@ fn verify_keybase(
if client.head(&url).send()?.status().is_success() {
Ok(())
} else {
Err(format!("keybase_username could not be confirmed at: {}. Please add this pubkey file to your keybase profile to connect", url))?
Err(format!("keybase_username could not be confirmed at: {}. Please add this pubkey file to your keybase profile to connect", url).into())
}
} else {
Err(format!(
"keybase_username could not be parsed as String: {}",
keybase_username
))?
)
.into())
}
}
@ -136,7 +137,8 @@ fn parse_validator_info(
Err(format!(
"account {} found, but could not be parsed as ValidatorInfo",
pubkey
))?
)
.into())
}
}

View File

@ -145,9 +145,10 @@ pub fn process_show_vote_account(
let vote_account = rpc_client.get_account(vote_account_pubkey)?;
if vote_account.owner != solana_vote_api::id() {
Err(WalletError::RpcRequestError(
return Err(WalletError::RpcRequestError(
format!("{:?} is not a vote account", vote_account_pubkey).to_string(),
))?;
)
.into());
}
let vote_state = VoteState::deserialize(&vote_account.data).map_err(|_| {
@ -218,9 +219,10 @@ pub fn process_uptime(
let vote_account = rpc_client.get_account(vote_account_pubkey)?;
if vote_account.owner != solana_vote_api::id() {
Err(WalletError::RpcRequestError(
return Err(WalletError::RpcRequestError(
format!("{:?} is not a vote account", vote_account_pubkey).to_string(),
))?;
)
.into());
}
let vote_state = VoteState::deserialize(&vote_account.data).map_err(|_| {

View File

@ -423,7 +423,7 @@ fn check_account_for_multiple_fees(
return Ok(());
}
}
Err(WalletError::InsufficientFundsForFee)?
Err(WalletError::InsufficientFundsForFee.into())
}
pub fn check_unique_pubkeys(
@ -462,9 +462,12 @@ fn process_airdrop(
);
let previous_balance = match rpc_client.retry_get_balance(&config.keypair.pubkey(), 5)? {
Some(lamports) => lamports,
None => Err(WalletError::RpcRequestError(
"Received result of an unexpected type".to_string(),
))?,
None => {
return Err(WalletError::RpcRequestError(
"Received result of an unexpected type".to_string(),
)
.into())
}
};
request_and_confirm_airdrop(&rpc_client, drone_addr, &config.keypair.pubkey(), lamports)?;
@ -486,7 +489,8 @@ fn process_balance(
Some(lamports) => Ok(build_balance_message(lamports, use_lamports_unit)),
None => Err(WalletError::RpcRequestError(
"Received result of an unexpected type".to_string(),
))?,
)
.into()),
}
}
@ -502,10 +506,9 @@ fn process_confirm(rpc_client: &RpcClient, signature: &Signature) -> ProcessResu
Ok("Not found".to_string())
}
}
Err(err) => Err(WalletError::RpcRequestError(format!(
"Unable to confirm: {:?}",
err
)))?,
Err(err) => {
Err(WalletError::RpcRequestError(format!("Unable to confirm: {:?}", err)).into())
}
}
}
@ -619,9 +622,10 @@ fn process_show_storage_account(
let account = rpc_client.get_account(storage_account_pubkey)?;
if account.owner != solana_storage_api::id() {
Err(WalletError::RpcRequestError(
return Err(WalletError::RpcRequestError(
format!("{:?} is not a storage account", storage_account_pubkey).to_string(),
))?;
)
.into());
}
use solana_storage_api::storage_contract::StorageContract;
@ -771,9 +775,10 @@ fn process_pay(
let witness = if let Some(ref witness_vec) = *witnesses {
witness_vec[0]
} else {
Err(WalletError::BadParameter(
return Err(WalletError::BadParameter(
"Could not parse required signature pubkey(s)".to_string(),
))?
)
.into());
};
let contract_state = Keypair::new();
@ -1361,22 +1366,22 @@ pub fn log_instruction_custom_error<E>(result: Result<String, ClientError>) -> P
where
E: 'static + std::error::Error + DecodeError<E> + FromPrimitive,
{
if result.is_err() {
let err = result.unwrap_err();
if let ClientError::TransactionError(TransactionError::InstructionError(
_,
InstructionError::CustomError(code),
)) = err
{
if let Some(specific_error) = E::decode_custom_error_to_enum(code) {
error!("{}::{:?}", E::type_of(), specific_error);
Err(specific_error)?
match result {
Err(err) => {
if let ClientError::TransactionError(TransactionError::InstructionError(
_,
InstructionError::CustomError(code),
)) = err
{
if let Some(specific_error) = E::decode_custom_error_to_enum(code) {
error!("{}::{:?}", E::type_of(), specific_error);
return Err(specific_error.into());
}
}
error!("{:?}", err);
Err(err.into())
}
error!("{:?}", err);
Err(err)?
} else {
Ok(result.unwrap())
Ok(sig) => Ok(sig),
}
}

View File

@ -266,7 +266,7 @@ impl Blocktree {
"Error: {:?} while submitting write batch for slot {:?} retrying...",
e, from_slot
);
Err(e)?;
return Err(e);
}
Ok(end)
}

View File

@ -809,7 +809,7 @@ impl ClusterInfo {
// by a valid tvu port location
let valid: Vec<_> = self.repair_peers();
if valid.is_empty() {
Err(ClusterInfoError::NoPeers)?;
return Err(ClusterInfoError::NoPeers.into());
}
let n = thread_rng().gen::<usize>() % valid.len();
let addr = valid[n].gossip; // send the request to the peer's gossip port

View File

@ -605,7 +605,7 @@ impl Blob {
"error sending {} byte packet to {:?}: {:?}",
p.meta.size, a, e
);
Err(e)?;
return Err(e.into());
}
}
}

View File

@ -448,7 +448,7 @@ impl ReplayStage {
trace!("new root {}", new_root);
if let Err(e) = root_bank_sender.send(rooted_banks) {
trace!("root_bank_sender failed: {:?}", e);
Err(e)?;
return Err(e.into());
}
}
Self::update_confidence_cache(bank.clone(), total_staked, lockouts_sender);

View File

@ -582,10 +582,9 @@ impl Replicator {
) -> Result<()> {
// make sure replicator has some balance
if client.poll_get_balance(&keypair.pubkey())? == 0 {
Err(io::Error::new(
io::ErrorKind::Other,
"keypair account has no balance",
))?
return Err(
io::Error::new(io::ErrorKind::Other, "keypair account has no balance").into(),
);
}
// check if the storage account exists
@ -705,10 +704,7 @@ impl Replicator {
.as_u64()
.unwrap())
} else {
Err(io::Error::new(
io::ErrorKind::Other,
"No RPC peers...".to_string(),
))?
Err(io::Error::new(io::ErrorKind::Other, "No RPC peers...".to_string()).into())
}
}
@ -889,10 +885,9 @@ impl Replicator {
// check if all the slots in the segment are complete
if !Self::segment_complete(start_slot, slots_per_segment, blocktree) {
Err(io::Error::new(
ErrorKind::Other,
"Unable to download the full segment",
))?
return Err(
io::Error::new(ErrorKind::Other, "Unable to download the full segment").into(),
);
}
Ok(start_slot)
}

View File

@ -572,7 +572,7 @@ impl Shredder {
shred_bufs.append(&mut pending_shreds);
if shred_bufs.len() != fec_set_size {
Err(reed_solomon_erasure::Error::TooFewShardsPresent)?;
return Err(reed_solomon_erasure::Error::TooFewShardsPresent);
}
let session = Session::new(num_data, num_coding).unwrap();
@ -623,7 +623,7 @@ impl Shredder {
};
if num_data.saturating_add(first_index) != last_index.saturating_add(1) {
Err(reed_solomon_erasure::Error::TooFewDataShards)?;
return Err(reed_solomon_erasure::Error::TooFewDataShards);
}
shreds.iter().map(|shred| &shred.payload).collect()

View File

@ -432,7 +432,7 @@ impl StorageStage {
}
Err(e) => {
info!("error encrypting file: {:?}", e);
Err(e)?;
return Err(e.into());
}
}
}

View File

@ -158,11 +158,11 @@ impl Tvu {
fork_confidence_cache,
);
let blockstream_service = if blockstream_unix_socket.is_some() {
let blockstream_service = if let Some(blockstream_unix_socket) = blockstream_unix_socket {
let blockstream_service = BlockstreamService::new(
blockstream_slot_receiver,
blocktree.clone(),
blockstream_unix_socket.unwrap(),
blockstream_unix_socket,
&exit,
);
Some(blockstream_service)

View File

@ -528,8 +528,8 @@ pub fn new_banks_from_blocktree(
dev_halt_at_slot,
);
if snapshot_config.is_some() {
bank_forks.set_snapshot_config(snapshot_config.unwrap());
if let Some(snapshot_config) = snapshot_config {
bank_forks.set_snapshot_config(snapshot_config);
}
(

View File

@ -77,8 +77,7 @@ fn recv_window<F>(
leader_schedule_cache: &Arc<LeaderScheduleCache>,
) -> Result<()>
where
F: Fn(&Shred, u64) -> bool,
F: Sync,
F: Fn(&Shred, u64) -> bool + Sync,
{
let timer = Duration::from_millis(200);
let mut packets = r.recv_timeout(timer)?;

View File

@ -173,12 +173,14 @@ fn main() -> Result<(), Box<dyn error::Error>> {
}
}
}
if num_nodes_exactly.is_some() && nodes.len() > num_nodes_exactly.unwrap() {
eprintln!(
"Error: Extra nodes discovered. Expecting exactly {}",
num_nodes_exactly.unwrap()
);
exit(1);
if let Some(num_nodes_exactly) = num_nodes_exactly {
if nodes.len() > num_nodes_exactly {
eprintln!(
"Error: Extra nodes discovered. Expecting exactly {}",
num_nodes_exactly
);
exit(1);
}
}
}
("get-rpc-url", Some(matches)) => {

View File

@ -273,7 +273,7 @@ pub fn process_instruction(
trace!("keyed_accounts: {:?}", keyed_accounts);
if keyed_accounts.is_empty() {
Err(InstructionError::InvalidInstructionData)?;
return Err(InstructionError::InvalidInstructionData);
}
let (me, rest) = &mut keyed_accounts.split_at_mut(1);
@ -287,7 +287,7 @@ pub fn process_instruction(
}
StakeInstruction::DelegateStake => {
if rest.len() < 3 {
Err(InstructionError::InvalidInstructionData)?;
return Err(InstructionError::InvalidInstructionData);
}
let vote = &rest[0];
@ -300,7 +300,7 @@ pub fn process_instruction(
}
StakeInstruction::RedeemVoteCredits => {
if rest.len() != 4 {
Err(InstructionError::InvalidInstructionData)?;
return Err(InstructionError::InvalidInstructionData);
}
let (vote, rest) = rest.split_at_mut(1);
let vote = &mut vote[0];
@ -316,7 +316,7 @@ pub fn process_instruction(
}
StakeInstruction::Withdraw(lamports) => {
if rest.len() < 3 {
Err(InstructionError::InvalidInstructionData)?;
return Err(InstructionError::InvalidInstructionData);
}
let (to, rest) = &mut rest.split_at_mut(1);
let mut to = &mut to[0];
@ -331,7 +331,7 @@ pub fn process_instruction(
}
StakeInstruction::Deactivate => {
if rest.len() < 2 {
Err(InstructionError::InvalidInstructionData)?;
return Err(InstructionError::InvalidInstructionData);
}
let (vote, rest) = rest.split_at_mut(1);
let vote = &mut vote[0];

View File

@ -614,7 +614,7 @@ impl<'a> StakeAccount for KeyedAccount<'a> {
};
if lockup.slot > clock.slot && lockup.custodian != *to.unsigned_key() {
return Err(StakeError::LockupInForce)?;
return Err(StakeError::LockupInForce.into());
}
if lamports > self.account.lamports {
return Err(InstructionError::InsufficientFunds);

View File

@ -277,8 +277,7 @@ impl Accounts {
/// returns only the latest/current version of B for this fork
fn scan_fork<F, B>(&self, fork: Fork, func: F) -> Vec<B>
where
F: Fn(&StoredAccount) -> Option<B>,
F: Send + Sync,
F: Fn(&StoredAccount) -> Option<B> + Send + Sync,
B: Send + Default,
{
let accumulator: Vec<Vec<(Pubkey, u64, B)>> = self.accounts_db.scan_account_storage(

View File

@ -593,8 +593,7 @@ impl AccountsDB {
// PERF: Sequentially read each storage entry in parallel
pub fn scan_account_storage<F, B>(&self, fork_id: Fork, scan_func: F) -> Vec<B>
where
F: Fn(&StoredAccount, AppendVecId, &mut B) -> (),
F: Send + Sync,
F: Fn(&StoredAccount, AppendVecId, &mut B) -> () + Send + Sync,
B: Send + Default,
{
let storage_maps: Vec<Arc<AccountStorageEntry>> = self

View File

@ -20,7 +20,7 @@ fn create_system_account(
"CreateAccount: invalid account[from] owner {} ",
&keyed_accounts[FROM_ACCOUNT_INDEX].account.owner
);
Err(SystemError::SourceNotSystemAccount)?;
return Err(SystemError::SourceNotSystemAccount);
}
if !keyed_accounts[TO_ACCOUNT_INDEX].account.data.is_empty()
@ -30,7 +30,7 @@ fn create_system_account(
"CreateAccount: invalid argument; account {} already in use",
keyed_accounts[TO_ACCOUNT_INDEX].unsigned_key()
);
Err(SystemError::AccountAlreadyInUse)?;
return Err(SystemError::AccountAlreadyInUse);
}
if sysvar::check_id(&program_id) {
@ -38,7 +38,7 @@ fn create_system_account(
"CreateAccount: invalid argument; program id {} invalid",
program_id
);
Err(SystemError::InvalidProgramId)?;
return Err(SystemError::InvalidProgramId);
}
if sysvar::is_sysvar_id(&keyed_accounts[TO_ACCOUNT_INDEX].unsigned_key()) {
@ -46,7 +46,7 @@ fn create_system_account(
"CreateAccount: invalid argument; account id {} invalid",
program_id
);
Err(SystemError::InvalidAccountId)?;
return Err(SystemError::InvalidAccountId);
}
if lamports > keyed_accounts[FROM_ACCOUNT_INDEX].account.lamports {
@ -54,7 +54,7 @@ fn create_system_account(
"CreateAccount: insufficient lamports ({}, need {})",
keyed_accounts[FROM_ACCOUNT_INDEX].account.lamports, lamports
);
Err(SystemError::ResultWithNegativeLamports)?;
return Err(SystemError::ResultWithNegativeLamports);
}
keyed_accounts[FROM_ACCOUNT_INDEX].account.lamports -= lamports;
keyed_accounts[TO_ACCOUNT_INDEX].account.lamports += lamports;
@ -80,7 +80,7 @@ fn transfer_lamports(
"Transfer: insufficient lamports ({}, need {})",
keyed_accounts[FROM_ACCOUNT_INDEX].account.lamports, lamports
);
Err(SystemError::ResultWithNegativeLamports)?;
return Err(SystemError::ResultWithNegativeLamports);
}
keyed_accounts[FROM_ACCOUNT_INDEX].account.lamports -= lamports;
keyed_accounts[TO_ACCOUNT_INDEX].account.lamports += lamports;
@ -99,7 +99,7 @@ pub fn process_instruction(
// All system instructions require that accounts_keys[0] be a signer
if keyed_accounts[FROM_ACCOUNT_INDEX].signer_key().is_none() {
debug!("account[from] is unsigned");
Err(InstructionError::MissingRequiredSignature)?;
return Err(InstructionError::MissingRequiredSignature);
}
match instruction {
@ -110,7 +110,7 @@ pub fn process_instruction(
} => create_system_account(keyed_accounts, lamports, space, &program_id),
SystemInstruction::Assign { program_id } => {
if !system_program::check_id(&keyed_accounts[FROM_ACCOUNT_INDEX].account.owner) {
Err(InstructionError::IncorrectProgramId)?;
return Err(InstructionError::IncorrectProgramId);
}
assign_account_to_program(keyed_accounts, &program_id)
}