Skip to content

Commit

Permalink
fix: better error handling when waiting for receipt (#9253)
Browse files Browse the repository at this point in the history
* fix: better error handling when waiting for receipt

* fmt
  • Loading branch information
klkvr authored Nov 2, 2024
1 parent 97be9b9 commit d402afd
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions crates/script/src/receipts.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use alloy_chains::Chain;
use alloy_primitives::{utils::format_units, TxHash, U256};
use alloy_provider::{PendingTransactionBuilder, Provider};
use alloy_provider::{PendingTransactionBuilder, PendingTransactionError, Provider, WatchTxError};
use alloy_rpc_types::AnyTransactionReceipt;
use eyre::Result;
use foundry_common::provider::RetryProvider;
Expand Down Expand Up @@ -40,12 +40,16 @@ pub async fn check_tx_status(
}

loop {
if let Ok(receipt) = PendingTransactionBuilder::new(provider.clone(), hash)
match PendingTransactionBuilder::new(provider.clone(), hash)
.with_timeout(Some(Duration::from_secs(timeout)))
.get_receipt()
.await
{
return Ok(receipt.into())
Ok(receipt) => return Ok(receipt.into()),
// do nothing on timeout, we will check whether tx is dropped below
Err(PendingTransactionError::TxWatcher(WatchTxError::Timeout)) => {}
// treat other errors as fatal
Err(e) => return Err(e.into()),
}

if provider.get_transaction_by_hash(hash).await?.is_some() {
Expand Down

0 comments on commit d402afd

Please sign in to comment.