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 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 balances::Call as BalancesCall;33pub use 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 system::{self as system};5354pub use timestamp::Call as TimestampCall;555657pub use nft;585960pub type BlockNumber = u32;616263pub type Signature = MultiSignature;64656667pub type AccountId = <<Signature as Verify>::Signer as IdentifyAccount>::AccountId;68697071pub type AccountIndex = u32;727374pub type Balance = u128;757677pub type Index = u32;787980pub type Hash = sp_core::H256;818283pub type DigestItem = generic::DigestItem<Hash>;848586878889pub mod opaque {90 use super::*;9192 pub use sp_runtime::OpaqueExtrinsic as UncheckedExtrinsic;9394 95 pub type Header = generic::Header<BlockNumber, BlakeTwo256>;96 97 pub type Block = generic::Block<Header, UncheckedExtrinsic>;98 99 pub type BlockId = generic::BlockId<Block>;100101 impl_opaque_keys! {102 pub struct SessionKeys {103 pub aura: Aura,104 pub grandpa: Grandpa,105 }106 }107}108109110pub const VERSION: RuntimeVersion = RuntimeVersion {111 spec_name: create_runtime_str!("nft"),112 impl_name: create_runtime_str!("nft"),113 authoring_version: 1,114 spec_version: 1,115 impl_version: 1,116 apis: RUNTIME_API_VERSIONS,117 transaction_version: 1,118};119120pub const MILLISECS_PER_BLOCK: u64 = 6000;121122pub const SLOT_DURATION: u64 = MILLISECS_PER_BLOCK;123124125pub const MINUTES: BlockNumber = 60_000 / (MILLISECS_PER_BLOCK as BlockNumber);126pub const HOURS: BlockNumber = MINUTES * 60;127pub const DAYS: BlockNumber = HOURS * 24;128129130#[cfg(feature = "std")]131pub fn native_version() -> NativeVersion {132 NativeVersion {133 runtime_version: VERSION,134 can_author_with: Default::default(),135 }136}137138parameter_types! {139 pub const BlockHashCount: BlockNumber = 2400;140 141 pub const MaximumBlockWeight: Weight = 2 * WEIGHT_PER_SECOND;142 pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);143 144 pub MaximumExtrinsicWeight: Weight = AvailableBlockRatio::get()145 .saturating_sub(Perbill::from_percent(10)) * MaximumBlockWeight::get();146 pub const MaximumBlockLength: u32 = 5 * 1024 * 1024;147 pub const Version: RuntimeVersion = VERSION;148}149150impl system::Trait for Runtime {151 152 type BaseCallFilter = ();153 154 type AccountId = AccountId;155 156 type Call = Call;157 158 type Lookup = IdentityLookup<AccountId>;159 160 type Index = Index;161 162 type BlockNumber = BlockNumber;163 164 type Hash = Hash;165 166 type Hashing = BlakeTwo256;167 168 type Header = generic::Header<BlockNumber, BlakeTwo256>;169 170 type Event = Event;171 172 type Origin = Origin;173 174 type BlockHashCount = BlockHashCount;175 176 type MaximumBlockWeight = MaximumBlockWeight;177 178 type DbWeight = RocksDbWeight;179 180 181 type BlockExecutionWeight = BlockExecutionWeight;182 183 184 type ExtrinsicBaseWeight = ExtrinsicBaseWeight;185 186 187 188 type MaximumExtrinsicWeight = MaximumExtrinsicWeight;189 190 type MaximumBlockLength = MaximumBlockLength;191 192 type AvailableBlockRatio = AvailableBlockRatio;193 194 type Version = Version;195 196 197 type ModuleToIndex = ModuleToIndex;198 199 type OnNewAccount = ();200 201 type OnKilledAccount = ();202 203 type AccountData = balances::AccountData<Balance>;204}205206impl aura::Trait for Runtime {207 type AuthorityId = AuraId;208}209210impl grandpa::Trait for Runtime {211 type Event = Event;212 type Call = Call;213214 type KeyOwnerProofSystem = ();215216 type KeyOwnerProof =217 <Self::KeyOwnerProofSystem as KeyOwnerProofSystem<(KeyTypeId, GrandpaId)>>::Proof;218219 type KeyOwnerIdentification = <Self::KeyOwnerProofSystem as KeyOwnerProofSystem<(220 KeyTypeId,221 GrandpaId,222 )>>::IdentificationTuple;223224 type HandleEquivocation = ();225}226227parameter_types! {228 pub const MinimumPeriod: u64 = SLOT_DURATION / 2;229}230231impl timestamp::Trait for Runtime {232 233 type Moment = u64;234 type OnTimestampSet = Aura;235 type MinimumPeriod = MinimumPeriod;236}237238parameter_types! {239 240 pub const ExistentialDeposit: u128 = 0;241}242243impl balances::Trait for Runtime {244 245 type Balance = Balance;246 247 type Event = Event;248 type DustRemoval = ();249 type ExistentialDeposit = ExistentialDeposit;250 type AccountStore = System;251}252253pub const MILLICENTS: Balance = 1_000_000_000;254pub const CENTS: Balance = 1_000 * MILLICENTS;255pub const DOLLARS: Balance = 100 * CENTS;256257parameter_types! {258 pub const TombstoneDeposit: Balance = 16 * MILLICENTS;259 pub const RentByteFee: Balance = 4 * MILLICENTS;260 pub const RentDepositOffset: Balance = 1000 * MILLICENTS;261 pub const SurchargeReward: Balance = 150 * MILLICENTS;262}263264impl contracts::Trait for Runtime {265 type Call = Call;266 type Time = Timestamp;267 type Randomness = RandomnessCollectiveFlip;268 type Currency = Balances;269 type Event = Event;270 type DetermineContractAddress = contracts::SimpleAddressDeterminer<Runtime>;271 type TrieIdGenerator = contracts::TrieIdFromParentCounter<Runtime>;272 type RentPayment = ();273 type SignedClaimHandicap = contracts::DefaultSignedClaimHandicap;274 type TombstoneDeposit = TombstoneDeposit;275 type StorageSizeOffset = contracts::DefaultStorageSizeOffset;276 type RentByteFee = RentByteFee;277 type RentDepositOffset = RentDepositOffset;278 type SurchargeReward = SurchargeReward;279 type MaxDepth = contracts::DefaultMaxDepth;280 type MaxValueSize = contracts::DefaultMaxValueSize;281 type WeightPrice = transaction_payment::Module<Self>;282}283284parameter_types! {285 pub const TransactionByteFee: Balance = 1;286}287288impl transaction_payment::Trait for Runtime {289 type Currency = balances::Module<Runtime>;290 type OnTransactionPayment = ();291 type TransactionByteFee = TransactionByteFee;292 type WeightToFee = IdentityFee<Balance>;293 type FeeMultiplierUpdate = ();294}295296impl sudo::Trait for Runtime {297 type Event = Event;298 type Call = Call;299}300301302impl nft::Trait for Runtime {303 type Event = Event;304}305306construct_runtime!(307 pub enum Runtime where308 Block = Block,309 NodeBlock = opaque::Block,310 UncheckedExtrinsic = UncheckedExtrinsic311 {312 System: system::{Module, Call, Config, Storage, Event<T>},313 RandomnessCollectiveFlip: randomness_collective_flip::{Module, Call, Storage},314 Contracts: contracts::{Module, Call, Config, Storage, Event<T>},315 Timestamp: timestamp::{Module, Call, Storage, Inherent},316 Aura: aura::{Module, Config<T>, Inherent(Timestamp)},317 Grandpa: grandpa::{Module, Call, Storage, Config, Event},318 Balances: balances::{Module, Call, Storage, Config<T>, Event<T>},319 TransactionPayment: transaction_payment::{Module, Storage},320 Sudo: sudo::{Module, Call, Config<T>, Storage, Event<T>},321 Nft: nft::{Module, Call, Storage, Event<T>},322 }323);324325326pub type Address = AccountId;327328pub type Header = generic::Header<BlockNumber, BlakeTwo256>;329330pub type Block = generic::Block<Header, UncheckedExtrinsic>;331332pub type SignedBlock = generic::SignedBlock<Block>;333334pub type BlockId = generic::BlockId<Block>;335336pub type SignedExtra = (337 system::CheckSpecVersion<Runtime>,338 system::CheckTxVersion<Runtime>,339 system::CheckGenesis<Runtime>,340 system::CheckEra<Runtime>,341 system::CheckNonce<Runtime>,342 system::CheckWeight<Runtime>,343 nft::ChargeTransactionPayment<Runtime>,344);345346pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<Address, Call, Signature, SignedExtra>;347348pub type CheckedExtrinsic = generic::CheckedExtrinsic<AccountId, Call, SignedExtra>;349350pub type Executive =351 frame_executive::Executive<Runtime, Block, system::ChainContext<Runtime>, Runtime, AllModules>;352353impl_runtime_apis! {354355 impl contracts_rpc_runtime_api::ContractsApi<Block, AccountId, Balance, BlockNumber>356 for Runtime357 {358 fn call(359 origin: AccountId,360 dest: AccountId,361 value: Balance,362 gas_limit: u64,363 input_data: Vec<u8>,364 ) -> ContractExecResult {365 let exec_result =366 Contracts::bare_call(origin, dest.into(), value, gas_limit, input_data);367 match exec_result {368 Ok(v) => ContractExecResult::Success {369 status: v.status,370 data: v.data,371 },372 Err(_) => ContractExecResult::Error,373 }374 }375376 fn get_storage(377 address: AccountId,378 key: [u8; 32],379 ) -> contracts_primitives::GetStorageResult {380 Contracts::get_storage(address, key)381 }382383 fn rent_projection(384 address: AccountId,385 ) -> contracts_primitives::RentProjectionResult<BlockNumber> {386 Contracts::rent_projection(address)387 }388 }389390 impl sp_api::Core<Block> for Runtime {391 fn version() -> RuntimeVersion {392 VERSION393 }394395 fn execute_block(block: Block) {396 Executive::execute_block(block)397 }398399 fn initialize_block(header: &<Block as BlockT>::Header) {400 Executive::initialize_block(header)401 }402 }403404 impl sp_api::Metadata<Block> for Runtime {405 fn metadata() -> OpaqueMetadata {406 Runtime::metadata().into()407 }408 }409410 impl sp_block_builder::BlockBuilder<Block> for Runtime {411 fn apply_extrinsic(extrinsic: <Block as BlockT>::Extrinsic) -> ApplyExtrinsicResult {412 Executive::apply_extrinsic(extrinsic)413 }414415 fn finalize_block() -> <Block as BlockT>::Header {416 Executive::finalize_block()417 }418419 fn inherent_extrinsics(data: sp_inherents::InherentData) -> Vec<<Block as BlockT>::Extrinsic> {420 data.create_extrinsics()421 }422423 fn check_inherents(424 block: Block,425 data: sp_inherents::InherentData,426 ) -> sp_inherents::CheckInherentsResult {427 data.check_extrinsics(&block)428 }429430 fn random_seed() -> <Block as BlockT>::Hash {431 RandomnessCollectiveFlip::random_seed()432 }433 }434435 impl sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block> for Runtime {436 fn validate_transaction(437 source: TransactionSource,438 tx: <Block as BlockT>::Extrinsic,439 ) -> TransactionValidity {440 Executive::validate_transaction(source, tx)441 }442 }443444 impl sp_offchain::OffchainWorkerApi<Block> for Runtime {445 fn offchain_worker(header: &<Block as BlockT>::Header) {446 Executive::offchain_worker(header)447 }448 }449450 impl sp_consensus_aura::AuraApi<Block, AuraId> for Runtime {451 fn slot_duration() -> u64 {452 Aura::slot_duration()453 }454455 fn authorities() -> Vec<AuraId> {456 Aura::authorities()457 }458 }459460 impl sp_session::SessionKeys<Block> for Runtime {461 fn generate_session_keys(seed: Option<Vec<u8>>) -> Vec<u8> {462 opaque::SessionKeys::generate(seed)463 }464465 fn decode_session_keys(466 encoded: Vec<u8>,467 ) -> Option<Vec<(Vec<u8>, KeyTypeId)>> {468 opaque::SessionKeys::decode_into_raw_public_keys(&encoded)469 }470 }471472 impl fg_primitives::GrandpaApi<Block> for Runtime {473 fn grandpa_authorities() -> GrandpaAuthorityList {474 Grandpa::grandpa_authorities()475 }476477 fn submit_report_equivocation_extrinsic(478 _equivocation_proof: fg_primitives::EquivocationProof<479 <Block as BlockT>::Hash,480 NumberFor<Block>,481 >,482 _key_owner_proof: fg_primitives::OpaqueKeyOwnershipProof,483 ) -> Option<()> {484 None485 }486487 fn generate_key_ownership_proof(488 _set_id: fg_primitives::SetId,489 _authority_id: GrandpaId,490 ) -> Option<fg_primitives::OpaqueKeyOwnershipProof> {491 492 493 494 None495 }496 }497}