ac_primitives/config/
mod.rs1use codec::{Decode, Encode, FullCodec};
15use core::{fmt::Debug, marker::PhantomData};
16use serde::{de::DeserializeOwned, Serialize};
17use sp_core::Pair;
18use sp_runtime::traits::{
19 AtLeast32Bit, AtLeast32BitUnsigned, Block, Hash as HashTrait, Header as HeaderTrait,
20 MaybeSerializeDeserialize,
21};
22
23use crate::{extrinsic_params, ExtrinsicSigner, SignExtrinsic};
24
25pub use asset_runtime_config::*;
26pub use default_runtime_config::*;
27pub use rococo_runtime_config::*;
28
29pub mod asset_runtime_config;
30pub mod default_runtime_config;
31pub mod rococo_runtime_config;
32
33pub trait Config {
35 type Index: Default + Debug + Copy + DeserializeOwned + AtLeast32Bit + Decode;
40
41 type BlockNumber: Debug
43 + Copy
44 + Encode
45 + Default
46 + Serialize
47 + DeserializeOwned
48 + core::hash::Hash
49 + core::str::FromStr
50 + Into<u64>
51 + AtLeast32BitUnsigned;
52
53 type Hash: Debug
55 + Copy
56 + Send
57 + Sync
58 + Decode
59 + Default
60 + AsRef<[u8]>
61 + Serialize
62 + DeserializeOwned
63 + Encode
64 + PartialEq;
65
66 type AccountId: Debug
68 + Clone
69 + Encode
70 + MaybeSerializeDeserialize
71 + From<<Self::CryptoKey as Pair>::Public>;
72
73 type Address: Debug + Clone + Encode + From<Self::AccountId>; type Signature: Debug + Encode + From<<Self::CryptoKey as Pair>::Signature>;
78
79 type Hasher: Debug + HashTrait<Output = Self::Hash>;
81
82 type Header: Debug
84 + HeaderTrait<Number = Self::BlockNumber, Hashing = Self::Hasher>
85 + Send
86 + DeserializeOwned;
87
88 type AccountData: Debug + Clone + FullCodec;
90
91 type ExtrinsicParams: extrinsic_params::ExtrinsicParams<Self::Index, Self::Hash>;
93
94 type CryptoKey: Pair;
96
97 type ExtrinsicSigner: SignExtrinsic<Self::AccountId>;
99
100 type Block: Block + DeserializeOwned;
102
103 type Balance: Debug
105 + Decode
106 + Encode
107 + AtLeast32BitUnsigned
108 + Default
109 + Copy
110 + Serialize
111 + DeserializeOwned;
112
113 type ContractCurrency: Debug
115 + Decode
116 + Encode
117 + AtLeast32BitUnsigned
118 + Default
119 + Copy
120 + Serialize
121 + DeserializeOwned;
122
123 type StakingBalance: Debug
125 + Decode
126 + Encode
127 + AtLeast32BitUnsigned
128 + Default
129 + Copy
130 + Serialize
131 + DeserializeOwned;
132}
133
134#[derive(Decode, Encode, Clone, Eq, PartialEq, Debug)]
149pub struct WithExtrinsicParams<T: Config, E: extrinsic_params::ExtrinsicParams<T::Index, T::Hash>> {
150 _marker: PhantomData<(T, E)>,
151}
152
153impl<T: Config, E: extrinsic_params::ExtrinsicParams<T::Index, T::Hash>> Config
154 for WithExtrinsicParams<T, E>
155{
156 type Index = T::Index;
157 type BlockNumber = T::BlockNumber;
158 type Hash = T::Hash;
159 type AccountId = T::AccountId;
160 type Address = T::Address;
161 type Signature = T::Signature;
162 type Hasher = T::Hasher;
163 type Header = T::Header;
164 type AccountData = T::AccountData;
165 type ExtrinsicParams = E;
166 type CryptoKey = T::CryptoKey;
167 type ExtrinsicSigner = ExtrinsicSigner<Self>;
168 type Block = T::Block;
169 type Balance = T::Balance;
170 type ContractCurrency = T::ContractCurrency;
171 type StakingBalance = T::StakingBalance;
172}
173
174#[derive(Decode, Encode, Clone, Eq, PartialEq, Debug)]
185pub struct WithAddress<T, A>
186where
187 T: Config,
188 A: Debug + Clone + Encode + From<T::AccountId>,
189{
190 _marker: PhantomData<(T, A)>,
191}
192
193impl<T, A> Config for WithAddress<T, A>
194where
195 T: Config,
196 A: Debug + Clone + Encode + From<T::AccountId>,
197{
198 type Index = T::Index;
199 type BlockNumber = T::BlockNumber;
200 type Hash = T::Hash;
201 type AccountId = T::AccountId;
202 type Address = A;
203 type Signature = T::Signature;
204 type Hasher = T::Hasher;
205 type Header = T::Header;
206 type AccountData = T::AccountData;
207 type ExtrinsicParams = T::ExtrinsicParams;
208 type CryptoKey = T::CryptoKey;
209 type ExtrinsicSigner = ExtrinsicSigner<Self>;
210 type Block = T::Block;
211 type Balance = T::Balance;
212 type ContractCurrency = T::ContractCurrency;
213 type StakingBalance = T::StakingBalance;
214}