Skip to content

Commit

Permalink
core: add chain Error → TxStatusError conversion (#7912)
Browse files Browse the repository at this point in the history
Having conversion from near_chain_primitves::Error to TxStatusError
eliminates a handful of trivial map_error calls.
  • Loading branch information
mina86 committed Oct 24, 2022
1 parent 8ab9f8b commit 663f210
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
6 changes: 6 additions & 0 deletions chain/client-primitives/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,12 @@ pub enum TxStatusError {
TimeoutError,
}

impl From<near_chain_primitives::Error> for TxStatusError {
fn from(error: near_chain_primitives::Error) -> Self {
Self::ChainError(error)
}
}

impl Message for TxStatus {
type Result = Result<Option<FinalExecutionOutcomeViewEnum>, TxStatusError>;
}
Expand Down
17 changes: 6 additions & 11 deletions chain/client/src/view_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,
)
Expand All @@ -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 {
Expand All @@ -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(
Expand Down Expand Up @@ -907,7 +902,7 @@ impl Handler<WithSpanContext<GetExecutionOutcome>> 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(
Expand Down

0 comments on commit 663f210

Please sign in to comment.