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