@@ -53,7 +53,7 @@ pub const JSON_RPC_ERROR_DEFAULT: i32 = -32000;
53
53
/// The types contained in this module are required for backwards compatility when decoding
54
54
/// results produced by old versions of substrate.
55
55
/// The changes contained in https://github.com/paritytech/substrate/pull/10776 changed the
56
- /// serde encoding for variant `DispatchError::Module`.
56
+ /// scale encoding for variant `DispatchError::Module`.
57
57
mod old_types {
58
58
use scale_codec:: { Decode , Encode } ;
59
59
@@ -90,11 +90,7 @@ mod old_types {
90
90
#[ derive( PartialEq , Eq , Clone , Copy , Encode , Decode , Debug ) ]
91
91
pub enum DispatchErrorV1 {
92
92
/// Some error occurred.
93
- Other (
94
- #[ codec( skip) ]
95
- #[ cfg_attr( feature = "std" , serde( skip_deserializing) ) ]
96
- & ' static str ,
97
- ) ,
93
+ Other ( #[ codec( skip) ] & ' static str ) ,
98
94
/// Failed to lookup some data.
99
95
CannotLookup ,
100
96
/// A bad origin.
@@ -107,7 +103,6 @@ mod old_types {
107
103
error : u8 ,
108
104
/// Optional error message.
109
105
#[ codec( skip) ]
110
- #[ cfg_attr( feature = "std" , serde( skip_deserializing) ) ]
111
106
message : Option < & ' static str > ,
112
107
} ,
113
108
/// At least one consumer is remaining so the account cannot be destroyed.
@@ -123,11 +118,7 @@ mod old_types {
123
118
#[ derive( PartialEq , Eq , Clone , Copy , Encode , Decode , Debug ) ]
124
119
pub enum DispatchErrorV2 {
125
120
/// Some error occurred.
126
- Other (
127
- #[ codec( skip) ]
128
- #[ cfg_attr( feature = "std" , serde( skip_deserializing) ) ]
129
- & ' static str ,
130
- ) ,
121
+ Other ( #[ codec( skip) ] & ' static str ) ,
131
122
/// Failed to lookup some data.
132
123
CannotLookup ,
133
124
/// A bad origin.
@@ -140,7 +131,6 @@ mod old_types {
140
131
error : u8 ,
141
132
/// Optional error message.
142
133
#[ codec( skip) ]
143
- #[ cfg_attr( feature = "std" , serde( skip_deserializing) ) ]
144
134
message : Option < & ' static str > ,
145
135
} ,
146
136
/// At least one consumer is remaining so the account cannot be destroyed.
@@ -157,22 +147,22 @@ mod old_types {
157
147
158
148
/// Reason why a dispatch call failed.
159
149
#[ derive( PartialEq , Eq , Clone , Copy , Debug ) ]
160
- pub enum DispatchError {
150
+ pub enum OldDispatchError {
161
151
V1 ( DispatchErrorV1 ) ,
162
152
V2 ( DispatchErrorV2 ) ,
163
153
}
164
154
165
- impl Decode for DispatchError {
155
+ impl Decode for OldDispatchError {
166
156
fn decode < I : scale_codec:: Input > ( input : & mut I ) -> Result < Self , scale_codec:: Error > {
167
157
let remaining = input. remaining_len ( ) ?;
168
158
let mut v = vec ! [ 0u8 ; remaining. unwrap_or( 0 ) ] ;
169
159
let _ = input. read ( & mut v) ;
170
160
171
161
if let Ok ( r) = DispatchErrorV1 :: decode ( & mut v. as_slice ( ) ) {
172
- return Ok ( DispatchError :: V1 ( r) ) ;
162
+ return Ok ( OldDispatchError :: V1 ( r) ) ;
173
163
}
174
164
175
- Ok ( DispatchError :: V2 ( DispatchErrorV2 :: decode (
165
+ Ok ( OldDispatchError :: V2 ( DispatchErrorV2 :: decode (
176
166
& mut v. as_slice ( ) ,
177
167
) ?) )
178
168
}
@@ -392,7 +382,7 @@ where
392
382
. call_api_at ( params)
393
383
. and_then ( |r| {
394
384
Result :: map_err (
395
- <Result < ExecutionInfo :: < Vec < u8 > > , old_types:: DispatchError > as Decode >:: decode ( & mut & r[ ..] ) ,
385
+ <Result < ExecutionInfo :: < Vec < u8 > > , old_types:: OldDispatchError > as Decode >:: decode ( & mut & r[ ..] ) ,
396
386
|error| sp_api:: ApiError :: FailedToDecodeReturnValue {
397
387
function : "EthereumRuntimeRPCApi_call" ,
398
388
error,
@@ -1190,28 +1180,28 @@ fn fee_details(
1190
1180
1191
1181
#[ cfg( test) ]
1192
1182
mod tests {
1193
- use super :: old_types;
1183
+ use super :: old_types:: * ;
1194
1184
use scale_codec:: { Decode , Encode } ;
1195
1185
1196
1186
#[ test]
1197
1187
fn test_dispatch_error ( ) {
1198
- let v1 = old_types :: DispatchErrorV1 :: Module {
1188
+ let v1 = DispatchErrorV1 :: Module {
1199
1189
index : 1 ,
1200
1190
error : 1 ,
1201
1191
message : None ,
1202
1192
} ;
1203
- let v2 = old_types :: DispatchErrorV2 :: TooManyConsumers ;
1193
+ let v2 = DispatchErrorV2 :: TooManyConsumers ;
1204
1194
1205
1195
let encoded_v1 = v1. encode ( ) ;
1206
1196
let encoded_v2 = v2. encode ( ) ;
1207
1197
1208
1198
assert_eq ! (
1209
- old_types :: DispatchError :: decode( & mut encoded_v1. as_slice( ) ) ,
1210
- Ok ( old_types :: DispatchError :: V1 ( v1) )
1199
+ OldDispatchError :: decode( & mut encoded_v1. as_slice( ) ) ,
1200
+ Ok ( OldDispatchError :: V1 ( v1) )
1211
1201
) ;
1212
1202
assert_eq ! (
1213
- old_types :: DispatchError :: decode( & mut encoded_v2. as_slice( ) ) ,
1214
- Ok ( old_types :: DispatchError :: V2 ( v2) )
1203
+ OldDispatchError :: decode( & mut encoded_v2. as_slice( ) ) ,
1204
+ Ok ( OldDispatchError :: V2 ( v2) )
1215
1205
) ;
1216
1206
}
1217
1207
}
0 commit comments