12345678#![cfg_attr(not(feature = "std"), no_std)]910#![recursion_limit = "1024"]111213#[cfg(feature = "std")]14include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));1516use sp_api::impl_runtime_apis;17use sp_core::{ crypto::KeyTypeId, OpaqueMetadata, H256, U256, H160 };18192021use sp_runtime::{22 Permill, Perbill, Percent,23 create_runtime_str, generic, impl_opaque_keys,24 traits::{25 AccountIdLookup, ConvertInto, BlakeTwo256, Block as BlockT, IdentifyAccount, 26 Verify, AccountIdConversion,27 },28 transaction_validity::{TransactionSource, TransactionValidity},29 ApplyExtrinsicResult, MultiSignature,30};3132use sp_std::prelude::*;3334#[cfg(feature = "std")]35use sp_version::NativeVersion;36use sp_version::RuntimeVersion;37pub use pallet_transaction_payment::{Multiplier, TargetedFeeAdjustment, FeeDetails, RuntimeDispatchInfo};3839pub use pallet_balances::Call as BalancesCall;40pub use pallet_evm::{EnsureAddressTruncated, HashedAddressMapping, Runner};41pub use frame_support::{42 construct_runtime,43 match_type,44 dispatch::DispatchResult,45 PalletId,46 parameter_types,47 StorageValue,48 ConsensusEngineId,49 traits::{50 All, Currency, ExistenceRequirement, Get, IsInVec, KeyOwnerProofSystem, LockIdentifier, OnUnbalanced, Randomness, FindAuthor51 },52 weights::{53 constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND},54 DispatchClass, DispatchInfo, GetDispatchInfo, IdentityFee, Pays, PostDispatchInfo, Weight,55 WeightToFeePolynomial, WeightToFeeCoefficient, WeightToFeeCoefficients56 },57};58use nft_data_structs::*;59use pallet_contracts::weights::WeightInfo;6061use frame_system::{62 self as system,63 EnsureRoot, EnsureSigned,64 limits::{BlockWeights, BlockLength},65};66use sp_arithmetic::{traits::{BaseArithmetic, Unsigned}};67use smallvec::smallvec;68use codec::{Encode, Decode};69use pallet_evm::{Account as EVMAccount, FeeCalculator, OnMethodCall};70use fp_rpc::TransactionStatus;71use sp_core::crypto::Public;72use sp_runtime::{73 traits::{ 74 Dispatchable,75 },76};77use pallet_contracts::chain_extension::UncheckedFrom;787980pub use pallet_timestamp::Call as TimestampCall;81pub use sp_consensus_aura::sr25519::AuthorityId as AuraId;828384use pallet_xcm::XcmPassthrough;85use polkadot_parachain::primitives::Sibling;86use xcm::v0::Xcm;87use xcm::v0::{BodyId, Junction::*, MultiAsset, MultiLocation, MultiLocation::*, NetworkId};88use xcm_builder::{89 AccountId32Aliases, AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, CurrencyAdapter,90 EnsureXcmOrigin, FixedWeightBounds, IsConcrete, LocationInverter, NativeAsset,91 ParentAsSuperuser, ParentIsDefault, RelayChainAsNative, SiblingParachainAsNative,92 SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32,93 SovereignSignedViaLocation, TakeWeightCredit, UsingComponents,94};95use xcm_executor::{Config, XcmExecutor};969798mod chain_extension;99use crate::chain_extension::{ NFTExtension, Imbalance };100101102103104105106107108109110111pub type BlockNumber = u32;112113114pub type Signature = MultiSignature;115116117118pub type AccountId = <<Signature as Verify>::Signer as IdentifyAccount>::AccountId;119120121122pub type AccountIndex = u32;123124125pub type Balance = u128;126127128pub type Index = u32;129130131pub type Hash = sp_core::H256;132133134pub type DigestItem = generic::DigestItem<Hash>;135136mod nft_weights;137138139140141142pub mod opaque {143 use super::*;144145 pub use sp_runtime::OpaqueExtrinsic as UncheckedExtrinsic;146147 148 pub type Block = generic::Block<Header, UncheckedExtrinsic>;149150 pub type SessionHandlers = ();151152 impl_opaque_keys! {153 pub struct SessionKeys {154 pub aura: Aura,155 }156 }157}158159160pub const VERSION: RuntimeVersion = RuntimeVersion {161 spec_name: create_runtime_str!("nft"),162 impl_name: create_runtime_str!("nft"),163 authoring_version: 1,164 spec_version: 3,165 impl_version: 1,166 apis: RUNTIME_API_VERSIONS,167 transaction_version: 1,168};169170pub const MILLISECS_PER_BLOCK: u64 = 12000;171172pub const SLOT_DURATION: u64 = MILLISECS_PER_BLOCK;173174175pub const MINUTES: BlockNumber = 60_000 / (MILLISECS_PER_BLOCK as BlockNumber);176pub const HOURS: BlockNumber = MINUTES * 60;177pub const DAYS: BlockNumber = HOURS * 24;178179#[derive(codec::Encode, codec::Decode)]180pub enum XCMPMessage<XAccountId, XBalance> {181 182 TransferToken(XAccountId, XBalance),183}184185186#[cfg(feature = "std")]187pub fn native_version() -> NativeVersion {188 NativeVersion {189 runtime_version: VERSION,190 can_author_with: Default::default(),191 }192}193194type NegativeImbalance = <Balances as Currency<AccountId>>::NegativeImbalance;195196pub struct DealWithFees;197impl OnUnbalanced<NegativeImbalance> for DealWithFees {198 fn on_unbalanceds<B>(mut fees_then_tips: impl Iterator<Item=NegativeImbalance>) {199 if let Some(fees) = fees_then_tips.next() {200 201 let mut split = fees.ration(100, 0);202 if let Some(tips) = fees_then_tips.next() {203 204 tips.ration_merge_into(100, 0, &mut split);205 }206 Treasury::on_unbalanced(split.0);207 208 }209 }210}211212213214const AVERAGE_ON_INITIALIZE_RATIO: Perbill = Perbill::from_percent(10);215216217const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);218219const MAXIMUM_BLOCK_WEIGHT: Weight = 2 * WEIGHT_PER_SECOND;220221parameter_types! {222 pub const BlockHashCount: BlockNumber = 2400;223 pub RuntimeBlockLength: BlockLength =224 BlockLength::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO);225 pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);226 pub const MaximumBlockLength: u32 = 5 * 1024 * 1024;227 pub RuntimeBlockWeights: BlockWeights = BlockWeights::builder()228 .base_block(BlockExecutionWeight::get())229 .for_class(DispatchClass::all(), |weights| {230 weights.base_extrinsic = ExtrinsicBaseWeight::get();231 })232 .for_class(DispatchClass::Normal, |weights| {233 weights.max_total = Some(NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT);234 })235 .for_class(DispatchClass::Operational, |weights| {236 weights.max_total = Some(MAXIMUM_BLOCK_WEIGHT);237 238 239 weights.reserved = Some(240 MAXIMUM_BLOCK_WEIGHT - NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT241 );242 })243 .avg_block_initialization(AVERAGE_ON_INITIALIZE_RATIO)244 .build_or_panic();245 pub const Version: RuntimeVersion = VERSION;246 pub const SS58Prefix: u8 = 42;247}248249250parameter_types! {251 pub const ChainId: u64 = 8888;252}253254impl pallet_evm::Config for Runtime {255 type BlockGasLimit = BlockGasLimit;256 type FeeCalculator = ();257 type GasWeightMapping = ();258 type CallOrigin = EnsureAddressTruncated;259 type WithdrawOrigin = EnsureAddressTruncated;260 type AddressMapping = HashedAddressMapping<Self::Hashing>;261 type Precompiles = ();262 type Currency = Balances;263 type Event = Event;264 type OnMethodCall = pallet_nft::NftErcSupport<Self>;265 type ChainId = ChainId;266 type Runner = pallet_evm::runner::stack::Runner<Self>;267 type OnChargeTransaction = ();268}269270pub struct EthereumFindAuthor<F>(core::marker::PhantomData<F>);271impl<F: FindAuthor<u32>> FindAuthor<H160> for EthereumFindAuthor<F>272{273 fn find_author<'a, I>(digests: I) -> Option<H160> where274 I: 'a + IntoIterator<Item=(ConsensusEngineId, &'a [u8])>275 {276 if let Some(author_index) = F::find_author(digests) {277 let authority_id = Aura::authorities()[author_index as usize].clone();278 return Some(H160::from_slice(&authority_id.to_raw_vec()[4..24]));279 }280 None281 }282}283284parameter_types! {285 pub BlockGasLimit: U256 = U256::from(u32::max_value());286}287288impl pallet_ethereum::Config for Runtime {289 type Event = Event;290 type FindAuthor = EthereumFindAuthor<Aura>;291 type StateRoot = pallet_ethereum::IntermediateStateRoot;292 type EvmSubmitLog = pallet_evm::Pallet<Runtime>;293}294295impl system::Config for Runtime {296 297 type AccountData = pallet_balances::AccountData<Balance>;298 299 type AccountId = AccountId;300 301 type BaseCallFilter = ();302 303 type BlockHashCount = BlockHashCount;304 305 type BlockLength = RuntimeBlockLength;306 307 type BlockNumber = BlockNumber;308 309 type BlockWeights = RuntimeBlockWeights;310 311 type Call = Call;312 313 type DbWeight = RocksDbWeight;314 315 type Event = Event;316 317 type Hash = Hash;318 319 type Hashing = BlakeTwo256;320 321 type Header = generic::Header<BlockNumber, BlakeTwo256>;322 323 type Index = Index;324 325 type Lookup = AccountIdLookup<AccountId, ()>;326 327 type OnKilledAccount = ();328 329 type OnNewAccount = ();330 type OnSetCode = cumulus_pallet_parachain_system::ParachainSetCode<Self>;331 332 type Origin = Origin;333 334 type PalletInfo = PalletInfo;335 336 type SS58Prefix = SS58Prefix;337 338 type SystemWeightInfo = system::weights::SubstrateWeight<Runtime>;339 340 type Version = Version;341}342343parameter_types! {344 pub const MinimumPeriod: u64 = SLOT_DURATION / 2;345}346347impl pallet_timestamp::Config for Runtime {348 349 type Moment = u64;350 type OnTimestampSet = ();351 type MinimumPeriod = MinimumPeriod;352 type WeightInfo = ();353}354355parameter_types! {356 357 pub const ExistentialDeposit: u128 = 0;358 pub const MaxLocks: u32 = 50;359}360361impl pallet_balances::Config for Runtime {362 type MaxLocks = MaxLocks;363 364 type Balance = Balance;365 366 type Event = Event;367 type DustRemoval = Treasury;368 type ExistentialDeposit = ExistentialDeposit;369 type AccountStore = System;370 type WeightInfo = pallet_balances::weights::SubstrateWeight<Runtime>;371}372373pub const MICROUNIQUE: Balance = 1_000_000_000;374pub const MILLIUNIQUE: Balance = 1_000 * MICROUNIQUE;375pub const CENTIUNIQUE: Balance = 10 * MILLIUNIQUE;376pub const UNIQUE: Balance = 100 * CENTIUNIQUE;377378pub const fn deposit(items: u32, bytes: u32) -> Balance {379 items as Balance * 15 * CENTIUNIQUE + (bytes as Balance) * 6 * CENTIUNIQUE380}381382parameter_types! {383 pub TombstoneDeposit: Balance = deposit(384 1,385 sp_std::mem::size_of::<pallet_contracts::Pallet<Runtime>> as u32,386 );387 pub DepositPerContract: Balance = TombstoneDeposit::get();388 pub const DepositPerStorageByte: Balance = deposit(0, 1);389 pub const DepositPerStorageItem: Balance = deposit(1, 0);390 pub RentFraction: Perbill = Perbill::from_rational(1u32, 30 * DAYS);391 pub const SurchargeReward: Balance = 150 * MILLIUNIQUE;392 pub const SignedClaimHandicap: u32 = 2;393 pub const MaxDepth: u32 = 32;394 pub const MaxValueSize: u32 = 16 * 1024;395 pub const MaxCodeSize: u32 = 1024 * 1024 * 25; 396 397 pub DeletionWeightLimit: Weight = AVERAGE_ON_INITIALIZE_RATIO *398 RuntimeBlockWeights::get().max_block;399 400 401 pub DeletionQueueDepth: u32 = ((DeletionWeightLimit::get() / (402 <Runtime as pallet_contracts::Config>::WeightInfo::on_initialize_per_queue_item(1) -403 <Runtime as pallet_contracts::Config>::WeightInfo::on_initialize_per_queue_item(0)404 )) / 5) as u32;405 pub Schedule: pallet_contracts::Schedule<Runtime> = Default::default();406}407408impl pallet_contracts::Config for Runtime {409 type Time = Timestamp;410 type Randomness = RandomnessCollectiveFlip;411 type Currency = Balances;412 type Event = Event;413 type RentPayment = ();414 type SignedClaimHandicap = SignedClaimHandicap;415 type TombstoneDeposit = TombstoneDeposit;416 type DepositPerContract = DepositPerContract;417 type DepositPerStorageByte = DepositPerStorageByte;418 type DepositPerStorageItem = DepositPerStorageItem;419 type RentFraction = RentFraction;420 type SurchargeReward = SurchargeReward;421 422 423 type WeightPrice = pallet_transaction_payment::Module<Self>;424 type WeightInfo = pallet_contracts::weights::SubstrateWeight<Self>;425 type ChainExtension = NFTExtension;426 type DeletionQueueDepth = DeletionQueueDepth;427 type DeletionWeightLimit = DeletionWeightLimit;428 429 type Schedule = Schedule;430 type CallStack = [pallet_contracts::Frame<Self>; 31];431}432433parameter_types! {434 pub const TransactionByteFee: Balance = 501 * MICROUNIQUE; 435}436437438pub struct LinearFee<T>(sp_std::marker::PhantomData<T>);439440impl<T> WeightToFeePolynomial for LinearFee<T> where441 T: BaseArithmetic + From<u32> + Copy + Unsigned442{443 type Balance = T;444445 fn polynomial() -> WeightToFeeCoefficients<Self::Balance> {446 smallvec!(WeightToFeeCoefficient {447 coeff_integer: 146_700u32.into(), 448 coeff_frac: Perbill::zero(),449 negative: false,450 degree: 1,451 })452 }453}454455impl pallet_transaction_payment::Config for Runtime {456 type OnChargeTransaction = pallet_transaction_payment::CurrencyAdapter<Balances, ()>;457 type TransactionByteFee = TransactionByteFee;458 type WeightToFee = LinearFee<Balance>;459 type FeeMultiplierUpdate = ();460}461462parameter_types! {463 pub const ProposalBond: Permill = Permill::from_percent(5);464 pub const ProposalBondMinimum: Balance = 1 * UNIQUE;465 pub const SpendPeriod: BlockNumber = 5 * MINUTES;466 pub const Burn: Permill = Permill::from_percent(0);467 pub const TipCountdown: BlockNumber = 1 * DAYS;468 pub const TipFindersFee: Percent = Percent::from_percent(20);469 pub const TipReportDepositBase: Balance = 1 * UNIQUE;470 pub const DataDepositPerByte: Balance = 1 * CENTIUNIQUE;471 pub const BountyDepositBase: Balance = 1 * UNIQUE;472 pub const BountyDepositPayoutDelay: BlockNumber = 1 * DAYS;473 pub const TreasuryModuleId: PalletId = PalletId(*b"py/trsry");474 pub const BountyUpdatePeriod: BlockNumber = 14 * DAYS;475 pub const MaximumReasonLength: u32 = 16384;476 pub const BountyCuratorDeposit: Permill = Permill::from_percent(50);477 pub const BountyValueMinimum: Balance = 5 * UNIQUE;478 pub const MaxApprovals: u32 = 100;479}480481impl pallet_treasury::Config for Runtime {482 type PalletId = TreasuryModuleId;483 type Currency = Balances;484 type ApproveOrigin = EnsureRoot<AccountId>;485 type RejectOrigin = EnsureRoot<AccountId>;486 type Event = Event;487 type OnSlash = ();488 type ProposalBond = ProposalBond;489 type ProposalBondMinimum = ProposalBondMinimum;490 type SpendPeriod = SpendPeriod;491 type Burn = Burn;492 type BurnDestination = ();493 type SpendFunds = ();494 type WeightInfo = pallet_treasury::weights::SubstrateWeight<Runtime>;495 type MaxApprovals = MaxApprovals;496}497498impl pallet_sudo::Config for Runtime {499 type Event = Event;500 type Call = Call;501}502503parameter_types! {504 pub const MinVestedTransfer: Balance = 10 * UNIQUE;505}506507impl pallet_vesting::Config for Runtime {508 type Event = Event;509 type Currency = Balances;510 type BlockNumberToBalance = ConvertInto;511 type MinVestedTransfer = MinVestedTransfer;512 type WeightInfo = ();513}514515parameter_types! {516 pub const ReservedDmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT / 4;517 pub const ReservedXcmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT / 4;518}519520impl cumulus_pallet_parachain_system::Config for Runtime {521 type Event = Event;522 type OnValidationData = ();523 type SelfParaId = parachain_info::Pallet<Runtime>;524 525 526 527 528 529 type OutboundXcmpMessageSource = XcmpQueue;530 type DmpMessageHandler = DmpQueue;531 type ReservedDmpWeight = ReservedDmpWeight;532 type ReservedXcmpWeight = ReservedXcmpWeight;533 type XcmpMessageHandler = XcmpQueue;534}535536impl parachain_info::Config for Runtime {}537538impl cumulus_pallet_aura_ext::Config for Runtime {}539540parameter_types! {541 pub const RelayLocation: MultiLocation = X1(Parent);542 pub const RelayNetwork: NetworkId = NetworkId::Polkadot;543 pub RelayOrigin: Origin = cumulus_pallet_xcm::Origin::Relay.into();544 pub Ancestry: MultiLocation = X1(Parachain(ParachainInfo::parachain_id().into()));545}546547548549550pub type LocationToAccountId = (551 552 ParentIsDefault<AccountId>,553 554 SiblingParachainConvertsVia<Sibling, AccountId>,555 556 AccountId32Aliases<RelayNetwork, AccountId>,557);558559560pub type LocalAssetTransactor = CurrencyAdapter<561 562 Balances,563 564 IsConcrete<RelayLocation>,565 566 LocationToAccountId,567 568 AccountId,569 570 (),571>;572573574575576pub type XcmOriginToTransactDispatchOrigin = (577 578 579 580 SovereignSignedViaLocation<LocationToAccountId, Origin>,581 582 583 RelayChainAsNative<RelayOrigin, Origin>,584 585 586 SiblingParachainAsNative<cumulus_pallet_xcm::Origin, Origin>,587 588 589 ParentAsSuperuser<Origin>,590 591 592 SignedAccountId32AsNative<RelayNetwork, Origin>,593 594 XcmPassthrough<Origin>,595);596597parameter_types! {598 599 pub UnitWeightCost: Weight = 1_000_000;600 601 pub const WeightPrice: (MultiLocation, u128) = (X1(Parent), 1_200 * UNIQUE);602}603604match_type! {605 pub type ParentOrParentsUnitPlurality: impl Contains<MultiLocation> = {606 X1(Parent) | X2(Parent, Plurality { id: BodyId::Unit, .. })607 };608}609610pub type Barrier = (611 TakeWeightCredit,612 AllowTopLevelPaidExecutionFrom<All<MultiLocation>>,613 AllowUnpaidExecutionFrom<ParentOrParentsUnitPlurality>,614 615);616617pub struct XcmConfig;618impl Config for XcmConfig {619 type Call = Call;620 type XcmSender = XcmRouter;621 622 type AssetTransactor = LocalAssetTransactor;623 type OriginConverter = XcmOriginToTransactDispatchOrigin;624 type IsReserve = NativeAsset;625 type IsTeleporter = NativeAsset; 626 type LocationInverter = LocationInverter<Ancestry>;627 type Barrier = Barrier;628 type Weigher = FixedWeightBounds<UnitWeightCost, Call>;629 type Trader = UsingComponents<IdentityFee<Balance>, RelayLocation, AccountId, Balances, ()>;630 type ResponseHandler = (); 631}632633634635636637638pub type LocalOriginToLocation = (SignedToAccountId32<Origin, AccountId, RelayNetwork>,);639640641642pub type XcmRouter = (643 644 cumulus_primitives_utility::ParentAsUmp<ParachainSystem>,645 646 XcmpQueue,647);648649impl pallet_xcm::Config for Runtime {650 type Event = Event;651 type SendXcmOrigin = EnsureXcmOrigin<Origin, LocalOriginToLocation>;652 type XcmRouter = XcmRouter;653 type ExecuteXcmOrigin = EnsureXcmOrigin<Origin, LocalOriginToLocation>;654 type XcmExecuteFilter = All<(MultiLocation, Xcm<Call>)>;655 type XcmExecutor = XcmExecutor<XcmConfig>;656 type XcmTeleportFilter = All<(MultiLocation, Vec<MultiAsset>)>;657 type XcmReserveTransferFilter = ();658 type Weigher = FixedWeightBounds<UnitWeightCost, Call>;659}660661impl cumulus_pallet_xcm::Config for Runtime {662 type Event = Event;663 type XcmExecutor = XcmExecutor<XcmConfig>;664}665666impl cumulus_pallet_xcmp_queue::Config for Runtime {667 type Event = Event;668 type XcmExecutor = XcmExecutor<XcmConfig>;669 type ChannelInfo = ParachainSystem;670}671672impl cumulus_pallet_dmp_queue::Config for Runtime {673 type Event = Event;674 type XcmExecutor = XcmExecutor<XcmConfig>;675 type ExecuteOverweightOrigin = frame_system::EnsureRoot<AccountId>;676}677678impl pallet_aura::Config for Runtime {679 type AuthorityId = AuraId;680}681682parameter_types! {683 pub TreasuryAccountId: AccountId = TreasuryModuleId::get().into_account();684 pub const CollectionCreationPrice: Balance = 100 * UNIQUE;685}686687688impl pallet_nft::Config for Runtime {689 type Event = Event;690 type WeightInfo = nft_weights::WeightInfo;691692 type EvmBackwardsAddressMapping = pallet_nft::MapBackwardsAddressTruncated;693 type EvmAddressMapping = HashedAddressMapping<Self::Hashing>;694 type CrossAccountId = pallet_nft::BasicCrossAccountId<Self>;695696 type Currency = Balances;697 type CollectionCreationPrice = CollectionCreationPrice;698 type TreasuryAccountId = TreasuryAccountId;699700 type EthereumChainId = ChainId;701 type EthereumTransactionSender = pallet_ethereum::Module<Runtime>;702}703704parameter_types! {705 pub const InflationBlockInterval: BlockNumber = 100; 706}707708709impl pallet_inflation::Config for Runtime {710 type Currency = Balances;711 type TreasuryAccountId = TreasuryAccountId;712 type InflationBlockInterval = InflationBlockInterval;713}714715parameter_types! {716 pub MaximumSchedulerWeight: Weight = Perbill::from_percent(50) *717 RuntimeBlockWeights::get().max_block;718 pub const MaxScheduledPerBlock: u32 = 50;719}720721pub struct Sponsoring;722impl SponsoringResolve<AccountId, Call> for Sponsoring {723724 fn resolve(who: &AccountId, call: &Call) -> Option<AccountId> 725 where 726 Call: Dispatchable<Info=DispatchInfo>,727 Call: IsSubType<pallet_nft::Call<Runtime>>, 728 Call: IsSubType<pallet_contracts::Call<Runtime>>,729 AccountId: AsRef<[u8]>,730 AccountId: UncheckedFrom<Hash>731 {732 pallet_nft_transaction_payment::Module::<Runtime>::withdraw_type(who, call)733 }734}735736type SponsorshipHandler = (737 pallet_nft::NftSponsorshipHandler<Runtime>,738 pallet_contract_helpers::ContractSponsorshipHandler<Runtime>,739);740741impl pallet_scheduler::Config for Runtime {742 type Event = Event;743 type Origin = Origin;744 type PalletsOrigin = OriginCaller;745 type Call = Call;746 type MaximumWeight = MaximumSchedulerWeight;747 type ScheduleOrigin = EnsureSigned<AccountId>;748 type MaxScheduledPerBlock = MaxScheduledPerBlock;749 type SponsorshipHandler = SponsorshipHandler;750 type WeightInfo = ();751}752753impl pallet_nft_transaction_payment::Config for Runtime {754 type SponsorshipHandler = SponsorshipHandler;755}756757impl pallet_nft_charge_transaction::Config for Runtime {}758759impl pallet_contract_helpers::Config for Runtime {}760761construct_runtime!(762 pub enum Runtime where763 Block = Block,764 NodeBlock = opaque::Block,765 UncheckedExtrinsic = UncheckedExtrinsic766 {767 Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>} = 30,768 Contracts: pallet_contracts::{Pallet, Call, Storage, Event<T>},769 RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Pallet, Call, Storage},770 Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent},771 TransactionPayment: pallet_transaction_payment::{Pallet, Storage},772 Treasury: pallet_treasury::{Pallet, Call, Storage, Config, Event<T>},773 Sudo: pallet_sudo::{Pallet, Call, Storage, Config<T>, Event<T>},774 System: system::{Pallet, Call, Storage, Config, Event<T>},775 Vesting: pallet_vesting::{Pallet, Call, Config<T>, Storage, Event<T>},776777 ParachainSystem: cumulus_pallet_parachain_system::{Pallet, Call, Storage, Inherent, Event<T>, ValidateUnsigned} = 20,778 ParachainInfo: parachain_info::{Pallet, Storage, Config} = 21,779780 Aura: pallet_aura::{Pallet, Config<T>},781 AuraExt: cumulus_pallet_aura_ext::{Pallet, Config},782783 784 EVM: pallet_evm::{Pallet, Config, Call, Storage, Event<T>},785 Ethereum: pallet_ethereum::{Pallet, Config, Call, Storage, Event, ValidateUnsigned},786787 788 XcmpQueue: cumulus_pallet_xcmp_queue::{Pallet, Call, Storage, Event<T>} = 50,789 PolkadotXcm: pallet_xcm::{Pallet, Call, Event<T>, Origin} = 51,790 CumulusXcm: cumulus_pallet_xcm::{Pallet, Call, Event<T>, Origin} = 52,791 DmpQueue: cumulus_pallet_dmp_queue::{Pallet, Call, Storage, Event<T>} = 53,792793794 795 Inflation: pallet_inflation::{Pallet, Call, Storage},796 Nft: pallet_nft::{Pallet, Call, Config<T>, Storage, Event<T>},797 Scheduler: pallet_scheduler::{Pallet, Call, Storage, Event<T>},798 NftPayment: pallet_nft_transaction_payment::{Pallet, Call, Storage},799 Charging: pallet_nft_charge_transaction::{Pallet, Call, Storage },800 ContractHelpers: pallet_contract_helpers::{Pallet, Call, Storage},801 }802);803804pub struct TransactionConverter;805806impl fp_rpc::ConvertTransaction<UncheckedExtrinsic> for TransactionConverter {807 fn convert_transaction(&self, transaction: pallet_ethereum::Transaction) -> UncheckedExtrinsic {808 UncheckedExtrinsic::new_unsigned(pallet_ethereum::Call::<Runtime>::transact(transaction).into())809 }810}811812impl fp_rpc::ConvertTransaction<opaque::UncheckedExtrinsic> for TransactionConverter {813 fn convert_transaction(&self, transaction: pallet_ethereum::Transaction) -> opaque::UncheckedExtrinsic {814 let extrinsic = UncheckedExtrinsic::new_unsigned(pallet_ethereum::Call::<Runtime>::transact(transaction).into());815 let encoded = extrinsic.encode();816 opaque::UncheckedExtrinsic::decode(&mut &encoded[..]).expect("Encoded extrinsic is always valid")817 }818}819820821pub type Address = sp_runtime::MultiAddress<AccountId, ()>;822823pub type Header = generic::Header<BlockNumber, BlakeTwo256>;824825pub type Block = generic::Block<Header, UncheckedExtrinsic>;826827pub type SignedBlock = generic::SignedBlock<Block>;828829pub type BlockId = generic::BlockId<Block>;830831pub type SignedExtra = (832 system::CheckSpecVersion<Runtime>,833 834 system::CheckGenesis<Runtime>,835 system::CheckEra<Runtime>,836 system::CheckNonce<Runtime>,837 system::CheckWeight<Runtime>,838 pallet_nft_charge_transaction::ChargeTransactionPayment<Runtime>,839 pallet_contract_helpers::ContractHelpersExtension<Runtime>,840);841842pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<Address, Call, Signature, SignedExtra>;843844pub type CheckedExtrinsic = generic::CheckedExtrinsic<AccountId, Call, SignedExtra>;845846pub type Executive = frame_executive::Executive<847 Runtime,848 Block,849 frame_system::ChainContext<Runtime>,850 Runtime,851 AllPallets,852>;853854impl_opaque_keys! {855 pub struct SessionKeys {856 pub aura: Aura,857 }858}859860impl_runtime_apis! {861 impl pallet_nft::NftApi<Block>862 for Runtime863 {864 fn eth_contract_code(account: H160) -> Option<Vec<u8>> {865 <pallet_nft::NftErcSupport<Runtime>>::get_code(&account)866 }867 }868869 impl sp_api::Core<Block> for Runtime {870 fn version() -> RuntimeVersion {871 VERSION872 }873874 fn execute_block(block: Block) {875 Executive::execute_block(block)876 }877878 fn initialize_block(header: &<Block as BlockT>::Header) {879 Executive::initialize_block(header)880 }881 }882883 impl sp_api::Metadata<Block> for Runtime {884 fn metadata() -> OpaqueMetadata {885 Runtime::metadata().into()886 }887 }888889 impl sp_block_builder::BlockBuilder<Block> for Runtime {890 fn apply_extrinsic(extrinsic: <Block as BlockT>::Extrinsic) -> ApplyExtrinsicResult {891 Executive::apply_extrinsic(extrinsic)892 }893894 fn finalize_block() -> <Block as BlockT>::Header {895 Executive::finalize_block()896 }897898 fn inherent_extrinsics(data: sp_inherents::InherentData) -> Vec<<Block as BlockT>::Extrinsic> {899 data.create_extrinsics()900 }901902 fn check_inherents(903 block: Block,904 data: sp_inherents::InherentData,905 ) -> sp_inherents::CheckInherentsResult {906 data.check_extrinsics(&block)907 }908909 910 911 912 }913914 impl sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block> for Runtime {915 fn validate_transaction(916 source: TransactionSource,917 tx: <Block as BlockT>::Extrinsic,918 ) -> TransactionValidity {919 Executive::validate_transaction(source, tx)920 }921 }922923 impl sp_offchain::OffchainWorkerApi<Block> for Runtime {924 fn offchain_worker(header: &<Block as BlockT>::Header) {925 Executive::offchain_worker(header)926 }927 }928929 impl fp_rpc::EthereumRuntimeRPCApi<Block> for Runtime {930 fn chain_id() -> u64 {931 <Runtime as pallet_evm::Config>::ChainId::get()932 }933934 fn account_basic(address: H160) -> EVMAccount {935 EVM::account_basic(&address)936 }937938 fn gas_price() -> U256 {939 <Runtime as pallet_evm::Config>::FeeCalculator::min_gas_price()940 }941942 fn account_code_at(address: H160) -> Vec<u8> {943 EVM::account_codes(address)944 }945946 fn author() -> H160 {947 <pallet_ethereum::Module<Runtime>>::find_author()948 }949950 fn storage_at(address: H160, index: U256) -> H256 {951 let mut tmp = [0u8; 32];952 index.to_big_endian(&mut tmp);953 EVM::account_storages(address, H256::from_slice(&tmp[..]))954 }955956 fn call(957 from: H160,958 to: H160,959 data: Vec<u8>,960 value: U256,961 gas_limit: U256,962 gas_price: Option<U256>,963 nonce: Option<U256>,964 estimate: bool,965 ) -> Result<pallet_evm::CallInfo, sp_runtime::DispatchError> {966 let config = if estimate {967 let mut config = <Runtime as pallet_evm::Config>::config().clone();968 config.estimate = true;969 Some(config)970 } else {971 None972 };973974 <Runtime as pallet_evm::Config>::Runner::call(975 from,976 to,977 data,978 value,979 gas_limit.low_u64(),980 gas_price,981 nonce,982 config.as_ref().unwrap_or(<Runtime as pallet_evm::Config>::config()),983 ).map_err(|err| err.into())984 }985986 fn create(987 from: H160,988 data: Vec<u8>,989 value: U256,990 gas_limit: U256,991 gas_price: Option<U256>,992 nonce: Option<U256>,993 estimate: bool,994 ) -> Result<pallet_evm::CreateInfo, sp_runtime::DispatchError> {995 let config = if estimate {996 let mut config = <Runtime as pallet_evm::Config>::config().clone();997 config.estimate = true;998 Some(config)999 } else {1000 None1001 };10021003 <Runtime as pallet_evm::Config>::Runner::create(1004 from,1005 data,1006 value,1007 gas_limit.low_u64(),1008 gas_price,1009 nonce,1010 config.as_ref().unwrap_or(<Runtime as pallet_evm::Config>::config()),1011 ).map_err(|err| err.into())1012 }10131014 fn current_transaction_statuses() -> Option<Vec<TransactionStatus>> {1015 Ethereum::current_transaction_statuses()1016 }10171018 fn current_block() -> Option<pallet_ethereum::Block> {1019 Ethereum::current_block()1020 }10211022 fn current_receipts() -> Option<Vec<pallet_ethereum::Receipt>> {1023 Ethereum::current_receipts()1024 }10251026 fn current_all() -> (1027 Option<pallet_ethereum::Block>,1028 Option<Vec<pallet_ethereum::Receipt>>,1029 Option<Vec<TransactionStatus>>1030 ) {1031 (1032 Ethereum::current_block(),1033 Ethereum::current_receipts(),1034 Ethereum::current_transaction_statuses()1035 )1036 }1037 }10381039 impl sp_session::SessionKeys<Block> for Runtime {1040 fn decode_session_keys(1041 encoded: Vec<u8>,1042 ) -> Option<Vec<(Vec<u8>, KeyTypeId)>> {1043 SessionKeys::decode_into_raw_public_keys(&encoded)1044 }10451046 fn generate_session_keys(seed: Option<Vec<u8>>) -> Vec<u8> {1047 SessionKeys::generate(seed)1048 }1049 }10501051 impl sp_consensus_aura::AuraApi<Block, AuraId> for Runtime {1052 fn slot_duration() -> sp_consensus_aura::SlotDuration {1053 sp_consensus_aura::SlotDuration::from_millis(Aura::slot_duration())1054 }10551056 fn authorities() -> Vec<AuraId> {1057 Aura::authorities()1058 }1059 }10601061 impl cumulus_primitives_core::CollectCollationInfo<Block> for Runtime {1062 fn collect_collation_info() -> cumulus_primitives_core::CollationInfo {1063 ParachainSystem::collect_collation_info()1064 }1065 }10661067 impl frame_system_rpc_runtime_api::AccountNonceApi<Block, AccountId, Index> for Runtime {1068 fn account_nonce(account: AccountId) -> Index {1069 System::account_nonce(account)1070 }1071 }10721073 impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance> for Runtime {1074 fn query_info(uxt: <Block as BlockT>::Extrinsic, len: u32) -> RuntimeDispatchInfo<Balance> {1075 TransactionPayment::query_info(uxt, len)1076 }1077 fn query_fee_details(uxt: <Block as BlockT>::Extrinsic, len: u32) -> FeeDetails<Balance> {1078 TransactionPayment::query_fee_details(uxt, len)1079 }1080 }10811082 impl pallet_contracts_rpc_runtime_api::ContractsApi<Block, AccountId, Balance, BlockNumber, Hash>1083 for Runtime1084 {1085 fn call(1086 origin: AccountId,1087 dest: AccountId,1088 value: Balance,1089 gas_limit: u64,1090 input_data: Vec<u8>,1091 ) -> pallet_contracts_primitives::ContractExecResult {1092 Contracts::bare_call(origin, dest, value, gas_limit, input_data, false)1093 }10941095 fn instantiate(1096 origin: AccountId,1097 endowment: Balance,1098 gas_limit: u64,1099 code: pallet_contracts_primitives::Code<Hash>,1100 data: Vec<u8>,1101 salt: Vec<u8>,1102 ) -> pallet_contracts_primitives::ContractInstantiateResult<AccountId, BlockNumber>1103 {1104 Contracts::bare_instantiate(origin, endowment, gas_limit, code, data, salt, true, false)1105 }11061107 fn get_storage(1108 address: AccountId,1109 key: [u8; 32],1110 ) -> pallet_contracts_primitives::GetStorageResult {1111 Contracts::get_storage(address, key)1112 }11131114 fn rent_projection(1115 address: AccountId,1116 ) -> pallet_contracts_primitives::RentProjectionResult<BlockNumber> {1117 Contracts::rent_projection(address)1118 }1119 }11201121 #[cfg(feature = "runtime-benchmarks")]1122 impl frame_benchmarking::Benchmark<Block> for Runtime {1123 fn dispatch_benchmark(1124 config: frame_benchmarking::BenchmarkConfig1125 ) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, sp_runtime::RuntimeString> {1126 use frame_benchmarking::{Benchmarking, BenchmarkBatch, add_benchmark, TrackedStorageKey};11271128 let whitelist: Vec<TrackedStorageKey> = vec![1129 1130 hex_literal::hex!("d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d").to_vec().into(),1131 1132 1133 1134 1135 1136 1137 1138 1139 ];11401141 let mut batches = Vec::<BenchmarkBatch>::new();1142 let params = (&config, &whitelist);11431144 add_benchmark!(params, batches, pallet_nft, Nft);1145 add_benchmark!(params, batches, pallet_inflation, Inflation);11461147 if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) }1148 Ok(batches)1149 }1150 }1151}11521153cumulus_pallet_parachain_system::register_validate_block!(1154 Runtime,1155 cumulus_pallet_aura_ext::BlockExecutor::<Runtime, Executive>,1156);