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
use codec::{Compact, Decode, Encode};
use sp_std::marker::PhantomData;
pub trait PalletError: Encode + Decode {
const MAX_ENCODED_SIZE: usize;
}
macro_rules! impl_for_types {
(size: $size:expr, $($typ:ty),+) => {
$(
impl PalletError for $typ {
const MAX_ENCODED_SIZE: usize = $size;
}
)+
};
}
impl_for_types!(size: 0, (), crate::Never);
impl_for_types!(size: 1, u8, i8, bool);
impl_for_types!(size: 2, u16, i16, Compact<u8>);
impl_for_types!(size: 4, u32, i32, Compact<u16>);
impl_for_types!(size: 5, Compact<u32>);
impl_for_types!(size: 8, u64, i64);
impl_for_types!(size: 9, Compact<u64>);
impl_for_types!(size: 12, core::time::Duration);
impl_for_types!(size: 16, u128, i128);
impl_for_types!(size: 17, Compact<u128>);
impl<T> PalletError for PhantomData<T> {
const MAX_ENCODED_SIZE: usize = 0;
}
impl<T: PalletError> PalletError for core::ops::Range<T> {
const MAX_ENCODED_SIZE: usize = T::MAX_ENCODED_SIZE.saturating_mul(2);
}
impl<T: PalletError, const N: usize> PalletError for [T; N] {
const MAX_ENCODED_SIZE: usize = T::MAX_ENCODED_SIZE.saturating_mul(N);
}
impl<T: PalletError> PalletError for Option<T> {
const MAX_ENCODED_SIZE: usize = T::MAX_ENCODED_SIZE.saturating_add(1);
}
impl<T: PalletError, E: PalletError> PalletError for Result<T, E> {
const MAX_ENCODED_SIZE: usize = if T::MAX_ENCODED_SIZE > E::MAX_ENCODED_SIZE {
T::MAX_ENCODED_SIZE
} else {
E::MAX_ENCODED_SIZE
}
.saturating_add(1);
}
#[impl_trait_for_tuples::impl_for_tuples(1, 18)]
impl PalletError for Tuple {
const MAX_ENCODED_SIZE: usize = {
let mut size = 0_usize;
for_tuples!( #(size = size.saturating_add(Tuple::MAX_ENCODED_SIZE);)* );
size
};
}