avail_rust_core/
config.rs

1use codec::{Decode, Encode};
2use primitive_types::H256;
3use serde::{Deserialize, Serialize};
4use subxt_core::utils::AccountId32;
5
6pub type AccountId = AccountId32;
7pub type AccountIndex = u32;
8pub type BlockHeight = u32;
9pub type BlockHash = H256;
10pub type Signature = MultiSignature;
11pub type BlakeTwo256 = subxt_core::config::substrate::BlakeTwo256;
12
13#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, Debug, scale_info::TypeInfo)]
14#[repr(u8)]
15pub enum MultiSignature {
16	/// An Ed25519 signature.
17	Ed25519([u8; 64]) = 0,
18	/// An Sr25519 signature.
19	Sr25519([u8; 64]) = 1,
20	/// An ECDSA/SECP256k1 signature (a 512-bit value, plus 8 bits for recovery ID).
21	Ecdsa([u8; 65]) = 2,
22}
23
24#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, Debug, scale_info::TypeInfo)]
25#[repr(u8)]
26pub enum MultiAddress {
27	/// It's an account ID (pubkey).
28	Id(AccountId) = 0,
29	/// It's an account index.
30	Index(#[codec(compact)] u32) = 1,
31	/// It's some arbitrary raw bytes.
32	Raw(Vec<u8>) = 2,
33	/// It's a 32 byte representation.
34	Address32([u8; 32]) = 3,
35	/// Its a 20 byte representation.
36	Address20([u8; 20]) = 4,
37}
38
39impl From<AccountId> for MultiAddress {
40	fn from(a: AccountId) -> Self {
41		Self::Id(a)
42	}
43}
44
45#[derive(Debug, Clone, Copy, Default, Encode, Decode, Eq, PartialEq)]
46pub struct AppId(#[codec(compact)] pub u32);
47
48pub type DispatchIndex = (u8, u8);
49pub type EmittedIndex = (u8, u8);
50
51#[derive(Debug, Clone, Copy, Deserialize)]
52pub struct BlockLocation {
53	pub hash: H256,
54	pub height: u32,
55}
56
57impl From<(H256, u32)> for BlockLocation {
58	fn from(value: (H256, u32)) -> Self {
59		Self {
60			hash: value.0,
61			height: value.1,
62		}
63	}
64}
65
66impl From<BlockLocation> for H256 {
67	fn from(value: BlockLocation) -> Self {
68		value.hash
69	}
70}
71
72#[derive(Debug, Clone, Copy, Deserialize)]
73pub struct TransactionLocation {
74	pub hash: H256,
75	pub index: u32,
76}
77
78impl From<(H256, u32)> for TransactionLocation {
79	fn from(value: (H256, u32)) -> Self {
80		Self {
81			hash: value.0,
82			index: value.1,
83		}
84	}
85}
86
87impl From<TransactionLocation> for H256 {
88	fn from(value: TransactionLocation) -> Self {
89		value.hash
90	}
91}
92
93#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
94pub enum HashNumber {
95	Hash(H256),
96	Number(u32),
97}
98
99impl From<BlockLocation> for HashNumber {
100	fn from(value: BlockLocation) -> Self {
101		Self::Hash(value.hash)
102	}
103}
104
105impl From<TransactionLocation> for HashNumber {
106	fn from(value: TransactionLocation) -> Self {
107		Self::Number(value.index)
108	}
109}