Skip to content

Commit

Permalink
clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
mvines committed Oct 2, 2019
1 parent cd01967 commit 277c878
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 62 deletions.
21 changes: 10 additions & 11 deletions client/src/rpc_client.rs
Expand Up @@ -61,9 +61,11 @@ impl RpcClient {
Err(io::Error::new(
io::ErrorKind::Other,
"Received result of an unexpected type",
))?;
)
.into())
} else {
Ok(signature.as_str().unwrap().to_string())
}
Ok(signature.as_str().unwrap().to_string())
}

pub fn get_signature_status(
Expand Down Expand Up @@ -195,14 +197,11 @@ impl RpcClient {
send_retries - 1
};
if send_retries == 0 {
if status.is_some() {
status.unwrap()?
} else {
Err(io::Error::new(
io::ErrorKind::Other,
format!("Transaction {:?} failed: {:?}", signature_str, status),
))?;
}
return Err(io::Error::new(
io::ErrorKind::Other,
format!("Transaction {:?} failed: {:?}", signature_str, status),
)
.into());
}
}
}
Expand Down Expand Up @@ -262,7 +261,7 @@ impl RpcClient {
}

if send_retries == 0 {
Err(io::Error::new(io::ErrorKind::Other, "Transactions failed"))?;
return Err(io::Error::new(io::ErrorKind::Other, "Transactions failed").into());
}
send_retries -= 1;

Expand Down
7 changes: 4 additions & 3 deletions client/src/rpc_client_request.rs
Expand Up @@ -53,10 +53,11 @@ impl GenericRpcClientRequest for RpcClientRequest {
Ok(mut response) => {
let json: serde_json::Value = serde_json::from_str(&response.text()?)?;
if json["error"].is_object() {
Err(RpcError::RpcRequestError(format!(
return Err(RpcError::RpcRequestError(format!(
"RPC Error response: {}",
serde_json::to_string(&json["error"]).unwrap()
)))?
))
.into());
}
return Ok(json["result"].clone());
}
Expand All @@ -66,7 +67,7 @@ impl GenericRpcClientRequest for RpcClientRequest {
request, retries, e
);
if retries == 0 {
Err(e)?;
return Err(e.into());
}
retries -= 1;

Expand Down
4 changes: 2 additions & 2 deletions client/src/thin_client.rs
Expand Up @@ -339,7 +339,7 @@ impl SyncClient for ThinClient {
}
Err(e) => {
self.optimizer.report(index, std::u64::MAX);
Err(e)?
Err(e.into())
}
}
}
Expand Down Expand Up @@ -380,7 +380,7 @@ impl SyncClient for ThinClient {
}
Err(e) => {
self.optimizer.report(index, std::u64::MAX);
Err(e)?
Err(e.into())
}
}
}
Expand Down
14 changes: 7 additions & 7 deletions install/src/command.rs
Expand Up @@ -127,7 +127,7 @@ fn download_to_temp_archive(
.map_err(|err| format!("Unable to hash {:?}: {}", temp_file, err))?;

if expected_sha256.is_some() && expected_sha256 != Some(&temp_file_sha256) {
Err(io::Error::new(io::ErrorKind::Other, "Incorrect hash"))?;
return Err(io::Error::new(io::ErrorKind::Other, "Incorrect hash").into());
}

source.progress_bar.finish_and_clear();
Expand Down Expand Up @@ -651,7 +651,7 @@ pub fn deploy(
})?;
progress_bar.finish_and_clear();
if balance.unwrap_or(0) == 0 {
Err(format!("{} account balance is empty", from_keypair_file))?;
return Err(format!("{} account balance is empty", from_keypair_file));
}

// Download the release
Expand Down Expand Up @@ -780,12 +780,12 @@ pub fn update(config_file: &str) -> Result<bool, String> {
if timestamp_secs()
< u64::from_str_radix(crate::build_env::BUILD_SECONDS_SINCE_UNIX_EPOCH, 10).unwrap()
{
Err("Unable to update as system time seems unreliable".to_string())?
return Err("Unable to update as system time seems unreliable".to_string());
}

if let Some(ref current_update_manifest) = config.current_update_manifest {
if update_manifest.timestamp_secs < current_update_manifest.timestamp_secs {
Err("Unable to update to an older version".to_string())?
return Err("Unable to update to an older version".to_string());
}
}
let release_dir = config.release_dir(&update_manifest.download_sha256);
Expand Down Expand Up @@ -818,7 +818,7 @@ pub fn update(config_file: &str) -> Result<bool, String> {
})?;

if release_target != crate::build_env::TARGET {
Err(format!("Incompatible update target: {}", release_target))?;
return Err(format!("Incompatible update target: {}", release_target));
}

let _ = fs::remove_dir_all(config.active_release_dir());
Expand Down Expand Up @@ -854,10 +854,10 @@ pub fn run(
}

if !full_program_path.exists() {
Err(format!(
return Err(format!(
"{} does not exist",
full_program_path.to_str().unwrap()
))?;
));
}

let mut child_option: Option<std::process::Child> = None;
Expand Down
8 changes: 3 additions & 5 deletions install/src/update_manifest.rs
Expand Up @@ -47,12 +47,10 @@ impl SignedUpdateManifest {
let mut manifest: SignedUpdateManifest = bincode::deserialize(input)?;
manifest.account_pubkey = *account_pubkey;
if !manifest.verify() {
Err(io::Error::new(
io::ErrorKind::Other,
"Manifest failed to verify",
))?;
Err(io::Error::new(io::ErrorKind::Other, "Manifest failed to verify").into())
} else {
Ok(manifest)
}
Ok(manifest)
}
}

Expand Down
16 changes: 8 additions & 8 deletions programs/config_api/src/config_processor.rs
Expand Up @@ -33,7 +33,7 @@ pub fn process_instruction(
// or when no signers specified in Config data
if keyed_accounts[0].signer_key().is_none() {
error!("account[0].signer_key().is_none()");
Err(InstructionError::MissingRequiredSignature)?;
return Err(InstructionError::MissingRequiredSignature);
}
}

Expand All @@ -50,19 +50,19 @@ pub fn process_instruction(
let signer_account = keyed_accounts.get(account_index);
if signer_account.is_none() {
error!("account {:?} is not in account list", signer);
Err(InstructionError::MissingRequiredSignature)?;
return Err(InstructionError::MissingRequiredSignature);
}
let signer_key = signer_account.unwrap().signer_key();
if signer_key.is_none() {
error!("account {:?} signer_key().is_none()", signer);
Err(InstructionError::MissingRequiredSignature)?;
return Err(InstructionError::MissingRequiredSignature);
}
if signer_key.unwrap() != signer {
error!(
"account[{:?}].signer_key() does not match Config data)",
account_index
);
Err(InstructionError::MissingRequiredSignature)?;
return Err(InstructionError::MissingRequiredSignature);
}
// If Config account is already initialized, update signatures must match Config data
if !current_data.keys.is_empty()
Expand All @@ -72,11 +72,11 @@ pub fn process_instruction(
.is_none()
{
error!("account {:?} is not in stored signer list", signer);
Err(InstructionError::MissingRequiredSignature)?;
return Err(InstructionError::MissingRequiredSignature);
}
} else if keyed_accounts[0].signer_key().is_none() {
error!("account[0].signer_key().is_none()");
Err(InstructionError::MissingRequiredSignature)?;
return Err(InstructionError::MissingRequiredSignature);
}
}

Expand All @@ -87,12 +87,12 @@ pub fn process_instruction(
counter,
current_signer_keys.len()
);
Err(InstructionError::MissingRequiredSignature)?;
return Err(InstructionError::MissingRequiredSignature);
}

if keyed_accounts[0].account.data.len() < data.len() {
error!("instruction data too large");
Err(InstructionError::InvalidInstructionData)?;
return Err(InstructionError::InvalidInstructionData);
}

keyed_accounts[0].account.data[0..data.len()].copy_from_slice(&data);
Expand Down
2 changes: 1 addition & 1 deletion programs/librapay_api/src/librapay_transaction.rs
Expand Up @@ -121,7 +121,7 @@ pub fn get_libra_balance<T: Client>(
}
state => {
info!("Unknown account state: {:?}", state);
return Err(LibrapayError::UnknownAccountState)?;
return Err(LibrapayError::UnknownAccountState.into());
}
}
let resource = data_store
Expand Down
37 changes: 19 additions & 18 deletions programs/storage_api/src/storage_contract.rs
Expand Up @@ -141,7 +141,7 @@ impl<'a> StorageAccount<'a> {
};
self.account.set_state(storage_contract)
} else {
Err(InstructionError::AccountAlreadyInitialized)?
Err(InstructionError::AccountAlreadyInitialized)
}
}

Expand All @@ -157,7 +157,7 @@ impl<'a> StorageAccount<'a> {
};
self.account.set_state(storage_contract)
} else {
Err(InstructionError::AccountAlreadyInitialized)?
Err(InstructionError::AccountAlreadyInitialized)
}
}

Expand Down Expand Up @@ -234,7 +234,7 @@ impl<'a> StorageAccount<'a> {
segment_proofs.push(proof);
self.account.set_state(storage_contract)
} else {
Err(InstructionError::InvalidArgument)?
Err(InstructionError::InvalidArgument)
}
}

Expand Down Expand Up @@ -270,7 +270,7 @@ impl<'a> StorageAccount<'a> {
credits.current_epoch += total_validations;
self.account.set_state(storage_contract)
} else {
Err(InstructionError::InvalidArgument)?
Err(InstructionError::InvalidArgument)
}
}

Expand Down Expand Up @@ -360,7 +360,7 @@ impl<'a> StorageAccount<'a> {

self.account.set_state(storage_contract)
} else {
Err(InstructionError::InvalidArgument)?
Err(InstructionError::InvalidArgument)
}
}

Expand All @@ -380,9 +380,9 @@ impl<'a> StorageAccount<'a> {
} = &mut storage_contract
{
if owner.id != *account_owner {
Err(InstructionError::CustomError(
return Err(InstructionError::CustomError(
StorageError::InvalidOwner as u32,
))?
));
}

credits.update_epoch(clock.epoch);
Expand All @@ -397,9 +397,9 @@ impl<'a> StorageAccount<'a> {
} = &mut storage_contract
{
if owner.id != *account_owner {
Err(InstructionError::CustomError(
return Err(InstructionError::CustomError(
StorageError::InvalidOwner as u32,
))?
));
}
credits.update_epoch(clock.epoch);
let (num_validations, _total_proofs) = count_valid_proofs(&validations);
Expand All @@ -409,7 +409,7 @@ impl<'a> StorageAccount<'a> {

self.account.set_state(storage_contract)
} else {
Err(InstructionError::InvalidArgument)?
Err(InstructionError::InvalidArgument)
}
}
}
Expand All @@ -424,15 +424,16 @@ fn check_redeemable(
if rewards_pool.account.lamports < rewards {
Err(InstructionError::CustomError(
StorageError::RewardPoolDepleted as u32,
))?
}
if rewards >= 1 {
rewards_pool.account.lamports -= rewards;
owner.account.lamports += rewards;
//clear credits
credits.redeemable = 0;
))
} else {
if rewards >= 1 {
rewards_pool.account.lamports -= rewards;
owner.account.lamports += rewards;
//clear credits
credits.redeemable = 0;
}
Ok(())
}
Ok(())
}

pub fn create_rewards_pool() -> Account {
Expand Down
14 changes: 7 additions & 7 deletions programs/storage_api/src/storage_processor.rs
Expand Up @@ -22,13 +22,13 @@ pub fn process_instruction(
match bincode::deserialize(data).map_err(|_| InstructionError::InvalidInstructionData)? {
StorageInstruction::InitializeReplicatorStorage { owner } => {
if !rest.is_empty() {
Err(InstructionError::InvalidArgument)?;
return Err(InstructionError::InvalidArgument);
}
storage_account.initialize_replicator_storage(owner)
}
StorageInstruction::InitializeValidatorStorage { owner } => {
if !rest.is_empty() {
Err(InstructionError::InvalidArgument)?;
return Err(InstructionError::InvalidArgument);
}
storage_account.initialize_validator_storage(owner)
}
Expand All @@ -40,7 +40,7 @@ pub fn process_instruction(
} => {
if me_unsigned || rest.len() != 1 {
// This instruction must be signed by `me`
Err(InstructionError::InvalidArgument)?;
return Err(InstructionError::InvalidArgument);
}
let clock = sysvar::clock::from_keyed_account(&rest[0])?;
storage_account.submit_mining_proof(
Expand All @@ -54,14 +54,14 @@ pub fn process_instruction(
StorageInstruction::AdvertiseStorageRecentBlockhash { hash, segment } => {
if me_unsigned || rest.len() != 1 {
// This instruction must be signed by `me`
Err(InstructionError::InvalidArgument)?;
return Err(InstructionError::InvalidArgument);
}
let clock = sysvar::clock::from_keyed_account(&rest[0])?;
storage_account.advertise_storage_recent_blockhash(hash, segment, clock)
}
StorageInstruction::ClaimStorageReward => {
if rest.len() != 4 {
Err(InstructionError::InvalidArgument)?;
return Err(InstructionError::InvalidArgument);
}
let (clock, rest) = rest.split_at_mut(1);
let (rewards, rest) = rest.split_at_mut(1);
Expand All @@ -75,13 +75,13 @@ pub fn process_instruction(
}
StorageInstruction::ProofValidation { segment, proofs } => {
if rest.is_empty() {
Err(InstructionError::InvalidArgument)?;
return Err(InstructionError::InvalidArgument);
}

let (clock, rest) = rest.split_at_mut(1);
if me_unsigned || rest.is_empty() {
// This instruction must be signed by `me` and `rest` cannot be empty
Err(InstructionError::InvalidArgument)?;
return Err(InstructionError::InvalidArgument);
}
let me_id = storage_account.id;
let clock = sysvar::clock::from_keyed_account(&clock[0])?;
Expand Down

0 comments on commit 277c878

Please sign in to comment.