/home/runner/work/creditcoin/creditcoin/runtime/src/lib.rs
Line | Count | Source (jump to first uncovered line) |
1 | 1 | #![cfg_attr(not(feature = "std"), no_std)]#![cfg_attr(not(feature = "std"), no_std)] |
2 | | // `construct_runtime!` does a lot of recursion and requires us to increase the limit to 256. |
3 | | #![recursion_limit = "256"] |
4 | | // Make the WASM binary available. |
5 | | #[cfg(feature = "std")] |
6 | | include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); |
7 | | |
8 | | pub use frame_support::traits::EqualPrivilegeOnly; |
9 | | use frame_support::{ |
10 | | traits::{ConstU32, ConstU8}, |
11 | | weights::{WeightToFeeCoefficient, WeightToFeeCoefficients, WeightToFeePolynomial}, |
12 | | }; |
13 | | use pallet_creditcoin::weights::WeightInfo as creditcoin_weights; |
14 | | use pallet_creditcoin::WeightInfo; |
15 | | use sp_api::impl_runtime_apis; |
16 | | use sp_core::{crypto::KeyTypeId, Encode, OpaqueMetadata}; |
17 | | use sp_runtime::{ |
18 | | generic, |
19 | | traits::{AccountIdLookup, BlakeTwo256, Block as BlockT, IdentifyAccount, Verify}, |
20 | | transaction_validity::{TransactionSource, TransactionValidity}, |
21 | | ApplyExtrinsicResult, FixedPointNumber, MultiAddress, MultiSignature, Perquintill, |
22 | | SaturatedConversion, |
23 | | }; |
24 | | use sp_std::prelude::*; |
25 | | #[cfg(feature = "std")] |
26 | | use sp_version::NativeVersion; |
27 | | use sp_version::RuntimeVersion; |
28 | | |
29 | | mod version; |
30 | | pub use version::VERSION; |
31 | | |
32 | | #[cfg(test)] |
33 | | mod tests; |
34 | | |
35 | | // A few exports that help ease life for downstream crates. |
36 | | pub use frame_support::{ |
37 | | construct_runtime, parameter_types, |
38 | | traits::{KeyOwnerProofSystem, Randomness, StorageInfo}, |
39 | | weights::{ |
40 | | constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND}, |
41 | | IdentityFee, Weight, |
42 | | }, |
43 | | StorageValue, |
44 | | }; |
45 | | pub use pallet_balances::Call as BalancesCall; |
46 | | pub use pallet_timestamp::Call as TimestampCall; |
47 | | use pallet_transaction_payment::{CurrencyAdapter, Multiplier, TargetedFeeAdjustment}; |
48 | | #[cfg(any(feature = "std", test))] |
49 | | pub use sp_runtime::BuildStorage; |
50 | | pub use sp_runtime::{Perbill, Permill}; |
51 | | |
52 | | /// An index to a block. |
53 | | pub type BlockNumber = u32; |
54 | | |
55 | | /// Alias to 512-bit hash when used in the context of a transaction signature on the chain. |
56 | | pub type Signature = MultiSignature; |
57 | | |
58 | | pub type Signer = <Signature as Verify>::Signer; |
59 | | |
60 | | /// Some way of identifying an account on the chain. We intentionally make it equivalent |
61 | | /// to the public key of our transaction signing scheme. |
62 | | pub type AccountId = <Signer as IdentifyAccount>::AccountId; |
63 | | |
64 | | /// Balance of an account. |
65 | | pub type Balance = u128; |
66 | | |
67 | | /// Index of a transaction in the chain. |
68 | | pub type Index = u32; |
69 | | |
70 | | /// A hash of some data used by the chain. |
71 | | pub type Hash = sp_core::H256; |
72 | | |
73 | | /// Opaque types. These are used by the CLI to instantiate machinery that don't need to know |
74 | | /// the specifics of the runtime. They can then be made to be agnostic over specific formats |
75 | | /// of data like extrinsics, allowing for them to continue syncing the network through upgrades |
76 | | /// to even the core data structures. |
77 | | pub mod opaque { |
78 | | use super::*; |
79 | | |
80 | | pub use sp_runtime::OpaqueExtrinsic as UncheckedExtrinsic; |
81 | | |
82 | | /// Opaque block header type. |
83 | | pub type Header = generic::Header<BlockNumber, BlakeTwo256>; |
84 | | /// Opaque block type. |
85 | | pub type Block = generic::Block<Header, UncheckedExtrinsic>; |
86 | | /// Opaque block identifier type. |
87 | | pub type BlockId = generic::BlockId<Block>; |
88 | | } |
89 | | |
90 | | /// This determines the average expected block time that we are targeting. |
91 | | /// Blocks will be produced at a minimum duration defined by `SLOT_DURATION`. |
92 | | /// `SLOT_DURATION` is picked up by `pallet_timestamp` which is in turn picked |
93 | | /// up by `pallet_aura` to implement `fn slot_duration()`. |
94 | | /// |
95 | | /// Change this to adjust the block time. |
96 | | pub const MILLISECS_PER_BLOCK: u64 = 60_000; |
97 | | |
98 | | // NOTE: Currently it is not possible to change the slot duration after the chain has started. |
99 | | // Attempting to do so will brick block production. |
100 | | pub const SLOT_DURATION: u64 = MILLISECS_PER_BLOCK; |
101 | | |
102 | | // Time is measured by number of blocks. |
103 | | pub const MINUTES: BlockNumber = 60_000 / (MILLISECS_PER_BLOCK as BlockNumber); |
104 | | pub const HOURS: BlockNumber = MINUTES * 60; |
105 | | pub const DAYS: BlockNumber = HOURS * 24; |
106 | | |
107 | | /// The version information used to identify this runtime when compiled natively. |
108 | | #[cfg(feature = "std")] |
109 | 6 | pub fn native_version() -> NativeVersion { |
110 | 6 | NativeVersion { runtime_version: VERSION, can_author_with: Default::default() } |
111 | 6 | } |
112 | | |
113 | | const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75); |
114 | | |
115 | | parameter_types! { |
116 | | pub const Version: RuntimeVersion = VERSION; |
117 | | pub const BlockHashCount: BlockNumber = 2400; |
118 | | /// The portion of the `NORMAL_DISPATCH_RATIO` that we adjust the fees with. Blocks filled less |
119 | | /// than this will decrease the weight and more will increase. |
120 | | pub const TargetBlockFullness: Perquintill = Perquintill::from_percent(25); |
121 | | /// The adjustment variable of the runtime. Higher values will cause `TargetBlockFullness` to |
122 | | /// change the fees more rapidly. |
123 | | pub AdjustmentVariable: Multiplier = Multiplier::saturating_from_rational(3, 100_000); |
124 | | /// Minimum amount of the multiplier. This value cannot be too low. A test case should ensure |
125 | | /// that combined with `AdjustmentVariable`, we can recover from the minimum. |
126 | | /// See `multiplier_can_grow_from_zero`. |
127 | | pub MinimumMultiplier: Multiplier = Multiplier::saturating_from_rational(1, 1_000_000u128); |
128 | | /// We allow for 20 seconds of compute with a 60 second average block time. |
129 | | pub BlockWeights: frame_system::limits::BlockWeights = frame_system::limits::BlockWeights |
130 | | ::with_sensible_defaults(20 * WEIGHT_PER_SECOND, NORMAL_DISPATCH_RATIO); |
131 | | pub BlockLength: frame_system::limits::BlockLength = frame_system::limits::BlockLength |
132 | | ::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO); |
133 | | pub const SS58Prefix: u8 = 42; |
134 | | |
135 | | pub MaximumSchedulerWeight: Weight = 10_000_000; |
136 | | pub const MaxScheduledPerBlock: u32 = 50; |
137 | | |
138 | | } |
139 | | |
140 | | impl pallet_scheduler::Config for Runtime { |
141 | | type Event = Event; |
142 | | type Origin = Origin; |
143 | | type PalletsOrigin = OriginCaller; |
144 | | type Call = Call; |
145 | | type MaximumWeight = MaximumSchedulerWeight; |
146 | | type ScheduleOrigin = frame_system::EnsureRoot<AccountId>; |
147 | | type MaxScheduledPerBlock = MaxScheduledPerBlock; |
148 | | type WeightInfo = (); |
149 | | type OriginPrivilegeCmp = EqualPrivilegeOnly; |
150 | | type PreimageProvider = (); |
151 | | type NoPreimagePostponement = (); |
152 | | } |
153 | | |
154 | | // Configure FRAME pallets to include in runtime. |
155 | | |
156 | | impl frame_system::Config for Runtime { |
157 | | /// The basic call filter to use in dispatchable. |
158 | | type BaseCallFilter = frame_support::traits::Everything; |
159 | | /// Block & extrinsics weights: base values and limits. |
160 | | type BlockWeights = BlockWeights; |
161 | | /// The maximum length of a block (in bytes). |
162 | | type BlockLength = BlockLength; |
163 | | /// The identifier used to distinguish between accounts. |
164 | | type AccountId = AccountId; |
165 | | /// The aggregated dispatch type that is available for extrinsics. |
166 | | type Call = Call; |
167 | | /// The lookup mechanism to get account ID from whatever is passed in dispatchers. |
168 | | type Lookup = AccountIdLookup<AccountId, ()>; |
169 | | /// The index type for storing how many extrinsics an account has signed. |
170 | | type Index = Index; |
171 | | /// The index type for blocks. |
172 | | type BlockNumber = BlockNumber; |
173 | | /// The type for hashing blocks and tries. |
174 | | type Hash = Hash; |
175 | | /// The hashing algorithm used. |
176 | | type Hashing = BlakeTwo256; |
177 | | /// The header type. |
178 | | type Header = generic::Header<BlockNumber, BlakeTwo256>; |
179 | | /// The ubiquitous event type. |
180 | | type Event = Event; |
181 | | /// The ubiquitous origin type. |
182 | | type Origin = Origin; |
183 | | /// Maximum number of block number to block hash mappings to keep (oldest pruned first). |
184 | | type BlockHashCount = BlockHashCount; |
185 | | /// The weight of database operations that the runtime can invoke. |
186 | | type DbWeight = RocksDbWeight; |
187 | | /// Version of the runtime. |
188 | | type Version = Version; |
189 | | /// Converts a module to the index of the module in `construct_runtime!`. |
190 | | /// |
191 | | /// This type is being generated by `construct_runtime!`. |
192 | | type PalletInfo = PalletInfo; |
193 | | /// What to do if a new account is created. |
194 | | type OnNewAccount = (); |
195 | | /// What to do if an account is fully reaped from the system. |
196 | | type OnKilledAccount = (); |
197 | | /// The data to be stored in an account. |
198 | | type AccountData = pallet_balances::AccountData<Balance>; |
199 | | /// Weight information for the extrinsics of this pallet. |
200 | | type SystemWeightInfo = (); |
201 | | /// This is used as an identifier of the chain. 42 is the generic substrate prefix. |
202 | | type SS58Prefix = SS58Prefix; |
203 | | /// The set code logic, just the default since we're not a parachain. |
204 | | type OnSetCode = (); |
205 | | |
206 | | type MaxConsumers = ConstU32<{ u32::MAX }>; |
207 | | } |
208 | | |
209 | | parameter_types! { |
210 | | pub const MinimumPeriod: u64 = 1000; |
211 | | } |
212 | | |
213 | | impl pallet_timestamp::Config for Runtime { |
214 | | /// A timestamp: milliseconds since the unix epoch. |
215 | | type Moment = u64; |
216 | | type OnTimestampSet = Difficulty; |
217 | | type MinimumPeriod = MinimumPeriod; |
218 | | type WeightInfo = (); |
219 | | } |
220 | | |
221 | | parameter_types! { |
222 | | pub const ExistentialDeposit: u128 = 500; |
223 | | pub const MaxLocks: u32 = 50; |
224 | | } |
225 | | |
226 | | impl pallet_balances::Config for Runtime { |
227 | | type MaxLocks = MaxLocks; |
228 | | type MaxReserves = (); |
229 | | type ReserveIdentifier = [u8; 8]; |
230 | | /// The type for recording an account's balance. |
231 | | type Balance = Balance; |
232 | | /// The ubiquitous event type. |
233 | | type Event = Event; |
234 | | type DustRemoval = (); |
235 | | type ExistentialDeposit = ExistentialDeposit; |
236 | | type AccountStore = System; |
237 | | type WeightInfo = pallet_balances::weights::SubstrateWeight<Runtime>; |
238 | | } |
239 | | |
240 | | parameter_types! { |
241 | | pub const TransactionByteFee: Balance = 1; |
242 | | } |
243 | | |
244 | | pub const TARGET_FEE_CREDO: Balance = 10_000_000_000_000_000; |
245 | | |
246 | | pub struct WeightToCtcFee; |
247 | | |
248 | | impl WeightToFeePolynomial for WeightToCtcFee { |
249 | | type Balance = Balance; |
250 | | |
251 | 0 | fn polynomial() -> WeightToFeeCoefficients<Self::Balance> { |
252 | 0 | let base = Balance::from(creditcoin_weights::<Runtime>::lock_deal_order()); |
253 | 0 | let ratio = TARGET_FEE_CREDO / base; |
254 | 0 | let rem = TARGET_FEE_CREDO % base; |
255 | 0 | smallvec::smallvec!(WeightToFeeCoefficient { |
256 | 0 | coeff_integer: ratio, |
257 | 0 | coeff_frac: Perbill::from_rational(rem, base), |
258 | | negative: false, |
259 | | degree: 1, |
260 | | }) |
261 | 0 | } |
262 | | } |
263 | | |
264 | | /// Parameterized slow adjusting fee updated based on |
265 | | /// https://research.web3.foundation/en/latest/polkadot/overview/2-token-economics.html#-2.-slow-adjusting-mechanism |
266 | | pub type SlowAdjustingFeeUpdate<R> = |
267 | | TargetedFeeAdjustment<R, TargetBlockFullness, AdjustmentVariable, MinimumMultiplier>; |
268 | | |
269 | | impl pallet_transaction_payment::Config for Runtime { |
270 | | type OnChargeTransaction = CurrencyAdapter<Balances, ()>; |
271 | | type TransactionByteFee = TransactionByteFee; |
272 | | type WeightToFee = WeightToCtcFee; |
273 | | type FeeMultiplierUpdate = SlowAdjustingFeeUpdate<Self>; |
274 | | type OperationalFeeMultiplier = ConstU8<1u8>; |
275 | | } |
276 | | |
277 | | impl pallet_sudo::Config for Runtime { |
278 | | type Event = Event; |
279 | | type Call = Call; |
280 | | } |
281 | | |
282 | | impl pallet_creditcoin::Config for Runtime { |
283 | | type Event = Event; |
284 | | type Call = Call; |
285 | | type AuthorityId = pallet_creditcoin::crypto::CtcAuthId; |
286 | | type Signer = Signer; |
287 | | type SignerSignature = Signature; |
288 | | type FromAccountId = AccountId; |
289 | | type PublicSigning = <Signature as Verify>::Signer; |
290 | | type InternalPublic = sp_core::sr25519::Public; |
291 | | type HashIntoNonce = Hash; |
292 | | type UnverifiedTaskTimeout = ConstU32<60>; |
293 | | type WeightInfo = pallet_creditcoin::weights::WeightInfo<Runtime>; |
294 | | } |
295 | | |
296 | | impl pallet_difficulty::Config for Runtime { |
297 | | type Moment = u64; |
298 | | type WeightInfo = pallet_difficulty::weights::WeightInfo<Runtime>; |
299 | | } |
300 | | |
301 | | impl pallet_rewards::Config for Runtime { |
302 | | type Event = Event; |
303 | | type Currency = Balances; |
304 | | type WeightInfo = pallet_rewards::weights::WeightInfo<Runtime>; |
305 | | } |
306 | | |
307 | | pub type SignedPayload = generic::SignedPayload<Call, SignedExtra>; |
308 | | |
309 | | impl<LocalCall> frame_system::offchain::CreateSignedTransaction<LocalCall> for Runtime |
310 | | where |
311 | | Call: From<LocalCall>, |
312 | | { |
313 | 0 | fn create_transaction<C: frame_system::offchain::AppCrypto<Self::Public, Self::Signature>>( |
314 | 0 | call: Call, |
315 | 0 | public: Self::Public, |
316 | 0 | account: AccountId, |
317 | 0 | nonce: Index, |
318 | 0 | ) -> Option<(Call, <UncheckedExtrinsic as sp_runtime::traits::Extrinsic>::SignaturePayload)> { |
319 | 0 | let period = BlockHashCount::get() as u64; |
320 | 0 | let current_block = System::block_number().saturated_into::<u64>().saturating_sub(1); |
321 | 0 | let tip = 0; |
322 | 0 |
|
323 | 0 | let extra: SignedExtra = ( |
324 | 0 | frame_system::CheckSpecVersion::<Runtime>::new(), |
325 | 0 | frame_system::CheckTxVersion::<Runtime>::new(), |
326 | 0 | frame_system::CheckGenesis::<Runtime>::new(), |
327 | 0 | frame_system::CheckEra::<Runtime>::from(generic::Era::mortal(period, current_block)), |
328 | 0 | frame_system::CheckNonce::<Runtime>::from(nonce), |
329 | 0 | frame_system::CheckWeight::<Runtime>::new(), |
330 | 0 | pallet_transaction_payment::ChargeTransactionPayment::<Runtime>::from(tip), |
331 | 0 | ); |
332 | | |
333 | | #[cfg_attr(not(feature = "std"), allow(unused_variables))] |
334 | 0 | let raw_payload = SignedPayload::new(call, extra) |
335 | 0 | .map_err(|e| { |
336 | 0 | frame_support::log::warn!("SignedPayload error: {:?}", e); |
337 | 0 | }) |
338 | 0 | .ok()?; |
339 | | |
340 | 0 | let signature = raw_payload.using_encoded(|payload| C::sign(payload, public))?; |
341 | | |
342 | 0 | let address = MultiAddress::Id(account); |
343 | 0 | let (call, extra, _) = raw_payload.deconstruct(); |
344 | 0 | Some((call, (address, signature, extra))) |
345 | 0 | } |
346 | | } |
347 | | |
348 | | // Create the runtime by composing the FRAME pallets that were previously configured. |
349 | 28 | construct_runtime!( |
350 | 0 | pub enum Runtime where |
351 | 0 | Block = Block, |
352 | 0 | NodeBlock = opaque::Block, |
353 | 0 | UncheckedExtrinsic = UncheckedExtrinsic |
354 | 0 | { |
355 | 0 | System: frame_system::{Pallet, Call, Config, Storage, Event<T>}, |
356 | 0 | Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent}, |
357 | 0 | Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>}, |
358 | 0 | TransactionPayment: pallet_transaction_payment::{Pallet, Storage}, |
359 | 0 | Sudo: pallet_sudo::{Pallet, Call, Config<T>, Storage, Event<T>}, |
360 | 0 | Creditcoin: pallet_creditcoin::{Pallet, Call, Storage, Config<T>, Event<T>}, |
361 | 0 | Difficulty: pallet_difficulty::{Pallet, Call, Config<T>, Storage}, |
362 | 0 | Rewards: pallet_rewards::{Pallet, Storage, Event<T>}, |
363 | 0 | Scheduler: pallet_scheduler, |
364 | 0 | } |
365 | 0 | ); |
366 | 0 |
|
367 | 0 | /// The address format for describing accounts. |
368 | 0 | pub type Address = sp_runtime::MultiAddress<AccountId, ()>; |
369 | 0 | /// Block header type as expected by this runtime. |
370 | 0 | pub type Header = generic::Header<BlockNumber, BlakeTwo256>; |
371 | 0 | /// Block type as expected by this runtime. |
372 | 0 | pub type Block = generic::Block<Header, UncheckedExtrinsic>; |
373 | 0 | /// The SignedExtension to the basic transaction logic. |
374 | 0 | pub type SignedExtra = ( |
375 | 0 | frame_system::CheckSpecVersion<Runtime>, |
376 | 0 | frame_system::CheckTxVersion<Runtime>, |
377 | 0 | frame_system::CheckGenesis<Runtime>, |
378 | 0 | frame_system::CheckEra<Runtime>, |
379 | 0 | frame_system::CheckNonce<Runtime>, |
380 | 0 | frame_system::CheckWeight<Runtime>, |
381 | 0 | pallet_transaction_payment::ChargeTransactionPayment<Runtime>, |
382 | 0 | ); |
383 | 0 | /// Unchecked extrinsic type as expected by this runtime. |
384 | 0 | pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<Address, Call, Signature, SignedExtra>; |
385 | 0 | /// Executive: handles dispatch to the various modules. |
386 | 0 | pub type Executive = frame_executive::Executive< |
387 | 0 | Runtime, |
388 | 0 | Block, |
389 | 0 | frame_system::ChainContext<Runtime>, |
390 | 0 | Runtime, |
391 | 0 | AllPalletsWithSystem, |
392 | 0 | >; |
393 | 0 |
|
394 | 2 | impl_runtime_apis! { |
395 | 11 | impl sp_api::Core<Block> for Runtime { |
396 | 11 | fn version() -> RuntimeVersion { |
397 | 0 | VERSION |
398 | 0 | } |
399 | 11 | |
400 | 11 | fn execute_block(0 block: Block0 ) { |
401 | 0 | Executive::execute_block(block); |
402 | 0 | } |
403 | 11 | |
404 | 11 | fn initialize_block(0 header: &<Block as BlockT>::Header0 ) { |
405 | 0 | Executive::initialize_block(header) |
406 | 0 | } |
407 | 11 | } |
408 | 11 | |
409 | 11 | impl sp_api::Metadata<Block> for Runtime { |
410 | 11 | fn metadata() -> OpaqueMetadata { |
411 | 0 | OpaqueMetadata::new(Runtime::metadata().into()) |
412 | 0 | } |
413 | 11 | } |
414 | 11 | |
415 | 11 | impl sp_block_builder::BlockBuilder<Block> for Runtime { |
416 | 11 | fn apply_extrinsic(0 extrinsic: <Block as BlockT>::Extrinsic0 ) -> ApplyExtrinsicResult { |
417 | 0 | Executive::apply_extrinsic(extrinsic) |
418 | 0 | } |
419 | 11 | |
420 | 11 | fn finalize_block() -> <Block as BlockT>::Header { |
421 | 0 | Executive::finalize_block() |
422 | 0 | } |
423 | 11 | |
424 | 11 | fn inherent_extrinsics(0 data: sp_inherents::InherentData0 ) -> Vec<<Block as BlockT>::Extrinsic> { |
425 | 0 | data.create_extrinsics() |
426 | 0 | } |
427 | 11 | |
428 | 11 | fn check_inherents( |
429 | 0 | block: Block, |
430 | 0 | data: sp_inherents::InherentData, |
431 | 0 | ) -> sp_inherents::CheckInherentsResult { |
432 | 0 | data.check_extrinsics(&block) |
433 | 0 | } |
434 | 11 | } |
435 | 11 | |
436 | 11 | impl sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block> for Runtime { |
437 | 11 | fn validate_transaction( |
438 | 0 | source: TransactionSource, |
439 | 0 | tx: <Block as BlockT>::Extrinsic, |
440 | 0 | block_hash: <Block as BlockT>::Hash, |
441 | 0 | ) -> TransactionValidity { |
442 | 0 | Executive::validate_transaction(source, tx, block_hash) |
443 | 0 | } |
444 | 11 | } |
445 | 11 | |
446 | 11 | impl sp_offchain::OffchainWorkerApi<Block> for Runtime { |
447 | 11 | fn offchain_worker(0 header: &<Block as BlockT>::Header0 ) { |
448 | 0 | Executive::offchain_worker(header) |
449 | 0 | } |
450 | 11 | } |
451 | 11 | |
452 | 11 | impl sp_session::SessionKeys<Block> for Runtime { |
453 | 11 | fn generate_session_keys(0 _seed: Option<Vec<u8>>0 ) -> Vec<u8> { |
454 | 0 | Vec::new() |
455 | 0 | } |
456 | 11 | |
457 | 11 | fn decode_session_keys( |
458 | 0 | _encoded: Vec<u8>, |
459 | 0 | ) -> Option<Vec<(Vec<u8>, KeyTypeId)>> { |
460 | 0 | None |
461 | 0 | } |
462 | 11 | } |
463 | 11 | |
464 | 11 | impl frame_system_rpc_runtime_api::AccountNonceApi<Block, AccountId, Index> for Runtime { |
465 | 11 | fn account_nonce(0 account: AccountId0 ) -> Index { |
466 | 0 | System::account_nonce(account) |
467 | 0 | } |
468 | 11 | } |
469 | 11 | |
470 | 11 | impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance> for Runtime { |
471 | 11 | fn query_info( |
472 | 0 | uxt: <Block as BlockT>::Extrinsic, |
473 | 0 | len: u32, |
474 | 0 | ) -> pallet_transaction_payment_rpc_runtime_api::RuntimeDispatchInfo<Balance> { |
475 | 0 | TransactionPayment::query_info(uxt, len) |
476 | 0 | } |
477 | 11 | fn query_fee_details( |
478 | 0 | uxt: <Block as BlockT>::Extrinsic, |
479 | 0 | len: u32, |
480 | 0 | ) -> pallet_transaction_payment::FeeDetails<Balance> { |
481 | 0 | TransactionPayment::query_fee_details(uxt, len) |
482 | 0 | } |
483 | 11 | } |
484 | 11 | |
485 | 11 | impl sp_consensus_pow::TimestampApi<Block, u64> for Runtime { |
486 | 11 | fn timestamp() -> u64 { |
487 | 0 | Timestamp::get() |
488 | 0 | } |
489 | 11 | } |
490 | 11 | |
491 | 11 | impl sp_consensus_pow::DifficultyApi<Block, primitives::Difficulty> for Runtime { |
492 | 11 | fn difficulty() -> primitives::Difficulty { |
493 | 0 | Difficulty::difficulty() |
494 | 0 | } |
495 | 11 | } |
496 | 11 | |
497 | 11 | #[cfg(feature = "runtime-benchmarks")] |
498 | 11 | impl frame_benchmarking::Benchmark<Block> for Runtime { |
499 | 11 | fn benchmark_metadata(extra: bool) -> ( |
500 | 11 | Vec<frame_benchmarking::BenchmarkList>, |
501 | 11 | Vec<frame_support::traits::StorageInfo>, |
502 | 11 | ) { |
503 | 11 | use frame_benchmarking::{list_benchmark, Benchmarking, BenchmarkList}; |
504 | 11 | use frame_support::traits::StorageInfoTrait; |
505 | 11 | use frame_system_benchmarking::Pallet as SystemBench; |
506 | 11 | |
507 | 11 | let mut list = Vec::<BenchmarkList>::new(); |
508 | 11 | |
509 | 11 | list_benchmark!(list, extra, frame_system, SystemBench::<Runtime>); |
510 | 11 | list_benchmark!(list, extra, pallet_balances, Balances); |
511 | 11 | list_benchmark!(list, extra, pallet_timestamp, Timestamp); |
512 | 11 | list_benchmark!(list, extra, pallet_creditcoin, Creditcoin); |
513 | 11 | list_benchmark!(list, extra, pallet_rewards, Rewards); |
514 | 11 | list_benchmark!(list, extra, pallet_difficulty, Difficulty); |
515 | 11 | |
516 | 11 | let storage_info = AllPalletsWithSystem::storage_info(); |
517 | 11 | |
518 | 11 | (list, storage_info) |
519 | 11 | } |
520 | 11 | |
521 | 11 | fn dispatch_benchmark( |
522 | 11 | config: frame_benchmarking::BenchmarkConfig |
523 | 11 | ) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, sp_runtime::RuntimeString> { |
524 | 11 | use frame_benchmarking::{Benchmarking, BenchmarkBatch, add_benchmark, TrackedStorageKey}; |
525 | 11 | |
526 | 11 | use frame_system_benchmarking::Pallet as SystemBench; |
527 | 11 | impl frame_system_benchmarking::Config for Runtime {} |
528 | 11 | |
529 | 11 | let whitelist: Vec<TrackedStorageKey> = vec![ |
530 | 11 | // Block Number |
531 | 11 | hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac").to_vec().into(), |
532 | 11 | // Total Issuance |
533 | 11 | hex_literal::hex!("c2261276cc9d1f8598ea4b6a74b15c2f57c875e4cff74148e4628f264b974c80").to_vec().into(), |
534 | 11 | // Execution Phase |
535 | 11 | hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef7ff553b5a9862a516939d82b3d3d8661a").to_vec().into(), |
536 | 11 | // Event Count |
537 | 11 | hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef70a98fdbe9ce6c55837576c60c7af3850").to_vec().into(), |
538 | 11 | // System Events |
539 | 11 | hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7").to_vec().into(), |
540 | 11 | ]; |
541 | 11 | |
542 | 11 | let mut batches = Vec::<BenchmarkBatch>::new(); |
543 | 11 | let params = (&config, &whitelist); |
544 | 11 | |
545 | 11 | add_benchmark!(params, batches, frame_system, SystemBench::<Runtime>); |
546 | 11 | add_benchmark!(params, batches, pallet_balances, Balances); |
547 | 11 | add_benchmark!(params, batches, pallet_timestamp, Timestamp); |
548 | 11 | add_benchmark!(params, batches, pallet_creditcoin, Creditcoin); |
549 | 11 | add_benchmark!(params, batches, pallet_rewards, Rewards); |
550 | 11 | add_benchmark!(params, batches, pallet_difficulty, Difficulty); |
551 | 11 | |
552 | 11 | if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) } |
553 | 11 | Ok(batches) |
554 | 11 | } |
555 | 11 | } |
556 | 11 | |
557 | 11 | impl creditcoin_runtime_api::TaskApi<Block, AccountId> for Runtime{ |
558 | 11 | fn offchain_nonce_key(2 acc: &AccountId0 ) -> Vec<u8>{ |
559 | 2 | pallet_creditcoin::ocw::nonce_key(acc) |
560 | 2 | } |
561 | 11 | } |
562 | 11 | }4
|
563 | 0 |
|
564 | 0 | impl frame_system::offchain::SigningTypes for Runtime { |
565 | 0 | type Public = <Signature as Verify>::Signer; |
566 | 0 | type Signature = Signature; |
567 | 0 | } |
568 | 0 |
|
569 | 0 | impl<C> frame_system::offchain::SendTransactionTypes<C> for Runtime |
570 | 0 | where |
571 | 0 | Call: From<C>, |
572 | 0 | { |
573 | 0 | type OverarchingCall = Call; |
574 | 0 | type Extrinsic = UncheckedExtrinsic; |
575 | 172 | }113 |