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, crypto::Public, OpaqueMetadata };17use sp_runtime::{18 create_runtime_str, generic, impl_opaque_keys,19 traits::{20 Convert, ConvertInto, BlakeTwo256, Block as BlockT, IdentifyAccount, 21 IdentityLookup, NumberFor, Saturating, 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, LockIdentifier,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, Permill, Percent, ModuleId };52use frame_system::{self as system, EnsureRoot };53use sp_std::{marker::PhantomData};5455pub use pallet_timestamp::Call as TimestampCall;56575859pub struct CurrencyToVoteHandler;6061impl CurrencyToVoteHandler {62 fn factor() -> Balance {63 (Balances::total_issuance() / u64::max_value() as Balance).max(1)64 }65}6667impl Convert<Balance, u64> for CurrencyToVoteHandler {68 fn convert(x: Balance) -> u64 {69 (x / Self::factor()) as u6470 }71}7273impl Convert<u128, Balance> for CurrencyToVoteHandler {74 fn convert(x: u128) -> Balance {75 x * Self::factor()76 }77}78798081extern crate pallet_nft;82pub use pallet_nft::*;838485pub type BlockNumber = u32;868788pub type Signature = MultiSignature;89909192pub type AccountId = <<Signature as Verify>::Signer as IdentifyAccount>::AccountId;93949596pub type AccountIndex = u32;979899pub type Balance = u128;100101102pub type Index = u32;103104105pub type Hash = sp_core::H256;106107108pub type DigestItem = generic::DigestItem<Hash>;109110mod nft_weights;111112113114115116pub mod opaque {117 use super::*;118119 pub use sp_runtime::OpaqueExtrinsic as UncheckedExtrinsic;120121 122 pub type Header = generic::Header<BlockNumber, BlakeTwo256>;123 124 pub type Block = generic::Block<Header, UncheckedExtrinsic>;125 126 pub type BlockId = generic::BlockId<Block>;127128 impl_opaque_keys! {129 pub struct SessionKeys {130 pub aura: Aura,131 pub grandpa: Grandpa,132 }133 }134}135136137pub const VERSION: RuntimeVersion = RuntimeVersion {138 spec_name: create_runtime_str!("nft"),139 impl_name: create_runtime_str!("nft"),140 authoring_version: 1,141 spec_version: 2,142 impl_version: 1,143 apis: RUNTIME_API_VERSIONS,144 transaction_version: 1,145};146147pub const MILLISECS_PER_BLOCK: u64 = 6000;148149pub const SLOT_DURATION: u64 = MILLISECS_PER_BLOCK;150151152pub const MINUTES: BlockNumber = 60_000 / (MILLISECS_PER_BLOCK as BlockNumber);153pub const HOURS: BlockNumber = MINUTES * 60;154pub const DAYS: BlockNumber = HOURS * 24;155156157#[cfg(feature = "std")]158pub fn native_version() -> NativeVersion {159 NativeVersion {160 runtime_version: VERSION,161 can_author_with: Default::default(),162 }163}164165166pub struct ValiudatorsOnly<Runtime: pallet_aura::Trait>(PhantomData<Runtime>);167impl frame_support::traits::Contains<AccountId> for ValiudatorsOnly<Runtime> {168 fn contains(t: &AccountId) -> bool {169 let arr: [u8; 32] = *t.as_ref();170 let raw_key: Vec<u8> = Vec::from(arr);171172 match pallet_aura::Module::<Runtime>::authorities().iter().find(|auth| auth.to_raw_vec() == raw_key) {173 Some(_) => true,174 None => false,175 } 176 }177 fn sorted_members() -> Vec<AccountId> {178 let mut members: Vec<AccountId> = Vec::new();179 for auth in pallet_aura::Module::<Runtime>::authorities() {180 let mut arr: [u8; 32] = Default::default(); 181 let bor_arr = auth.clone().to_raw_vec();182 let slice = bor_arr.as_slice();183 arr.copy_from_slice(slice);184 members.push(AccountId::from(arr));185 }186 members 187 }188 fn count() -> usize {189 pallet_aura::Module::<Runtime>::authorities().len()190 }191}192193impl frame_support::traits::ContainsLengthBound for ValiudatorsOnly<Runtime> {194 fn min_len() -> usize {195 1196 }197 fn max_len() -> usize {198 100199 }200}201202parameter_types! {203 pub const BlockHashCount: BlockNumber = 2400;204 205 pub const MaximumBlockWeight: Weight = 2 * WEIGHT_PER_SECOND;206 pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);207 208 pub MaximumExtrinsicWeight: Weight = AvailableBlockRatio::get()209 .saturating_sub(Perbill::from_percent(10)) * MaximumBlockWeight::get();210 pub const MaximumBlockLength: u32 = 5 * 1024 * 1024;211 pub const Version: RuntimeVersion = VERSION;212}213214impl system::Trait for Runtime {215 216 type BaseCallFilter = ();217 218 type AccountId = AccountId;219 220 type Call = Call;221 222 type Lookup = IdentityLookup<AccountId>;223 224 type Index = Index;225 226 type BlockNumber = BlockNumber;227 228 type Hash = Hash;229 230 type Hashing = BlakeTwo256;231 232 type Header = generic::Header<BlockNumber, BlakeTwo256>;233 234 type Event = Event;235 236 type Origin = Origin;237 238 type BlockHashCount = BlockHashCount;239 240 type MaximumBlockWeight = MaximumBlockWeight;241 242 type DbWeight = RocksDbWeight;243 244 245 type BlockExecutionWeight = BlockExecutionWeight;246 247 248 type ExtrinsicBaseWeight = ExtrinsicBaseWeight;249 250 251 252 type MaximumExtrinsicWeight = MaximumExtrinsicWeight;253 254 type MaximumBlockLength = MaximumBlockLength;255 256 type AvailableBlockRatio = AvailableBlockRatio;257 258 type Version = Version;259 260 type PalletInfo = PalletInfo;261 262 type OnNewAccount = ();263 264 type OnKilledAccount = ();265 266 type AccountData = pallet_balances::AccountData<Balance>;267 268 type SystemWeightInfo = ();269}270271impl pallet_aura::Trait for Runtime {272 type AuthorityId = AuraId;273}274275impl pallet_grandpa::Trait for Runtime {276 type Event = Event;277 type Call = Call;278279 type KeyOwnerProofSystem = ();280281 type KeyOwnerProof =282 <Self::KeyOwnerProofSystem as KeyOwnerProofSystem<(KeyTypeId, GrandpaId)>>::Proof;283284 type KeyOwnerIdentification = <Self::KeyOwnerProofSystem as KeyOwnerProofSystem<(285 KeyTypeId,286 GrandpaId,287 )>>::IdentificationTuple;288289 type HandleEquivocation = ();290291 type WeightInfo = ();292}293294parameter_types! {295 pub const MinimumPeriod: u64 = SLOT_DURATION / 2;296}297298impl pallet_timestamp::Trait for Runtime {299 300 type Moment = u64;301 type OnTimestampSet = Aura;302 type MinimumPeriod = MinimumPeriod;303 type WeightInfo = ();304}305306parameter_types! {307 308 pub const ExistentialDeposit: u128 = 0;309 pub const MaxLocks: u32 = 50;310}311312impl pallet_balances::Trait for Runtime {313 type MaxLocks = MaxLocks;314 315 type Balance = Balance;316 317 type Event = Event;318 type DustRemoval = Treasury;319 type ExistentialDeposit = ExistentialDeposit;320 type AccountStore = System;321 type WeightInfo = ();322}323324pub const MILLICENTS: Balance = 1_000_000_000;325pub const CENTS: Balance = 1_000 * MILLICENTS;326pub const DOLLARS: Balance = 100 * CENTS;327328parameter_types! {329 pub const TombstoneDeposit: Balance = 0;330 pub const RentByteFee: Balance = 4 * MILLICENTS;331 pub const RentDepositOffset: Balance = 1000 * MILLICENTS;332 pub const SurchargeReward: Balance = 150 * MILLICENTS;333}334335impl pallet_contracts::Trait for Runtime {336 type Time = Timestamp;337 type Randomness = RandomnessCollectiveFlip;338 type Currency = Balances;339 type Event = Event;340 type DetermineContractAddress = pallet_contracts::SimpleAddressDeterminer<Runtime>;341 type TrieIdGenerator = pallet_contracts::TrieIdFromParentCounter<Runtime>;342 type RentPayment = ();343 type SignedClaimHandicap = pallet_contracts::DefaultSignedClaimHandicap;344 type TombstoneDeposit = TombstoneDeposit;345 type StorageSizeOffset = pallet_contracts::DefaultStorageSizeOffset;346 type RentByteFee = RentByteFee;347 type RentDepositOffset = RentDepositOffset;348 type SurchargeReward = SurchargeReward;349 type MaxDepth = pallet_contracts::DefaultMaxDepth;350 type MaxValueSize = pallet_contracts::DefaultMaxValueSize;351 type WeightPrice = pallet_transaction_payment::Module<Self>;352}353354parameter_types! {355 pub const TransactionByteFee: Balance = 10 * MILLICENTS;356}357358impl pallet_transaction_payment::Trait for Runtime {359 type Currency = pallet_balances::Module<Runtime>;360 type OnTransactionPayment = Treasury;361 type TransactionByteFee = TransactionByteFee;362 type WeightToFee = IdentityFee<Balance>;363 type FeeMultiplierUpdate = ();364}365366parameter_types! {367 pub const ProposalBond: Permill = Permill::from_percent(5);368 pub const ProposalBondMinimum: Balance = 1 * DOLLARS;369 pub const SpendPeriod: BlockNumber = 5 * MINUTES;370 pub const Burn: Permill = Permill::from_percent(0);371 pub const TipCountdown: BlockNumber = 1 * DAYS;372 pub const TipFindersFee: Percent = Percent::from_percent(20);373 pub const TipReportDepositBase: Balance = 1 * DOLLARS;374 pub const DataDepositPerByte: Balance = 1 * CENTS;375 pub const BountyDepositBase: Balance = 1 * DOLLARS;376 pub const BountyDepositPayoutDelay: BlockNumber = 1 * DAYS;377 pub const TreasuryModuleId: ModuleId = ModuleId(*b"py/trsry");378 pub const BountyUpdatePeriod: BlockNumber = 14 * DAYS;379 pub const MaximumReasonLength: u32 = 16384;380 pub const BountyCuratorDeposit: Permill = Permill::from_percent(50);381 pub const BountyValueMinimum: Balance = 5 * DOLLARS;382}383384impl pallet_treasury::Trait for Runtime {385 type ModuleId = TreasuryModuleId;386 type Currency = Balances;387 type ApproveOrigin = EnsureRoot<AccountId>;388 type RejectOrigin = EnsureRoot<AccountId>;389 type Tippers = ValiudatorsOnly<Self>;390 type TipCountdown = TipCountdown;391 type TipFindersFee = TipFindersFee;392 type TipReportDepositBase = TipReportDepositBase;393 type DataDepositPerByte = DataDepositPerByte;394 type Event = Event;395 type OnSlash = ();396 type ProposalBond = ProposalBond;397 type ProposalBondMinimum = ProposalBondMinimum;398 type SpendPeriod = SpendPeriod;399 type Burn = Burn;400 type BountyDepositBase = BountyDepositBase;401 type BountyDepositPayoutDelay = BountyDepositPayoutDelay;402 type BountyUpdatePeriod = BountyUpdatePeriod;403 type BountyCuratorDeposit = BountyCuratorDeposit;404 type BountyValueMinimum = BountyValueMinimum;405 type MaximumReasonLength = MaximumReasonLength;406 type BurnDestination = ();407 type WeightInfo = ();408}409410impl pallet_sudo::Trait for Runtime {411 type Event = Event;412 type Call = Call;413}414415parameter_types! {416 pub const MinVestedTransfer: Balance = 100 * DOLLARS;417}418419impl pallet_vesting::Trait for Runtime {420 type Event = Event;421 type Currency = Balances;422 type BlockNumberToBalance = ConvertInto;423 type MinVestedTransfer = MinVestedTransfer;424 type WeightInfo = ();425}426427428impl pallet_nft::Trait for Runtime {429 type Event = Event;430 type WeightInfo = nft_weights::WeightInfo;431}432433construct_runtime!(434 pub enum Runtime where435 Block = Block,436 NodeBlock = opaque::Block,437 UncheckedExtrinsic = UncheckedExtrinsic438 {439 System: system::{Module, Call, Config, Storage, Event<T>},440 RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Module, Call, Storage},441 Contracts: pallet_contracts::{Module, Call, Config, Storage, Event<T>},442 Timestamp: pallet_timestamp::{Module, Call, Storage, Inherent},443 Aura: pallet_aura::{Module, Config<T>, Inherent},444 Grandpa: pallet_grandpa::{Module, Call, Storage, Config, Event},445 Balances: pallet_balances::{Module, Call, Storage, Config<T>, Event<T>},446 TransactionPayment: pallet_transaction_payment::{Module, Storage},447 Sudo: pallet_sudo::{Module, Call, Config<T>, Storage, Event<T>},448 Nft: pallet_nft::{Module, Call, Config<T>, Storage, Event<T>},449 Treasury: pallet_treasury::{Module, Call, Storage, Config, Event<T>},450 Vesting: pallet_vesting::{Module, Call, Config<T>, Storage, Event<T>},451 }452);453454455pub type Address = AccountId;456457pub type Header = generic::Header<BlockNumber, BlakeTwo256>;458459pub type Block = generic::Block<Header, UncheckedExtrinsic>;460461pub type SignedBlock = generic::SignedBlock<Block>;462463pub type BlockId = generic::BlockId<Block>;464465pub type SignedExtra = (466 system::CheckSpecVersion<Runtime>,467 system::CheckTxVersion<Runtime>,468 system::CheckGenesis<Runtime>,469 system::CheckEra<Runtime>,470 system::CheckNonce<Runtime>,471 system::CheckWeight<Runtime>,472 pallet_nft::ChargeTransactionPayment<Runtime>,473);474475pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<Address, Call, Signature, SignedExtra>;476477pub type CheckedExtrinsic = generic::CheckedExtrinsic<AccountId, Call, SignedExtra>;478479pub type Executive =480 frame_executive::Executive<Runtime, Block, system::ChainContext<Runtime>, Runtime, AllModules>;481482impl_runtime_apis! {483484 impl pallet_contracts_rpc_runtime_api::ContractsApi<Block, AccountId, Balance, BlockNumber>485 for Runtime486 {487 fn call(488 origin: AccountId,489 dest: AccountId,490 value: Balance,491 gas_limit: u64,492 input_data: Vec<u8>,493 ) -> ContractExecResult {494 let (exec_result, gas_consumed) =495 Contracts::bare_call(origin, dest.into(), value, gas_limit, input_data);496 match exec_result {497 Ok(v) => ContractExecResult::Success {498 flags: v.flags.bits(),499 data: v.data,500 gas_consumed: gas_consumed,501 },502 Err(_) => ContractExecResult::Error,503 }504 }505506 fn get_storage(507 address: AccountId,508 key: [u8; 32],509 ) -> pallet_contracts_primitives::GetStorageResult {510 Contracts::get_storage(address, key)511 }512513 fn rent_projection(514 address: AccountId,515 ) -> pallet_contracts_primitives::RentProjectionResult<BlockNumber> {516 Contracts::rent_projection(address)517 }518 }519520 impl sp_api::Core<Block> for Runtime {521 fn version() -> RuntimeVersion {522 VERSION523 }524525 fn execute_block(block: Block) {526 Executive::execute_block(block)527 }528529 fn initialize_block(header: &<Block as BlockT>::Header) {530 Executive::initialize_block(header)531 }532 }533534 impl sp_api::Metadata<Block> for Runtime {535 fn metadata() -> OpaqueMetadata {536 Runtime::metadata().into()537 }538 }539540 impl sp_block_builder::BlockBuilder<Block> for Runtime {541 fn apply_extrinsic(extrinsic: <Block as BlockT>::Extrinsic) -> ApplyExtrinsicResult {542 Executive::apply_extrinsic(extrinsic)543 }544545 fn finalize_block() -> <Block as BlockT>::Header {546 Executive::finalize_block()547 }548549 fn inherent_extrinsics(data: sp_inherents::InherentData) -> Vec<<Block as BlockT>::Extrinsic> {550 data.create_extrinsics()551 }552553 fn check_inherents(554 block: Block,555 data: sp_inherents::InherentData,556 ) -> sp_inherents::CheckInherentsResult {557 data.check_extrinsics(&block)558 }559560 fn random_seed() -> <Block as BlockT>::Hash {561 RandomnessCollectiveFlip::random_seed()562 }563 }564565 impl sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block> for Runtime {566 fn validate_transaction(567 source: TransactionSource,568 tx: <Block as BlockT>::Extrinsic,569 ) -> TransactionValidity {570 Executive::validate_transaction(source, tx)571 }572 }573574 impl sp_offchain::OffchainWorkerApi<Block> for Runtime {575 fn offchain_worker(header: &<Block as BlockT>::Header) {576 Executive::offchain_worker(header)577 }578 }579580 impl sp_consensus_aura::AuraApi<Block, AuraId> for Runtime {581 fn slot_duration() -> u64 {582 Aura::slot_duration()583 }584585 fn authorities() -> Vec<AuraId> {586 Aura::authorities()587 }588 }589590 impl sp_session::SessionKeys<Block> for Runtime {591 fn generate_session_keys(seed: Option<Vec<u8>>) -> Vec<u8> {592 opaque::SessionKeys::generate(seed)593 }594595 fn decode_session_keys(596 encoded: Vec<u8>,597 ) -> Option<Vec<(Vec<u8>, KeyTypeId)>> {598 opaque::SessionKeys::decode_into_raw_public_keys(&encoded)599 }600 }601602 impl fg_primitives::GrandpaApi<Block> for Runtime {603 fn grandpa_authorities() -> GrandpaAuthorityList {604 Grandpa::grandpa_authorities()605 }606607 fn submit_report_equivocation_unsigned_extrinsic(608 _equivocation_proof: fg_primitives::EquivocationProof<609 <Block as BlockT>::Hash,610 NumberFor<Block>,611 >,612 _key_owner_proof: fg_primitives::OpaqueKeyOwnershipProof,613 ) -> Option<()> {614 None615 }616617 fn generate_key_ownership_proof(618 _set_id: fg_primitives::SetId,619 _authority_id: GrandpaId,620 ) -> Option<fg_primitives::OpaqueKeyOwnershipProof> {621 622 623 624 None625 }626 }627 628 impl frame_system_rpc_runtime_api::AccountNonceApi<Block, AccountId, Index> for Runtime {629 fn account_nonce(account: AccountId) -> Index {630 System::account_nonce(account)631 }632 }633634 impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance> for Runtime {635 fn query_info(636 uxt: <Block as BlockT>::Extrinsic,637 len: u32,638 ) -> pallet_transaction_payment_rpc_runtime_api::RuntimeDispatchInfo<Balance> {639 TransactionPayment::query_info(uxt, len)640 }641 }642643 #[cfg(feature = "runtime-benchmarks")]644 impl frame_benchmarking::Benchmark<Block> for Runtime {645 fn dispatch_benchmark(646 config: frame_benchmarking::BenchmarkConfig647 ) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, sp_runtime::RuntimeString> {648 use frame_benchmarking::{Benchmarking, BenchmarkBatch, add_benchmark, TrackedStorageKey};649650 let whitelist: Vec<TrackedStorageKey> = vec![651 652 hex_literal::hex!("d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d").to_vec().into(),653 654 655 656 657 658 659 660 661 ];662663 let mut batches = Vec::<BenchmarkBatch>::new();664 let params = (&config, &whitelist);665666 add_benchmark!(params, batches, pallet_nft, Nft);667668 if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) }669 Ok(batches)670 }671 }672}