@@ -21,7 +21,7 @@ use foundry_common::{estimate_eip1559_fees, try_get_http_provider, RetryProvider
21
21
use foundry_config:: Chain ;
22
22
use futures:: StreamExt ;
23
23
use indicatif:: { ProgressBar , ProgressStyle } ;
24
- use std:: { cmp:: min, fmt , ops:: Mul , sync:: Arc } ;
24
+ use std:: { cmp:: min, ops:: Mul , sync:: Arc } ;
25
25
26
26
impl ScriptArgs {
27
27
/// Sends the transactions which haven't been broadcasted yet.
@@ -196,20 +196,18 @@ impl ScriptArgs {
196
196
signer : & WalletType ,
197
197
sequential_broadcast : bool ,
198
198
fork_url : & str ,
199
- ) -> Result < TxHash , BroadcastError > {
199
+ ) -> eyre :: Result < TxHash > {
200
200
let from = tx. from ( ) . expect ( "no sender" ) ;
201
201
202
202
if sequential_broadcast {
203
- let nonce = foundry_utils:: next_nonce ( * from, fork_url, None ) . await . map_err ( |_| {
204
- BroadcastError :: Simple ( "Not able to query the EOA nonce." . to_string ( ) )
205
- } ) ?;
203
+ let nonce = foundry_utils:: next_nonce ( * from, fork_url, None )
204
+ . await
205
+ . map_err ( |_| eyre :: eyre! ( "Not able to query the EOA nonce." ) ) ?;
206
206
207
207
let tx_nonce = tx. nonce ( ) . expect ( "no nonce" ) ;
208
208
209
209
if nonce != * tx_nonce {
210
- return Err ( BroadcastError :: Simple (
211
- "EOA nonce changed unexpectedly while sending transactions." . to_string ( ) ,
212
- ) )
210
+ eyre:: bail!( "EOA nonce changed unexpectedly while sending transactions." )
213
211
}
214
212
}
215
213
@@ -349,14 +347,14 @@ impl ScriptArgs {
349
347
}
350
348
/// Uses the signer to submit a transaction to the network. If it fails, it tries to retrieve
351
349
/// the transaction hash that can be used on a later run with `--resume`.
352
- async fn broadcast < T , U > (
350
+ async fn broadcast < T , S > (
353
351
& self ,
354
- signer : & SignerMiddleware < T , U > ,
352
+ signer : & SignerMiddleware < T , S > ,
355
353
mut legacy_or_1559 : TypedTransaction ,
356
- ) -> Result < TxHash , BroadcastError >
354
+ ) -> eyre :: Result < TxHash >
357
355
where
358
- T : Middleware ,
359
- U : Signer ,
356
+ T : Middleware + ' static ,
357
+ S : Signer + ' static ,
360
358
{
361
359
tracing:: debug!( "sending transaction: {:?}" , legacy_or_1559) ;
362
360
@@ -377,14 +375,11 @@ impl ScriptArgs {
377
375
* legacy_or_1559. from ( ) . expect ( "Tx should have a `from`." ) ,
378
376
)
379
377
. await
380
- . map_err ( |err| BroadcastError :: Simple ( err . to_string ( ) ) ) ?;
378
+ . wrap_err_with ( || "Failed to sign transaction" ) ?;
381
379
382
380
// Submit the raw transaction
383
- let pending = signer
384
- . provider ( )
385
- . send_raw_transaction ( legacy_or_1559. rlp_signed ( & signature) )
386
- . await
387
- . map_err ( |err| BroadcastError :: Simple ( err. to_string ( ) ) ) ?;
381
+ let pending =
382
+ signer. provider ( ) . send_raw_transaction ( legacy_or_1559. rlp_signed ( & signature) ) . await ?;
388
383
389
384
Ok ( pending. tx_hash ( ) )
390
385
}
@@ -393,36 +388,18 @@ impl ScriptArgs {
393
388
& self ,
394
389
tx : & mut TypedTransaction ,
395
390
provider : & Provider < T > ,
396
- ) -> Result < ( ) , BroadcastError >
391
+ ) -> eyre :: Result < ( ) >
397
392
where
398
393
T : JsonRpcClient ,
399
394
{
400
395
tx. set_gas (
401
396
provider
402
397
. estimate_gas ( tx, None )
403
398
. await
404
- . wrap_err_with ( || format ! ( "Failed to estimate gas for tx: {}" , tx. sighash( ) ) )
405
- . map_err ( |err| BroadcastError :: Simple ( err. to_string ( ) ) ) ? *
399
+ . wrap_err_with ( || format ! ( "Failed to estimate gas for tx: {:?}" , tx. sighash( ) ) ) ? *
406
400
self . gas_estimate_multiplier /
407
401
100 ,
408
402
) ;
409
403
Ok ( ( ) )
410
404
}
411
405
}
412
-
413
- #[ derive( thiserror:: Error , Debug , Clone ) ]
414
- pub enum BroadcastError {
415
- Simple ( String ) ,
416
- ErrorWithTxHash ( String , TxHash ) ,
417
- }
418
-
419
- impl fmt:: Display for BroadcastError {
420
- fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
421
- match self {
422
- BroadcastError :: Simple ( err) => write ! ( f, "{err}" ) ,
423
- BroadcastError :: ErrorWithTxHash ( err, tx_hash) => {
424
- write ! ( f, "\n Failed to wait for transaction {tx_hash:?}:\n {err}" )
425
- }
426
- }
427
- }
428
- }
0 commit comments