Skip to content

Commit

Permalink
fix: remove unwrap when getting tx receipt (#4231)
Browse files Browse the repository at this point in the history
* fix: don't unwrap on None tx receipt

* chore: nicer fmt
  • Loading branch information
kylezs committed Nov 16, 2023
1 parent 4e9d18a commit d96fada
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions engine/src/eth/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,21 +162,23 @@ impl EthRpcApi for EthRpcClient {
}

async fn transaction_receipt(&self, tx_hash: TxHash) -> Result<TransactionReceipt> {
Ok(self.signer.get_transaction_receipt(tx_hash).await?.unwrap())
self.signer.get_transaction_receipt(tx_hash).await?.ok_or_else(|| {
anyhow!("Getting ETH transaction receipt for tx hash {tx_hash} returned None")
})
}

/// Gets block, returning error when either:
/// - Request fails
/// - Request succeeds, but doesn't return a block
async fn block(&self, block_number: U64) -> Result<Block<H256>> {
self.signer.get_block(block_number).await?.ok_or_else(|| {
anyhow!("Getting ETH block for block number {} returned None", block_number)
anyhow!("Getting ETH block for block number {block_number} returned None")
})
}

async fn block_with_txs(&self, block_number: U64) -> Result<Block<Transaction>> {
self.signer.get_block_with_txs(block_number).await?.ok_or_else(|| {
anyhow!("Getting ETH block with txs for block number {} returned None", block_number)
anyhow!("Getting ETH block with txs for block number {block_number} returned None")
})
}

Expand All @@ -193,7 +195,7 @@ impl EthRpcApi for EthRpcClient {
self.signer
.get_transaction(tx_hash)
.await?
.ok_or_else(|| anyhow!("Getting ETH transaction for tx hash {} returned None", tx_hash))
.ok_or_else(|| anyhow!("Getting ETH transaction for tx hash {tx_hash} returned None"))
}
}

Expand Down

0 comments on commit d96fada

Please sign in to comment.