From 663f2100bb7ac5fdf3f802ab6bcdb6cc2dcf28fa Mon Sep 17 00:00:00 2001 From: Michal Nazarewicz Date: Mon, 24 Oct 2022 23:11:18 +0100 Subject: [PATCH] =?UTF-8?q?core:=20add=20chain=20Error=20=E2=86=92=20TxSta?= =?UTF-8?q?tusError=20conversion=20(#7912)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Having conversion from near_chain_primitves::Error to TxStatusError eliminates a handful of trivial map_error calls. --- chain/client-primitives/src/types.rs | 6 ++++++ chain/client/src/view_client.rs | 17 ++++++----------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/chain/client-primitives/src/types.rs b/chain/client-primitives/src/types.rs index ad2de642944..fedd8af30cd 100644 --- a/chain/client-primitives/src/types.rs +++ b/chain/client-primitives/src/types.rs @@ -598,6 +598,12 @@ pub enum TxStatusError { TimeoutError, } +impl From for TxStatusError { + fn from(error: near_chain_primitives::Error) -> Self { + Self::ChainError(error) + } +} + impl Message for TxStatus { type Result = Result, TxStatusError>; } diff --git a/chain/client/src/view_client.rs b/chain/client/src/view_client.rs index 4557883ac9a..6458a211e76 100644 --- a/chain/client/src/view_client.rs +++ b/chain/client/src/view_client.rs @@ -371,7 +371,7 @@ impl ViewClientActor { } } - let head = self.chain.head().map_err(|e| TxStatusError::ChainError(e))?; + let head = self.chain.head()?; let target_shard_id = self .runtime_adapter .account_id_to_shard_id(&signer_account_id, &head.epoch_id) @@ -386,10 +386,8 @@ impl ViewClientActor { match self.chain.get_final_transaction_result(&tx_hash) { Ok(tx_result) => { let res = if fetch_receipt { - let final_result = self - .chain - .get_final_transaction_result_with_receipt(tx_result) - .map_err(|e| TxStatusError::ChainError(e))?; + let final_result = + self.chain.get_final_transaction_result_with_receipt(tx_result)?; FinalExecutionOutcomeViewEnum::FinalExecutionOutcomeWithReceipt( final_result, ) @@ -407,7 +405,7 @@ impl ViewClientActor { } Err(err) => { warn!(target: "client", ?err, "Error trying to get transaction result"); - Err(TxStatusError::ChainError(err)) + Err(err.into()) } } } else { @@ -417,10 +415,7 @@ impl ViewClientActor { .runtime_adapter .account_id_to_shard_id(&signer_account_id, &head.epoch_id) .map_err(|err| TxStatusError::InternalError(err.to_string()))?; - let validator = self - .chain - .find_validator_for_forwarding(target_shard_id) - .map_err(|e| TxStatusError::ChainError(e))?; + let validator = self.chain.find_validator_for_forwarding(target_shard_id)?; self.network_adapter.do_send( PeerManagerMessageRequest::NetworkRequests(NetworkRequests::TxStatus( @@ -907,7 +902,7 @@ impl Handler> for ViewClientActor { } Err(e) => match e { near_chain::Error::DBNotFoundErr(_) => { - let head = self.chain.head().map_err(|e| TxStatusError::ChainError(e))?; + let head = self.chain.head()?; let target_shard_id = self.runtime_adapter.account_id_to_shard_id(&account_id, &head.epoch_id)?; if self.runtime_adapter.cares_about_shard(