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 EvmWithdrawOrigin = EnsureAddressTruncated;693 type EvmBackwardsAddressMapping = pallet_nft::MapBackwardsAddressTruncated;694 type EvmAddressMapping = HashedAddressMapping<Self::Hashing>;695 type CrossAccountId = pallet_nft::BasicCrossAccountId<Self>;696697 type Currency = Balances;698 type CollectionCreationPrice = CollectionCreationPrice;699 type TreasuryAccountId = TreasuryAccountId;700701 type EthereumChainId = ChainId;702 type EthereumTransactionSender = pallet_ethereum::Module<Runtime>;703}704705parameter_types! {706 pub const InflationBlockInterval: BlockNumber = 100; 707}708709710impl pallet_inflation::Config for Runtime {711 type Currency = Balances;712 type TreasuryAccountId = TreasuryAccountId;713 type InflationBlockInterval = InflationBlockInterval;714}715716parameter_types! {717 pub MaximumSchedulerWeight: Weight = Perbill::from_percent(50) *718 RuntimeBlockWeights::get().max_block;719 pub const MaxScheduledPerBlock: u32 = 50;720}721722pub struct Sponsoring;723impl SponsoringResolve<AccountId, Call> for Sponsoring {724725 fn resolve(who: &AccountId, call: &Call) -> Option<AccountId> 726 where 727 Call: Dispatchable<Info=DispatchInfo>,728 Call: IsSubType<pallet_nft::Call<Runtime>>, 729 Call: IsSubType<pallet_contracts::Call<Runtime>>,730 AccountId: AsRef<[u8]>,731 AccountId: UncheckedFrom<Hash>732 {733 pallet_nft_transaction_payment::Module::<Runtime>::withdraw_type(who, call)734 }735}736737type SponsorshipHandler = (738 pallet_nft::NftSponsorshipHandler<Runtime>,739 pallet_contract_helpers::ContractSponsorshipHandler<Runtime>,740);741742impl pallet_scheduler::Config for Runtime {743 type Event = Event;744 type Origin = Origin;745 type PalletsOrigin = OriginCaller;746 type Call = Call;747 type MaximumWeight = MaximumSchedulerWeight;748 type ScheduleOrigin = EnsureSigned<AccountId>;749 type MaxScheduledPerBlock = MaxScheduledPerBlock;750 type SponsorshipHandler = SponsorshipHandler;751 type WeightInfo = ();752}753754impl pallet_nft_transaction_payment::Config for Runtime {755 type SponsorshipHandler = SponsorshipHandler;756}757758impl pallet_nft_charge_transaction::Config for Runtime {}759760impl pallet_contract_helpers::Config for Runtime {}761762construct_runtime!(763 pub enum Runtime where764 Block = Block,765 NodeBlock = opaque::Block,766 UncheckedExtrinsic = UncheckedExtrinsic767 {768 Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>} = 30,769 Contracts: pallet_contracts::{Pallet, Call, Storage, Event<T>},770 RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Pallet, Call, Storage},771 Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent},772 TransactionPayment: pallet_transaction_payment::{Pallet, Storage},773 Treasury: pallet_treasury::{Pallet, Call, Storage, Config, Event<T>},774 Sudo: pallet_sudo::{Pallet, Call, Storage, Config<T>, Event<T>},775 System: system::{Pallet, Call, Storage, Config, Event<T>},776 Vesting: pallet_vesting::{Pallet, Call, Config<T>, Storage, Event<T>},777778 ParachainSystem: cumulus_pallet_parachain_system::{Pallet, Call, Storage, Inherent, Event<T>, ValidateUnsigned} = 20,779 ParachainInfo: parachain_info::{Pallet, Storage, Config} = 21,780781 Aura: pallet_aura::{Pallet, Config<T>},782 AuraExt: cumulus_pallet_aura_ext::{Pallet, Config},783784 785 EVM: pallet_evm::{Pallet, Config, Call, Storage, Event<T>},786 Ethereum: pallet_ethereum::{Pallet, Config, Call, Storage, Event, ValidateUnsigned},787788 789 XcmpQueue: cumulus_pallet_xcmp_queue::{Pallet, Call, Storage, Event<T>} = 50,790 PolkadotXcm: pallet_xcm::{Pallet, Call, Event<T>, Origin} = 51,791 CumulusXcm: cumulus_pallet_xcm::{Pallet, Call, Event<T>, Origin} = 52,792 DmpQueue: cumulus_pallet_dmp_queue::{Pallet, Call, Storage, Event<T>} = 53,793794795 796 Inflation: pallet_inflation::{Pallet, Call, Storage},797 Nft: pallet_nft::{Pallet, Call, Config<T>, Storage, Event<T>},798 Scheduler: pallet_scheduler::{Pallet, Call, Storage, Event<T>},799 NftPayment: pallet_nft_transaction_payment::{Pallet, Call, Storage},800 Charging: pallet_nft_charge_transaction::{Pallet, Call, Storage },801 ContractHelpers: pallet_contract_helpers::{Pallet, Call, Storage},802 }803);804805pub struct TransactionConverter;806807impl fp_rpc::ConvertTransaction<UncheckedExtrinsic> for TransactionConverter {808 fn convert_transaction(&self, transaction: pallet_ethereum::Transaction) -> UncheckedExtrinsic {809 UncheckedExtrinsic::new_unsigned(pallet_ethereum::Call::<Runtime>::transact(transaction).into())810 }811}812813impl fp_rpc::ConvertTransaction<opaque::UncheckedExtrinsic> for TransactionConverter {814 fn convert_transaction(&self, transaction: pallet_ethereum::Transaction) -> opaque::UncheckedExtrinsic {815 let extrinsic = UncheckedExtrinsic::new_unsigned(pallet_ethereum::Call::<Runtime>::transact(transaction).into());816 let encoded = extrinsic.encode();817 opaque::UncheckedExtrinsic::decode(&mut &encoded[..]).expect("Encoded extrinsic is always valid")818 }819}820821822pub type Address = sp_runtime::MultiAddress<AccountId, ()>;823824pub type Header = generic::Header<BlockNumber, BlakeTwo256>;825826pub type Block = generic::Block<Header, UncheckedExtrinsic>;827828pub type SignedBlock = generic::SignedBlock<Block>;829830pub type BlockId = generic::BlockId<Block>;831832pub type SignedExtra = (833 system::CheckSpecVersion<Runtime>,834 835 system::CheckGenesis<Runtime>,836 system::CheckEra<Runtime>,837 system::CheckNonce<Runtime>,838 system::CheckWeight<Runtime>,839 pallet_nft_charge_transaction::ChargeTransactionPayment<Runtime>,840 pallet_contract_helpers::ContractHelpersExtension<Runtime>,841);842843pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<Address, Call, Signature, SignedExtra>;844845pub type CheckedExtrinsic = generic::CheckedExtrinsic<AccountId, Call, SignedExtra>;846847pub type Executive = frame_executive::Executive<848 Runtime,849 Block,850 frame_system::ChainContext<Runtime>,851 Runtime,852 AllPallets,853>;854855impl_opaque_keys! {856 pub struct SessionKeys {857 pub aura: Aura,858 }859}860861impl_runtime_apis! {862 impl pallet_nft::NftApi<Block>863 for Runtime864 {865 fn eth_contract_code(account: H160) -> Option<Vec<u8>> {866 <pallet_nft::NftErcSupport<Runtime>>::get_code(&account)867 }868 }869870 impl sp_api::Core<Block> for Runtime {871 fn version() -> RuntimeVersion {872 VERSION873 }874875 fn execute_block(block: Block) {876 Executive::execute_block(block)877 }878879 fn initialize_block(header: &<Block as BlockT>::Header) {880 Executive::initialize_block(header)881 }882 }883884 impl sp_api::Metadata<Block> for Runtime {885 fn metadata() -> OpaqueMetadata {886 Runtime::metadata().into()887 }888 }889890 impl sp_block_builder::BlockBuilder<Block> for Runtime {891 fn apply_extrinsic(extrinsic: <Block as BlockT>::Extrinsic) -> ApplyExtrinsicResult {892 Executive::apply_extrinsic(extrinsic)893 }894895 fn finalize_block() -> <Block as BlockT>::Header {896 Executive::finalize_block()897 }898899 fn inherent_extrinsics(data: sp_inherents::InherentData) -> Vec<<Block as BlockT>::Extrinsic> {900 data.create_extrinsics()901 }902903 fn check_inherents(904 block: Block,905 data: sp_inherents::InherentData,906 ) -> sp_inherents::CheckInherentsResult {907 data.check_extrinsics(&block)908 }909910 911 912 913 }914915 impl sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block> for Runtime {916 fn validate_transaction(917 source: TransactionSource,918 tx: <Block as BlockT>::Extrinsic,919 ) -> TransactionValidity {920 Executive::validate_transaction(source, tx)921 }922 }923924 impl sp_offchain::OffchainWorkerApi<Block> for Runtime {925 fn offchain_worker(header: &<Block as BlockT>::Header) {926 Executive::offchain_worker(header)927 }928 }929930 impl fp_rpc::EthereumRuntimeRPCApi<Block> for Runtime {931 fn chain_id() -> u64 {932 <Runtime as pallet_evm::Config>::ChainId::get()933 }934935 fn account_basic(address: H160) -> EVMAccount {936 EVM::account_basic(&address)937 }938939 fn gas_price() -> U256 {940 <Runtime as pallet_evm::Config>::FeeCalculator::min_gas_price()941 }942943 fn account_code_at(address: H160) -> Vec<u8> {944 EVM::account_codes(address)945 }946947 fn author() -> H160 {948 <pallet_ethereum::Module<Runtime>>::find_author()949 }950951 fn storage_at(address: H160, index: U256) -> H256 {952 let mut tmp = [0u8; 32];953 index.to_big_endian(&mut tmp);954 EVM::account_storages(address, H256::from_slice(&tmp[..]))955 }956957 fn call(958 from: H160,959 to: H160,960 data: Vec<u8>,961 value: U256,962 gas_limit: U256,963 gas_price: Option<U256>,964 nonce: Option<U256>,965 estimate: bool,966 ) -> Result<pallet_evm::CallInfo, sp_runtime::DispatchError> {967 let config = if estimate {968 let mut config = <Runtime as pallet_evm::Config>::config().clone();969 config.estimate = true;970 Some(config)971 } else {972 None973 };974975 <Runtime as pallet_evm::Config>::Runner::call(976 from,977 to,978 data,979 value,980 gas_limit.low_u64(),981 gas_price,982 nonce,983 config.as_ref().unwrap_or(<Runtime as pallet_evm::Config>::config()),984 ).map_err(|err| err.into())985 }986987 fn create(988 from: H160,989 data: Vec<u8>,990 value: U256,991 gas_limit: U256,992 gas_price: Option<U256>,993 nonce: Option<U256>,994 estimate: bool,995 ) -> Result<pallet_evm::CreateInfo, sp_runtime::DispatchError> {996 let config = if estimate {997 let mut config = <Runtime as pallet_evm::Config>::config().clone();998 config.estimate = true;999 Some(config)1000 } else {1001 None1002 };10031004 <Runtime as pallet_evm::Config>::Runner::create(1005 from,1006 data,1007 value,1008 gas_limit.low_u64(),1009 gas_price,1010 nonce,1011 config.as_ref().unwrap_or(<Runtime as pallet_evm::Config>::config()),1012 ).map_err(|err| err.into())1013 }10141015 fn current_transaction_statuses() -> Option<Vec<TransactionStatus>> {1016 Ethereum::current_transaction_statuses()1017 }10181019 fn current_block() -> Option<pallet_ethereum::Block> {1020 Ethereum::current_block()1021 }10221023 fn current_receipts() -> Option<Vec<pallet_ethereum::Receipt>> {1024 Ethereum::current_receipts()1025 }10261027 fn current_all() -> (1028 Option<pallet_ethereum::Block>,1029 Option<Vec<pallet_ethereum::Receipt>>,1030 Option<Vec<TransactionStatus>>1031 ) {1032 (1033 Ethereum::current_block(),1034 Ethereum::current_receipts(),1035 Ethereum::current_transaction_statuses()1036 )1037 }1038 }10391040 impl sp_session::SessionKeys<Block> for Runtime {1041 fn decode_session_keys(1042 encoded: Vec<u8>,1043 ) -> Option<Vec<(Vec<u8>, KeyTypeId)>> {1044 SessionKeys::decode_into_raw_public_keys(&encoded)1045 }10461047 fn generate_session_keys(seed: Option<Vec<u8>>) -> Vec<u8> {1048 SessionKeys::generate(seed)1049 }1050 }10511052 impl sp_consensus_aura::AuraApi<Block, AuraId> for Runtime {1053 fn slot_duration() -> sp_consensus_aura::SlotDuration {1054 sp_consensus_aura::SlotDuration::from_millis(Aura::slot_duration())1055 }10561057 fn authorities() -> Vec<AuraId> {1058 Aura::authorities()1059 }1060 }10611062 impl cumulus_primitives_core::CollectCollationInfo<Block> for Runtime {1063 fn collect_collation_info() -> cumulus_primitives_core::CollationInfo {1064 ParachainSystem::collect_collation_info()1065 }1066 }10671068 impl frame_system_rpc_runtime_api::AccountNonceApi<Block, AccountId, Index> for Runtime {1069 fn account_nonce(account: AccountId) -> Index {1070 System::account_nonce(account)1071 }1072 }10731074 impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi<Block, Balance> for Runtime {1075 fn query_info(uxt: <Block as BlockT>::Extrinsic, len: u32) -> RuntimeDispatchInfo<Balance> {1076 TransactionPayment::query_info(uxt, len)1077 }1078 fn query_fee_details(uxt: <Block as BlockT>::Extrinsic, len: u32) -> FeeDetails<Balance> {1079 TransactionPayment::query_fee_details(uxt, len)1080 }1081 }10821083 impl pallet_contracts_rpc_runtime_api::ContractsApi<Block, AccountId, Balance, BlockNumber, Hash>1084 for Runtime1085 {1086 fn call(1087 origin: AccountId,1088 dest: AccountId,1089 value: Balance,1090 gas_limit: u64,1091 input_data: Vec<u8>,1092 ) -> pallet_contracts_primitives::ContractExecResult {1093 Contracts::bare_call(origin, dest, value, gas_limit, input_data, false)1094 }10951096 fn instantiate(1097 origin: AccountId,1098 endowment: Balance,1099 gas_limit: u64,1100 code: pallet_contracts_primitives::Code<Hash>,1101 data: Vec<u8>,1102 salt: Vec<u8>,1103 ) -> pallet_contracts_primitives::ContractInstantiateResult<AccountId, BlockNumber>1104 {1105 Contracts::bare_instantiate(origin, endowment, gas_limit, code, data, salt, true, false)1106 }11071108 fn get_storage(1109 address: AccountId,1110 key: [u8; 32],1111 ) -> pallet_contracts_primitives::GetStorageResult {1112 Contracts::get_storage(address, key)1113 }11141115 fn rent_projection(1116 address: AccountId,1117 ) -> pallet_contracts_primitives::RentProjectionResult<BlockNumber> {1118 Contracts::rent_projection(address)1119 }1120 }11211122 #[cfg(feature = "runtime-benchmarks")]1123 impl frame_benchmarking::Benchmark<Block> for Runtime {1124 fn dispatch_benchmark(1125 config: frame_benchmarking::BenchmarkConfig1126 ) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, sp_runtime::RuntimeString> {1127 use frame_benchmarking::{Benchmarking, BenchmarkBatch, add_benchmark, TrackedStorageKey};11281129 let whitelist: Vec<TrackedStorageKey> = vec![1130 1131 hex_literal::hex!("d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d").to_vec().into(),1132 1133 1134 1135 1136 1137 1138 1139 1140 ];11411142 let mut batches = Vec::<BenchmarkBatch>::new();1143 let params = (&config, &whitelist);11441145 add_benchmark!(params, batches, pallet_nft, Nft);1146 add_benchmark!(params, batches, pallet_inflation, Inflation);11471148 if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) }1149 Ok(batches)1150 }1151 }1152}11531154cumulus_pallet_parachain_system::register_validate_block!(1155 Runtime,1156 cumulus_pallet_aura_ext::BlockExecutor::<Runtime, Executive>,1157);