sp_runtime/
multiaddress.rs1use alloc::vec::Vec;
21use codec::{Decode, DecodeWithMemTracking, Encode};
22
23#[derive(
25 Encode,
26 Decode,
27 DecodeWithMemTracking,
28 PartialEq,
29 Eq,
30 Clone,
31 crate::RuntimeDebug,
32 scale_info::TypeInfo,
33)]
34#[cfg_attr(feature = "std", derive(Hash))]
35pub enum MultiAddress<AccountId, AccountIndex> {
36 Id(AccountId),
38 Index(#[codec(compact)] AccountIndex),
40 Raw(Vec<u8>),
42 Address32([u8; 32]),
44 Address20([u8; 20]),
46}
47
48#[cfg(feature = "std")]
49impl<AccountId, AccountIndex> std::fmt::Display for MultiAddress<AccountId, AccountIndex>
50where
51 AccountId: std::fmt::Debug,
52 AccountIndex: std::fmt::Debug,
53{
54 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
55 use sp_core::hexdisplay::HexDisplay;
56 match self {
57 Self::Raw(inner) => write!(f, "MultiAddress::Raw({})", HexDisplay::from(inner)),
58 Self::Address32(inner) => {
59 write!(f, "MultiAddress::Address32({})", HexDisplay::from(inner))
60 },
61 Self::Address20(inner) => {
62 write!(f, "MultiAddress::Address20({})", HexDisplay::from(inner))
63 },
64 _ => write!(f, "{:?}", self),
65 }
66 }
67}
68
69impl<AccountId, AccountIndex> From<AccountId> for MultiAddress<AccountId, AccountIndex> {
70 fn from(a: AccountId) -> Self {
71 Self::Id(a)
72 }
73}