Skip to content

Commit aec5b8f

Browse files
committed
remove serde and rename OldDispatchError
1 parent 2ef9a24 commit aec5b8f

File tree

1 file changed

+15
-25
lines changed

1 file changed

+15
-25
lines changed

client/rpc/src/eth/execute.rs

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub const JSON_RPC_ERROR_DEFAULT: i32 = -32000;
5353
/// The types contained in this module are required for backwards compatility when decoding
5454
/// results produced by old versions of substrate.
5555
/// 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`.
5757
mod old_types {
5858
use scale_codec::{Decode, Encode};
5959

@@ -90,11 +90,7 @@ mod old_types {
9090
#[derive(PartialEq, Eq, Clone, Copy, Encode, Decode, Debug)]
9191
pub enum DispatchErrorV1 {
9292
/// 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),
9894
/// Failed to lookup some data.
9995
CannotLookup,
10096
/// A bad origin.
@@ -107,7 +103,6 @@ mod old_types {
107103
error: u8,
108104
/// Optional error message.
109105
#[codec(skip)]
110-
#[cfg_attr(feature = "std", serde(skip_deserializing))]
111106
message: Option<&'static str>,
112107
},
113108
/// At least one consumer is remaining so the account cannot be destroyed.
@@ -123,11 +118,7 @@ mod old_types {
123118
#[derive(PartialEq, Eq, Clone, Copy, Encode, Decode, Debug)]
124119
pub enum DispatchErrorV2 {
125120
/// 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),
131122
/// Failed to lookup some data.
132123
CannotLookup,
133124
/// A bad origin.
@@ -140,7 +131,6 @@ mod old_types {
140131
error: u8,
141132
/// Optional error message.
142133
#[codec(skip)]
143-
#[cfg_attr(feature = "std", serde(skip_deserializing))]
144134
message: Option<&'static str>,
145135
},
146136
/// At least one consumer is remaining so the account cannot be destroyed.
@@ -157,22 +147,22 @@ mod old_types {
157147

158148
/// Reason why a dispatch call failed.
159149
#[derive(PartialEq, Eq, Clone, Copy, Debug)]
160-
pub enum DispatchError {
150+
pub enum OldDispatchError {
161151
V1(DispatchErrorV1),
162152
V2(DispatchErrorV2),
163153
}
164154

165-
impl Decode for DispatchError {
155+
impl Decode for OldDispatchError {
166156
fn decode<I: scale_codec::Input>(input: &mut I) -> Result<Self, scale_codec::Error> {
167157
let remaining = input.remaining_len()?;
168158
let mut v = vec![0u8; remaining.unwrap_or(0)];
169159
let _ = input.read(&mut v);
170160

171161
if let Ok(r) = DispatchErrorV1::decode(&mut v.as_slice()) {
172-
return Ok(DispatchError::V1(r));
162+
return Ok(OldDispatchError::V1(r));
173163
}
174164

175-
Ok(DispatchError::V2(DispatchErrorV2::decode(
165+
Ok(OldDispatchError::V2(DispatchErrorV2::decode(
176166
&mut v.as_slice(),
177167
)?))
178168
}
@@ -392,7 +382,7 @@ where
392382
.call_api_at(params)
393383
.and_then(|r| {
394384
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[..]),
396386
|error| sp_api::ApiError::FailedToDecodeReturnValue {
397387
function: "EthereumRuntimeRPCApi_call",
398388
error,
@@ -1190,28 +1180,28 @@ fn fee_details(
11901180

11911181
#[cfg(test)]
11921182
mod tests {
1193-
use super::old_types;
1183+
use super::old_types::*;
11941184
use scale_codec::{Decode, Encode};
11951185

11961186
#[test]
11971187
fn test_dispatch_error() {
1198-
let v1 = old_types::DispatchErrorV1::Module {
1188+
let v1 = DispatchErrorV1::Module {
11991189
index: 1,
12001190
error: 1,
12011191
message: None,
12021192
};
1203-
let v2 = old_types::DispatchErrorV2::TooManyConsumers;
1193+
let v2 = DispatchErrorV2::TooManyConsumers;
12041194

12051195
let encoded_v1 = v1.encode();
12061196
let encoded_v2 = v2.encode();
12071197

12081198
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))
12111201
);
12121202
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))
12151205
);
12161206
}
12171207
}

0 commit comments

Comments
 (0)