@@ -50,6 +50,93 @@ use crate::{
50
50
/// Default JSONRPC error code return by geth
51
51
pub const JSON_RPC_ERROR_DEFAULT : i32 = -32000 ;
52
52
53
+ /// The types contained in this module are required for backwards compatility when decoding
54
+ /// results produced by old versions of substrate.
55
+ /// The changes contained in https://github.com/paritytech/substrate/pull/10776 changed the
56
+ /// serde encoding for variant `DispatchError::Module`.
57
+ mod old_types {
58
+ use scale_codec:: { Decode , Encode } ;
59
+ #[ cfg( feature = "std" ) ]
60
+ pub use serde:: { de:: DeserializeOwned , Deserialize , Serialize } ;
61
+
62
+ /// Description of what went wrong when trying to complete an operation on a token.
63
+ #[ derive( Eq , PartialEq , Clone , Copy , Encode , Decode , Debug ) ]
64
+ #[ cfg_attr( feature = "std" , derive( Serialize , Deserialize ) ) ]
65
+ pub enum TokenError {
66
+ /// Funds are unavailable.
67
+ NoFunds ,
68
+ /// Account that must exist would die.
69
+ WouldDie ,
70
+ /// Account cannot exist with the funds that would be given.
71
+ BelowMinimum ,
72
+ /// Account cannot be created.
73
+ CannotCreate ,
74
+ /// The asset in question is unknown.
75
+ UnknownAsset ,
76
+ /// Funds exist but are frozen.
77
+ Frozen ,
78
+ /// Operation is not supported by the asset.
79
+ Unsupported ,
80
+ }
81
+
82
+ /// Arithmetic errors.
83
+ #[ derive( Eq , PartialEq , Clone , Copy , Encode , Decode , Debug ) ]
84
+ #[ cfg_attr( feature = "std" , derive( Serialize , Deserialize ) ) ]
85
+ pub enum ArithmeticError {
86
+ /// Underflow.
87
+ Underflow ,
88
+ /// Overflow.
89
+ Overflow ,
90
+ /// Division by zero.
91
+ DivisionByZero ,
92
+ }
93
+
94
+ #[ derive( PartialEq , Eq , Clone , Copy , Encode , Decode , Debug ) ]
95
+ #[ cfg_attr( feature = "std" , derive( Serialize , Deserialize ) ) ]
96
+ #[ cfg_attr( feature = "std" , serde( untagged) ) ]
97
+ pub enum DispatchErrorLegacy {
98
+ /// Some error occurred.
99
+ Other (
100
+ #[ codec( skip) ]
101
+ #[ cfg_attr( feature = "std" , serde( skip_deserializing) ) ]
102
+ & ' static str ,
103
+ ) ,
104
+ /// Failed to lookup some data.
105
+ CannotLookup ,
106
+ /// A bad origin.
107
+ BadOrigin ,
108
+ /// A custom error in a module.
109
+ Module {
110
+ /// Module index, matching the metadata module index.
111
+ index : u8 ,
112
+ /// Module specific error value.
113
+ error : u8 ,
114
+ /// Optional error message.
115
+ #[ codec( skip) ]
116
+ #[ cfg_attr( feature = "std" , serde( skip_deserializing) ) ]
117
+ message : Option < & ' static str > ,
118
+ } ,
119
+ /// At least one consumer is remaining so the account cannot be destroyed.
120
+ ConsumerRemaining ,
121
+ /// There are no providers so the account cannot be created.
122
+ NoProviders ,
123
+ /// There are too many consumers so the account cannot be created.
124
+ TooManyConsumers ,
125
+ /// An error to do with tokens.
126
+ Token ( TokenError ) ,
127
+ /// An arithmetic error.
128
+ Arithmetic ( ArithmeticError ) ,
129
+ }
130
+
131
+ /// Reason why a dispatch call failed.
132
+ #[ derive( PartialEq , Eq , Clone , Copy , Encode , Decode , Debug ) ]
133
+ #[ cfg_attr( feature = "std" , derive( Serialize , Deserialize ) ) ]
134
+ pub enum DispatchError {
135
+ V1 ( DispatchErrorLegacy ) ,
136
+ V2 ( sp_runtime:: DispatchError ) ,
137
+ }
138
+ }
139
+
53
140
/// Allow to adapt a request for `estimate_gas`.
54
141
/// Can be used to estimate gas of some contracts using a different function
55
142
/// in the case the normal gas estimation doesn't work.
@@ -104,7 +191,11 @@ where
104
191
(
105
192
details. gas_price ,
106
193
// Old runtimes require max_fee_per_gas to be None for non transactional calls.
107
- if details. max_fee_per_gas == Some ( U256 :: zero ( ) ) { None } else { details. max_fee_per_gas } ,
194
+ if details. max_fee_per_gas == Some ( U256 :: zero ( ) ) {
195
+ None
196
+ } else {
197
+ details. max_fee_per_gas
198
+ } ,
108
199
details. max_priority_fee_per_gas ,
109
200
)
110
201
} ;
@@ -259,7 +350,7 @@ where
259
350
. call_api_at ( params)
260
351
. and_then ( |r| {
261
352
Result :: map_err (
262
- <Result < ExecutionInfo :: < Vec < u8 > > , DispatchError > as Decode >:: decode ( & mut & r[ ..] ) ,
353
+ <Result < ExecutionInfo :: < Vec < u8 > > , old_types :: DispatchError > as Decode >:: decode ( & mut & r[ ..] ) ,
263
354
|error| sp_api:: ApiError :: FailedToDecodeReturnValue {
264
355
function : "EthereumRuntimeRPCApi_call" ,
265
356
error,
0 commit comments