polymesh_api_ink/
basic_types.rs

1use codec::{CompactAs, Decode, Encode};
2
3#[cfg(not(feature = "std"))]
4use alloc::vec::Vec;
5
6use alloc::fmt;
7
8#[cfg(feature = "std")]
9use scale_info::TypeInfo;
10
11#[cfg(feature = "std")]
12use ink::storage::traits::StorageLayout;
13
14pub use ink::primitives::AccountId;
15pub use sp_arithmetic::per_things;
16
17pub use sp_core::{ecdsa, ed25519, sr25519};
18
19// Re-impl `OldWeight`
20#[derive(
21  Clone, Copy, Debug, Encode, Decode, CompactAs, Default, PartialEq, Eq, PartialOrd, Ord,
22)]
23#[cfg_attr(feature = "std", derive(TypeInfo))]
24pub struct OldWeight(pub u64);
25
26#[derive(Clone, Debug, Encode, Decode, PartialEq, Eq)]
27#[cfg_attr(feature = "std", derive(TypeInfo))]
28pub enum MultiSignature {
29  /// An Ed25519 signature.
30  Ed25519(ed25519::Signature),
31  /// An Sr25519 signature.
32  Sr25519(sr25519::Signature),
33  /// An ECDSA/SECP256k1 signature.
34  Ecdsa(ecdsa::Signature),
35}
36
37#[derive(Clone, Debug, Encode, Decode, PartialEq, Eq, PartialOrd, Ord)]
38#[cfg_attr(feature = "std", derive(Hash))]
39#[cfg_attr(feature = "std", derive(TypeInfo))]
40pub enum MultiAddress<AccountId, AccountIndex> {
41  /// It's an account ID (pubkey).
42  Id(AccountId),
43  /// It's an account index.
44  Index(#[codec(compact)] AccountIndex),
45  /// It's some arbitrary raw bytes.
46  Raw(Vec<u8>),
47  /// It's a 32 byte representation.
48  Address32([u8; 32]),
49  /// Its a 20 byte representation.
50  Address20([u8; 20]),
51}
52
53impl<AccountId: Clone, AccountIndex> From<&AccountId> for MultiAddress<AccountId, AccountIndex> {
54  fn from(other: &AccountId) -> Self {
55    Self::Id(other.clone())
56  }
57}
58
59impl<AccountId, AccountIndex> From<AccountId> for MultiAddress<AccountId, AccountIndex> {
60  fn from(other: AccountId) -> Self {
61    Self::Id(other)
62  }
63}
64
65#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Encode, Decode)]
66#[cfg_attr(feature = "std", derive(TypeInfo, StorageLayout))]
67pub struct IdentityId(pub [u8; 32]);
68
69impl fmt::Debug for IdentityId {
70  fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
71    let h = hex::encode(&self.0);
72    write!(f, "0x{}", h)
73  }
74}
75
76impl From<[u8; 32]> for IdentityId {
77  fn from(raw: [u8; 32]) -> Self {
78    Self(raw)
79  }
80}
81
82#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd, Encode, Decode)]
83#[cfg_attr(feature = "std", derive(TypeInfo, StorageLayout))]
84pub struct AssetId([u8; 16]);