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
use codec::{Decode, Encode};
#[cfg(not(feature = "std"))]
use alloc::vec::Vec;
use alloc::fmt;
#[cfg(feature = "std")]
use scale_info::TypeInfo;
pub use sp_arithmetic::per_things;
#[derive(Clone, Debug, Encode, Decode, PartialEq, Eq, PartialOrd, Ord)]
#[cfg_attr(feature = "std", derive(Hash))]
#[cfg_attr(feature = "std", derive(TypeInfo))]
pub enum MultiAddress<AccountId, AccountIndex> {
Id(AccountId),
Index(#[codec(compact)] AccountIndex),
Raw(Vec<u8>),
Address32([u8; 32]),
Address20([u8; 20]),
}
impl<AccountId: Clone, AccountIndex> From<&AccountId> for MultiAddress<AccountId, AccountIndex> {
fn from(other: &AccountId) -> Self {
Self::Id(other.clone())
}
}
impl<AccountId, AccountIndex> From<AccountId> for MultiAddress<AccountId, AccountIndex> {
fn from(other: AccountId) -> Self {
Self::Id(other)
}
}
#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Encode, Decode)]
#[cfg_attr(feature = "std", derive(TypeInfo))]
pub struct AccountId(pub [u8; 32]);
impl fmt::Debug for AccountId {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let h = hex::encode(&self.0);
write!(f, "0x{}", h)
}
}
impl<'a> TryFrom<&'a [u8]> for AccountId {
type Error = ();
fn try_from(x: &'a [u8]) -> Result<Self, ()> {
Ok(AccountId(x.try_into().map_err(|_| ())?))
}
}
impl AsMut<[u8; 32]> for AccountId {
fn as_mut(&mut self) -> &mut [u8; 32] {
&mut self.0
}
}
impl AsMut<[u8]> for AccountId {
fn as_mut(&mut self) -> &mut [u8] {
&mut self.0[..]
}
}
impl AsRef<[u8; 32]> for AccountId {
fn as_ref(&self) -> &[u8; 32] {
&self.0
}
}
impl AsRef<[u8]> for AccountId {
fn as_ref(&self) -> &[u8] {
&self.0[..]
}
}
impl From<[u8; 32]> for AccountId {
fn from(p: [u8; 32]) -> Self {
Self(p)
}
}
#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Encode, Decode)]
#[cfg_attr(feature = "std", derive(TypeInfo))]
pub struct IdentityId(pub [u8; 32]);
impl fmt::Debug for IdentityId {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let h = hex::encode(&self.0);
write!(f, "0x{}", h)
}
}