sp_runtime/legacy/
byte_sized_error.rs1use crate::{ArithmeticError, TokenError};
21use codec::{Decode, Encode};
22use scale_info::TypeInfo;
23#[cfg(feature = "serde")]
24use serde::{Deserialize, Serialize};
25
26#[derive(Eq, Clone, Copy, Encode, Decode, Debug, TypeInfo)]
28#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
29pub struct ModuleError {
30 pub index: u8,
32 pub error: u8,
34 #[codec(skip)]
36 #[cfg_attr(feature = "serde", serde(skip_deserializing))]
37 pub message: Option<&'static str>,
38}
39
40impl PartialEq for ModuleError {
41 fn eq(&self, other: &Self) -> bool {
42 (self.index == other.index) && (self.error == other.error)
43 }
44}
45
46#[derive(Eq, Clone, Copy, Encode, Decode, Debug, TypeInfo, PartialEq)]
48#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
49pub enum DispatchError {
50 Other(
52 #[codec(skip)]
53 #[cfg_attr(feature = "serde", serde(skip_deserializing))]
54 &'static str,
55 ),
56 CannotLookup,
58 BadOrigin,
60 Module(ModuleError),
62 ConsumerRemaining,
64 NoProviders,
66 TooManyConsumers,
68 Token(TokenError),
70 Arithmetic(ArithmeticError),
72}
73
74pub type DispatchOutcome = Result<(), DispatchError>;
76
77pub type ApplyExtrinsicResult =
79 Result<DispatchOutcome, crate::transaction_validity::TransactionValidityError>;
80
81pub fn convert_to_latest(old: ApplyExtrinsicResult) -> crate::ApplyExtrinsicResult {
83 old.map(|outcome| {
84 outcome.map_err(|e| match e {
85 DispatchError::Other(s) => crate::DispatchError::Other(s),
86 DispatchError::CannotLookup => crate::DispatchError::CannotLookup,
87 DispatchError::BadOrigin => crate::DispatchError::BadOrigin,
88 DispatchError::Module(err) => crate::DispatchError::Module(crate::ModuleError {
89 index: err.index,
90 error: [err.error, 0, 0, 0],
91 message: err.message,
92 }),
93 DispatchError::ConsumerRemaining => crate::DispatchError::ConsumerRemaining,
94 DispatchError::NoProviders => crate::DispatchError::NoProviders,
95 DispatchError::TooManyConsumers => crate::DispatchError::TooManyConsumers,
96 DispatchError::Token(err) => crate::DispatchError::Token(err),
97 DispatchError::Arithmetic(err) => crate::DispatchError::Arithmetic(err),
98 })
99 })
100}