Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: better error handling when waiting for receipt #9253

Merged
merged 2 commits into from
Nov 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading