123#![cfg_attr(not(feature = "std"), no_std)]45#![recursion_limit = "256"]678#[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;303132pub 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;55565758extern crate pallet_nft;59pub use pallet_nft::*;606162pub type BlockNumber = u32;636465pub type Signature = MultiSignature;66676869pub type AccountId = <<Signature as Verify>::Signer as IdentifyAccount>::AccountId;70717273pub type AccountIndex = u32;747576pub type Balance = u128;777879pub type Index = u32;808182pub type Hash = sp_core::H256;838485pub type DigestItem = generic::DigestItem<Hash>;86878889909192pub mod opaque {93 use super::*;9495 pub use sp_runtime::OpaqueExtrinsic as UncheckedExtrinsic;9697 98 pub type Header = generic::Header<BlockNumber, BlakeTwo256>;99 100 pub type Block = generic::Block<Header, UncheckedExtrinsic>;101 102 pub type BlockId = generic::BlockId<Block>;103104 impl_opaque_keys! {105 pub struct SessionKeys {106 pub aura: Aura,107 pub grandpa: Grandpa,108 }109 }110}111112113pub const VERSION: RuntimeVersion = RuntimeVersion {114 spec_name: create_runtime_str!("nft"),115 impl_name: create_runtime_str!("nft"),116 authoring_version: 1,117 spec_version: 2,118 impl_version: 1,119 apis: RUNTIME_API_VERSIONS,120 transaction_version: 1,121};122123pub const MILLISECS_PER_BLOCK: u64 = 6000;124125pub const SLOT_DURATION: u64 = MILLISECS_PER_BLOCK;126127128pub const MINUTES: BlockNumber = 60_000 / (MILLISECS_PER_BLOCK as BlockNumber);129pub const HOURS: BlockNumber = MINUTES * 60;130pub const DAYS: BlockNumber = HOURS * 24;131132133#[cfg(feature = "std")]134pub fn native_version() -> NativeVersion {135 NativeVersion {136 runtime_version: VERSION,137 can_author_with: Default::default(),138 }139}140141parameter_types! {142 pub const BlockHashCount: BlockNumber = 2400;143 144 pub const MaximumBlockWeight: Weight = 2 * WEIGHT_PER_SECOND;145 pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);146 147 pub MaximumExtrinsicWeight: Weight = AvailableBlockRatio::get()148 .saturating_sub(Perbill::from_percent(10)) * MaximumBlockWeight::get();149 pub const MaximumBlockLength: u32 = 5 * 1024 * 1024;150 pub const Version: RuntimeVersion = VERSION;151}152153impl system::Trait for Runtime {154 155 type BaseCallFilter = ();156 157 type AccountId = AccountId;158 159 type Call = Call;160 161 type Lookup = IdentityLookup<AccountId>;162 163 type Index = Index;164 165 type BlockNumber = BlockNumber;166 167 type Hash = Hash;168 169 type Hashing = BlakeTwo256;170 171 type Header = generic::Header<BlockNumber, BlakeTwo256>;172 173 type Event = Event;174 175 type Origin = Origin;176 177 type BlockHashCount = BlockHashCount;178 179 type MaximumBlockWeight = MaximumBlockWeight;180 181 type DbWeight = RocksDbWeight;182 183 184 type BlockExecutionWeight = BlockExecutionWeight;185 186 187 type ExtrinsicBaseWeight = ExtrinsicBaseWeight;188 189 190 191 type MaximumExtrinsicWeight = MaximumExtrinsicWeight;192 193 type MaximumBlockLength = MaximumBlockLength;194 195 type AvailableBlockRatio = AvailableBlockRatio;196 197 type Version = Version;198 199 type PalletInfo = PalletInfo;200 201 type OnNewAccount = ();202 203 type OnKilledAccount = ();204 205 type AccountData = pallet_balances::AccountData<Balance>;206 207 type SystemWeightInfo = ();208}209210impl pallet_aura::Trait for Runtime {211 type AuthorityId = AuraId;212}213214impl pallet_grandpa::Trait for Runtime {215 type Event = Event;216 type Call = Call;217218 type KeyOwnerProofSystem = ();219220 type KeyOwnerProof =221 <Self::KeyOwnerProofSystem as KeyOwnerProofSystem<(KeyTypeId, GrandpaId)>>::Proof;222223 type KeyOwnerIdentification = <Self::KeyOwnerProofSystem as KeyOwnerProofSystem<(224 KeyTypeId,225 GrandpaId,226 )>>::IdentificationTuple;227228 type HandleEquivocation = ();229230 type WeightInfo = ();231}232233parameter_types! {234 pub const MinimumPeriod: u64 = SLOT_DURATION / 2;235}236237impl pallet_timestamp::Trait for Runtime {238 239 type Moment = u64;240 type OnTimestampSet = Aura;241 type MinimumPeriod = MinimumPeriod;242 type WeightInfo = ();243}244245parameter_types! {246 247 pub const ExistentialDeposit: u128 = 0;248 pub const MaxLocks: u32 = 50;249}250251impl pallet_balances::Trait for Runtime {252 type MaxLocks = MaxLocks;253 254 type Balance = Balance;255 256 type Event = Event;257 type DustRemoval = ();258 type ExistentialDeposit = ExistentialDeposit;259 type AccountStore = System;260 type WeightInfo = ();261}262263pub const MILLICENTS: Balance = 1_000_000_000;264pub const CENTS: Balance = 1_000 * MILLICENTS;265pub const DOLLARS: Balance = 100 * CENTS;266267parameter_types! {268 pub const TombstoneDeposit: Balance = 16 * MILLICENTS;269 pub const RentByteFee: Balance = 4 * MILLICENTS;270 pub const RentDepositOffset: Balance = 1000 * MILLICENTS;271 pub const SurchargeReward: Balance = 150 * MILLICENTS;272}273274impl pallet_contracts::Trait for Runtime {275 type Time = Timestamp;276 type Randomness = RandomnessCollectiveFlip;277 type Currency = Balances;278 type Event = Event;279 type DetermineContractAddress = pallet_contracts::SimpleAddressDeterminer<Runtime>;280 type TrieIdGenerator = pallet_contracts::TrieIdFromParentCounter<Runtime>;281 type RentPayment = ();282 type SignedClaimHandicap = pallet_contracts::DefaultSignedClaimHandicap;283 type TombstoneDeposit = TombstoneDeposit;284 type StorageSizeOffset = pallet_contracts::DefaultStorageSizeOffset;285 type RentByteFee = RentByteFee;286 type RentDepositOffset = RentDepositOffset;287 type SurchargeReward = SurchargeReward;288 type MaxDepth = pallet_contracts::DefaultMaxDepth;289 type MaxValueSize = pallet_contracts::DefaultMaxValueSize;290 type WeightPrice = pallet_transaction_payment::Module<Self>;291}292293parameter_types! {294 pub const TransactionByteFee: Balance = 1;295}296297impl pallet_transaction_payment::Trait for Runtime {298 type Currency = pallet_balances::Module<Runtime>;299 type OnTransactionPayment = ();300 type TransactionByteFee = TransactionByteFee;301 type WeightToFee = IdentityFee<Balance>;302 type FeeMultiplierUpdate = ();303}304305impl pallet_sudo::Trait for Runtime {306 type Event = Event;307 type Call = Call;308}309310311impl pallet_nft::Trait for Runtime {312 type Event = Event;313}314315construct_runtime!(316 pub enum Runtime where317 Block = Block,318 NodeBlock = opaque::Block,319 UncheckedExtrinsic = UncheckedExtrinsic320 {321 System: system::{Module, Call, Config, Storage, Event<T>},322 RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Module, Call, Storage},323 Contracts: pallet_contracts::{Module, Call, Config, Storage, Event<T>},324 Timestamp: pallet_timestamp::{Module, Call, Storage, Inherent},325 Aura: pallet_aura::{Module, Config<T>, Inherent},326 Grandpa: pallet_grandpa::{Module, Call, Storage, Config, Event},327 Balances: pallet_balances::{Module, Call, Storage, Config<T>, Event<T>},328 TransactionPayment: pallet_transaction_payment::{Module, Storage},329 Sudo: pallet_sudo::{Module, Call, Config<T>, Storage, Event<T>},330 Nft: pallet_nft::{Module, Call, Config<T>, Storage, Event<T>},331 }332);333334335pub type Address = AccountId;336337pub type Header = generic::Header<BlockNumber, BlakeTwo256>;338339pub type Block = generic::Block<Header, UncheckedExtrinsic>;340341pub type SignedBlock = generic::SignedBlock<Block>;342343pub type BlockId = generic::BlockId<Block>;344345pub type SignedExtra = (346 system::CheckSpecVersion<Runtime>,347 system::CheckTxVersion<Runtime>,348 system::CheckGenesis<Runtime>,349 system::CheckEra<Runtime>,350 system::CheckNonce<Runtime>,351 system::CheckWeight<Runtime>,352 pallet_nft::ChargeTransactionPayment<Runtime>,353);354355pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<Address, Call, Signature, SignedExtra>;356357pub type CheckedExtrinsic = generic::CheckedExtrinsic<AccountId, Call, SignedExtra>;358359pub type Executive =360 frame_executive::Executive<Runtime, Block, system::ChainContext<Runtime>, Runtime, AllModules>;361362impl_runtime_apis! {363364 impl pallet_contracts_rpc_runtime_api::ContractsApi<Block, AccountId, Balance, BlockNumber>365 for Runtime366 {367 fn call(368 origin: AccountId,369 dest: AccountId,370 value: Balance,371 gas_limit: u64,372 input_data: Vec<u8>,373 ) -> ContractExecResult {374 let (exec_result, gas_consumed) =375 Contracts::bare_call(origin, dest.into(), value, gas_limit, input_data);376 match exec_result {377 Ok(v) => ContractExecResult::Success {378 flags: v.flags.bits(),379 data: v.data,380 gas_consumed: gas_consumed,381 },382 Err(_) => ContractExecResult::Error,383 }384 }385386 fn get_storage(387 address: AccountId,388 key: [u8; 32],389 ) -> pallet_contracts_primitives::GetStorageResult {390 Contracts::get_storage(address, key)391 }392393 fn rent_projection(394 address: AccountId,395 ) -> pallet_contracts_primitives::RentProjectionResult<BlockNumber> {396 Contracts::rent_projection(address)397 }398 }399400 impl sp_api::Core<Block> for Runtime {401 fn version() -> RuntimeVersion {402 VERSION403 }404405 fn execute_block(block: Block) {406 Executive::execute_block(block)407 }408409 fn initialize_block(header: &<Block as BlockT>::Header) {410 Executive::initialize_block(header)411 }412 }413414 impl sp_api::Metadata<Block> for Runtime {415 fn metadata() -> OpaqueMetadata {416 Runtime::metadata().into()417 }418 }419420 impl sp_block_builder::BlockBuilder<Block> for Runtime {421 fn apply_extrinsic(extrinsic: <Block as BlockT>::Extrinsic) -> ApplyExtrinsicResult {422 Executive::apply_extrinsic(extrinsic)423 }424425 fn finalize_block() -> <Block as BlockT>::Header {426 Executive::finalize_block()427 }428429 fn inherent_extrinsics(data: sp_inherents::InherentData) -> Vec<<Block as BlockT>::Extrinsic> {430 data.create_extrinsics()431 }432433 fn check_inherents(434 block: Block,435 data: sp_inherents::InherentData,436 ) -> sp_inherents::CheckInherentsResult {437 data.check_extrinsics(&block)438 }439440 fn random_seed() -> <Block as BlockT>::Hash {441 RandomnessCollectiveFlip::random_seed()442 }443 }444445 impl sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block> for Runtime {446 fn validate_transaction(447 source: TransactionSource,448 tx: <Block as BlockT>::Extrinsic,449 ) -> TransactionValidity {450 Executive::validate_transaction(source, tx)451 }452 }453454 impl sp_offchain::OffchainWorkerApi<Block> for Runtime {455 fn offchain_worker(header: &<Block as BlockT>::Header) {456 Executive::offchain_worker(header)457 }458 }459460 impl sp_consensus_aura::AuraApi<Block, AuraId> for Runtime {461 fn slot_duration() -> u64 {462 Aura::slot_duration()463 }464465 fn authorities() -> Vec<AuraId> {466 Aura::authorities()467 }468 }469470 impl sp_session::SessionKeys<Block> for Runtime {471 fn generate_session_keys(seed: Option<Vec<u8>>) -> Vec<u8> {472 opaque::SessionKeys::generate(seed)473 }474475 fn decode_session_keys(476 encoded: Vec<u8>,477 ) -> Option<Vec<(Vec<u8>, KeyTypeId)>> {478 opaque::SessionKeys::decode_into_raw_public_keys(&encoded)479 }480 }481482 impl fg_primitives::GrandpaApi<Block> for Runtime {483 fn grandpa_authorities() -> GrandpaAuthorityList {484 Grandpa::grandpa_authorities()485 }486487 fn submit_report_equivocation_unsigned_extrinsic(488 _equivocation_proof: fg_primitives::EquivocationProof<489 <Block as BlockT>::Hash,490 NumberFor<Block>,491 >,492 _key_owner_proof: fg_primitives::OpaqueKeyOwnershipProof,493 ) -> Option<()> {494 None495 }496497 fn generate_key_ownership_proof(498 _set_id: fg_primitives::SetId,499 _authority_id: GrandpaId,500 ) -> Option<fg_primitives::OpaqueKeyOwnershipProof> {501 502 503 504 None505 }506 }507 508 impl frame_system_rpc_runtime_api::AccountNonceApi<Block, AccountId, Index> for Runtime {509 fn account_nonce(account: AccountId) -> Index {510 System::account_nonce(account)511 }512 }513514 impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance> for Runtime {515 fn query_info(516 uxt: <Block as BlockT>::Extrinsic,517 len: u32,518 ) -> pallet_transaction_payment_rpc_runtime_api::RuntimeDispatchInfo<Balance> {519 TransactionPayment::query_info(uxt, len)520 }521 }522523 #[cfg(feature = "runtime-benchmarks")]524 impl frame_benchmarking::Benchmark<Block> for Runtime {525 fn dispatch_benchmark(526 config: frame_benchmarking::BenchmarkConfig527 ) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, sp_runtime::RuntimeString> {528 use frame_benchmarking::{Benchmarking, BenchmarkBatch, add_benchmark, TrackedStorageKey};529530 let whitelist: Vec<TrackedStorageKey> = vec![531 532 hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac").to_vec().into(),533 534 hex_literal::hex!("c2261276cc9d1f8598ea4b6a74b15c2f57c875e4cff74148e4628f264b974c80").to_vec().into(),535 536 hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef7ff553b5a9862a516939d82b3d3d8661a").to_vec().into(),537 538 hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef70a98fdbe9ce6c55837576c60c7af3850").to_vec().into(),539 540 hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7").to_vec().into(),541 ];542543 let mut batches = Vec::<BenchmarkBatch>::new();544 let params = (&config, &whitelist);545546 add_benchmark!(params, batches, pallet_nft, Nft);547548 if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) }549 Ok(batches)550 }551 }552}