difftreelog
syncopan and unique runtimes
in: master
1 file changed
runtime/unique/src/lib.rsdiffbeforeafterboth28use sp_api::impl_runtime_apis;28use sp_api::impl_runtime_apis;29use sp_core::{crypto::KeyTypeId, OpaqueMetadata, H256, U256, H160};29use sp_core::{crypto::KeyTypeId, OpaqueMetadata, H256, U256, H160};30use sp_runtime::DispatchError;30use sp_runtime::DispatchError;31use fp_self_contained::*;31// #[cfg(any(feature = "std", test))]32// #[cfg(any(feature = "std", test))]32// pub use sp_runtime::BuildStorage;33// pub use sp_runtime::BuildStorage;333434use sp_runtime::{35use sp_runtime::{35 Permill, Perbill, Percent, create_runtime_str, generic, impl_opaque_keys,36 Permill, Perbill, Percent, create_runtime_str, generic, impl_opaque_keys,36 generic::Era,37 traits::{37 traits::{AccountIdLookup, BlakeTwo256, Block as BlockT, AccountIdConversion, Zero, Member},38 Applyable, BlockNumberProvider, Dispatchable, PostDispatchInfoOf, DispatchInfoOf, Saturating,39 CheckedConversion, AccountIdLookup, BlakeTwo256, Block as BlockT, AccountIdConversion,40 Zero, Member,41 },42 transaction_validity::{TransactionSource, TransactionValidity, TransactionValidityError},38 transaction_validity::{TransactionSource, TransactionValidity},43 ApplyExtrinsicResult, RuntimeAppPublic, SaturatedConversion, DispatchErrorWithPostInfo,39 ApplyExtrinsicResult, RuntimeAppPublic,44};40};4546use fp_self_contained::{SelfContainedCall, CheckedSignature};47use sp_std::{cmp::Ordering, marker::PhantomData};48use pallet_unq_scheduler::DispatchCall;494150use sp_std::prelude::*;42use sp_std::prelude::*;514376 WeightToFeePolynomial, WeightToFeeCoefficient, WeightToFeeCoefficients, ConstantMultiplier,68 WeightToFeePolynomial, WeightToFeeCoefficient, WeightToFeeCoefficients, ConstantMultiplier,77 },69 },78};70};71use pallet_unq_scheduler::DispatchCall;72use up_data_structs::{73 CollectionId, TokenId, TokenData, Property, PropertyKeyPermission, CollectionLimits,74 CollectionStats, RpcCollection,75 mapping::{EvmTokenAddressMapping, CrossTokenAddressMapping},76};7779// use pallet_contracts::weights::WeightInfo;78// use pallet_contracts::weights::WeightInfo;80// #[cfg(any(feature = "std", test))]79// #[cfg(any(feature = "std", test))]88use smallvec::smallvec;87use smallvec::smallvec;89use codec::{Encode, Decode};88use codec::{Encode, Decode};90use fp_rpc::TransactionStatus;89use fp_rpc::TransactionStatus;90use sp_runtime::{91 traits::{92 Applyable, BlockNumberProvider, Dispatchable, PostDispatchInfoOf, DispatchInfoOf,93 Saturating, CheckedConversion,94 },95 generic::Era,96 transaction_validity::TransactionValidityError,97 DispatchErrorWithPostInfo, SaturatedConversion,98};919992// pub use pallet_timestamp::Call as TimestampCall;100// pub use pallet_timestamp::Call as TimestampCall;101pub use sp_consensus_aura::sr25519::AuthorityId as AuraId;9310294// Polkadot imports103// Polkadot imports95use pallet_xcm::XcmPassthrough;104use pallet_xcm::XcmPassthrough;96use polkadot_parachain::primitives::Sibling;105use polkadot_parachain::primitives::Sibling;97use up_data_structs::{98 CollectionId, TokenId, TokenData, Property, PropertyKeyPermission, CollectionLimits, 99 CollectionStats, RpcCollection, 100 mapping::{EvmTokenAddressMapping, CrossTokenAddressMapping}101};102use xcm::v1::{BodyId, Junction::*, MultiLocation, NetworkId, Junctions::*};106use xcm::v1::{BodyId, Junction::*, MultiLocation, NetworkId, Junctions::*};103use xcm_builder::{107use xcm_builder::{104 AccountId32Aliases, AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, CurrencyAdapter,108 AccountId32Aliases, AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, CurrencyAdapter,108 ParentIsPreset,112 ParentIsPreset,109};113};110use xcm_executor::{Config, XcmExecutor, Assets};114use xcm_executor::{Config, XcmExecutor, Assets};115use sp_std::{cmp::Ordering, marker::PhantomData};111116112use xcm::latest::{117use xcm::latest::{113 // Xcm,118 // Xcm,143 }147 }144}148}149150/// The type for looking up accounts. We don't expect more than 4 billion of them, but you151/// never know...152pub type AccountIndex = u32;153154/// Balance of an account.155pub type Balance = u128;156157/// Index of a transaction in the chain.158pub type Index = u32;159160/// A hash of some data used by the chain.161pub type Hash = sp_core::H256;162163/// Digest item type.164pub type DigestItem = generic::DigestItem;145165146/// Opaque types. These are used by the CLI to instantiate machinery that don't need to know166/// Opaque types. These are used by the CLI to instantiate machinery that don't need to know147/// the specifics of the runtime. They can then be made to be agnostic over specific formats167/// the specifics of the runtime. They can then be made to be agnostic over specific formats272 }292 }273}293}294295impl pallet_evm::account::Config for Runtime {296 type CrossAccountId = pallet_evm::account::BasicCrossAccountId<Self>;297 type EvmAddressMapping = pallet_evm::HashedAddressMapping<Self::Hashing>;298 type EvmBackwardsAddressMapping = fp_evm_mapping::MapBackwardsAddressTruncated;299}274300275impl pallet_evm::Config for Runtime {301impl pallet_evm::Config for Runtime {276 type BlockGasLimit = BlockGasLimit;302 type BlockGasLimit = BlockGasLimit;388 // pub const ExistentialDeposit: u128 = 500;414 // pub const ExistentialDeposit: u128 = 500;389 pub const ExistentialDeposit: u128 = 0;415 pub const ExistentialDeposit: u128 = 0;390 pub const MaxLocks: u32 = 50;416 pub const MaxLocks: u32 = 50;417 pub const MaxReserves: u32 = 50;391}418}392419393impl pallet_balances::Config for Runtime {420impl pallet_balances::Config for Runtime {394 type MaxLocks = MaxLocks;421 type MaxLocks = MaxLocks;395 type MaxReserves = ();422 type MaxReserves = MaxReserves;396 type ReserveIdentifier = [u8; 16];423 type ReserveIdentifier = [u8; 16];397 /// The type for recording an account's balance.424 /// The type for recording an account's balance.398 type Balance = Balance;425 type Balance = Balance;874 type WeightInfo = pallet_structure::weights::SubstrateWeight<Self>;901 type WeightInfo = pallet_structure::weights::SubstrateWeight<Self>;875}902}876877impl pallet_evm::account::Config for Runtime {878 type CrossAccountId = pallet_evm::account::BasicCrossAccountId<Self>;879 type EvmAddressMapping = HashedAddressMapping<Self::Hashing>;880 type EvmBackwardsAddressMapping = fp_evm_mapping::MapBackwardsAddressTruncated;881}882903883impl pallet_fungible::Config for Runtime {904impl pallet_fungible::Config for Runtime {884 type WeightInfo = pallet_fungible::weights::SubstrateWeight<Self>;905 type WeightInfo = pallet_fungible::weights::SubstrateWeight<Self>;922 pub const MaxScheduledPerBlock: u32 = 50;943 pub const MaxScheduledPerBlock: u32 = 50;923}944}945946type ChargeTransactionPayment = pallet_charge_transaction::ChargeTransactionPayment<Runtime>;947use frame_support::traits::NamedReservableCurrency;948949fn get_signed_extras(from: <Runtime as frame_system::Config>::AccountId) -> SignedExtraScheduler {950 (951 frame_system::CheckSpecVersion::<Runtime>::new(),952 frame_system::CheckGenesis::<Runtime>::new(),953 frame_system::CheckEra::<Runtime>::from(Era::Immortal),954 frame_system::CheckNonce::<Runtime>::from(frame_system::Pallet::<Runtime>::account_nonce(955 from,956 )),957 frame_system::CheckWeight::<Runtime>::new(),958 // sponsoring transaction logic959 // pallet_charge_transaction::ChargeTransactionPayment::<Runtime>::new(0),960 )961}962963pub struct SchedulerPaymentExecutor;964impl<T: frame_system::Config + pallet_unq_scheduler::Config, SelfContainedSignedInfo>965 DispatchCall<T, SelfContainedSignedInfo> for SchedulerPaymentExecutor966where967 <T as frame_system::Config>::Call: Member968 + Dispatchable<Origin = Origin, Info = DispatchInfo>969 + SelfContainedCall<SignedInfo = SelfContainedSignedInfo>970 + GetDispatchInfo971 + From<frame_system::Call<Runtime>>,972 SelfContainedSignedInfo: Send + Sync + 'static,973 Call: From<<T as frame_system::Config>::Call>974 + From<<T as pallet_unq_scheduler::Config>::Call>975 + SelfContainedCall<SignedInfo = SelfContainedSignedInfo>,976 sp_runtime::AccountId32: From<<T as frame_system::Config>::AccountId>,977{978 fn dispatch_call(979 signer: <T as frame_system::Config>::AccountId,980 call: <T as pallet_unq_scheduler::Config>::Call,981 ) -> Result<982 Result<PostDispatchInfo, DispatchErrorWithPostInfo<PostDispatchInfo>>,983 TransactionValidityError,984 > {985 let dispatch_info = call.get_dispatch_info();986 let extrinsic = fp_self_contained::CheckedExtrinsic::<987 AccountId,988 Call,989 SignedExtraScheduler,990 SelfContainedSignedInfo,991 > {992 signed:993 CheckedSignature::<AccountId, SignedExtraScheduler, SelfContainedSignedInfo>::Signed(994 signer.clone().into(),995 get_signed_extras(signer.into()),996 ),997 function: call.into(),998 };9991000 extrinsic.apply::<Runtime>(&dispatch_info, 0)1001 }10021003 fn reserve_balance(1004 id: [u8; 16],1005 sponsor: <T as frame_system::Config>::AccountId,1006 call: <T as pallet_unq_scheduler::Config>::Call,1007 count: u32,1008 ) -> Result<(), DispatchError> {1009 let dispatch_info = call.get_dispatch_info();1010 let weight: Balance = ChargeTransactionPayment::traditional_fee(0, &dispatch_info, 0)1011 .saturating_mul(count.into());10121013 <Balances as NamedReservableCurrency<AccountId>>::reserve_named(1014 &id,1015 &(sponsor.into()),1016 weight,1017 )1018 }10191020 fn pay_for_call(1021 id: [u8; 16],1022 sponsor: <T as frame_system::Config>::AccountId,1023 call: <T as pallet_unq_scheduler::Config>::Call,1024 ) -> Result<u128, DispatchError> {1025 let dispatch_info = call.get_dispatch_info();1026 let weight: Balance = ChargeTransactionPayment::traditional_fee(0, &dispatch_info, 0);1027 Ok(1028 <Balances as NamedReservableCurrency<AccountId>>::unreserve_named(1029 &id,1030 &(sponsor.into()),1031 weight,1032 ),1033 )1034 }10351036 fn cancel_reserve(1037 id: [u8; 16],1038 sponsor: <T as frame_system::Config>::AccountId,1039 ) -> Result<u128, DispatchError> {1040 Ok(1041 <Balances as NamedReservableCurrency<AccountId>>::unreserve_named(1042 &id,1043 &(sponsor.into()),1044 u128::MAX,1045 ),1046 )1047 }1048}9241049925parameter_types! {1050parameter_types! {926 pub const NoPreimagePostponement: Option<u32> = Some(10);1051 pub const NoPreimagePostponement: Option<u32> = Some(10);951 type NoPreimagePostponement = NoPreimagePostponement;1077 type NoPreimagePostponement = NoPreimagePostponement;952}1078}953954type ChargeTransactionPayment = pallet_charge_transaction::ChargeTransactionPayment<Runtime>;955use frame_support::traits::NamedReservableCurrency;956957fn get_signed_extras(from: <Runtime as frame_system::Config>::AccountId) -> SignedExtraScheduler {958 (959 frame_system::CheckSpecVersion::<Runtime>::new(),960 frame_system::CheckGenesis::<Runtime>::new(),961 frame_system::CheckEra::<Runtime>::from(Era::Immortal),962 frame_system::CheckNonce::<Runtime>::from(frame_system::Pallet::<Runtime>::account_nonce(963 from,964 )),965 frame_system::CheckWeight::<Runtime>::new(),966 // sponsoring transaction logic967 // pallet_charge_transaction::ChargeTransactionPayment::<Runtime>::new(0),968 )969}970971pub struct SchedulerPaymentExecutor;972impl<T: frame_system::Config + pallet_unq_scheduler::Config, SelfContainedSignedInfo>973 DispatchCall<T, SelfContainedSignedInfo> for SchedulerPaymentExecutor974where975 <T as frame_system::Config>::Call: Member976 + Dispatchable<Origin = Origin, Info = DispatchInfo>977 + SelfContainedCall<SignedInfo = SelfContainedSignedInfo>978 + GetDispatchInfo979 + From<frame_system::Call<Runtime>>,980 SelfContainedSignedInfo: Send + Sync + 'static,981 Call: From<<T as frame_system::Config>::Call>982 + From<<T as pallet_unq_scheduler::Config>::Call>983 + SelfContainedCall<SignedInfo = SelfContainedSignedInfo>,984 sp_runtime::AccountId32: From<<T as frame_system::Config>::AccountId>,985{986 fn dispatch_call(987 signer: <T as frame_system::Config>::AccountId,988 call: <T as pallet_unq_scheduler::Config>::Call,989 ) -> Result<990 Result<PostDispatchInfo, DispatchErrorWithPostInfo<PostDispatchInfo>>,991 TransactionValidityError,992 > {993 let dispatch_info = call.get_dispatch_info();994 let extrinsic = fp_self_contained::CheckedExtrinsic::<995 AccountId,996 Call,997 SignedExtraScheduler,998 SelfContainedSignedInfo,999 > {1000 signed:1001 CheckedSignature::<AccountId, SignedExtraScheduler, SelfContainedSignedInfo>::Signed(1002 signer.clone().into(),1003 get_signed_extras(signer.into()),1004 ),1005 function: call.into(),1006 };10071008 extrinsic.apply::<Runtime>(&dispatch_info, 0)1009 }10101011 fn reserve_balance(1012 id: [u8; 16],1013 sponsor: <T as frame_system::Config>::AccountId,1014 call: <T as pallet_unq_scheduler::Config>::Call,1015 count: u32,1016 ) -> Result<(), DispatchError> {1017 let dispatch_info = call.get_dispatch_info();1018 let weight: Balance = ChargeTransactionPayment::traditional_fee(0, &dispatch_info, 0)1019 .saturating_mul(count.into());10201021 <Balances as NamedReservableCurrency<AccountId>>::reserve_named(1022 &id,1023 &(sponsor.into()),1024 weight.into(),1025 )1026 }10271028 fn pay_for_call(1029 id: [u8; 16],1030 sponsor: <T as frame_system::Config>::AccountId,1031 call: <T as pallet_unq_scheduler::Config>::Call,1032 ) -> Result<u128, DispatchError> {1033 let dispatch_info = call.get_dispatch_info();1034 let weight: Balance = ChargeTransactionPayment::traditional_fee(0, &dispatch_info, 0);1035 Ok(1036 <Balances as NamedReservableCurrency<AccountId>>::unreserve_named(1037 &id,1038 &(sponsor.into()),1039 weight.into(),1040 ),1041 )1042 }10431044 fn cancel_reserve(1045 id: [u8; 16],1046 sponsor: <T as frame_system::Config>::AccountId,1047 ) -> Result<u128, DispatchError> {1048 Ok(1049 <Balances as NamedReservableCurrency<AccountId>>::unreserve_named(1050 &id,1051 &(sponsor.into()),1052 u128::MAX,1053 ),1054 )1055 }1056}105710791058type EvmSponsorshipHandler = (1080type EvmSponsorshipHandler = (1059 UniqueEthSponsorshipHandler<Runtime>,1081 UniqueEthSponsorshipHandler<Runtime>,