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 contracts_rpc_runtime_api::ContractExecResult;12use grandpa::fg_primitives;13use 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 transaction_validity::{TransactionSource, TransactionValidity},20 ApplyExtrinsicResult, MultiSignature,21 traits::{22 BlakeTwo256, Block as BlockT, IdentifyAccount, IdentityLookup, NumberFor, Saturating, Verify,23 },24};25use sp_std::prelude::*;26#[cfg(feature = "std")]27use sp_version::NativeVersion;28use sp_version::RuntimeVersion;293031pub use balances::Call as BalancesCall;32pub use contracts::Schedule as ContractsSchedule;33pub use frame_support::{34 construct_runtime, parameter_types,35 traits::{Currency, Get, ExistenceRequirement, KeyOwnerProofSystem, OnUnbalanced, Randomness, WithdrawReason},36 weights::{37 DispatchInfo, PostDispatchInfo, constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND},38 IdentityFee, Weight, WeightToFeePolynomial, GetDispatchInfo, Pays,39 },40 StorageValue,41 dispatch::DispatchResult,42};43use system::{self as system};44#[cfg(any(feature = "std", test))]45pub use sp_runtime::BuildStorage;46use sp_runtime::{47 Perbill,48};495051pub use timestamp::Call as TimestampCall;525354pub use nft;555657pub type BlockNumber = u32;585960pub type Signature = MultiSignature;61626364pub type AccountId = <<Signature as Verify>::Signer as IdentifyAccount>::AccountId;65666768pub type AccountIndex = u32;697071pub type Balance = u128;727374pub type Index = u32;757677pub type Hash = sp_core::H256;787980pub type DigestItem = generic::DigestItem<Hash>;818283848586pub mod opaque {87 use super::*;8889 pub use sp_runtime::OpaqueExtrinsic as UncheckedExtrinsic;9091 92 pub type Header = generic::Header<BlockNumber, BlakeTwo256>;93 94 pub type Block = generic::Block<Header, UncheckedExtrinsic>;95 96 pub type BlockId = generic::BlockId<Block>;9798 impl_opaque_keys! {99 pub struct SessionKeys {100 pub aura: Aura,101 pub grandpa: Grandpa,102 }103 }104}105106107pub const VERSION: RuntimeVersion = RuntimeVersion {108 spec_name: create_runtime_str!("nft"),109 impl_name: create_runtime_str!("nft"),110 authoring_version: 1,111 spec_version: 1,112 impl_version: 1,113 apis: RUNTIME_API_VERSIONS,114 transaction_version: 1,115};116117pub const MILLISECS_PER_BLOCK: u64 = 6000;118119pub const SLOT_DURATION: u64 = MILLISECS_PER_BLOCK;120121122pub const MINUTES: BlockNumber = 60_000 / (MILLISECS_PER_BLOCK as BlockNumber);123pub const HOURS: BlockNumber = MINUTES * 60;124pub const DAYS: BlockNumber = HOURS * 24;125126127#[cfg(feature = "std")]128pub fn native_version() -> NativeVersion {129 NativeVersion {130 runtime_version: VERSION,131 can_author_with: Default::default(),132 }133}134135parameter_types! {136 pub const BlockHashCount: BlockNumber = 2400;137 138 pub const MaximumBlockWeight: Weight = 2 * WEIGHT_PER_SECOND;139 pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);140 141 pub MaximumExtrinsicWeight: Weight = AvailableBlockRatio::get()142 .saturating_sub(Perbill::from_percent(10)) * MaximumBlockWeight::get();143 pub const MaximumBlockLength: u32 = 5 * 1024 * 1024;144 pub const Version: RuntimeVersion = VERSION;145}146147impl system::Trait for Runtime {148 149 type BaseCallFilter = ();150 151 type AccountId = AccountId;152 153 type Call = Call;154 155 type Lookup = IdentityLookup<AccountId>;156 157 type Index = Index;158 159 type BlockNumber = BlockNumber;160 161 type Hash = Hash;162 163 type Hashing = BlakeTwo256;164 165 type Header = generic::Header<BlockNumber, BlakeTwo256>;166 167 type Event = Event;168 169 type Origin = Origin;170 171 type BlockHashCount = BlockHashCount;172 173 type MaximumBlockWeight = MaximumBlockWeight;174 175 type DbWeight = RocksDbWeight;176 177 178 type BlockExecutionWeight = BlockExecutionWeight;179 180 181 type ExtrinsicBaseWeight = ExtrinsicBaseWeight;182 183 184 185 type MaximumExtrinsicWeight = MaximumExtrinsicWeight;186 187 type MaximumBlockLength = MaximumBlockLength;188 189 type AvailableBlockRatio = AvailableBlockRatio;190 191 type Version = Version;192 193 194 195 type ModuleToIndex = ModuleToIndex;196 197 type OnNewAccount = ();198 199 type OnKilledAccount = ();200 201 type AccountData = balances::AccountData<Balance>;202}203204impl aura::Trait for Runtime {205 type AuthorityId = AuraId;206}207208impl grandpa::Trait for Runtime {209 type Event = Event;210 type Call = Call;211212 type KeyOwnerProofSystem = ();213214 type KeyOwnerProof =215 <Self::KeyOwnerProofSystem as KeyOwnerProofSystem<(KeyTypeId, GrandpaId)>>::Proof;216217 type KeyOwnerIdentification = <Self::KeyOwnerProofSystem as KeyOwnerProofSystem<(218 KeyTypeId,219 GrandpaId,220 )>>::IdentificationTuple;221222 type HandleEquivocation = ();223}224225parameter_types! {226 pub const MinimumPeriod: u64 = SLOT_DURATION / 2;227}228229impl timestamp::Trait for Runtime {230 231 type Moment = u64;232 type OnTimestampSet = Aura;233 type MinimumPeriod = MinimumPeriod;234}235236parameter_types! {237 238 pub const ExistentialDeposit: u128 = 0;239}240241impl balances::Trait for Runtime {242 243 type Balance = Balance;244 245 type Event = Event;246 type DustRemoval = ();247 type ExistentialDeposit = ExistentialDeposit;248 type AccountStore = System;249}250251pub const MILLICENTS: Balance = 1_000_000_000;252pub const CENTS: Balance = 1_000 * MILLICENTS;253pub const DOLLARS: Balance = 100 * CENTS;254255parameter_types! {256 pub const TombstoneDeposit: Balance = 16 * MILLICENTS;257 pub const RentByteFee: Balance = 4 * MILLICENTS;258 pub const RentDepositOffset: Balance = 1000 * MILLICENTS;259 pub const SurchargeReward: Balance = 150 * MILLICENTS;260}261262impl contracts::Trait for Runtime {263 type Call = Call;264 type Time = Timestamp;265 type Randomness = RandomnessCollectiveFlip;266 type Currency = Balances;267 type Event = Event;268 type DetermineContractAddress = contracts::SimpleAddressDeterminer<Runtime>;269 type TrieIdGenerator = contracts::TrieIdFromParentCounter<Runtime>;270 type RentPayment = ();271 type SignedClaimHandicap = contracts::DefaultSignedClaimHandicap;272 type TombstoneDeposit = TombstoneDeposit;273 type StorageSizeOffset = contracts::DefaultStorageSizeOffset;274 type RentByteFee = RentByteFee;275 type RentDepositOffset = RentDepositOffset;276 type SurchargeReward = SurchargeReward;277 type MaxDepth = contracts::DefaultMaxDepth;278 type MaxValueSize = contracts::DefaultMaxValueSize;279 type WeightPrice = transaction_payment::Module<Self>;280}281282parameter_types! {283 pub const TransactionByteFee: Balance = 1;284}285286impl transaction_payment::Trait for Runtime {287 type Currency = balances::Module<Runtime>;288 type OnTransactionPayment = ();289 type TransactionByteFee = TransactionByteFee;290 type WeightToFee = IdentityFee<Balance>;291 type FeeMultiplierUpdate = ();292}293294impl sudo::Trait for Runtime {295 type Event = Event;296 type Call = Call;297}298299300impl nft::Trait for Runtime {301 type Event = Event;302}303304construct_runtime!(305 pub enum Runtime where306 Block = Block,307 NodeBlock = opaque::Block,308 UncheckedExtrinsic = UncheckedExtrinsic309 {310 System: system::{Module, Call, Config, Storage, Event<T>},311 RandomnessCollectiveFlip: randomness_collective_flip::{Module, Call, Storage},312 Contracts: contracts::{Module, Call, Config, Storage, Event<T>},313 Timestamp: timestamp::{Module, Call, Storage, Inherent},314 Aura: aura::{Module, Config<T>, Inherent(Timestamp)},315 Grandpa: grandpa::{Module, Call, Storage, Config, Event},316 Balances: balances::{Module, Call, Storage, Config<T>, Event<T>},317 TransactionPayment: transaction_payment::{Module, Storage},318 Sudo: sudo::{Module, Call, Config<T>, Storage, Event<T>},319 Nft: nft::{Module, Call, Storage, Event<T>},320 }321);322323324pub type Address = AccountId;325326pub type Header = generic::Header<BlockNumber, BlakeTwo256>;327328pub type Block = generic::Block<Header, UncheckedExtrinsic>;329330pub type SignedBlock = generic::SignedBlock<Block>;331332pub type BlockId = generic::BlockId<Block>;333334pub type SignedExtra = (335 system::CheckSpecVersion<Runtime>,336 system::CheckTxVersion<Runtime>,337 system::CheckGenesis<Runtime>,338 system::CheckEra<Runtime>,339 system::CheckNonce<Runtime>,340 system::CheckWeight<Runtime>,341 nft::ChargeTransactionPayment<Runtime>,342);343344pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<Address, Call, Signature, SignedExtra>;345346pub type CheckedExtrinsic = generic::CheckedExtrinsic<AccountId, Call, SignedExtra>;347348pub type Executive =349 frame_executive::Executive<Runtime, Block, system::ChainContext<Runtime>, Runtime, AllModules>;350351impl_runtime_apis! {352353 impl contracts_rpc_runtime_api::ContractsApi<Block, AccountId, Balance, BlockNumber>354 for Runtime355 {356 fn call(357 origin: AccountId,358 dest: AccountId,359 value: Balance,360 gas_limit: u64,361 input_data: Vec<u8>,362 ) -> ContractExecResult {363 let exec_result =364 Contracts::bare_call(origin, dest.into(), value, gas_limit, input_data);365 match exec_result {366 Ok(v) => ContractExecResult::Success {367 status: v.status,368 data: v.data,369 },370 Err(_) => ContractExecResult::Error,371 }372 }373374 fn get_storage(375 address: AccountId,376 key: [u8; 32],377 ) -> contracts_primitives::GetStorageResult {378 Contracts::get_storage(address, key)379 }380381 fn rent_projection(382 address: AccountId,383 ) -> contracts_primitives::RentProjectionResult<BlockNumber> {384 Contracts::rent_projection(address)385 }386 }387388 impl sp_api::Core<Block> for Runtime {389 fn version() -> RuntimeVersion {390 VERSION391 }392393 fn execute_block(block: Block) {394 Executive::execute_block(block)395 }396397 fn initialize_block(header: &<Block as BlockT>::Header) {398 Executive::initialize_block(header)399 }400 }401402 impl sp_api::Metadata<Block> for Runtime {403 fn metadata() -> OpaqueMetadata {404 Runtime::metadata().into()405 }406 }407408 impl sp_block_builder::BlockBuilder<Block> for Runtime {409 fn apply_extrinsic(extrinsic: <Block as BlockT>::Extrinsic) -> ApplyExtrinsicResult {410 Executive::apply_extrinsic(extrinsic)411 }412413 fn finalize_block() -> <Block as BlockT>::Header {414 Executive::finalize_block()415 }416417 fn inherent_extrinsics(data: sp_inherents::InherentData) -> Vec<<Block as BlockT>::Extrinsic> {418 data.create_extrinsics()419 }420421 fn check_inherents(422 block: Block,423 data: sp_inherents::InherentData,424 ) -> sp_inherents::CheckInherentsResult {425 data.check_extrinsics(&block)426 }427428 fn random_seed() -> <Block as BlockT>::Hash {429 RandomnessCollectiveFlip::random_seed()430 }431 }432433 impl sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block> for Runtime {434 fn validate_transaction(435 source: TransactionSource,436 tx: <Block as BlockT>::Extrinsic,437 ) -> TransactionValidity {438 Executive::validate_transaction(source, tx)439 }440 }441442 impl sp_offchain::OffchainWorkerApi<Block> for Runtime {443 fn offchain_worker(header: &<Block as BlockT>::Header) {444 Executive::offchain_worker(header)445 }446 }447448 impl sp_consensus_aura::AuraApi<Block, AuraId> for Runtime {449 fn slot_duration() -> u64 {450 Aura::slot_duration()451 }452453 fn authorities() -> Vec<AuraId> {454 Aura::authorities()455 }456 }457458 impl sp_session::SessionKeys<Block> for Runtime {459 fn generate_session_keys(seed: Option<Vec<u8>>) -> Vec<u8> {460 opaque::SessionKeys::generate(seed)461 }462463 fn decode_session_keys(464 encoded: Vec<u8>,465 ) -> Option<Vec<(Vec<u8>, KeyTypeId)>> {466 opaque::SessionKeys::decode_into_raw_public_keys(&encoded)467 }468 }469470 impl fg_primitives::GrandpaApi<Block> for Runtime {471 fn grandpa_authorities() -> GrandpaAuthorityList {472 Grandpa::grandpa_authorities()473 }474475 fn submit_report_equivocation_extrinsic(476 _equivocation_proof: fg_primitives::EquivocationProof<477 <Block as BlockT>::Hash,478 NumberFor<Block>,479 >,480 _key_owner_proof: fg_primitives::OpaqueKeyOwnershipProof,481 ) -> Option<()> {482 None483 }484485 fn generate_key_ownership_proof(486 _set_id: fg_primitives::SetId,487 _authority_id: GrandpaId,488 ) -> Option<fg_primitives::OpaqueKeyOwnershipProof> {489 490 491 492 None493 }494 }495}496