11use std:: fmt;
22
3- use ethers:: types:: { Address , SignatureError } ;
3+ use ethers:: types:: { Address , Bytes , SignatureError } ;
44use tokio_tungstenite:: tungstenite;
55
6+ pub enum TransactionSendError {
7+ NoProofSubmitters ,
8+ NoFeePerProof ,
9+ InsufficientFeeForAggregator ,
10+ SubmissionInsufficientBalance ,
11+ BatchAlreadySubmitted ,
12+ InsufficientFunds ,
13+ OnlyBatcherAllowed ,
14+ Generic ( String ) ,
15+ }
16+
17+ impl From < Bytes > for TransactionSendError {
18+ fn from ( e : Bytes ) -> Self {
19+ let byte_string = e. to_string ( ) ;
20+ let str_code = if byte_string. len ( ) >= 10 {
21+ & byte_string[ ..10 ] // Extract the error code only
22+ } else {
23+ "" // Not gonna match
24+ } ;
25+ match str_code {
26+ "0xc43ac290" => TransactionSendError :: NoProofSubmitters , // can't happen, don't flush
27+ "0xa3a8658a" => TransactionSendError :: NoFeePerProof , // can't happen, don't flush
28+ "0x7899ec71" => TransactionSendError :: InsufficientFeeForAggregator , // shouldn't happen, don't flush
29+ // returning the proofs and retrying later may help
30+ "0x4f779ceb" => TransactionSendError :: SubmissionInsufficientBalance , // shouldn't happen,
31+ // flush can help if something went wrong
32+ "0x3102f10c" => TransactionSendError :: BatchAlreadySubmitted , // can happen, don't flush
33+ "0x5c54305e" => TransactionSendError :: InsufficientFunds , // shouldn't happen, don't flush
34+ "0x152bc288" => TransactionSendError :: OnlyBatcherAllowed , // won't happen, don't flush
35+ _ => {
36+ TransactionSendError :: Generic ( format ! ( "Unknown bytestring error: {}" , byte_string) )
37+ }
38+ }
39+ }
40+ }
41+
642pub enum BatcherError {
743 TcpListenerError ( String ) ,
844 ConnectionError ( tungstenite:: Error ) ,
@@ -12,7 +48,7 @@ pub enum BatcherError {
1248 BatchUploadError ( String ) ,
1349 TaskCreationError ( String ) ,
1450 ReceiptNotFoundError ,
15- TransactionSendError ( String ) ,
51+ TransactionSendError ( TransactionSendError ) ,
1652 MaxRetriesReachedError ,
1753 SerializationError ( String ) ,
1854 GasPriceError ,
@@ -101,3 +137,34 @@ impl fmt::Debug for BatcherError {
101137 }
102138 }
103139}
140+
141+ impl fmt:: Display for TransactionSendError {
142+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
143+ match self {
144+ TransactionSendError :: NoProofSubmitters => {
145+ write ! ( f, "No proof submitter error" )
146+ }
147+ TransactionSendError :: NoFeePerProof => {
148+ write ! ( f, "No fee per proof" )
149+ }
150+ TransactionSendError :: InsufficientFeeForAggregator => {
151+ write ! ( f, "Insufficient fee for aggregator" )
152+ }
153+ TransactionSendError :: SubmissionInsufficientBalance => {
154+ write ! ( f, "Submission insufficient balance" )
155+ }
156+ TransactionSendError :: BatchAlreadySubmitted => {
157+ write ! ( f, "Batch already submitted" )
158+ }
159+ TransactionSendError :: InsufficientFunds => {
160+ write ! ( f, "Insufficient funds" )
161+ }
162+ TransactionSendError :: OnlyBatcherAllowed => {
163+ write ! ( f, "Only batcher allowed" )
164+ }
165+ TransactionSendError :: Generic ( e) => {
166+ write ! ( f, "Generic error: {}" , e)
167+ }
168+ }
169+ }
170+ }
0 commit comments