diff --git a/client/src/rpc_client.rs b/client/src/rpc_client.rs index 195c6331fc6df7..15cd9a1b27635f 100644 --- a/client/src/rpc_client.rs +++ b/client/src/rpc_client.rs @@ -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( @@ -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()); } } } @@ -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; diff --git a/client/src/rpc_client_request.rs b/client/src/rpc_client_request.rs index cb1f534bf08712..ce7fb0d292c019 100644 --- a/client/src/rpc_client_request.rs +++ b/client/src/rpc_client_request.rs @@ -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()); } @@ -66,7 +67,7 @@ impl GenericRpcClientRequest for RpcClientRequest { request, retries, e ); if retries == 0 { - Err(e)?; + return Err(e.into()); } retries -= 1; diff --git a/client/src/thin_client.rs b/client/src/thin_client.rs index 5c18ef82e2a3d3..bf45a66b637b50 100644 --- a/client/src/thin_client.rs +++ b/client/src/thin_client.rs @@ -339,7 +339,7 @@ impl SyncClient for ThinClient { } Err(e) => { self.optimizer.report(index, std::u64::MAX); - Err(e)? + Err(e.into()) } } } @@ -380,7 +380,7 @@ impl SyncClient for ThinClient { } Err(e) => { self.optimizer.report(index, std::u64::MAX); - Err(e)? + Err(e.into()) } } } diff --git a/install/src/command.rs b/install/src/command.rs index 322424c644a9c7..b42337721c8a1e 100644 --- a/install/src/command.rs +++ b/install/src/command.rs @@ -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(); @@ -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 @@ -780,12 +780,12 @@ pub fn update(config_file: &str) -> Result { 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); @@ -818,7 +818,7 @@ pub fn update(config_file: &str) -> Result { })?; 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()); @@ -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 = None; diff --git a/install/src/update_manifest.rs b/install/src/update_manifest.rs index 2a6a2e16fdbd81..b10de79abdde4c 100644 --- a/install/src/update_manifest.rs +++ b/install/src/update_manifest.rs @@ -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) } } diff --git a/programs/config_api/src/config_processor.rs b/programs/config_api/src/config_processor.rs index 1cadbbe90f016d..553bb8c544cf1a 100644 --- a/programs/config_api/src/config_processor.rs +++ b/programs/config_api/src/config_processor.rs @@ -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); } } @@ -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() @@ -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); } } @@ -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); diff --git a/programs/librapay_api/src/librapay_transaction.rs b/programs/librapay_api/src/librapay_transaction.rs index 37bb2c88b9a560..2f21714ec578b5 100644 --- a/programs/librapay_api/src/librapay_transaction.rs +++ b/programs/librapay_api/src/librapay_transaction.rs @@ -121,7 +121,7 @@ pub fn get_libra_balance( } state => { info!("Unknown account state: {:?}", state); - return Err(LibrapayError::UnknownAccountState)?; + return Err(LibrapayError::UnknownAccountState.into()); } } let resource = data_store diff --git a/programs/storage_api/src/storage_contract.rs b/programs/storage_api/src/storage_contract.rs index 4d777253673b17..08d40d7f94658a 100644 --- a/programs/storage_api/src/storage_contract.rs +++ b/programs/storage_api/src/storage_contract.rs @@ -141,7 +141,7 @@ impl<'a> StorageAccount<'a> { }; self.account.set_state(storage_contract) } else { - Err(InstructionError::AccountAlreadyInitialized)? + Err(InstructionError::AccountAlreadyInitialized) } } @@ -157,7 +157,7 @@ impl<'a> StorageAccount<'a> { }; self.account.set_state(storage_contract) } else { - Err(InstructionError::AccountAlreadyInitialized)? + Err(InstructionError::AccountAlreadyInitialized) } } @@ -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) } } @@ -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) } } @@ -360,7 +360,7 @@ impl<'a> StorageAccount<'a> { self.account.set_state(storage_contract) } else { - Err(InstructionError::InvalidArgument)? + Err(InstructionError::InvalidArgument) } } @@ -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); @@ -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); @@ -409,7 +409,7 @@ impl<'a> StorageAccount<'a> { self.account.set_state(storage_contract) } else { - Err(InstructionError::InvalidArgument)? + Err(InstructionError::InvalidArgument) } } } @@ -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 { diff --git a/programs/storage_api/src/storage_processor.rs b/programs/storage_api/src/storage_processor.rs index 2c4c46f4e8c978..2c40f5177ea9cc 100644 --- a/programs/storage_api/src/storage_processor.rs +++ b/programs/storage_api/src/storage_processor.rs @@ -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) } @@ -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( @@ -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); @@ -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])?;