More clippy

This commit is contained in:
Michael Vines
2019-10-02 18:33:01 -07:00
parent 9fe8c98047
commit f9f5bc2eb5
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),
}
}