1
1
use alloy:: primitives:: { Address , TxHash } ;
2
2
use alloy:: providers:: Provider ;
3
+ use engine_core:: error:: { AlloyRpcErrorToEngineError , EngineError } ;
3
4
use engine_core:: {
4
5
chain:: { Chain , ChainService , RpcCredentials } ,
5
6
execution_options:: WebhookOptions ,
@@ -62,13 +63,25 @@ pub struct Eip7702ConfirmationResult {
62
63
#[ serde( rename_all = "SCREAMING_SNAKE_CASE" , tag = "errorCode" ) ]
63
64
pub enum Eip7702ConfirmationError {
64
65
#[ error( "Chain service error for chainId {chain_id}: {message}" ) ]
66
+ #[ serde( rename_all = "camelCase" ) ]
65
67
ChainServiceError { chain_id : u64 , message : String } ,
66
68
67
69
#[ error( "Failed to get transaction hash from bundler: {message}" ) ]
68
70
TransactionHashError { message : String } ,
69
71
70
72
#[ error( "Failed to confirm transaction: {message}" ) ]
71
- ConfirmationError { message : String } ,
73
+ #[ serde( rename_all = "camelCase" ) ]
74
+ ConfirmationError {
75
+ message : String ,
76
+ inner_error : Option < EngineError > ,
77
+ } ,
78
+
79
+ #[ error( "Receipt not yet available for transaction: {message}" ) ]
80
+ #[ serde( rename_all = "camelCase" ) ]
81
+ ReceiptNotAvailable {
82
+ message : String ,
83
+ transaction_hash : TxHash ,
84
+ } ,
72
85
73
86
#[ error( "Transaction failed: {message}" ) ]
74
87
TransactionFailed { message : String } ,
@@ -169,26 +182,25 @@ where
169
182
. bundler_client ( )
170
183
. tw_get_transaction_hash ( & job_data. bundler_transaction_id )
171
184
. await
172
- . map_err ( |e| {
173
- // Check if it's a "not found" or "pending" error
174
- let error_msg = e. to_string ( ) ;
175
- if error_msg. contains ( "not found" ) || error_msg. contains ( "pending" ) {
176
- // Transaction not ready yet, nack and retry
177
- Eip7702ConfirmationError :: TransactionHashError {
178
- message : format ! ( "Transaction not ready: {}" , error_msg) ,
179
- }
180
- . nack ( Some ( Duration :: from_secs ( 5 ) ) , RequeuePosition :: Last )
181
- } else {
182
- Eip7702ConfirmationError :: TransactionHashError { message : error_msg } . fail ( )
183
- }
184
- } ) ?;
185
+ . map_err ( |e| Eip7702ConfirmationError :: TransactionHashError {
186
+ message : e. to_string ( ) ,
187
+ } )
188
+ . map_err_fail ( ) ?;
185
189
186
- let transaction_hash = transaction_hash_str. parse :: < TxHash > ( ) . map_err ( |e| {
187
- Eip7702ConfirmationError :: TransactionHashError {
188
- message : format ! ( "Invalid transaction hash format: {}" , e) ,
190
+ let transaction_hash = match transaction_hash_str {
191
+ Some ( hash) => hash. parse :: < TxHash > ( ) . map_err ( |e| {
192
+ Eip7702ConfirmationError :: TransactionHashError {
193
+ message : format ! ( "Invalid transaction hash format: {}" , e) ,
194
+ }
195
+ . fail ( )
196
+ } ) ?,
197
+ None => {
198
+ return Err ( Eip7702ConfirmationError :: TransactionHashError {
199
+ message : "Transaction not found" . to_string ( ) ,
200
+ } )
201
+ . map_err_nack ( Some ( Duration :: from_secs ( 2 ) ) , RequeuePosition :: Last ) ;
189
202
}
190
- . fail ( )
191
- } ) ?;
203
+ } ;
192
204
193
205
tracing:: debug!(
194
206
transaction_hash = ?transaction_hash,
@@ -205,18 +217,20 @@ where
205
217
// If transaction not found, nack and retry
206
218
Eip7702ConfirmationError :: ConfirmationError {
207
219
message : format ! ( "Failed to get transaction receipt: {}" , e) ,
220
+ inner_error : Some ( e. to_engine_error ( & chain) ) ,
208
221
}
209
- . nack ( Some ( Duration :: from_secs ( 10 ) ) , RequeuePosition :: Last )
222
+ . nack ( Some ( Duration :: from_secs ( 5 ) ) , RequeuePosition :: Last )
210
223
} ) ?;
211
224
212
225
let receipt = match receipt {
213
226
Some ( receipt) => receipt,
214
227
None => {
215
228
// Transaction not mined yet, nack and retry
216
- return Err ( Eip7702ConfirmationError :: ConfirmationError {
229
+ return Err ( Eip7702ConfirmationError :: ReceiptNotAvailable {
217
230
message : "Transaction not mined yet" . to_string ( ) ,
231
+ transaction_hash,
218
232
} )
219
- . map_err_nack ( Some ( Duration :: from_secs ( 10 ) ) , RequeuePosition :: Last ) ;
233
+ . map_err_nack ( Some ( Duration :: from_secs ( 2 ) ) , RequeuePosition :: Last ) ;
220
234
}
221
235
} ;
222
236
0 commit comments