@@ -16,73 +16,120 @@ use katana_rpc_types::transaction::{
16
16
DeclareTxResult , DeployAccountTxResult , InvokeTxResult , Tx ,
17
17
} ;
18
18
use katana_rpc_types:: { ContractClass , FeeEstimate , FeltAsHex , FunctionCall } ;
19
- use starknet:: core:: types:: TransactionStatus ;
19
+ use starknet:: core:: types:: { ContractErrorData , TransactionStatus } ;
20
20
21
- #[ derive( thiserror:: Error , Clone , Copy , Debug ) ]
21
+ #[ derive( thiserror:: Error , Clone , Debug ) ]
22
+ #[ repr( i32 ) ]
22
23
pub enum StarknetApiError {
23
24
#[ error( "Failed to write transaction" ) ]
24
- FailedToReceiveTxn = 1 ,
25
+ FailedToReceiveTxn ,
25
26
#[ error( "Contract not found" ) ]
26
- ContractNotFound = 20 ,
27
+ ContractNotFound ,
27
28
#[ error( "Invalid message selector" ) ]
28
- InvalidMessageSelector = 21 ,
29
+ InvalidMessageSelector ,
29
30
#[ error( "Invalid call data" ) ]
30
- InvalidCallData = 22 ,
31
+ InvalidCallData ,
31
32
#[ error( "Block not found" ) ]
32
- BlockNotFound = 24 ,
33
+ BlockNotFound ,
33
34
#[ error( "Transaction hash not found" ) ]
34
- TxnHashNotFound = 29 ,
35
+ TxnHashNotFound ,
35
36
#[ error( "Invalid transaction index in a block" ) ]
36
- InvalidTxnIndex = 27 ,
37
+ InvalidTxnIndex ,
37
38
#[ error( "Class hash not found" ) ]
38
- ClassHashNotFound = 28 ,
39
+ ClassHashNotFound ,
39
40
#[ error( "Requested page size is too big" ) ]
40
- PageSizeTooBig = 31 ,
41
+ PageSizeTooBig ,
41
42
#[ error( "There are no blocks" ) ]
42
- NoBlocks = 32 ,
43
+ NoBlocks ,
43
44
#[ error( "The supplied continuation token is invalid or unknown" ) ]
44
- InvalidContinuationToken = 33 ,
45
+ InvalidContinuationToken ,
45
46
#[ error( "Contract error" ) ]
46
- ContractError = 40 ,
47
+ ContractError { revert_error : String } ,
47
48
#[ error( "Invalid contract class" ) ]
48
- InvalidContractClass = 50 ,
49
+ InvalidContractClass ,
49
50
#[ error( "Class already declared" ) ]
50
- ClassAlreadyDeclared = 51 ,
51
+ ClassAlreadyDeclared ,
51
52
#[ error( "Invalid transaction nonce" ) ]
52
- InvalidTransactionNonce = 52 ,
53
+ InvalidTransactionNonce ,
53
54
#[ error( "Max fee is smaller than the minimal transaction cost (validation plus fee transfer)" ) ]
54
- InsufficientMaxFee = 53 ,
55
+ InsufficientMaxFee ,
55
56
#[ error( "Account balance is smaller than the transaction's max_fee" ) ]
56
- InsufficientAccountBalance = 54 ,
57
+ InsufficientAccountBalance ,
57
58
#[ error( "Account validation failed" ) ]
58
- ValidationFailure = 55 ,
59
+ ValidationFailure ,
59
60
#[ error( "Compilation failed" ) ]
60
- CompilationFailed = 56 ,
61
+ CompilationFailed ,
61
62
#[ error( "Contract class size is too large" ) ]
62
- ContractClassSizeIsTooLarge = 57 ,
63
+ ContractClassSizeIsTooLarge ,
63
64
#[ error( "Sender address in not an account contract" ) ]
64
- NonAccount = 58 ,
65
+ NonAccount ,
65
66
#[ error( "A transaction with the same hash already exists in the mempool" ) ]
66
- DuplicateTransaction = 59 ,
67
+ DuplicateTransaction ,
67
68
#[ error( "The compiled class hash did not match the one supplied in the transaction" ) ]
68
- CompiledClassHashMismatch = 60 ,
69
+ CompiledClassHashMismatch ,
69
70
#[ error( "The transaction version is not supported" ) ]
70
- UnsupportedTransactionVersion = 61 ,
71
+ UnsupportedTransactionVersion ,
71
72
#[ error( "The contract class version is not supported" ) ]
72
- UnsupportedContractClassVersion = 62 ,
73
+ UnsupportedContractClassVersion ,
73
74
#[ error( "An unexpected error occured" ) ]
74
- UnexpectedError = 63 ,
75
+ UnexpectedError ,
75
76
#[ error( "Too many storage keys requested" ) ]
76
- ProofLimitExceeded = 10000 ,
77
+ ProofLimitExceeded ,
77
78
#[ error( "Too many keys provided in a filter" ) ]
78
- TooManyKeysInFilter = 34 ,
79
+ TooManyKeysInFilter ,
79
80
#[ error( "Failed to fetch pending transactions" ) ]
80
- FailedToFetchPendingTransactions = 38 ,
81
+ FailedToFetchPendingTransactions ,
82
+ }
83
+
84
+ impl StarknetApiError {
85
+ fn code ( & self ) -> i32 {
86
+ match self {
87
+ StarknetApiError :: FailedToReceiveTxn => 1 ,
88
+ StarknetApiError :: ContractNotFound => 20 ,
89
+ StarknetApiError :: InvalidMessageSelector => 21 ,
90
+ StarknetApiError :: InvalidCallData => 22 ,
91
+ StarknetApiError :: BlockNotFound => 24 ,
92
+ StarknetApiError :: InvalidTxnIndex => 27 ,
93
+ StarknetApiError :: ClassHashNotFound => 28 ,
94
+ StarknetApiError :: TxnHashNotFound => 29 ,
95
+ StarknetApiError :: PageSizeTooBig => 31 ,
96
+ StarknetApiError :: NoBlocks => 32 ,
97
+ StarknetApiError :: InvalidContinuationToken => 33 ,
98
+ StarknetApiError :: TooManyKeysInFilter => 34 ,
99
+ StarknetApiError :: FailedToFetchPendingTransactions => 38 ,
100
+ StarknetApiError :: ContractError { .. } => 40 ,
101
+ StarknetApiError :: InvalidContractClass => 50 ,
102
+ StarknetApiError :: ClassAlreadyDeclared => 51 ,
103
+ StarknetApiError :: InvalidTransactionNonce => 52 ,
104
+ StarknetApiError :: InsufficientMaxFee => 53 ,
105
+ StarknetApiError :: InsufficientAccountBalance => 54 ,
106
+ StarknetApiError :: ValidationFailure => 55 ,
107
+ StarknetApiError :: CompilationFailed => 56 ,
108
+ StarknetApiError :: ContractClassSizeIsTooLarge => 57 ,
109
+ StarknetApiError :: NonAccount => 58 ,
110
+ StarknetApiError :: DuplicateTransaction => 59 ,
111
+ StarknetApiError :: CompiledClassHashMismatch => 60 ,
112
+ StarknetApiError :: UnsupportedTransactionVersion => 61 ,
113
+ StarknetApiError :: UnsupportedContractClassVersion => 62 ,
114
+ StarknetApiError :: UnexpectedError => 63 ,
115
+ StarknetApiError :: ProofLimitExceeded => 10000 ,
116
+ }
117
+ }
81
118
}
82
119
83
120
impl From < StarknetApiError > for Error {
84
121
fn from ( err : StarknetApiError ) -> Self {
85
- Error :: Call ( CallError :: Custom ( ErrorObject :: owned ( err as i32 , err. to_string ( ) , None :: < ( ) > ) ) )
122
+ let code = err. code ( ) ;
123
+ let message = err. to_string ( ) ;
124
+
125
+ let data = match err {
126
+ StarknetApiError :: ContractError { revert_error } => {
127
+ Some ( ContractErrorData { revert_error } )
128
+ }
129
+ _ => None ,
130
+ } ;
131
+
132
+ Error :: Call ( CallError :: Custom ( ErrorObject :: owned ( code, message, data) ) )
86
133
}
87
134
}
88
135
0 commit comments