subxt_core/utils/
multi_address.rs

1// Copyright 2019-2024 Parity Technologies (UK) Ltd.
2// This file is dual-licensed as Apache-2.0 or GPL-3.0.
3// see LICENSE for license details.
4
5//! The "default" Substrate/Polkadot Address type. This is used in codegen, as well as signing related bits.
6//! This doesn't contain much functionality itself, but is easy to convert to/from an `sp_runtime::MultiAddress`
7//! for instance, to gain functionality without forcing a dependency on Substrate crates here.
8
9use alloc::vec::Vec;
10use codec::{Decode, Encode};
11
12/// A multi-format address wrapper for on-chain accounts. This is a simplified version of Substrate's
13/// `sp_runtime::MultiAddress`.
14#[derive(
15    Clone,
16    Eq,
17    PartialEq,
18    Ord,
19    PartialOrd,
20    Encode,
21    Decode,
22    Debug,
23    scale_encode::EncodeAsType,
24    scale_decode::DecodeAsType,
25    scale_info::TypeInfo,
26)]
27pub enum MultiAddress<AccountId, AccountIndex> {
28    /// It's an account ID (pubkey).
29    Id(AccountId),
30    /// It's an account index.
31    Index(#[codec(compact)] AccountIndex),
32    /// It's some arbitrary raw bytes.
33    Raw(Vec<u8>),
34    /// It's a 32 byte representation.
35    Address32([u8; 32]),
36    /// Its a 20 byte representation.
37    Address20([u8; 20]),
38}
39
40impl<AccountId, AccountIndex> From<AccountId> for MultiAddress<AccountId, AccountIndex> {
41    fn from(a: AccountId) -> Self {
42        Self::Id(a)
43    }
44}