Skip to content

Commit c9dc3f1

Browse files
committed
Adds patch to make DispatchError compatible with old runtimes
1 parent c6a962f commit c9dc3f1

File tree

1 file changed

+85
-1
lines changed

1 file changed

+85
-1
lines changed

client/rpc/src/eth/execute.rs

Lines changed: 85 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,90 @@ use crate::{
4747
frontier_backend_client, internal_err,
4848
};
4949

50+
/// The types contained in this module are required for backwards compatility when decoding
51+
/// results produced by old versions of substrate.
52+
/// The changes contained in https://github.com/paritytech/substrate/pull/10776 changed the
53+
/// serde encoding for variant `DispatchError::Module`.
54+
mod old_types {
55+
use scale_codec::{Decode, Encode};
56+
57+
/// Description of what went wrong when trying to complete an operation on a token.
58+
#[derive(Eq, PartialEq, Clone, Copy, Encode, Decode, Debug)]
59+
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
60+
pub enum TokenError {
61+
/// Funds are unavailable.
62+
NoFunds,
63+
/// Account that must exist would die.
64+
WouldDie,
65+
/// Account cannot exist with the funds that would be given.
66+
BelowMinimum,
67+
/// Account cannot be created.
68+
CannotCreate,
69+
/// The asset in question is unknown.
70+
UnknownAsset,
71+
/// Funds exist but are frozen.
72+
Frozen,
73+
/// Operation is not supported by the asset.
74+
Unsupported,
75+
}
76+
77+
/// Arithmetic errors.
78+
#[derive(Eq, PartialEq, Clone, Copy, Encode, Decode, Debug)]
79+
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
80+
pub enum ArithmeticError {
81+
/// Underflow.
82+
Underflow,
83+
/// Overflow.
84+
Overflow,
85+
/// Division by zero.
86+
DivisionByZero,
87+
}
88+
89+
#[derive(PartialEq, Eq, Clone, Copy, Encode, Decode, Debug)]
90+
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
91+
pub enum DispatchErrorLegacy {
92+
/// Some error occurred.
93+
Other(
94+
#[codec(skip)]
95+
#[cfg_attr(feature = "std", serde(skip_deserializing))]
96+
&'static str,
97+
),
98+
/// Failed to lookup some data.
99+
CannotLookup,
100+
/// A bad origin.
101+
BadOrigin,
102+
/// A custom error in a module.
103+
Module {
104+
/// Module index, matching the metadata module index.
105+
index: u8,
106+
/// Module specific error value.
107+
error: u8,
108+
/// Optional error message.
109+
#[codec(skip)]
110+
#[cfg_attr(feature = "std", serde(skip_deserializing))]
111+
message: Option<&'static str>,
112+
},
113+
/// At least one consumer is remaining so the account cannot be destroyed.
114+
ConsumerRemaining,
115+
/// There are no providers so the account cannot be created.
116+
NoProviders,
117+
/// There are too many consumers so the account cannot be created.
118+
TooManyConsumers,
119+
/// An error to do with tokens.
120+
Token(TokenError),
121+
/// An arithmetic error.
122+
Arithmetic(ArithmeticError),
123+
}
124+
125+
/// Reason why a dispatch call failed.
126+
#[derive(PartialEq, Eq, Clone, Copy, Encode, Decode, Debug)]
127+
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
128+
pub enum DispatchError {
129+
V1(DispatchErrorLegacy),
130+
V2(sp_runtime::DispatchError),
131+
}
132+
}
133+
50134
/// Allow to adapt a request for `estimate_gas`.
51135
/// Can be used to estimate gas of some contracts using a different function
52136
/// in the case the normal gas estimation doesn't work.
@@ -254,7 +338,7 @@ where
254338
.call_api_at(params)
255339
.and_then(|r| {
256340
Result::map_err(
257-
<Result<ExecutionInfo::<Vec<u8>>, DispatchError> as Decode>::decode(&mut &r[..]),
341+
<Result<ExecutionInfo::<Vec<u8>>, old_types::DispatchError> as Decode>::decode(&mut &r[..]),
258342
|error| sp_api::ApiError::FailedToDecodeReturnValue {
259343
function: "EthereumRuntimeRPCApi_call",
260344
error,

0 commit comments

Comments
 (0)