Skip to content

Commit

Permalink
Move back to anyhow Result
Browse files Browse the repository at this point in the history
  • Loading branch information
elmattic committed Feb 16, 2024
1 parent d22730d commit ce33815
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/rpc/eth_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::rpc::error::JsonRpcError;
use crate::rpc_api::{data_types::RPCState, eth_api::BigInt as EthBigInt, eth_api::*};
use crate::shim::{clock::ChainEpoch, state_tree::StateTree};

use anyhow::{Context, Result};
use anyhow::{bail, Context, Result};
use fvm_ipld_blockstore::Blockstore;
use jsonrpsee::types::Params;
use num_bigint::BigInt;
Expand Down Expand Up @@ -99,14 +99,12 @@ pub async fn eth_get_balance<DB: Blockstore>(
fn tipset_by_block_number_or_hash<DB: Blockstore>(
chain: &Arc<ChainStore<DB>>,
block_param: BlockNumberOrHash,
) -> Result<Arc<Tipset>, JsonRpcError> {
) -> anyhow::Result<Arc<Tipset>> {
let head = chain.heaviest_tipset();

match block_param {
BlockNumberOrHash::PredefinedBlock(predefined) => match predefined {
Predefined::Earliest => {
Err(anyhow::anyhow!("block param \"earliest\" is not supported").into())
}
Predefined::Earliest => bail!("block param \"earliest\" is not supported"),
Predefined::Pending => Ok(head),
Predefined::Latest => {
let parent = chain.chain_index.load_required_tipset(head.parents())?;
Expand All @@ -116,7 +114,7 @@ fn tipset_by_block_number_or_hash<DB: Blockstore>(
BlockNumberOrHash::BlockNumber(number) => {
let height = ChainEpoch::from(number);
if height > head.epoch() - 1 {
return Err(anyhow::anyhow!("requested a future epoch (beyond \"latest\")").into());
bail!("requested a future epoch (beyond \"latest\")");
}
let ts =
chain
Expand All @@ -139,7 +137,7 @@ fn tipset_by_block_number_or_hash<DB: Blockstore>(
)?;
// verify that it equals the expected tipset
if walk_ts != ts {
return Err(anyhow::anyhow!("tipset is not canonical").into());
bail!("tipset is not canonical");
}
}
Ok(ts)
Expand Down

0 comments on commit ce33815

Please sign in to comment.