@@ -2,8 +2,8 @@ use alloy_chains::Chain;
22use alloy_network:: AnyTransactionReceipt ;
33use alloy_primitives:: { utils:: format_units, TxHash , U256 } ;
44use alloy_provider:: { PendingTransactionBuilder , PendingTransactionError , Provider , WatchTxError } ;
5- use eyre:: Result ;
6- use foundry_common:: { provider:: RetryProvider , shell} ;
5+ use eyre:: { eyre , Result } ;
6+ use foundry_common:: { provider:: RetryProvider , retry , retry :: RetryError , shell} ;
77use std:: time:: Duration ;
88
99/// Convenience enum for internal signalling of transaction status
@@ -30,39 +30,28 @@ pub async fn check_tx_status(
3030 hash : TxHash ,
3131 timeout : u64 ,
3232) -> ( TxHash , Result < TxStatus , eyre:: Report > ) {
33- // We use the inner future so that we can use ? operator in the future, but
34- // still neatly return the tuple
35- let result = async move {
36- // First check if there's a receipt
37- let receipt_opt = provider. get_transaction_receipt ( hash) . await ?;
38- if let Some ( receipt) = receipt_opt {
39- return Ok ( receipt. into ( ) ) ;
40- }
41-
42- loop {
33+ let result = retry:: Retry :: new_no_delay ( 3 )
34+ . run_async_until_break ( || async {
4335 match PendingTransactionBuilder :: new ( provider. clone ( ) , hash)
4436 . with_timeout ( Some ( Duration :: from_secs ( timeout) ) )
4537 . get_receipt ( )
4638 . await
4739 {
48- Ok ( receipt) => return Ok ( receipt. into ( ) ) ,
49- // do nothing on timeout, we will check whether tx is dropped below
50- Err ( PendingTransactionError :: TxWatcher ( WatchTxError :: Timeout ) ) => { }
51- // treat other errors as fatal
52- Err ( e ) => return Err ( e . into ( ) ) ,
53- }
54-
55- if provider . get_transaction_by_hash ( hash ) . await ? . is_some ( ) {
56- trace ! ( "tx is still known to the node, waiting for receipt" ) ;
57- } else {
58- trace ! ( "eth_getTransactionByHash returned null, assuming dropped" ) ;
59- break
40+ Ok ( receipt) => Ok ( receipt. into ( ) ) ,
41+ Err ( e ) => match provider . get_transaction_by_hash ( hash ) . await {
42+ Ok ( _ ) => match e {
43+ PendingTransactionError :: TxWatcher ( WatchTxError :: Timeout ) => {
44+ Err ( RetryError :: Continue ( eyre ! (
45+ "tx is still known to the node, waiting for receipt"
46+ ) ) )
47+ }
48+ _ => Err ( RetryError :: Retry ( e . into ( ) ) ) ,
49+ } ,
50+ Err ( _ ) => Ok ( TxStatus :: Dropped ) ,
51+ } ,
6052 }
61- }
62-
63- Ok ( TxStatus :: Dropped )
64- }
65- . await ;
53+ } )
54+ . await ;
6655
6756 ( hash, result)
6857}
0 commit comments