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