Skip to content

Commit

Permalink
clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
mvines committed Oct 3, 2019
1 parent 1baa0f7 commit d98c3ac
Show file tree
Hide file tree
Showing 20 changed files with 89 additions and 84 deletions.
5 changes: 3 additions & 2 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
Expand Down
13 changes: 8 additions & 5 deletions cli/src/stake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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()),
}
}

Expand Down
8 changes: 5 additions & 3 deletions cli/src/validator_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}

Expand Down Expand Up @@ -136,7 +137,8 @@ fn parse_validator_info(
Err(format!(
"account {} found, but could not be parsed as ValidatorInfo",
pubkey
))?
)
.into())
}
}

Expand Down
10 changes: 6 additions & 4 deletions cli/src/vote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(|_| {
Expand Down Expand Up @@ -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(|_| {
Expand Down
59 changes: 32 additions & 27 deletions cli/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ fn check_account_for_multiple_fees(
return Ok(());
}
}
Err(WalletError::InsufficientFundsForFee)?
Err(WalletError::InsufficientFundsForFee.into())
}

pub fn check_unique_pubkeys(
Expand Down Expand Up @@ -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)?;
Expand All @@ -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()),
}
}

Expand All @@ -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())
}
}
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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),
}
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/blocktree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ impl Blocktree {
"Error: {:?} while submitting write batch for slot {:?} retrying...",
e, from_slot
);
Err(e)?;
return Err(e);
}
Ok(end)
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/cluster_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion core/src/packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ impl Blob {
"error sending {} byte packet to {:?}: {:?}",
p.meta.size, a, e
);
Err(e)?;
return Err(e.into());
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/replay_stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
19 changes: 7 additions & 12 deletions core/src/replicator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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())
}
}

Expand Down Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions core/src/shred.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion core/src/storage_stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ impl StorageStage {
}
Err(e) => {
info!("error encrypting file: {:?}", e);
Err(e)?;
return Err(e.into());
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions core/src/tvu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions core/src/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

(
Expand Down
3 changes: 1 addition & 2 deletions core/src/window_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down
10 changes: 5 additions & 5 deletions programs/stake_api/src/stake_instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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];

Expand All @@ -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];
Expand All @@ -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];
Expand All @@ -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];
Expand Down
Loading

0 comments on commit d98c3ac

Please sign in to comment.