1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
use crate::{ArithmeticError, TokenError};
use codec::{Decode, Encode};
use scale_info::TypeInfo;
#[cfg(feature = "std")]
use serde::{Deserialize, Serialize};
#[derive(Eq, Clone, Copy, Encode, Decode, Debug, TypeInfo)]
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
pub struct ModuleError {
pub index: u8,
pub error: u8,
#[codec(skip)]
#[cfg_attr(feature = "std", serde(skip_deserializing))]
pub message: Option<&'static str>,
}
impl PartialEq for ModuleError {
fn eq(&self, other: &Self) -> bool {
(self.index == other.index) && (self.error == other.error)
}
}
#[derive(Eq, Clone, Copy, Encode, Decode, Debug, TypeInfo, PartialEq)]
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
pub enum DispatchError {
Other(
#[codec(skip)]
#[cfg_attr(feature = "std", serde(skip_deserializing))]
&'static str,
),
CannotLookup,
BadOrigin,
Module(ModuleError),
ConsumerRemaining,
NoProviders,
TooManyConsumers,
Token(TokenError),
Arithmetic(ArithmeticError),
}
pub type DispatchOutcome = Result<(), DispatchError>;
pub type ApplyExtrinsicResult =
Result<DispatchOutcome, crate::transaction_validity::TransactionValidityError>;
pub fn convert_to_latest(old: ApplyExtrinsicResult) -> crate::ApplyExtrinsicResult {
old.map(|outcome| {
outcome.map_err(|e| match e {
DispatchError::Other(s) => crate::DispatchError::Other(s),
DispatchError::CannotLookup => crate::DispatchError::CannotLookup,
DispatchError::BadOrigin => crate::DispatchError::BadOrigin,
DispatchError::Module(err) => crate::DispatchError::Module(crate::ModuleError {
index: err.index,
error: [err.error, 0, 0, 0],
message: err.message,
}),
DispatchError::ConsumerRemaining => crate::DispatchError::ConsumerRemaining,
DispatchError::NoProviders => crate::DispatchError::NoProviders,
DispatchError::TooManyConsumers => crate::DispatchError::TooManyConsumers,
DispatchError::Token(err) => crate::DispatchError::Token(err),
DispatchError::Arithmetic(err) => crate::DispatchError::Arithmetic(err),
})
})
}