difftreelog
Pallet Democracy
in: master
3 files changed
node/src/chain_spec.rsdiffbeforeafterboth--- a/node/src/chain_spec.rs
+++ b/node/src/chain_spec.rs
@@ -147,12 +147,24 @@
pallet_aura: Some(AuraConfig {
authorities: initial_authorities.iter().map(|x| (x.0.clone())).collect(),
}),
- pallet_grandpa: Some(GrandpaConfig {
+ pallet_collective_Instance1: Some(CouncilConfig {
+ members: vec![],
+ phantom: Default::default(),
+ }),
+ pallet_collective_Instance2: Some(TechnicalCommitteeConfig {
+ members: vec![],
+ phantom: Default::default(),
+ }),
+ pallet_democracy: Some(DemocracyConfig::default()),
+ pallet_grandpa: Some(GrandpaConfig {
authorities: initial_authorities
.iter()
.map(|x| (x.1.clone(), 1))
.collect(),
- }),
+ }),
+ pallet_elections_phragmen: Some(Default::default()),
+ pallet_membership: Some(Default::default()),
+ pallet_treasury: Some(Default::default()),
pallet_sudo: Some(SudoConfig { key: root_key }),
pallet_nft: Some(NftConfig {
collection: vec![(
runtime/Cargo.tomldiffbeforeafterboth--- a/runtime/Cargo.toml
+++ b/runtime/Cargo.toml
@@ -57,6 +57,13 @@
sp-transaction-pool = { default-features = false, version = '2.0.0' , git = 'https://github.com/usetech-llc/substrate.git', branch = 'v2.0.0_release' }
sp-version = { default-features = false, version = '2.0.0' , git = 'https://github.com/usetech-llc/substrate.git', branch = 'v2.0.0_release' }
+pallet-membership = { version = "2.0.0", default-features = false, git = 'https://github.com/usetech-llc/substrate.git', branch = 'v2.0.0_release' }
+pallet-collective = { default-features = false, version = '2.0.0' , git = 'https://github.com/usetech-llc/substrate.git', branch = 'v2.0.0_release' }
+pallet-democracy = { default-features = false, version = '2.0.0' , git = 'https://github.com/usetech-llc/substrate.git', branch = 'v2.0.0_release' }
+pallet-elections-phragmen = { version = "2.0.0", default-features = false, git = 'https://github.com/usetech-llc/substrate.git', branch = 'v2.0.0_release' }
+pallet-treasury = { version = "2.0.0", default-features = false, git = 'https://github.com/usetech-llc/substrate.git', branch = 'v2.0.0_release' }
+pallet-scheduler = { version = "2.0.0", default-features = false, git = 'https://github.com/usetech-llc/substrate.git', branch = 'v2.0.0_release' }
+
[features]
default = ['std']
runtime-benchmarks = [
@@ -100,4 +107,11 @@
'sp-std/std',
'sp-transaction-pool/std',
'sp-version/std',
+
+ 'pallet-collective/std',
+ 'pallet-democracy/std',
+ 'pallet-elections-phragmen/std',
+ 'pallet-membership/std',
+ 'pallet-treasury/std',
+ 'pallet-scheduler/std',
]
runtime/src/lib.rsdiffbeforeafterboth1//! The Substrate Node Template runtime. This can be compiled with `#[no_std]`, ready for Wasm.23#![cfg_attr(not(feature = "std"), no_std)]4// `construct_runtime!` does a lot of recursion and requires us to increase the limit to 256.5#![recursion_limit = "256"]67// Make the WASM binary available.8#[cfg(feature = "std")]9include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));1011use pallet_contracts_rpc_runtime_api::ContractExecResult;12use pallet_grandpa::fg_primitives;13use pallet_grandpa::{AuthorityId as GrandpaId, AuthorityList as GrandpaAuthorityList};14use sp_api::impl_runtime_apis;15use sp_consensus_aura::sr25519::AuthorityId as AuraId;16use sp_core::{crypto::KeyTypeId, OpaqueMetadata};17use sp_runtime::{18 create_runtime_str, generic, impl_opaque_keys,19 traits::{20 BlakeTwo256, Block as BlockT, IdentifyAccount, IdentityLookup, NumberFor, Saturating,21 Verify,22 },23 transaction_validity::{TransactionSource, TransactionValidity},24 ApplyExtrinsicResult, MultiSignature,25};26use sp_std::prelude::*;27#[cfg(feature = "std")]28use sp_version::NativeVersion;29use sp_version::RuntimeVersion;3031// A few exports that help ease life for downstream crates.32pub use pallet_balances::Call as BalancesCall;33pub use pallet_contracts::Schedule as ContractsSchedule;34pub use frame_support::{35 construct_runtime,36 dispatch::DispatchResult,37 parameter_types,38 traits::{39 Currency, ExistenceRequirement, Get, KeyOwnerProofSystem, OnUnbalanced, Randomness,40 WithdrawReason,41 },42 weights::{43 constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND},44 DispatchInfo, GetDispatchInfo, IdentityFee, Pays, PostDispatchInfo, Weight,45 WeightToFeePolynomial,46 },47 StorageValue,48};49#[cfg(any(feature = "std", test))]50pub use sp_runtime::BuildStorage;51use sp_runtime::Perbill;52use frame_system::{self as system};5354pub use pallet_timestamp::Call as TimestampCall;5556/// Re-export a nft pallet57/// TODO: Check this re-export. Is this safe and good style?58extern crate pallet_nft;59pub use pallet_nft::*;6061/// An index to a block.62pub type BlockNumber = u32;6364/// Alias to 512-bit hash when used in the context of a transaction signature on the chain.65pub type Signature = MultiSignature;6667/// Some way of identifying an account on the chain. We intentionally make it equivalent68/// to the public key of our transaction signing scheme.69pub type AccountId = <<Signature as Verify>::Signer as IdentifyAccount>::AccountId;7071/// The type for looking up accounts. We don't expect more than 4 billion of them, but you72/// never know...73pub type AccountIndex = u32;7475/// Balance of an account.76pub type Balance = u128;7778/// Index of a transaction in the chain.79pub type Index = u32;8081/// A hash of some data used by the chain.82pub type Hash = sp_core::H256;8384/// Digest item type.85pub type DigestItem = generic::DigestItem<Hash>;8687mod nft_weights;8889/// Opaque types. These are used by the CLI to instantiate machinery that don't need to know90/// the specifics of the runtime. They can then be made to be agnostic over specific formats91/// of data like extrinsics, allowing for them to continue syncing the network through upgrades92/// to even the core data structures.93pub mod opaque {94 use super::*;9596 pub use sp_runtime::OpaqueExtrinsic as UncheckedExtrinsic;9798 /// Opaque block header type.99 pub type Header = generic::Header<BlockNumber, BlakeTwo256>;100 /// Opaque block type.101 pub type Block = generic::Block<Header, UncheckedExtrinsic>;102 /// Opaque block identifier type.103 pub type BlockId = generic::BlockId<Block>;104105 impl_opaque_keys! {106 pub struct SessionKeys {107 pub aura: Aura,108 pub grandpa: Grandpa,109 }110 }111}112113/// This runtime version.114pub const VERSION: RuntimeVersion = RuntimeVersion {115 spec_name: create_runtime_str!("nft"),116 impl_name: create_runtime_str!("nft"),117 authoring_version: 1,118 spec_version: 2,119 impl_version: 1,120 apis: RUNTIME_API_VERSIONS,121 transaction_version: 1,122};123124pub const MILLISECS_PER_BLOCK: u64 = 6000;125126pub const SLOT_DURATION: u64 = MILLISECS_PER_BLOCK;127128// These time units are defined in number of blocks.129pub const MINUTES: BlockNumber = 60_000 / (MILLISECS_PER_BLOCK as BlockNumber);130pub const HOURS: BlockNumber = MINUTES * 60;131pub const DAYS: BlockNumber = HOURS * 24;132133/// The version information used to identify this runtime when compiled natively.134#[cfg(feature = "std")]135pub fn native_version() -> NativeVersion {136 NativeVersion {137 runtime_version: VERSION,138 can_author_with: Default::default(),139 }140}141142parameter_types! {143 pub const BlockHashCount: BlockNumber = 2400;144 /// We allow for 2 seconds of compute with a 6 second average block time.145 pub const MaximumBlockWeight: Weight = 2 * WEIGHT_PER_SECOND;146 pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);147 /// Assume 10% of weight for average on_initialize calls.148 pub MaximumExtrinsicWeight: Weight = AvailableBlockRatio::get()149 .saturating_sub(Perbill::from_percent(10)) * MaximumBlockWeight::get();150 pub const MaximumBlockLength: u32 = 5 * 1024 * 1024;151 pub const Version: RuntimeVersion = VERSION;152}153154impl system::Trait for Runtime {155 /// The basic call filter to use in dispatchable.156 type BaseCallFilter = ();157 /// The identifier used to distinguish between accounts.158 type AccountId = AccountId;159 /// The aggregated dispatch type that is available for extrinsics.160 type Call = Call;161 /// The lookup mechanism to get account ID from whatever is passed in dispatchers.162 type Lookup = IdentityLookup<AccountId>;163 /// The index type for storing how many extrinsics an account has signed.164 type Index = Index;165 /// The index type for blocks.166 type BlockNumber = BlockNumber;167 /// The type for hashing blocks and tries.168 type Hash = Hash;169 /// The hashing algorithm used.170 type Hashing = BlakeTwo256;171 /// The header type.172 type Header = generic::Header<BlockNumber, BlakeTwo256>;173 /// The ubiquitous event type.174 type Event = Event;175 /// The ubiquitous origin type.176 type Origin = Origin;177 /// Maximum number of block number to block hash mappings to keep (oldest pruned first).178 type BlockHashCount = BlockHashCount;179 /// Maximum weight of each block.180 type MaximumBlockWeight = MaximumBlockWeight;181 /// The weight of database operations that the runtime can invoke.182 type DbWeight = RocksDbWeight;183 /// The weight of the overhead invoked on the block import process, independent of the184 /// extrinsics included in that block.185 type BlockExecutionWeight = BlockExecutionWeight;186 /// The base weight of any extrinsic processed by the runtime, independent of the187 /// logic of that extrinsic. (Signature verification, nonce increment, fee, etc...)188 type ExtrinsicBaseWeight = ExtrinsicBaseWeight;189 /// The maximum weight that a single extrinsic of `Normal` dispatch class can have,190 /// idependent of the logic of that extrinsics. (Roughly max block weight - average on191 /// initialize cost).192 type MaximumExtrinsicWeight = MaximumExtrinsicWeight;193 /// Maximum size of all encoded transactions (in bytes) that are allowed in one block.194 type MaximumBlockLength = MaximumBlockLength;195 /// Portion of the block weight that is available to all normal transactions.196 type AvailableBlockRatio = AvailableBlockRatio;197 /// Version of the runtime.198 type Version = Version;199 /// This type is being generated by `construct_runtime!`.200 type PalletInfo = PalletInfo;201 /// What to do if a new account is created.202 type OnNewAccount = ();203 /// What to do if an account is fully reaped from the system.204 type OnKilledAccount = ();205 /// The data to be stored in an account.206 type AccountData = pallet_balances::AccountData<Balance>;207 /// Weight information for the extrinsics of this pallet.208 type SystemWeightInfo = ();209}210211impl pallet_aura::Trait for Runtime {212 type AuthorityId = AuraId;213}214215impl pallet_grandpa::Trait for Runtime {216 type Event = Event;217 type Call = Call;218219 type KeyOwnerProofSystem = ();220221 type KeyOwnerProof =222 <Self::KeyOwnerProofSystem as KeyOwnerProofSystem<(KeyTypeId, GrandpaId)>>::Proof;223224 type KeyOwnerIdentification = <Self::KeyOwnerProofSystem as KeyOwnerProofSystem<(225 KeyTypeId,226 GrandpaId,227 )>>::IdentificationTuple;228229 type HandleEquivocation = ();230231 type WeightInfo = ();232}233234parameter_types! {235 pub const MinimumPeriod: u64 = SLOT_DURATION / 2;236}237238impl pallet_timestamp::Trait for Runtime {239 /// A timestamp: milliseconds since the unix epoch.240 type Moment = u64;241 type OnTimestampSet = Aura;242 type MinimumPeriod = MinimumPeriod;243 type WeightInfo = ();244}245246parameter_types! {247 // pub const ExistentialDeposit: u128 = 500;248 pub const ExistentialDeposit: u128 = 0;249 pub const MaxLocks: u32 = 50;250}251252impl pallet_balances::Trait for Runtime {253 type MaxLocks = MaxLocks;254 /// The type for recording an account's balance.255 type Balance = Balance;256 /// The ubiquitous event type.257 type Event = Event;258 type DustRemoval = ();259 type ExistentialDeposit = ExistentialDeposit;260 type AccountStore = System;261 type WeightInfo = ();262}263264pub const MILLICENTS: Balance = 1_000_000_000;265pub const CENTS: Balance = 1_000 * MILLICENTS;266pub const DOLLARS: Balance = 100 * CENTS;267268parameter_types! {269 pub const TombstoneDeposit: Balance = 16 * MILLICENTS;270 pub const RentByteFee: Balance = 4 * MILLICENTS;271 pub const RentDepositOffset: Balance = 1000 * MILLICENTS;272 pub const SurchargeReward: Balance = 150 * MILLICENTS;273}274275impl pallet_contracts::Trait for Runtime {276 type Time = Timestamp;277 type Randomness = RandomnessCollectiveFlip;278 type Currency = Balances;279 type Event = Event;280 type DetermineContractAddress = pallet_contracts::SimpleAddressDeterminer<Runtime>;281 type TrieIdGenerator = pallet_contracts::TrieIdFromParentCounter<Runtime>;282 type RentPayment = ();283 type SignedClaimHandicap = pallet_contracts::DefaultSignedClaimHandicap;284 type TombstoneDeposit = TombstoneDeposit;285 type StorageSizeOffset = pallet_contracts::DefaultStorageSizeOffset;286 type RentByteFee = RentByteFee;287 type RentDepositOffset = RentDepositOffset;288 type SurchargeReward = SurchargeReward;289 type MaxDepth = pallet_contracts::DefaultMaxDepth;290 type MaxValueSize = pallet_contracts::DefaultMaxValueSize;291 type WeightPrice = pallet_transaction_payment::Module<Self>;292}293294parameter_types! {295 pub const TransactionByteFee: Balance = 10 * MILLICENTS;296}297298impl pallet_transaction_payment::Trait for Runtime {299 type Currency = pallet_balances::Module<Runtime>;300 type OnTransactionPayment = ();301 type TransactionByteFee = TransactionByteFee;302 type WeightToFee = IdentityFee<Balance>;303 type FeeMultiplierUpdate = ();304}305306impl pallet_sudo::Trait for Runtime {307 type Event = Event;308 type Call = Call;309}310311/// Used for the module nft in `./nft.rs`312impl pallet_nft::Trait for Runtime {313 type Event = Event;314 type WeightInfo = nft_weights::WeightInfo;315}316317construct_runtime!(318 pub enum Runtime where319 Block = Block,320 NodeBlock = opaque::Block,321 UncheckedExtrinsic = UncheckedExtrinsic322 {323 System: system::{Module, Call, Config, Storage, Event<T>},324 RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Module, Call, Storage},325 Contracts: pallet_contracts::{Module, Call, Config, Storage, Event<T>},326 Timestamp: pallet_timestamp::{Module, Call, Storage, Inherent},327 Aura: pallet_aura::{Module, Config<T>, Inherent},328 Grandpa: pallet_grandpa::{Module, Call, Storage, Config, Event},329 Balances: pallet_balances::{Module, Call, Storage, Config<T>, Event<T>},330 TransactionPayment: pallet_transaction_payment::{Module, Storage},331 Sudo: pallet_sudo::{Module, Call, Config<T>, Storage, Event<T>},332 Nft: pallet_nft::{Module, Call, Config<T>, Storage, Event<T>},333 }334);335336/// The address format for describing accounts.337pub type Address = AccountId;338/// Block header type as expected by this runtime.339pub type Header = generic::Header<BlockNumber, BlakeTwo256>;340/// Block type as expected by this runtime.341pub type Block = generic::Block<Header, UncheckedExtrinsic>;342/// A Block signed with a Justification343pub type SignedBlock = generic::SignedBlock<Block>;344/// BlockId type as expected by this runtime.345pub type BlockId = generic::BlockId<Block>;346/// The SignedExtension to the basic transaction logic.347pub type SignedExtra = (348 system::CheckSpecVersion<Runtime>,349 system::CheckTxVersion<Runtime>,350 system::CheckGenesis<Runtime>,351 system::CheckEra<Runtime>,352 system::CheckNonce<Runtime>,353 system::CheckWeight<Runtime>,354 pallet_nft::ChargeTransactionPayment<Runtime>,355);356/// Unchecked extrinsic type as expected by this runtime.357pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<Address, Call, Signature, SignedExtra>;358/// Extrinsic type that has already been checked.359pub type CheckedExtrinsic = generic::CheckedExtrinsic<AccountId, Call, SignedExtra>;360/// Executive: handles dispatch to the various modules.361pub type Executive =362 frame_executive::Executive<Runtime, Block, system::ChainContext<Runtime>, Runtime, AllModules>;363364impl_runtime_apis! {365366 impl pallet_contracts_rpc_runtime_api::ContractsApi<Block, AccountId, Balance, BlockNumber>367 for Runtime368 {369 fn call(370 origin: AccountId,371 dest: AccountId,372 value: Balance,373 gas_limit: u64,374 input_data: Vec<u8>,375 ) -> ContractExecResult {376 let (exec_result, gas_consumed) =377 Contracts::bare_call(origin, dest.into(), value, gas_limit, input_data);378 match exec_result {379 Ok(v) => ContractExecResult::Success {380 flags: v.flags.bits(),381 data: v.data,382 gas_consumed: gas_consumed,383 },384 Err(_) => ContractExecResult::Error,385 }386 }387388 fn get_storage(389 address: AccountId,390 key: [u8; 32],391 ) -> pallet_contracts_primitives::GetStorageResult {392 Contracts::get_storage(address, key)393 }394395 fn rent_projection(396 address: AccountId,397 ) -> pallet_contracts_primitives::RentProjectionResult<BlockNumber> {398 Contracts::rent_projection(address)399 }400 }401402 impl sp_api::Core<Block> for Runtime {403 fn version() -> RuntimeVersion {404 VERSION405 }406407 fn execute_block(block: Block) {408 Executive::execute_block(block)409 }410411 fn initialize_block(header: &<Block as BlockT>::Header) {412 Executive::initialize_block(header)413 }414 }415416 impl sp_api::Metadata<Block> for Runtime {417 fn metadata() -> OpaqueMetadata {418 Runtime::metadata().into()419 }420 }421422 impl sp_block_builder::BlockBuilder<Block> for Runtime {423 fn apply_extrinsic(extrinsic: <Block as BlockT>::Extrinsic) -> ApplyExtrinsicResult {424 Executive::apply_extrinsic(extrinsic)425 }426427 fn finalize_block() -> <Block as BlockT>::Header {428 Executive::finalize_block()429 }430431 fn inherent_extrinsics(data: sp_inherents::InherentData) -> Vec<<Block as BlockT>::Extrinsic> {432 data.create_extrinsics()433 }434435 fn check_inherents(436 block: Block,437 data: sp_inherents::InherentData,438 ) -> sp_inherents::CheckInherentsResult {439 data.check_extrinsics(&block)440 }441442 fn random_seed() -> <Block as BlockT>::Hash {443 RandomnessCollectiveFlip::random_seed()444 }445 }446447 impl sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block> for Runtime {448 fn validate_transaction(449 source: TransactionSource,450 tx: <Block as BlockT>::Extrinsic,451 ) -> TransactionValidity {452 Executive::validate_transaction(source, tx)453 }454 }455456 impl sp_offchain::OffchainWorkerApi<Block> for Runtime {457 fn offchain_worker(header: &<Block as BlockT>::Header) {458 Executive::offchain_worker(header)459 }460 }461462 impl sp_consensus_aura::AuraApi<Block, AuraId> for Runtime {463 fn slot_duration() -> u64 {464 Aura::slot_duration()465 }466467 fn authorities() -> Vec<AuraId> {468 Aura::authorities()469 }470 }471472 impl sp_session::SessionKeys<Block> for Runtime {473 fn generate_session_keys(seed: Option<Vec<u8>>) -> Vec<u8> {474 opaque::SessionKeys::generate(seed)475 }476477 fn decode_session_keys(478 encoded: Vec<u8>,479 ) -> Option<Vec<(Vec<u8>, KeyTypeId)>> {480 opaque::SessionKeys::decode_into_raw_public_keys(&encoded)481 }482 }483484 impl fg_primitives::GrandpaApi<Block> for Runtime {485 fn grandpa_authorities() -> GrandpaAuthorityList {486 Grandpa::grandpa_authorities()487 }488489 fn submit_report_equivocation_unsigned_extrinsic(490 _equivocation_proof: fg_primitives::EquivocationProof<491 <Block as BlockT>::Hash,492 NumberFor<Block>,493 >,494 _key_owner_proof: fg_primitives::OpaqueKeyOwnershipProof,495 ) -> Option<()> {496 None497 }498499 fn generate_key_ownership_proof(500 _set_id: fg_primitives::SetId,501 _authority_id: GrandpaId,502 ) -> Option<fg_primitives::OpaqueKeyOwnershipProof> {503 // NOTE: this is the only implementation possible since we've504 // defined our key owner proof type as a bottom type (i.e. a type505 // with no values).506 None507 }508 }509 510 impl frame_system_rpc_runtime_api::AccountNonceApi<Block, AccountId, Index> for Runtime {511 fn account_nonce(account: AccountId) -> Index {512 System::account_nonce(account)513 }514 }515516 impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance> for Runtime {517 fn query_info(518 uxt: <Block as BlockT>::Extrinsic,519 len: u32,520 ) -> pallet_transaction_payment_rpc_runtime_api::RuntimeDispatchInfo<Balance> {521 TransactionPayment::query_info(uxt, len)522 }523 }524525 #[cfg(feature = "runtime-benchmarks")]526 impl frame_benchmarking::Benchmark<Block> for Runtime {527 fn dispatch_benchmark(528 config: frame_benchmarking::BenchmarkConfig529 ) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, sp_runtime::RuntimeString> {530 use frame_benchmarking::{Benchmarking, BenchmarkBatch, add_benchmark, TrackedStorageKey};531532 let whitelist: Vec<TrackedStorageKey> = vec![533 // Alice account534 hex_literal::hex!("d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d").to_vec().into(),535 // // Total Issuance536 // hex_literal::hex!("c2261276cc9d1f8598ea4b6a74b15c2f57c875e4cff74148e4628f264b974c80").to_vec().into(),537 // // Execution Phase538 // hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef7ff553b5a9862a516939d82b3d3d8661a").to_vec().into(),539 // // Event Count540 // hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef70a98fdbe9ce6c55837576c60c7af3850").to_vec().into(),541 // // System Events542 // hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7").to_vec().into(),543 ];544545 let mut batches = Vec::<BenchmarkBatch>::new();546 let params = (&config, &whitelist);547548 add_benchmark!(params, batches, pallet_nft, Nft);549550 if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) }551 Ok(batches)552 }553 }554}1//! The Substrate Node Template runtime. This can be compiled with `#[no_std]`, ready for Wasm.23#![cfg_attr(not(feature = "std"), no_std)]4// `construct_runtime!` does a lot of recursion and requires us to increase the limit to 256.5#![recursion_limit = "256"]67// Make the WASM binary available.8#[cfg(feature = "std")]9include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));1011use pallet_contracts_rpc_runtime_api::ContractExecResult;12use pallet_grandpa::fg_primitives;13use pallet_grandpa::{AuthorityId as GrandpaId, AuthorityList as GrandpaAuthorityList};14use sp_api::impl_runtime_apis;15use sp_consensus_aura::sr25519::AuthorityId as AuraId;16use sp_core::{17 crypto::KeyTypeId, 18 OpaqueMetadata, 19 u32_trait::{_1, _2, _3, _4},20};21use sp_runtime::{22 create_runtime_str, generic, impl_opaque_keys,23 traits::{24 Convert, BlakeTwo256, Block as BlockT, IdentifyAccount, 25 IdentityLookup, NumberFor, Saturating, Verify,26 },27 transaction_validity::{TransactionSource, TransactionValidity},28 ApplyExtrinsicResult, MultiSignature,29};30use sp_std::prelude::*;31#[cfg(feature = "std")]32use sp_version::NativeVersion;33use sp_version::RuntimeVersion;3435// A few exports that help ease life for downstream crates.36pub use pallet_balances::Call as BalancesCall;37pub use pallet_contracts::Schedule as ContractsSchedule;38pub use frame_support::{39 construct_runtime,40 dispatch::DispatchResult,41 parameter_types,42 traits::{43 Currency, ExistenceRequirement, Get, KeyOwnerProofSystem, OnUnbalanced, Randomness,44 WithdrawReason, LockIdentifier,45 },46 weights::{47 constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND},48 DispatchInfo, GetDispatchInfo, IdentityFee, Pays, PostDispatchInfo, Weight,49 WeightToFeePolynomial,50 },51 StorageValue,52};53#[cfg(any(feature = "std", test))]54pub use sp_runtime::BuildStorage;55use sp_runtime:: { Perbill, Permill, Percent, ModuleId };56use frame_system::{self as system, EnsureRoot, EnsureOneOf };5758pub use pallet_timestamp::Call as TimestampCall;5960/// Struct that handles the conversion of Balance -> `u64`. This is used for61/// staking's election calculation.62pub struct CurrencyToVoteHandler;6364impl CurrencyToVoteHandler {65 fn factor() -> Balance {66 (Balances::total_issuance() / u64::max_value() as Balance).max(1)67 }68}6970impl Convert<Balance, u64> for CurrencyToVoteHandler {71 fn convert(x: Balance) -> u64 {72 (x / Self::factor()) as u6473 }74}7576impl Convert<u128, Balance> for CurrencyToVoteHandler {77 fn convert(x: u128) -> Balance {78 x * Self::factor()79 }80}8182/// Re-export a nft pallet83/// TODO: Check this re-export. Is this safe and good style?84extern crate pallet_nft;85pub use pallet_nft::*;8687/// An index to a block.88pub type BlockNumber = u32;8990/// Alias to 512-bit hash when used in the context of a transaction signature on the chain.91pub type Signature = MultiSignature;9293/// Some way of identifying an account on the chain. We intentionally make it equivalent94/// to the public key of our transaction signing scheme.95pub type AccountId = <<Signature as Verify>::Signer as IdentifyAccount>::AccountId;9697/// The type for looking up accounts. We don't expect more than 4 billion of them, but you98/// never know...99pub type AccountIndex = u32;100101/// Balance of an account.102pub type Balance = u128;103104/// Index of a transaction in the chain.105pub type Index = u32;106107/// A hash of some data used by the chain.108pub type Hash = sp_core::H256;109110/// Digest item type.111pub type DigestItem = generic::DigestItem<Hash>;112113mod nft_weights;114115/// Opaque types. These are used by the CLI to instantiate machinery that don't need to know116/// the specifics of the runtime. They can then be made to be agnostic over specific formats117/// of data like extrinsics, allowing for them to continue syncing the network through upgrades118/// to even the core data structures.119pub mod opaque {120 use super::*;121122 pub use sp_runtime::OpaqueExtrinsic as UncheckedExtrinsic;123124 /// Opaque block header type.125 pub type Header = generic::Header<BlockNumber, BlakeTwo256>;126 /// Opaque block type.127 pub type Block = generic::Block<Header, UncheckedExtrinsic>;128 /// Opaque block identifier type.129 pub type BlockId = generic::BlockId<Block>;130131 impl_opaque_keys! {132 pub struct SessionKeys {133 pub aura: Aura,134 pub grandpa: Grandpa,135 }136 }137}138139/// This runtime version.140pub const VERSION: RuntimeVersion = RuntimeVersion {141 spec_name: create_runtime_str!("nft"),142 impl_name: create_runtime_str!("nft"),143 authoring_version: 1,144 spec_version: 2,145 impl_version: 1,146 apis: RUNTIME_API_VERSIONS,147 transaction_version: 1,148};149150pub const MILLISECS_PER_BLOCK: u64 = 6000;151152pub const SLOT_DURATION: u64 = MILLISECS_PER_BLOCK;153154// These time units are defined in number of blocks.155pub const MINUTES: BlockNumber = 60_000 / (MILLISECS_PER_BLOCK as BlockNumber);156pub const HOURS: BlockNumber = MINUTES * 60;157pub const DAYS: BlockNumber = HOURS * 24;158159/// The version information used to identify this runtime when compiled natively.160#[cfg(feature = "std")]161pub fn native_version() -> NativeVersion {162 NativeVersion {163 runtime_version: VERSION,164 can_author_with: Default::default(),165 }166}167168parameter_types! {169 pub const BlockHashCount: BlockNumber = 2400;170 /// We allow for 2 seconds of compute with a 6 second average block time.171 pub const MaximumBlockWeight: Weight = 2 * WEIGHT_PER_SECOND;172 pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);173 /// Assume 10% of weight for average on_initialize calls.174 pub MaximumExtrinsicWeight: Weight = AvailableBlockRatio::get()175 .saturating_sub(Perbill::from_percent(10)) * MaximumBlockWeight::get();176 pub const MaximumBlockLength: u32 = 5 * 1024 * 1024;177 pub const Version: RuntimeVersion = VERSION;178}179180impl system::Trait for Runtime {181 /// The basic call filter to use in dispatchable.182 type BaseCallFilter = ();183 /// The identifier used to distinguish between accounts.184 type AccountId = AccountId;185 /// The aggregated dispatch type that is available for extrinsics.186 type Call = Call;187 /// The lookup mechanism to get account ID from whatever is passed in dispatchers.188 type Lookup = IdentityLookup<AccountId>;189 /// The index type for storing how many extrinsics an account has signed.190 type Index = Index;191 /// The index type for blocks.192 type BlockNumber = BlockNumber;193 /// The type for hashing blocks and tries.194 type Hash = Hash;195 /// The hashing algorithm used.196 type Hashing = BlakeTwo256;197 /// The header type.198 type Header = generic::Header<BlockNumber, BlakeTwo256>;199 /// The ubiquitous event type.200 type Event = Event;201 /// The ubiquitous origin type.202 type Origin = Origin;203 /// Maximum number of block number to block hash mappings to keep (oldest pruned first).204 type BlockHashCount = BlockHashCount;205 /// Maximum weight of each block.206 type MaximumBlockWeight = MaximumBlockWeight;207 /// The weight of database operations that the runtime can invoke.208 type DbWeight = RocksDbWeight;209 /// The weight of the overhead invoked on the block import process, independent of the210 /// extrinsics included in that block.211 type BlockExecutionWeight = BlockExecutionWeight;212 /// The base weight of any extrinsic processed by the runtime, independent of the213 /// logic of that extrinsic. (Signature verification, nonce increment, fee, etc...)214 type ExtrinsicBaseWeight = ExtrinsicBaseWeight;215 /// The maximum weight that a single extrinsic of `Normal` dispatch class can have,216 /// idependent of the logic of that extrinsics. (Roughly max block weight - average on217 /// initialize cost).218 type MaximumExtrinsicWeight = MaximumExtrinsicWeight;219 /// Maximum size of all encoded transactions (in bytes) that are allowed in one block.220 type MaximumBlockLength = MaximumBlockLength;221 /// Portion of the block weight that is available to all normal transactions.222 type AvailableBlockRatio = AvailableBlockRatio;223 /// Version of the runtime.224 type Version = Version;225 /// This type is being generated by `construct_runtime!`.226 type PalletInfo = PalletInfo;227 /// What to do if a new account is created.228 type OnNewAccount = ();229 /// What to do if an account is fully reaped from the system.230 type OnKilledAccount = ();231 /// The data to be stored in an account.232 type AccountData = pallet_balances::AccountData<Balance>;233 /// Weight information for the extrinsics of this pallet.234 type SystemWeightInfo = ();235}236237impl pallet_aura::Trait for Runtime {238 type AuthorityId = AuraId;239}240241impl pallet_grandpa::Trait for Runtime {242 type Event = Event;243 type Call = Call;244245 type KeyOwnerProofSystem = ();246247 type KeyOwnerProof =248 <Self::KeyOwnerProofSystem as KeyOwnerProofSystem<(KeyTypeId, GrandpaId)>>::Proof;249250 type KeyOwnerIdentification = <Self::KeyOwnerProofSystem as KeyOwnerProofSystem<(251 KeyTypeId,252 GrandpaId,253 )>>::IdentificationTuple;254255 type HandleEquivocation = ();256257 type WeightInfo = ();258}259260parameter_types! {261 pub const MinimumPeriod: u64 = SLOT_DURATION / 2;262}263264impl pallet_timestamp::Trait for Runtime {265 /// A timestamp: milliseconds since the unix epoch.266 type Moment = u64;267 type OnTimestampSet = Aura;268 type MinimumPeriod = MinimumPeriod;269 type WeightInfo = ();270}271272parameter_types! {273 // pub const ExistentialDeposit: u128 = 500;274 pub const ExistentialDeposit: u128 = 0;275 pub const MaxLocks: u32 = 50;276}277278impl pallet_balances::Trait for Runtime {279 type MaxLocks = MaxLocks;280 /// The type for recording an account's balance.281 type Balance = Balance;282 /// The ubiquitous event type.283 type Event = Event;284 type DustRemoval = ();285 type ExistentialDeposit = ExistentialDeposit;286 type AccountStore = System;287 type WeightInfo = ();288}289290pub const MILLICENTS: Balance = 1_000_000_000;291pub const CENTS: Balance = 1_000 * MILLICENTS;292pub const DOLLARS: Balance = 100 * CENTS;293294parameter_types! {295 pub const TombstoneDeposit: Balance = 16 * MILLICENTS;296 pub const RentByteFee: Balance = 4 * MILLICENTS;297 pub const RentDepositOffset: Balance = 1000 * MILLICENTS;298 pub const SurchargeReward: Balance = 150 * MILLICENTS;299}300301impl pallet_contracts::Trait for Runtime {302 type Time = Timestamp;303 type Randomness = RandomnessCollectiveFlip;304 type Currency = Balances;305 type Event = Event;306 type DetermineContractAddress = pallet_contracts::SimpleAddressDeterminer<Runtime>;307 type TrieIdGenerator = pallet_contracts::TrieIdFromParentCounter<Runtime>;308 type RentPayment = ();309 type SignedClaimHandicap = pallet_contracts::DefaultSignedClaimHandicap;310 type TombstoneDeposit = TombstoneDeposit;311 type StorageSizeOffset = pallet_contracts::DefaultStorageSizeOffset;312 type RentByteFee = RentByteFee;313 type RentDepositOffset = RentDepositOffset;314 type SurchargeReward = SurchargeReward;315 type MaxDepth = pallet_contracts::DefaultMaxDepth;316 type MaxValueSize = pallet_contracts::DefaultMaxValueSize;317 type WeightPrice = pallet_transaction_payment::Module<Self>;318}319320parameter_types! {321 pub const TransactionByteFee: Balance = 10 * MILLICENTS;322}323324impl pallet_transaction_payment::Trait for Runtime {325 type Currency = pallet_balances::Module<Runtime>;326 type OnTransactionPayment = ();327 type TransactionByteFee = TransactionByteFee;328 type WeightToFee = IdentityFee<Balance>;329 type FeeMultiplierUpdate = ();330}331332parameter_types! {333 pub MaximumSchedulerWeight: Weight = Perbill::from_percent(80) * MaximumBlockWeight::get();334 pub const MaxScheduledPerBlock: u32 = 50;335}336337impl pallet_scheduler::Trait for Runtime {338 type Event = Event;339 type Origin = Origin;340 type PalletsOrigin = OriginCaller;341 type Call = Call;342 type MaximumWeight = MaximumSchedulerWeight;343 type ScheduleOrigin = EnsureRoot<AccountId>;344 type MaxScheduledPerBlock = MaxScheduledPerBlock;345 type WeightInfo = ();346}347348parameter_types! {349 pub const ProposalBond: Permill = Permill::from_percent(5);350 pub const ProposalBondMinimum: Balance = 1 * DOLLARS;351 pub const SpendPeriod: BlockNumber = 1 * DAYS;352 pub const Burn: Permill = Permill::from_percent(50);353 pub const TipCountdown: BlockNumber = 1 * DAYS;354 pub const TipFindersFee: Percent = Percent::from_percent(20);355 pub const TipReportDepositBase: Balance = 1 * DOLLARS;356 pub const DataDepositPerByte: Balance = 1 * CENTS;357 pub const BountyDepositBase: Balance = 1 * DOLLARS;358 pub const BountyDepositPayoutDelay: BlockNumber = 1 * DAYS;359 pub const TreasuryModuleId: ModuleId = ModuleId(*b"py/trsry");360 pub const BountyUpdatePeriod: BlockNumber = 14 * DAYS;361 pub const MaximumReasonLength: u32 = 16384;362 pub const BountyCuratorDeposit: Permill = Permill::from_percent(50);363 pub const BountyValueMinimum: Balance = 5 * DOLLARS;364}365366impl pallet_treasury::Trait for Runtime {367 type ModuleId = TreasuryModuleId;368 type Currency = Balances;369 type ApproveOrigin = 370 EnsureOneOf<371 AccountId,372 EnsureRoot<AccountId>,373 pallet_collective::EnsureMembers<_4, AccountId, CouncilCollective>374 >;375 type RejectOrigin = 376 EnsureOneOf<377 AccountId,378 EnsureRoot<AccountId>,379 pallet_collective::EnsureMembers<_2, AccountId, CouncilCollective>380 >;381 type Tippers = Elections;382 type TipCountdown = TipCountdown;383 type TipFindersFee = TipFindersFee;384 type TipReportDepositBase = TipReportDepositBase;385 type DataDepositPerByte = DataDepositPerByte;386 type Event = Event;387 type OnSlash = ();388 type ProposalBond = ProposalBond;389 type ProposalBondMinimum = ProposalBondMinimum;390 type SpendPeriod = SpendPeriod;391 type Burn = Burn;392 type BountyDepositBase = BountyDepositBase;393 type BountyDepositPayoutDelay = BountyDepositPayoutDelay;394 type BountyUpdatePeriod = BountyUpdatePeriod;395 type BountyCuratorDeposit = BountyCuratorDeposit;396 type BountyValueMinimum = BountyValueMinimum;397 type MaximumReasonLength = MaximumReasonLength;398 type BurnDestination = ();399 type WeightInfo = ();400}401402parameter_types! {403 pub const TechnicalMotionDuration: BlockNumber = 5 * DAYS;404 pub const TechnicalMaxProposals: u32 = 100;405 pub const TechnicalMaxMembers: u32 = 100;406}407408type TechnicalCollective = pallet_collective::Instance2;409impl pallet_collective::Trait<TechnicalCollective> for Runtime {410 type Origin = Origin;411 type Proposal = Call;412 type Event = Event;413 type MotionDuration = TechnicalMotionDuration;414 type MaxProposals = TechnicalMaxProposals;415 type MaxMembers = TechnicalMaxMembers;416 type DefaultVote = pallet_collective::PrimeDefaultVote;417 type WeightInfo = ();418}419420parameter_types! {421 pub const LaunchPeriod: BlockNumber = 28 * 24 * 60 * MINUTES;422 pub const VotingPeriod: BlockNumber = 28 * 24 * 60 * MINUTES;423 pub const FastTrackVotingPeriod: BlockNumber = 3 * 24 * 60 * MINUTES;424 pub const InstantAllowed: bool = true;425 pub const MinimumDeposit: Balance = 100 * DOLLARS;426 pub const EnactmentPeriod: BlockNumber = 30 * 24 * 60 * MINUTES;427 pub const CooloffPeriod: BlockNumber = 28 * 24 * 60 * MINUTES;428 // One cent: $10,000 / MB429 pub const PreimageByteDeposit: Balance = 1 * CENTS;430 pub const MaxVotes: u32 = 100;431}432433impl pallet_democracy::Trait for Runtime {434 type Proposal = Call;435 type Event = Event;436 type Currency = Balances;437 type EnactmentPeriod = EnactmentPeriod;438 type LaunchPeriod = LaunchPeriod;439 type VotingPeriod = VotingPeriod;440 type MinimumDeposit = MinimumDeposit;441 /// A straight majority of the council can decide what their next motion is.442 type ExternalOrigin = pallet_collective::EnsureProportionAtLeast<_1, _2, AccountId, CouncilCollective>;443 /// A super-majority can have the next scheduled referendum be a straight majority-carries vote.444 type ExternalMajorityOrigin = pallet_collective::EnsureProportionAtLeast<_3, _4, AccountId, CouncilCollective>;445 /// A unanimous council can have the next scheduled referendum be a straight default-carries446 /// (NTB) vote.447 type ExternalDefaultOrigin = pallet_collective::EnsureProportionAtLeast<_1, _1, AccountId, CouncilCollective>;448 /// Two thirds of the technical committee can have an ExternalMajority/ExternalDefault vote449 /// be tabled immediately and with a shorter voting/enactment period.450 type FastTrackOrigin = pallet_collective::EnsureProportionAtLeast<_2, _3, AccountId, TechnicalCollective>;451 type InstantOrigin = pallet_collective::EnsureProportionAtLeast<_1, _1, AccountId, TechnicalCollective>;452 type InstantAllowed = InstantAllowed;453 type FastTrackVotingPeriod = FastTrackVotingPeriod;454 // To cancel a proposal which has been passed, 2/3 of the council must agree to it.455 type CancellationOrigin = EnsureOneOf<456 AccountId,457 EnsureRoot<AccountId>,458 pallet_collective::EnsureProportionAtLeast<_2, _3, AccountId, CouncilCollective>,459 >;460 // Any single technical committee member may veto a coming council proposal, however they can461 // only do it once and it lasts only for the cooloff period.462 type VetoOrigin = pallet_collective::EnsureMember<AccountId, TechnicalCollective>;463 type CooloffPeriod = CooloffPeriod;464 type PreimageByteDeposit = PreimageByteDeposit;465 type OperationalPreimageOrigin = pallet_collective::EnsureMember<AccountId, CouncilCollective>;466 type Slash = Treasury;467 type Scheduler = Scheduler;468 type PalletsOrigin = OriginCaller;469 type MaxVotes = MaxVotes;470 type WeightInfo = (); //weights::pallet_democracy::WeightInfo;471}472473parameter_types! {474 pub const CouncilMotionDuration: BlockNumber = 5 * DAYS;475 pub const CouncilMaxProposals: u32 = 100;476 pub const CouncilMaxMembers: u32 = 100;477}478479type CouncilCollective = pallet_collective::Instance1;480impl pallet_collective::Trait<CouncilCollective> for Runtime {481 type Origin = Origin;482 type Proposal = Call;483 type Event = Event;484 type MotionDuration = CouncilMotionDuration;485 type MaxProposals = CouncilMaxProposals;486 type MaxMembers = CouncilMaxMembers;487 type DefaultVote = pallet_collective::PrimeDefaultVote;488 type WeightInfo = (); //weights::pallet_collective::WeightInfo;489}490491parameter_types! {492 pub const CandidacyBond: Balance = 10 * DOLLARS;493 pub const VotingBond: Balance = 1 * DOLLARS;494 pub const TermDuration: BlockNumber = 7 * DAYS;495 pub const DesiredMembers: u32 = 13;496 pub const DesiredRunnersUp: u32 = 7;497 pub const ElectionsPhragmenModuleId: LockIdentifier = *b"phrelect";498}499500// Make sure that there are no more than `MaxMembers` members elected via elections-phragmen.501// const_assert!(DesiredMembers::get() <= CouncilMaxMembers::get());502503impl pallet_elections_phragmen::Trait for Runtime {504 type Event = Event;505 type ModuleId = ElectionsPhragmenModuleId;506 type Currency = Balances;507 type ChangeMembers = Council;508 // NOTE: this implies that council's genesis members cannot be set directly and must come from509 // this module.510 type InitializeMembers = Council;511 type CurrencyToVote = CurrencyToVoteHandler;512 type CandidacyBond = CandidacyBond;513 type VotingBond = VotingBond;514 type LoserCandidate = ();515 type BadReport = ();516 type KickedMember = ();517 type DesiredMembers = DesiredMembers;518 type DesiredRunnersUp = DesiredRunnersUp;519 type TermDuration = TermDuration;520 type WeightInfo = (); //weights::pallet_elections_phragmen::WeightInfo;521}522523type EnsureRootOrHalfCouncil = EnsureOneOf<524 AccountId,525 EnsureRoot<AccountId>,526 pallet_collective::EnsureProportionMoreThan<_1, _2, AccountId, CouncilCollective>527>;528impl pallet_membership::Trait for Runtime {529 type Event = Event;530 type AddOrigin = EnsureRootOrHalfCouncil;531 type RemoveOrigin = EnsureRootOrHalfCouncil;532 type SwapOrigin = EnsureRootOrHalfCouncil;533 type ResetOrigin = EnsureRootOrHalfCouncil;534 type PrimeOrigin = EnsureRootOrHalfCouncil;535 type MembershipInitialized = TechnicalCommittee;536 type MembershipChanged = TechnicalCommittee;537}538539impl pallet_sudo::Trait for Runtime {540 type Event = Event;541 type Call = Call;542}543544/// Used for the module nft in `./nft.rs`545impl pallet_nft::Trait for Runtime {546 type Event = Event;547 type WeightInfo = nft_weights::WeightInfo;548}549550construct_runtime!(551 pub enum Runtime where552 Block = Block,553 NodeBlock = opaque::Block,554 UncheckedExtrinsic = UncheckedExtrinsic555 {556 System: system::{Module, Call, Config, Storage, Event<T>},557 RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Module, Call, Storage},558 Contracts: pallet_contracts::{Module, Call, Config, Storage, Event<T>},559 Timestamp: pallet_timestamp::{Module, Call, Storage, Inherent},560 Aura: pallet_aura::{Module, Config<T>, Inherent},561 Grandpa: pallet_grandpa::{Module, Call, Storage, Config, Event},562 Balances: pallet_balances::{Module, Call, Storage, Config<T>, Event<T>},563 TransactionPayment: pallet_transaction_payment::{Module, Storage},564 Sudo: pallet_sudo::{Module, Call, Config<T>, Storage, Event<T>},565 Nft: pallet_nft::{Module, Call, Config<T>, Storage, Event<T>},566567 Democracy: pallet_democracy::{Module, Call, Storage, Config, Event<T>},568 Council: pallet_collective::<Instance1>::{Module, Call, Storage, Origin<T>, Event<T>, Config<T>},569 TechnicalCommittee: pallet_collective::<Instance2>::{Module, Call, Storage, Origin<T>, Event<T>, Config<T>},570 Elections: pallet_elections_phragmen::{Module, Call, Storage, Event<T>, Config<T>}, 571 TechnicalMembership: pallet_membership::{Module, Call, Storage, Event<T>, Config<T>},572 Treasury: pallet_treasury::{Module, Call, Storage, Config, Event<T>},573 Scheduler: pallet_scheduler::{Module, Call, Storage, Event<T>},574 }575);576577/// The address format for describing accounts.578pub type Address = AccountId;579/// Block header type as expected by this runtime.580pub type Header = generic::Header<BlockNumber, BlakeTwo256>;581/// Block type as expected by this runtime.582pub type Block = generic::Block<Header, UncheckedExtrinsic>;583/// A Block signed with a Justification584pub type SignedBlock = generic::SignedBlock<Block>;585/// BlockId type as expected by this runtime.586pub type BlockId = generic::BlockId<Block>;587/// The SignedExtension to the basic transaction logic.588pub type SignedExtra = (589 system::CheckSpecVersion<Runtime>,590 system::CheckTxVersion<Runtime>,591 system::CheckGenesis<Runtime>,592 system::CheckEra<Runtime>,593 system::CheckNonce<Runtime>,594 system::CheckWeight<Runtime>,595 pallet_nft::ChargeTransactionPayment<Runtime>,596);597/// Unchecked extrinsic type as expected by this runtime.598pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<Address, Call, Signature, SignedExtra>;599/// Extrinsic type that has already been checked.600pub type CheckedExtrinsic = generic::CheckedExtrinsic<AccountId, Call, SignedExtra>;601/// Executive: handles dispatch to the various modules.602pub type Executive =603 frame_executive::Executive<Runtime, Block, system::ChainContext<Runtime>, Runtime, AllModules>;604605impl_runtime_apis! {606607 impl pallet_contracts_rpc_runtime_api::ContractsApi<Block, AccountId, Balance, BlockNumber>608 for Runtime609 {610 fn call(611 origin: AccountId,612 dest: AccountId,613 value: Balance,614 gas_limit: u64,615 input_data: Vec<u8>,616 ) -> ContractExecResult {617 let (exec_result, gas_consumed) =618 Contracts::bare_call(origin, dest.into(), value, gas_limit, input_data);619 match exec_result {620 Ok(v) => ContractExecResult::Success {621 flags: v.flags.bits(),622 data: v.data,623 gas_consumed: gas_consumed,624 },625 Err(_) => ContractExecResult::Error,626 }627 }628629 fn get_storage(630 address: AccountId,631 key: [u8; 32],632 ) -> pallet_contracts_primitives::GetStorageResult {633 Contracts::get_storage(address, key)634 }635636 fn rent_projection(637 address: AccountId,638 ) -> pallet_contracts_primitives::RentProjectionResult<BlockNumber> {639 Contracts::rent_projection(address)640 }641 }642643 impl sp_api::Core<Block> for Runtime {644 fn version() -> RuntimeVersion {645 VERSION646 }647648 fn execute_block(block: Block) {649 Executive::execute_block(block)650 }651652 fn initialize_block(header: &<Block as BlockT>::Header) {653 Executive::initialize_block(header)654 }655 }656657 impl sp_api::Metadata<Block> for Runtime {658 fn metadata() -> OpaqueMetadata {659 Runtime::metadata().into()660 }661 }662663 impl sp_block_builder::BlockBuilder<Block> for Runtime {664 fn apply_extrinsic(extrinsic: <Block as BlockT>::Extrinsic) -> ApplyExtrinsicResult {665 Executive::apply_extrinsic(extrinsic)666 }667668 fn finalize_block() -> <Block as BlockT>::Header {669 Executive::finalize_block()670 }671672 fn inherent_extrinsics(data: sp_inherents::InherentData) -> Vec<<Block as BlockT>::Extrinsic> {673 data.create_extrinsics()674 }675676 fn check_inherents(677 block: Block,678 data: sp_inherents::InherentData,679 ) -> sp_inherents::CheckInherentsResult {680 data.check_extrinsics(&block)681 }682683 fn random_seed() -> <Block as BlockT>::Hash {684 RandomnessCollectiveFlip::random_seed()685 }686 }687688 impl sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block> for Runtime {689 fn validate_transaction(690 source: TransactionSource,691 tx: <Block as BlockT>::Extrinsic,692 ) -> TransactionValidity {693 Executive::validate_transaction(source, tx)694 }695 }696697 impl sp_offchain::OffchainWorkerApi<Block> for Runtime {698 fn offchain_worker(header: &<Block as BlockT>::Header) {699 Executive::offchain_worker(header)700 }701 }702703 impl sp_consensus_aura::AuraApi<Block, AuraId> for Runtime {704 fn slot_duration() -> u64 {705 Aura::slot_duration()706 }707708 fn authorities() -> Vec<AuraId> {709 Aura::authorities()710 }711 }712713 impl sp_session::SessionKeys<Block> for Runtime {714 fn generate_session_keys(seed: Option<Vec<u8>>) -> Vec<u8> {715 opaque::SessionKeys::generate(seed)716 }717718 fn decode_session_keys(719 encoded: Vec<u8>,720 ) -> Option<Vec<(Vec<u8>, KeyTypeId)>> {721 opaque::SessionKeys::decode_into_raw_public_keys(&encoded)722 }723 }724725 impl fg_primitives::GrandpaApi<Block> for Runtime {726 fn grandpa_authorities() -> GrandpaAuthorityList {727 Grandpa::grandpa_authorities()728 }729730 fn submit_report_equivocation_unsigned_extrinsic(731 _equivocation_proof: fg_primitives::EquivocationProof<732 <Block as BlockT>::Hash,733 NumberFor<Block>,734 >,735 _key_owner_proof: fg_primitives::OpaqueKeyOwnershipProof,736 ) -> Option<()> {737 None738 }739740 fn generate_key_ownership_proof(741 _set_id: fg_primitives::SetId,742 _authority_id: GrandpaId,743 ) -> Option<fg_primitives::OpaqueKeyOwnershipProof> {744 // NOTE: this is the only implementation possible since we've745 // defined our key owner proof type as a bottom type (i.e. a type746 // with no values).747 None748 }749 }750 751 impl frame_system_rpc_runtime_api::AccountNonceApi<Block, AccountId, Index> for Runtime {752 fn account_nonce(account: AccountId) -> Index {753 System::account_nonce(account)754 }755 }756757 impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance> for Runtime {758 fn query_info(759 uxt: <Block as BlockT>::Extrinsic,760 len: u32,761 ) -> pallet_transaction_payment_rpc_runtime_api::RuntimeDispatchInfo<Balance> {762 TransactionPayment::query_info(uxt, len)763 }764 }765766 #[cfg(feature = "runtime-benchmarks")]767 impl frame_benchmarking::Benchmark<Block> for Runtime {768 fn dispatch_benchmark(769 config: frame_benchmarking::BenchmarkConfig770 ) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, sp_runtime::RuntimeString> {771 use frame_benchmarking::{Benchmarking, BenchmarkBatch, add_benchmark, TrackedStorageKey};772773 let whitelist: Vec<TrackedStorageKey> = vec![774 // Alice account775 hex_literal::hex!("d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d").to_vec().into(),776 // // Total Issuance777 // hex_literal::hex!("c2261276cc9d1f8598ea4b6a74b15c2f57c875e4cff74148e4628f264b974c80").to_vec().into(),778 // // Execution Phase779 // hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef7ff553b5a9862a516939d82b3d3d8661a").to_vec().into(),780 // // Event Count781 // hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef70a98fdbe9ce6c55837576c60c7af3850").to_vec().into(),782 // // System Events783 // hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7").to_vec().into(),784 ];785786 let mut batches = Vec::<BenchmarkBatch>::new();787 let params = (&config, &whitelist);788789 add_benchmark!(params, batches, pallet_nft, Nft);790791 if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) }792 Ok(batches)793 }794 }795}