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 sp_std::prelude::*;12use sp_core::OpaqueMetadata;13use sp_runtime::{14 ApplyExtrinsicResult, generic, create_runtime_str, impl_opaque_keys, MultiSignature,15 transaction_validity::{TransactionValidity, TransactionSource},16};17use sp_runtime::traits::{18 BlakeTwo256, Block as BlockT, IdentityLookup, Verify, ConvertInto, IdentifyAccount19};20use sp_api::impl_runtime_apis;21use sp_consensus_aura::sr25519::AuthorityId as AuraId;22use grandpa::AuthorityList as GrandpaAuthorityList;23use grandpa::fg_primitives;24use sp_version::RuntimeVersion;25#[cfg(feature = "std")]26use sp_version::NativeVersion;27use contracts_rpc_runtime_api::ContractExecResult;282930#[cfg(any(feature = "std", test))]31pub use sp_runtime::BuildStorage;32pub use timestamp::Call as TimestampCall;3334pub use balances::Call as BalancesCall;35pub use sp_runtime::{Permill, Perbill};36pub use contracts::Schedule as ContractsSchedule;37pub use frame_support::{38 construct_runtime, parameter_types, traits::Randomness, weights::Weight, StorageValue,39};404142pub use nft;434445pub type BlockNumber = u32;464748pub type Signature = MultiSignature;49505152pub type AccountId = <<Signature as Verify>::Signer as IdentifyAccount>::AccountId;53545556pub type AccountIndex = u32;575859pub type Balance = u128;606162pub type Index = u32;636465pub type Hash = sp_core::H256;666768pub type DigestItem = generic::DigestItem<Hash>;6970pub const MILLICENTS: Balance = 1_000_000_000;71pub const CENTS: Balance = 1_000 * MILLICENTS;72pub const DOLLARS: Balance = 100 * CENTS;737475767778pub mod opaque {79 use super::*;8081 pub use sp_runtime::OpaqueExtrinsic as UncheckedExtrinsic;8283 84 pub type Header = generic::Header<BlockNumber, BlakeTwo256>;85 86 pub type Block = generic::Block<Header, UncheckedExtrinsic>;87 88 pub type BlockId = generic::BlockId<Block>;8990 impl_opaque_keys! {91 pub struct SessionKeys {92 pub aura: Aura,93 pub grandpa: Grandpa,94 }95 }96}979899pub const VERSION: RuntimeVersion = RuntimeVersion {100 spec_name: create_runtime_str!("nft"),101 impl_name: create_runtime_str!("nft"),102 authoring_version: 1,103 spec_version: 1,104 impl_version: 1,105 apis: RUNTIME_API_VERSIONS,106 transaction_version: 1,107};108109pub const MILLISECS_PER_BLOCK: u64 = 6000;110111pub const SLOT_DURATION: u64 = MILLISECS_PER_BLOCK;112113114pub const MINUTES: BlockNumber = 60_000 / (MILLISECS_PER_BLOCK as BlockNumber);115pub const HOURS: BlockNumber = MINUTES * 60;116pub const DAYS: BlockNumber = HOURS * 24;117118119#[cfg(feature = "std")]120pub fn native_version() -> NativeVersion {121 NativeVersion {122 runtime_version: VERSION,123 can_author_with: Default::default(),124 }125}126127parameter_types! {128 pub const BlockHashCount: BlockNumber = 2400;129 130 131 pub const MaximumBlockWeight: Weight = 1_000_000_000;132 pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);133 134 135 136 pub const MaximumBlockLength: u32 = 5 * 1024 * 1024;137 pub const Version: RuntimeVersion = VERSION;138}139140impl system::Trait for Runtime {141 142 type AccountId = AccountId;143 144 type Call = Call;145 146 type Lookup = IdentityLookup<AccountId>;147 148 type Index = Index;149 150 type BlockNumber = BlockNumber;151 152 type Hash = Hash;153 154 type Hashing = BlakeTwo256;155 156 type Header = generic::Header<BlockNumber, BlakeTwo256>;157 158 type Event = Event;159 160 type Origin = Origin;161 162 type BlockHashCount = BlockHashCount;163 164 type MaximumBlockWeight = MaximumBlockWeight;165 166 type MaximumBlockLength = MaximumBlockLength;167 168 type AvailableBlockRatio = AvailableBlockRatio;169 170 type Version = Version;171 172 173 174 type ModuleToIndex = ModuleToIndex;175 176 type OnNewAccount = ();177 178 type OnKilledAccount = ();179 180 type AccountData = balances::AccountData<Balance>;181}182183impl aura::Trait for Runtime {184 type AuthorityId = AuraId;185}186187impl grandpa::Trait for Runtime {188 type Event = Event;189}190191parameter_types! {192 pub const MinimumPeriod: u64 = SLOT_DURATION / 2;193}194195impl timestamp::Trait for Runtime {196 197 type Moment = u64;198 type OnTimestampSet = Aura;199 type MinimumPeriod = MinimumPeriod;200}201202impl contracts::Trait for Runtime {203 type Time = Timestamp;204 type Randomness = RandomnessCollectiveFlip;205 type Currency = Balances;206 type Event = Event;207 type DetermineContractAddress = contracts::SimpleAddressDeterminer<Runtime>;208 type TrieIdGenerator = contracts::TrieIdFromParentCounter<Runtime>;209 type RentPayment = ();210 type SignedClaimHandicap = contracts::DefaultSignedClaimHandicap;211 212 type StorageSizeOffset = contracts::DefaultStorageSizeOffset;213 214 215 216 type MaxDepth = contracts::DefaultMaxDepth;217 type MaxValueSize = contracts::DefaultMaxValueSize;218 219}220221parameter_types! {222 pub const ExistentialDeposit: u128 = 500;223}224225impl balances::Trait for Runtime {226 227 type Balance = Balance;228 229 type Event = Event;230 type DustRemoval = ();231 type ExistentialDeposit = ExistentialDeposit;232 type AccountStore = System;233}234235parameter_types! {236 pub const TransactionBaseFee: Balance = 0;237 pub const TransactionByteFee: Balance = 1;238}239240impl transaction_payment::Trait for Runtime {241 type Currency = balances::Module<Runtime>;242 type OnTransactionPayment = ();243 type TransactionBaseFee = TransactionBaseFee;244 type TransactionByteFee = TransactionByteFee;245 type WeightToFee = ConvertInto;246 type FeeMultiplierUpdate = ();247}248249impl sudo::Trait for Runtime {250 type Event = Event;251 type Call = Call;252}253254255impl nft::Trait for Runtime {256 type Event = Event;257}258259construct_runtime!(260 pub enum Runtime where261 Block = Block,262 NodeBlock = opaque::Block,263 UncheckedExtrinsic = UncheckedExtrinsic264 {265 System: system::{Module, Call, Config, Storage, Event<T>},266 RandomnessCollectiveFlip: randomness_collective_flip::{Module, Call, Storage},267 Contracts: contracts::{Module, Call, Config, Storage, Event<T>},268 Timestamp: timestamp::{Module, Call, Storage, Inherent},269 Aura: aura::{Module, Config<T>, Inherent(Timestamp)},270 Grandpa: grandpa::{Module, Call, Storage, Config, Event},271 Balances: balances::{Module, Call, Storage, Config<T>, Event<T>},272 TransactionPayment: transaction_payment::{Module, Storage},273 Sudo: sudo::{Module, Call, Config<T>, Storage, Event<T>},274 275 Nft: nft::{Module, Call, Storage, Event<T>},276 }277);278279280pub type Address = AccountId;281282pub type Header = generic::Header<BlockNumber, BlakeTwo256>;283284pub type Block = generic::Block<Header, UncheckedExtrinsic>;285286pub type SignedBlock = generic::SignedBlock<Block>;287288pub type BlockId = generic::BlockId<Block>;289290pub type SignedExtra = (291 system::CheckVersion<Runtime>,292 system::CheckGenesis<Runtime>,293 system::CheckEra<Runtime>,294 system::CheckNonce<Runtime>,295 system::CheckWeight<Runtime>,296 transaction_payment::ChargeTransactionPayment<Runtime>297);298299pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<Address, Call, Signature, SignedExtra>;300301pub type CheckedExtrinsic = generic::CheckedExtrinsic<AccountId, Call, SignedExtra>;302303pub type Executive = frame_executive::Executive<Runtime, Block, system::ChainContext<Runtime>, Runtime, AllModules>;304305impl_runtime_apis! {306 impl sp_api::Core<Block> for Runtime {307 fn version() -> RuntimeVersion {308 VERSION309 }310311 fn execute_block(block: Block) {312 Executive::execute_block(block)313 }314315 fn initialize_block(header: &<Block as BlockT>::Header) {316 Executive::initialize_block(header)317 }318 }319320 impl sp_api::Metadata<Block> for Runtime {321 fn metadata() -> OpaqueMetadata {322 Runtime::metadata().into()323 }324 }325326 impl sp_block_builder::BlockBuilder<Block> for Runtime {327 fn apply_extrinsic(extrinsic: <Block as BlockT>::Extrinsic) -> ApplyExtrinsicResult {328 Executive::apply_extrinsic(extrinsic)329 }330331 fn finalize_block() -> <Block as BlockT>::Header {332 Executive::finalize_block()333 }334335 fn inherent_extrinsics(data: sp_inherents::InherentData) -> Vec<<Block as BlockT>::Extrinsic> {336 data.create_extrinsics()337 }338339 fn check_inherents(340 block: Block,341 data: sp_inherents::InherentData,342 ) -> sp_inherents::CheckInherentsResult {343 data.check_extrinsics(&block)344 }345346 fn random_seed() -> <Block as BlockT>::Hash {347 RandomnessCollectiveFlip::random_seed()348 }349 }350351 impl sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block> for Runtime {352 fn validate_transaction(353 source: TransactionSource,354 tx: <Block as BlockT>::Extrinsic,355 ) -> TransactionValidity {356 Executive::validate_transaction(source, tx)357 }358 }359360 impl sp_offchain::OffchainWorkerApi<Block> for Runtime {361 fn offchain_worker(header: &<Block as BlockT>::Header) {362 Executive::offchain_worker(header)363 }364 }365366 impl sp_consensus_aura::AuraApi<Block, AuraId> for Runtime {367 fn slot_duration() -> u64 {368 Aura::slot_duration()369 }370371 fn authorities() -> Vec<AuraId> {372 Aura::authorities()373 }374 }375376 impl sp_session::SessionKeys<Block> for Runtime {377 fn generate_session_keys(seed: Option<Vec<u8>>) -> Vec<u8> {378 opaque::SessionKeys::generate(seed)379 }380381 fn decode_session_keys(382 encoded: Vec<u8>,383 ) -> Option<Vec<(Vec<u8>, sp_core::crypto::KeyTypeId)>> {384 opaque::SessionKeys::decode_into_raw_public_keys(&encoded)385 }386 }387388 impl fg_primitives::GrandpaApi<Block> for Runtime {389 fn grandpa_authorities() -> GrandpaAuthorityList {390 Grandpa::grandpa_authorities()391 }392 }393394 impl contracts_rpc_runtime_api::ContractsApi<Block, AccountId, Balance, BlockNumber>395 for Runtime396 {397 fn call(398 origin: AccountId,399 dest: AccountId,400 value: Balance,401 gas_limit: u64,402 input_data: Vec<u8>,403 ) -> ContractExecResult {404 let exec_result =405 Contracts::bare_call(origin, dest.into(), value, gas_limit, input_data);406 match exec_result {407 Ok(v) => ContractExecResult::Success {408 status: v.status,409 data: v.data,410 },411 Err(_) => ContractExecResult::Error,412 }413 }414415 fn get_storage(416 address: AccountId,417 key: [u8; 32],418 ) -> contracts_primitives::GetStorageResult {419 Contracts::get_storage(address, key)420 }421422 fn rent_projection(423 address: AccountId,424 ) -> contracts_primitives::RentProjectionResult<BlockNumber> {425 Contracts::rent_projection(address)426 }427 }428429}