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>;8687mod nft_weights;888990919293pub mod opaque {94 use super::*;9596 pub use sp_runtime::OpaqueExtrinsic as UncheckedExtrinsic;9798 99 pub type Header = generic::Header<BlockNumber, BlakeTwo256>;100 101 pub type Block = generic::Block<Header, UncheckedExtrinsic>;102 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}112113114pub 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;127128129pub const MINUTES: BlockNumber = 60_000 / (MILLISECS_PER_BLOCK as BlockNumber);130pub const HOURS: BlockNumber = MINUTES * 60;131pub const DAYS: BlockNumber = HOURS * 24;132133134#[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 145 pub const MaximumBlockWeight: Weight = 2 * WEIGHT_PER_SECOND;146 pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);147 148 149 150151 pub MaximumExtrinsicWeight: Weight = 4_294_967_295; 152 153 pub const MaximumBlockLength: u32 = 4_294_967_295;154 pub const Version: RuntimeVersion = VERSION;155}156157impl system::Trait for Runtime {158 159 type BaseCallFilter = ();160 161 type AccountId = AccountId;162 163 type Call = Call;164 165 type Lookup = IdentityLookup<AccountId>;166 167 type Index = Index;168 169 type BlockNumber = BlockNumber;170 171 type Hash = Hash;172 173 type Hashing = BlakeTwo256;174 175 type Header = generic::Header<BlockNumber, BlakeTwo256>;176 177 type Event = Event;178 179 type Origin = Origin;180 181 type BlockHashCount = BlockHashCount;182 183 type MaximumBlockWeight = MaximumBlockWeight;184 185 type DbWeight = RocksDbWeight;186 187 188 type BlockExecutionWeight = BlockExecutionWeight;189 190 191 type ExtrinsicBaseWeight = ExtrinsicBaseWeight;192 193 194 195 type MaximumExtrinsicWeight = MaximumExtrinsicWeight;196 197 type MaximumBlockLength = MaximumBlockLength;198 199 type AvailableBlockRatio = AvailableBlockRatio;200 201 type Version = Version;202 203 type PalletInfo = PalletInfo;204 205 type OnNewAccount = ();206 207 type OnKilledAccount = ();208 209 type AccountData = pallet_balances::AccountData<Balance>;210 211 type SystemWeightInfo = ();212}213214impl pallet_aura::Trait for Runtime {215 type AuthorityId = AuraId;216}217218impl pallet_grandpa::Trait for Runtime {219 type Event = Event;220 type Call = Call;221222 type KeyOwnerProofSystem = ();223224 type KeyOwnerProof =225 <Self::KeyOwnerProofSystem as KeyOwnerProofSystem<(KeyTypeId, GrandpaId)>>::Proof;226227 type KeyOwnerIdentification = <Self::KeyOwnerProofSystem as KeyOwnerProofSystem<(228 KeyTypeId,229 GrandpaId,230 )>>::IdentificationTuple;231232 type HandleEquivocation = ();233234 type WeightInfo = ();235}236237parameter_types! {238 pub const MinimumPeriod: u64 = SLOT_DURATION / 2;239}240241impl pallet_timestamp::Trait for Runtime {242 243 type Moment = u64;244 type OnTimestampSet = Aura;245 type MinimumPeriod = MinimumPeriod;246 type WeightInfo = ();247}248249parameter_types! {250 251 pub const ExistentialDeposit: u128 = 0;252 pub const MaxLocks: u32 = 50;253}254255impl pallet_balances::Trait for Runtime {256 type MaxLocks = MaxLocks;257 258 type Balance = Balance;259 260 type Event = Event;261 type DustRemoval = ();262 type ExistentialDeposit = ExistentialDeposit;263 type AccountStore = System;264 type WeightInfo = ();265}266267pub const MILLICENTS: Balance = 1_000_000_000;268pub const CENTS: Balance = 1_000 * MILLICENTS;269pub const DOLLARS: Balance = 100 * CENTS;270271parameter_types! {272 pub const TombstoneDeposit: Balance = 16 * MILLICENTS;273 pub const RentByteFee: Balance = 4 * MILLICENTS;274 pub const RentDepositOffset: Balance = 1000 * MILLICENTS;275 pub const SurchargeReward: Balance = 150 * MILLICENTS;276}277278impl pallet_contracts::Trait for Runtime {279 type Time = Timestamp;280 type Randomness = RandomnessCollectiveFlip;281 type Currency = Balances;282 type Event = Event;283 type DetermineContractAddress = pallet_contracts::SimpleAddressDeterminer<Runtime>;284 type TrieIdGenerator = pallet_contracts::TrieIdFromParentCounter<Runtime>;285 type RentPayment = ();286 type SignedClaimHandicap = pallet_contracts::DefaultSignedClaimHandicap;287 type TombstoneDeposit = TombstoneDeposit;288 type StorageSizeOffset = pallet_contracts::DefaultStorageSizeOffset;289 type RentByteFee = RentByteFee;290 type RentDepositOffset = RentDepositOffset;291 type SurchargeReward = SurchargeReward;292 type MaxDepth = pallet_contracts::DefaultMaxDepth;293 type MaxValueSize = pallet_contracts::DefaultMaxValueSize;294 type WeightPrice = pallet_transaction_payment::Module<Self>;295}296297parameter_types! {298 pub const TransactionByteFee: Balance = 10 * MILLICENTS;299}300301impl pallet_transaction_payment::Trait for Runtime {302 type Currency = pallet_balances::Module<Runtime>;303 type OnTransactionPayment = ();304 type TransactionByteFee = TransactionByteFee;305 type WeightToFee = IdentityFee<Balance>;306 type FeeMultiplierUpdate = ();307}308309impl pallet_sudo::Trait for Runtime {310 type Event = Event;311 type Call = Call;312}313314315impl pallet_nft::Trait for Runtime {316 type Event = Event;317 type WeightInfo = nft_weights::WeightInfo;318}319320construct_runtime!(321 pub enum Runtime where322 Block = Block,323 NodeBlock = opaque::Block,324 UncheckedExtrinsic = UncheckedExtrinsic325 {326 System: system::{Module, Call, Config, Storage, Event<T>},327 RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Module, Call, Storage},328 Contracts: pallet_contracts::{Module, Call, Config, Storage, Event<T>},329 Timestamp: pallet_timestamp::{Module, Call, Storage, Inherent},330 Aura: pallet_aura::{Module, Config<T>, Inherent},331 Grandpa: pallet_grandpa::{Module, Call, Storage, Config, Event},332 Balances: pallet_balances::{Module, Call, Storage, Config<T>, Event<T>},333 TransactionPayment: pallet_transaction_payment::{Module, Storage},334 Sudo: pallet_sudo::{Module, Call, Config<T>, Storage, Event<T>},335 Nft: pallet_nft::{Module, Call, Config<T>, Storage, Event<T>},336 }337);338339340pub type Address = AccountId;341342pub type Header = generic::Header<BlockNumber, BlakeTwo256>;343344pub type Block = generic::Block<Header, UncheckedExtrinsic>;345346pub type SignedBlock = generic::SignedBlock<Block>;347348pub type BlockId = generic::BlockId<Block>;349350pub type SignedExtra = (351 system::CheckSpecVersion<Runtime>,352 system::CheckTxVersion<Runtime>,353 system::CheckGenesis<Runtime>,354 system::CheckEra<Runtime>,355 system::CheckNonce<Runtime>,356 system::CheckWeight<Runtime>,357 pallet_nft::ChargeTransactionPayment<Runtime>,358);359360pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<Address, Call, Signature, SignedExtra>;361362pub type CheckedExtrinsic = generic::CheckedExtrinsic<AccountId, Call, SignedExtra>;363364pub type Executive =365 frame_executive::Executive<Runtime, Block, system::ChainContext<Runtime>, Runtime, AllModules>;366367impl_runtime_apis! {368369 impl pallet_contracts_rpc_runtime_api::ContractsApi<Block, AccountId, Balance, BlockNumber>370 for Runtime371 {372 fn call(373 origin: AccountId,374 dest: AccountId,375 value: Balance,376 gas_limit: u64,377 input_data: Vec<u8>,378 ) -> ContractExecResult {379 let (exec_result, gas_consumed) =380 Contracts::bare_call(origin, dest.into(), value, gas_limit, input_data);381 match exec_result {382 Ok(v) => ContractExecResult::Success {383 flags: v.flags.bits(),384 data: v.data,385 gas_consumed: gas_consumed,386 },387 Err(_) => ContractExecResult::Error,388 }389 }390391 fn get_storage(392 address: AccountId,393 key: [u8; 32],394 ) -> pallet_contracts_primitives::GetStorageResult {395 Contracts::get_storage(address, key)396 }397398 fn rent_projection(399 address: AccountId,400 ) -> pallet_contracts_primitives::RentProjectionResult<BlockNumber> {401 Contracts::rent_projection(address)402 }403 }404405 impl sp_api::Core<Block> for Runtime {406 fn version() -> RuntimeVersion {407 VERSION408 }409410 fn execute_block(block: Block) {411 Executive::execute_block(block)412 }413414 fn initialize_block(header: &<Block as BlockT>::Header) {415 Executive::initialize_block(header)416 }417 }418419 impl sp_api::Metadata<Block> for Runtime {420 fn metadata() -> OpaqueMetadata {421 Runtime::metadata().into()422 }423 }424425 impl sp_block_builder::BlockBuilder<Block> for Runtime {426 fn apply_extrinsic(extrinsic: <Block as BlockT>::Extrinsic) -> ApplyExtrinsicResult {427 Executive::apply_extrinsic(extrinsic)428 }429430 fn finalize_block() -> <Block as BlockT>::Header {431 Executive::finalize_block()432 }433434 fn inherent_extrinsics(data: sp_inherents::InherentData) -> Vec<<Block as BlockT>::Extrinsic> {435 data.create_extrinsics()436 }437438 fn check_inherents(439 block: Block,440 data: sp_inherents::InherentData,441 ) -> sp_inherents::CheckInherentsResult {442 data.check_extrinsics(&block)443 }444445 fn random_seed() -> <Block as BlockT>::Hash {446 RandomnessCollectiveFlip::random_seed()447 }448 }449450 impl sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block> for Runtime {451 fn validate_transaction(452 source: TransactionSource,453 tx: <Block as BlockT>::Extrinsic,454 ) -> TransactionValidity {455 Executive::validate_transaction(source, tx)456 }457 }458459 impl sp_offchain::OffchainWorkerApi<Block> for Runtime {460 fn offchain_worker(header: &<Block as BlockT>::Header) {461 Executive::offchain_worker(header)462 }463 }464465 impl sp_consensus_aura::AuraApi<Block, AuraId> for Runtime {466 fn slot_duration() -> u64 {467 Aura::slot_duration()468 }469470 fn authorities() -> Vec<AuraId> {471 Aura::authorities()472 }473 }474475 impl sp_session::SessionKeys<Block> for Runtime {476 fn generate_session_keys(seed: Option<Vec<u8>>) -> Vec<u8> {477 opaque::SessionKeys::generate(seed)478 }479480 fn decode_session_keys(481 encoded: Vec<u8>,482 ) -> Option<Vec<(Vec<u8>, KeyTypeId)>> {483 opaque::SessionKeys::decode_into_raw_public_keys(&encoded)484 }485 }486487 impl fg_primitives::GrandpaApi<Block> for Runtime {488 fn grandpa_authorities() -> GrandpaAuthorityList {489 Grandpa::grandpa_authorities()490 }491492 fn submit_report_equivocation_unsigned_extrinsic(493 _equivocation_proof: fg_primitives::EquivocationProof<494 <Block as BlockT>::Hash,495 NumberFor<Block>,496 >,497 _key_owner_proof: fg_primitives::OpaqueKeyOwnershipProof,498 ) -> Option<()> {499 None500 }501502 fn generate_key_ownership_proof(503 _set_id: fg_primitives::SetId,504 _authority_id: GrandpaId,505 ) -> Option<fg_primitives::OpaqueKeyOwnershipProof> {506 507 508 509 None510 }511 }512 513 impl frame_system_rpc_runtime_api::AccountNonceApi<Block, AccountId, Index> for Runtime {514 fn account_nonce(account: AccountId) -> Index {515 System::account_nonce(account)516 }517 }518519 impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance> for Runtime {520 fn query_info(521 uxt: <Block as BlockT>::Extrinsic,522 len: u32,523 ) -> pallet_transaction_payment_rpc_runtime_api::RuntimeDispatchInfo<Balance> {524 TransactionPayment::query_info(uxt, len)525 }526 }527528 #[cfg(feature = "runtime-benchmarks")]529 impl frame_benchmarking::Benchmark<Block> for Runtime {530 fn dispatch_benchmark(531 config: frame_benchmarking::BenchmarkConfig532 ) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, sp_runtime::RuntimeString> {533 use frame_benchmarking::{Benchmarking, BenchmarkBatch, add_benchmark, TrackedStorageKey};534535 let whitelist: Vec<TrackedStorageKey> = vec![536 537 hex_literal::hex!("d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d").to_vec().into(),538 539 540 541 542 543 544 545 546 ];547548 let mut batches = Vec::<BenchmarkBatch>::new();549 let params = (&config, &whitelist);550551 add_benchmark!(params, batches, pallet_nft, Nft);552553 if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) }554 Ok(batches)555 }556 }557}