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 BlockRef {
53	pub hash: H256,
54	pub height: u32,
55}
56
57impl From<(H256, u32)> for BlockRef {
58	fn from(value: (H256, u32)) -> Self {
59		Self { hash: value.0, height: value.1 }
60	}
61}
62
63impl From<BlockRef> for H256 {
64	fn from(value: BlockRef) -> Self {
65		value.hash
66	}
67}
68
69#[derive(Debug, Clone, Copy, Deserialize)]
70pub struct TxRef {
71	pub hash: H256,
72	pub index: u32,
73}
74
75impl From<(H256, u32)> for TxRef {
76	fn from(value: (H256, u32)) -> Self {
77		Self { hash: value.0, index: value.1 }
78	}
79}
80
81impl From<TxRef> for H256 {
82	fn from(value: TxRef) -> Self {
83		value.hash
84	}
85}
86
87#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
88pub enum HashNumber {
89	Hash(H256),
90	Number(u32),
91}
92
93impl From<BlockRef> for HashNumber {
94	fn from(value: BlockRef) -> Self {
95		Self::Hash(value.hash)
96	}
97}
98
99impl From<TxRef> for HashNumber {
100	fn from(value: TxRef) -> Self {
101		Self::Number(value.index)
102	}
103}
104
105impl From<H256> for HashNumber {
106	fn from(value: H256) -> Self {
107		Self::Hash(value)
108	}
109}
110
111impl From<u32> for HashNumber {
112	fn from(value: u32) -> Self {
113		Self::Number(value)
114	}
115}