--- a/runtime/opal/Cargo.toml +++ b/runtime/opal/Cargo.toml @@ -119,8 +119,9 @@ "orml-vesting/std", ] limit-testing = ['pallet-unique/limit-testing', 'up-data-structs/limit-testing'] -opal-runtime = ['rmrk'] +opal-runtime = ['scheduler', 'rmrk'] +scheduler = [] rmrk = [] ################################################################################ --- a/runtime/opal/src/lib.rs +++ b/runtime/opal/src/lib.rs @@ -110,7 +110,7 @@ use polkadot_parachain::primitives::Sibling; use xcm::v1::{BodyId, Junction::*, MultiLocation, NetworkId, Junctions::*}; use xcm_builder::{ - AccountId32Aliases, AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, CurrencyAdapter, + AccountId32Aliases, AllowTopLevelPaidExecutionFrom, CurrencyAdapter, EnsureXcmOrigin, FixedWeightBounds, LocationInverter, NativeAsset, ParentAsSuperuser, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, @@ -966,6 +966,8 @@ } pub struct SchedulerPaymentExecutor; + +#[cfg(feature = "scheduler")] impl DispatchCall for SchedulerPaymentExecutor where @@ -1066,6 +1068,7 @@ } } +#[cfg(feature = "scheduler")] impl pallet_unique_scheduler::Config for Runtime { type Event = Event; type Origin = Origin; --- a/runtime/quartz/Cargo.toml +++ b/runtime/quartz/Cargo.toml @@ -120,6 +120,7 @@ limit-testing = ['pallet-unique/limit-testing', 'up-data-structs/limit-testing'] quartz-runtime = [] +scheduler = [] rmrk = [] ################################################################################ --- a/runtime/quartz/src/lib.rs +++ b/runtime/quartz/src/lib.rs @@ -28,13 +28,21 @@ use sp_api::impl_runtime_apis; use sp_core::{crypto::KeyTypeId, OpaqueMetadata, H256, U256, H160}; use sp_runtime::DispatchError; +#[cfg(feature = "scheduler")] use fp_self_contained::*; + +#[cfg(feature = "scheduler")] +use sp_runtime::{ + traits::Member, + generic::Era, + DispatchErrorWithPostInfo +}; // #[cfg(any(feature = "std", test))] // pub use sp_runtime::BuildStorage; use sp_runtime::{ Permill, Perbill, Percent, create_runtime_str, generic, impl_opaque_keys, - traits::{AccountIdLookup, BlakeTwo256, Block as BlockT, AccountIdConversion, Zero, Member}, + traits::{AccountIdLookup, BlakeTwo256, Block as BlockT, AccountIdConversion, Zero}, transaction_validity::{TransactionSource, TransactionValidity}, ApplyExtrinsicResult, RuntimeAppPublic, }; @@ -69,7 +77,10 @@ WeightToFee, }, }; + +#[cfg(feature = "scheduler")] use pallet_unique_scheduler::DispatchCall; + use up_data_structs::{ CollectionId, TokenId, TokenData, Property, PropertyKeyPermission, CollectionLimits, CollectionStats, RpcCollection, @@ -93,12 +104,10 @@ use fp_rpc::TransactionStatus; use sp_runtime::{ traits::{ - Applyable, BlockNumberProvider, Dispatchable, PostDispatchInfoOf, DispatchInfoOf, + BlockNumberProvider, Dispatchable, PostDispatchInfoOf, DispatchInfoOf, Saturating, CheckedConversion, }, - generic::Era, - transaction_validity::TransactionValidityError, - DispatchErrorWithPostInfo, SaturatedConversion, + transaction_validity::TransactionValidityError, SaturatedConversion, }; // pub use pallet_timestamp::Call as TimestampCall; @@ -109,7 +118,7 @@ use polkadot_parachain::primitives::Sibling; use xcm::v1::{BodyId, Junction::*, MultiLocation, NetworkId, Junctions::*}; use xcm_builder::{ - AccountId32Aliases, AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, CurrencyAdapter, + AccountId32Aliases, AllowTopLevelPaidExecutionFrom, CurrencyAdapter, EnsureXcmOrigin, FixedWeightBounds, LocationInverter, NativeAsset, ParentAsSuperuser, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, @@ -948,8 +957,11 @@ } type ChargeTransactionPayment = pallet_charge_transaction::ChargeTransactionPayment; + +#[cfg(feature = "scheduler")] use frame_support::traits::NamedReservableCurrency; +#[cfg(feature = "scheduler")] fn get_signed_extras(from: ::AccountId) -> SignedExtraScheduler { ( frame_system::CheckSpecVersion::::new(), @@ -964,92 +976,95 @@ ) } -// pub struct SchedulerPaymentExecutor; -// impl -// DispatchCall for SchedulerPaymentExecutor -// where -// ::Call: Member -// + Dispatchable -// + SelfContainedCall -// + GetDispatchInfo -// + From>, -// SelfContainedSignedInfo: Send + Sync + 'static, -// Call: From<::Call> -// + From<::Call> -// + SelfContainedCall, -// sp_runtime::AccountId32: From<::AccountId>, -// { -// fn dispatch_call( -// signer: ::AccountId, -// call: ::Call, -// ) -> Result< -// Result>, -// TransactionValidityError, -// > { -// let dispatch_info = call.get_dispatch_info(); -// let extrinsic = fp_self_contained::CheckedExtrinsic::< -// AccountId, -// Call, -// SignedExtraScheduler, -// SelfContainedSignedInfo, -// > { -// signed: -// CheckedSignature::::Signed( -// signer.clone().into(), -// get_signed_extras(signer.into()), -// ), -// function: call.into(), -// }; +#[cfg(feature = "scheduler")] +pub struct SchedulerPaymentExecutor; + +#[cfg(feature = "scheduler")] +impl + DispatchCall for SchedulerPaymentExecutor +where + ::Call: Member + + Dispatchable + + SelfContainedCall + + GetDispatchInfo + + From>, + SelfContainedSignedInfo: Send + Sync + 'static, + Call: From<::Call> + + From<::Call> + + SelfContainedCall, + sp_runtime::AccountId32: From<::AccountId>, +{ + fn dispatch_call( + signer: ::AccountId, + call: ::Call, + ) -> Result< + Result>, + TransactionValidityError, + > { + let dispatch_info = call.get_dispatch_info(); + let extrinsic = fp_self_contained::CheckedExtrinsic::< + AccountId, + Call, + SignedExtraScheduler, + SelfContainedSignedInfo, + > { + signed: + CheckedSignature::::Signed( + signer.clone().into(), + get_signed_extras(signer.into()), + ), + function: call.into(), + }; -// extrinsic.apply::(&dispatch_info, 0) -// } + extrinsic.apply::(&dispatch_info, 0) + } -// fn reserve_balance( -// id: [u8; 16], -// sponsor: ::AccountId, -// call: ::Call, -// count: u32, -// ) -> Result<(), DispatchError> { -// let dispatch_info = call.get_dispatch_info(); -// let weight: Balance = ChargeTransactionPayment::traditional_fee(0, &dispatch_info, 0) -// .saturating_mul(count.into()); + fn reserve_balance( + id: [u8; 16], + sponsor: ::AccountId, + call: ::Call, + count: u32, + ) -> Result<(), DispatchError> { + let dispatch_info = call.get_dispatch_info(); + let weight: Balance = ChargeTransactionPayment::traditional_fee(0, &dispatch_info, 0) + .saturating_mul(count.into()); -// >::reserve_named( -// &id, -// &(sponsor.into()), -// weight.into(), -// ) -// } + >::reserve_named( + &id, + &(sponsor.into()), + weight.into(), + ) + } -// fn pay_for_call( -// id: [u8; 16], -// sponsor: ::AccountId, -// call: ::Call, -// ) -> Result { -// let dispatch_info = call.get_dispatch_info(); -// let weight: Balance = ChargeTransactionPayment::traditional_fee(0, &dispatch_info, 0); -// Ok( -// >::unreserve_named( -// &id, -// &(sponsor.into()), -// weight.into(), -// ), -// ) -// } + fn pay_for_call( + id: [u8; 16], + sponsor: ::AccountId, + call: ::Call, + ) -> Result { + let dispatch_info = call.get_dispatch_info(); + let weight: Balance = ChargeTransactionPayment::traditional_fee(0, &dispatch_info, 0); + Ok( + >::unreserve_named( + &id, + &(sponsor.into()), + weight.into(), + ), + ) + } -// fn cancel_reserve( -// id: [u8; 16], -// sponsor: ::AccountId, -// ) -> Result { -// Ok( -// >::unreserve_named( -// &id, -// &(sponsor.into()), -// u128::MAX, -// ), -// ) -// } -// } + fn cancel_reserve( + id: [u8; 16], + sponsor: ::AccountId, + ) -> Result { + Ok( + >::unreserve_named( + &id, + &(sponsor.into()), + u128::MAX, + ), + ) + } +} parameter_types! { pub const NoPreimagePostponement: Option = Some(10); @@ -1065,21 +1080,22 @@ } } -// impl pallet_unique_scheduler::Config for Runtime { -// type Event = Event; -// type Origin = Origin; -// type Currency = Balances; -// type PalletsOrigin = OriginCaller; -// type Call = Call; -// type MaximumWeight = MaximumSchedulerWeight; -// type ScheduleOrigin = EnsureSigned; -// type MaxScheduledPerBlock = MaxScheduledPerBlock; -// type WeightInfo = (); -// type CallExecutor = SchedulerPaymentExecutor; -// type OriginPrivilegeCmp = OriginPrivilegeCmp; -// type PreimageProvider = (); -// type NoPreimagePostponement = NoPreimagePostponement; -// } +#[cfg(feature = "scheduler")] +impl pallet_unique_scheduler::Config for Runtime { + type Event = Event; + type Origin = Origin; + type Currency = Balances; + type PalletsOrigin = OriginCaller; + type Call = Call; + type MaximumWeight = MaximumSchedulerWeight; + type ScheduleOrigin = EnsureSigned; + type MaxScheduledPerBlock = MaxScheduledPerBlock; + type WeightInfo = (); + type CallExecutor = SchedulerPaymentExecutor; + type OriginPrivilegeCmp = OriginPrivilegeCmp; + type PreimageProvider = (); + type NoPreimagePostponement = NoPreimagePostponement; +} type EvmSponsorshipHandler = ( UniqueEthSponsorshipHandler, --- a/runtime/unique/Cargo.toml +++ b/runtime/unique/Cargo.toml @@ -121,6 +121,9 @@ limit-testing = ['pallet-unique/limit-testing', 'up-data-structs/limit-testing'] unique-runtime = [] +scheduler = [] +rmrk = [] + ################################################################################ # Substrate Dependencies --- a/runtime/unique/src/lib.rs +++ b/runtime/unique/src/lib.rs @@ -28,13 +28,22 @@ use sp_api::impl_runtime_apis; use sp_core::{crypto::KeyTypeId, OpaqueMetadata, H256, U256, H160}; use sp_runtime::DispatchError; + +#[cfg(feature = "scheduler")] use fp_self_contained::*; + +#[cfg(feature = "scheduler")] +use sp_runtime::{ + traits::Member, + generic::Era, + DispatchErrorWithPostInfo +}; // #[cfg(any(feature = "std", test))] // pub use sp_runtime::BuildStorage; use sp_runtime::{ Permill, Perbill, Percent, create_runtime_str, generic, impl_opaque_keys, - traits::{AccountIdLookup, BlakeTwo256, Block as BlockT, AccountIdConversion, Zero, Member}, + traits::{AccountIdLookup, BlakeTwo256, Block as BlockT, AccountIdConversion, Zero}, transaction_validity::{TransactionSource, TransactionValidity}, ApplyExtrinsicResult, RuntimeAppPublic, }; @@ -69,7 +78,10 @@ WeightToFee, }, }; + +#[cfg(feature = "scheduler")] use pallet_unique_scheduler::DispatchCall; + use up_data_structs::{ CollectionId, TokenId, TokenData, Property, PropertyKeyPermission, CollectionLimits, CollectionStats, RpcCollection, @@ -93,12 +105,10 @@ use fp_rpc::TransactionStatus; use sp_runtime::{ traits::{ - Applyable, BlockNumberProvider, Dispatchable, PostDispatchInfoOf, DispatchInfoOf, + BlockNumberProvider, Dispatchable, PostDispatchInfoOf, DispatchInfoOf, Saturating, CheckedConversion, }, - generic::Era, - transaction_validity::TransactionValidityError, - DispatchErrorWithPostInfo, SaturatedConversion, + transaction_validity::TransactionValidityError, SaturatedConversion, }; // pub use pallet_timestamp::Call as TimestampCall; @@ -109,7 +119,7 @@ use polkadot_parachain::primitives::Sibling; use xcm::v1::{BodyId, Junction::*, MultiLocation, NetworkId, Junctions::*}; use xcm_builder::{ - AccountId32Aliases, AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, CurrencyAdapter, + AccountId32Aliases, AllowTopLevelPaidExecutionFrom, CurrencyAdapter, EnsureXcmOrigin, FixedWeightBounds, LocationInverter, NativeAsset, ParentAsSuperuser, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, @@ -949,8 +959,11 @@ } type ChargeTransactionPayment = pallet_charge_transaction::ChargeTransactionPayment; + +#[cfg(feature = "scheduler")] use frame_support::traits::NamedReservableCurrency; +#[cfg(feature = "scheduler")] fn get_signed_extras(from: ::AccountId) -> SignedExtraScheduler { ( frame_system::CheckSpecVersion::::new(), @@ -965,92 +978,95 @@ ) } -// pub struct SchedulerPaymentExecutor; -// impl -// DispatchCall for SchedulerPaymentExecutor -// where -// ::Call: Member -// + Dispatchable -// + SelfContainedCall -// + GetDispatchInfo -// + From>, -// SelfContainedSignedInfo: Send + Sync + 'static, -// Call: From<::Call> -// + From<::Call> -// + SelfContainedCall, -// sp_runtime::AccountId32: From<::AccountId>, -// { -// fn dispatch_call( -// signer: ::AccountId, -// call: ::Call, -// ) -> Result< -// Result>, -// TransactionValidityError, -// > { -// let dispatch_info = call.get_dispatch_info(); -// let extrinsic = fp_self_contained::CheckedExtrinsic::< -// AccountId, -// Call, -// SignedExtraScheduler, -// SelfContainedSignedInfo, -// > { -// signed: -// CheckedSignature::::Signed( -// signer.clone().into(), -// get_signed_extras(signer.into()), -// ), -// function: call.into(), -// }; +#[cfg(feature = "scheduler")] +pub struct SchedulerPaymentExecutor; -// extrinsic.apply::(&dispatch_info, 0) -// } +#[cfg(feature = "scheduler")] +impl + DispatchCall for SchedulerPaymentExecutor +where + ::Call: Member + + Dispatchable + + SelfContainedCall + + GetDispatchInfo + + From>, + SelfContainedSignedInfo: Send + Sync + 'static, + Call: From<::Call> + + From<::Call> + + SelfContainedCall, + sp_runtime::AccountId32: From<::AccountId>, +{ + fn dispatch_call( + signer: ::AccountId, + call: ::Call, + ) -> Result< + Result>, + TransactionValidityError, + > { + let dispatch_info = call.get_dispatch_info(); + let extrinsic = fp_self_contained::CheckedExtrinsic::< + AccountId, + Call, + SignedExtraScheduler, + SelfContainedSignedInfo, + > { + signed: + CheckedSignature::::Signed( + signer.clone().into(), + get_signed_extras(signer.into()), + ), + function: call.into(), + }; -// fn reserve_balance( -// id: [u8; 16], -// sponsor: ::AccountId, -// call: ::Call, -// count: u32, -// ) -> Result<(), DispatchError> { -// let dispatch_info = call.get_dispatch_info(); -// let weight: Balance = ChargeTransactionPayment::traditional_fee(0, &dispatch_info, 0) -// .saturating_mul(count.into()); + extrinsic.apply::(&dispatch_info, 0) + } -// >::reserve_named( -// &id, -// &(sponsor.into()), -// weight, -// ) -// } + fn reserve_balance( + id: [u8; 16], + sponsor: ::AccountId, + call: ::Call, + count: u32, + ) -> Result<(), DispatchError> { + let dispatch_info = call.get_dispatch_info(); + let weight: Balance = ChargeTransactionPayment::traditional_fee(0, &dispatch_info, 0) + .saturating_mul(count.into()); -// fn pay_for_call( -// id: [u8; 16], -// sponsor: ::AccountId, -// call: ::Call, -// ) -> Result { -// let dispatch_info = call.get_dispatch_info(); -// let weight: Balance = ChargeTransactionPayment::traditional_fee(0, &dispatch_info, 0); -// Ok( -// >::unreserve_named( -// &id, -// &(sponsor.into()), -// weight, -// ), -// ) -// } + >::reserve_named( + &id, + &(sponsor.into()), + weight, + ) + } -// fn cancel_reserve( -// id: [u8; 16], -// sponsor: ::AccountId, -// ) -> Result { -// Ok( -// >::unreserve_named( -// &id, -// &(sponsor.into()), -// u128::MAX, -// ), -// ) -// } -// } + fn pay_for_call( + id: [u8; 16], + sponsor: ::AccountId, + call: ::Call, + ) -> Result { + let dispatch_info = call.get_dispatch_info(); + let weight: Balance = ChargeTransactionPayment::traditional_fee(0, &dispatch_info, 0); + Ok( + >::unreserve_named( + &id, + &(sponsor.into()), + weight, + ), + ) + } + + fn cancel_reserve( + id: [u8; 16], + sponsor: ::AccountId, + ) -> Result { + Ok( + >::unreserve_named( + &id, + &(sponsor.into()), + u128::MAX, + ), + ) + } +} parameter_types! { pub const NoPreimagePostponement: Option = Some(10); @@ -1066,21 +1082,22 @@ } } -// impl pallet_unique_scheduler::Config for Runtime { -// type Event = Event; -// type Origin = Origin; -// type Currency = Balances; -// type PalletsOrigin = OriginCaller; -// type Call = Call; -// type MaximumWeight = MaximumSchedulerWeight; -// type ScheduleOrigin = EnsureSigned; -// type MaxScheduledPerBlock = MaxScheduledPerBlock; -// type WeightInfo = (); -// type CallExecutor = SchedulerPaymentExecutor; -// type OriginPrivilegeCmp = OriginPrivilegeCmp; -// type PreimageProvider = (); -// type NoPreimagePostponement = NoPreimagePostponement; -// } +#[cfg(feature = "scheduler")] +impl pallet_unique_scheduler::Config for Runtime { + type Event = Event; + type Origin = Origin; + type Currency = Balances; + type PalletsOrigin = OriginCaller; + type Call = Call; + type MaximumWeight = MaximumSchedulerWeight; + type ScheduleOrigin = EnsureSigned; + type MaxScheduledPerBlock = MaxScheduledPerBlock; + type WeightInfo = (); + type CallExecutor = SchedulerPaymentExecutor; + type OriginPrivilegeCmp = OriginPrivilegeCmp; + type PreimageProvider = (); + type NoPreimagePostponement = NoPreimagePostponement; +} type EvmSponsorshipHandler = ( UniqueEthSponsorshipHandler, @@ -1166,7 +1183,7 @@ frame_system::CheckEra, frame_system::CheckNonce, frame_system::CheckWeight, - pallet_charge_transaction::ChargeTransactionPayment, + ChargeTransactionPayment, //pallet_contract_helpers::ContractHelpersExtension, pallet_ethereum::FakeTransactionFinalizer, );