difftreelog
Scheduler without sponsorship features
in: master
5 files changed
pallets/scheduler/src/lib.rsdiffbeforeafterboth419 )418 )420 .unwrap();419 .unwrap();421420422 // if call have id and periodic, it was be reserved421 // // if call have id it was be reserved423 if s.maybe_id.is_some() && s.maybe_periodic.is_some() {422 // if s.maybe_id.is_some() {424 let _ = T::CallExecutor::pay_for_call(423 // let _ = T::CallExecutor::pay_for_call(425 s.maybe_id.unwrap(),424 // s.maybe_id.unwrap(),426 sender.clone(),425 // sender.clone(),427 call.clone(),426 // call.clone(),428 );427 // );429 }428 // }430429431 let r = T::CallExecutor::dispatch_call(sender, call.clone());430 let r = T::CallExecutor::dispatch_call(sender, call.clone());432431433 let mut actual_call_weight: Weight = item_weight; //PostDispatchInfo;432 let mut actual_call_weight: Weight = item_weight;434 let result: Result<_, DispatchError> = match r {433 let result: Result<_, DispatchError> = match r {435 Ok(o) => match o {434 Ok(o) => match o {436 Ok(di) => {435 Ok(di) => {472 Agenda::<T>::append(wake, Some(s));471 Agenda::<T>::append(wake, Some(s));473 }472 }474 }473 }475 total_weight474 0475 //total_weight476 }476 }477 }477 }478478719 };719 };720720721 // reserve balance for periodic execution721 // reserve balance for periodic execution722 let sender =722 // let sender =723 ensure_signed(<<T as Config>::Origin as From<T::PalletsOrigin>>::from(origin).into())?;723 // ensure_signed(<<T as Config>::Origin as From<T::PalletsOrigin>>::from(origin).into())?;724 let repeats = match maybe_periodic {724 // let repeats = match maybe_periodic {725 Some(p) => p.1,725 // Some(p) => p.1,726 None => 0,726 // None => 1,727 };727 // };728 let _ = T::CallExecutor::reserve_balance(728 // let _ = T::CallExecutor::reserve_balance(729 id.clone(),729 // id.clone(),730 sender,730 // sender,731 call.as_value().unwrap().clone(),731 // call.as_value().unwrap().clone(),732 repeats,732 // repeats,733 );733 // );734734735 Agenda::<T>::append(when, Some(s));735 Agenda::<T>::append(when, Some(s));736 let index = Agenda::<T>::decode_len(when).unwrap_or(1) as u32 - 1;736 let index = Agenda::<T>::decode_len(when).unwrap_or(1) as u32 - 1;755 return Err(BadOrigin.into());755 return Err(BadOrigin.into());756 }756 }757 // release balance reserve757 // release balance reserve758 let sender = ensure_signed(758 // let sender = ensure_signed(759 <<T as Config>::Origin as From<T::PalletsOrigin>>::from(759 // <<T as Config>::Origin as From<T::PalletsOrigin>>::from(760 origin.unwrap(),760 // origin.unwrap(),761 )761 // )762 .into(),762 // .into(),763 )?;763 // )?;764 let _ = T::CallExecutor::cancel_reserve(id, sender);764 // let _ = T::CallExecutor::cancel_reserve(id, sender);765765766 s.call.ensure_unrequested::<T::PreimageProvider>();766 s.call.ensure_unrequested::<T::PreimageProvider>();767 }767 }runtime/opal/src/lib.rsdiffbeforeafterboth29use 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::*;31use fp_self_contained::*;32use sp_runtime::traits::{SignedExtension, Member};32use sp_runtime::traits::{Member};33// #[cfg(any(feature = "std", test))]33// #[cfg(any(feature = "std", test))]34// pub use sp_runtime::BuildStorage;34// pub use sp_runtime::BuildStorage;353578 traits::{BaseArithmetic, Unsigned},78 traits::{BaseArithmetic, Unsigned},79};79};80use smallvec::smallvec;80use smallvec::smallvec;81use scale_info::TypeInfo;81// use scale_info::TypeInfo;82use codec::{Encode, Decode};82use codec::{Encode, Decode};83use pallet_evm::{Account as EVMAccount, FeeCalculator, GasWeightMapping, OnMethodCall};83use pallet_evm::{Account as EVMAccount, FeeCalculator, GasWeightMapping, OnMethodCall};84use fp_rpc::TransactionStatus;84use fp_rpc::TransactionStatus;898type ChargeTransactionPayment = pallet_charge_transaction::ChargeTransactionPayment<Runtime>;898type ChargeTransactionPayment = pallet_charge_transaction::ChargeTransactionPayment<Runtime>;899use frame_support::traits::NamedReservableCurrency;899use frame_support::traits::NamedReservableCurrency;900900901fn get_signed_extras(from: <Runtime as frame_system::Config>::AccountId) -> SignedExtra {901fn get_signed_extras(from: <Runtime as frame_system::Config>::AccountId) -> SignedExtraScheduler {902 (902 (903 frame_system::CheckSpecVersion::<Runtime>::new(),903 frame_system::CheckSpecVersion::<Runtime>::new(),904 frame_system::CheckGenesis::<Runtime>::new(),904 frame_system::CheckGenesis::<Runtime>::new(),907 from,907 from,908 )),908 )),909 frame_system::CheckWeight::<Runtime>::new(),909 frame_system::CheckWeight::<Runtime>::new(),910 pallet_charge_transaction::ChargeTransactionPayment::<Runtime>::new(0),910 // sponsoring transaction logic911 // pallet_charge_transaction::ChargeTransactionPayment::<Runtime>::new(0),911 )912 )912}913}913914937 let extrinsic = fp_self_contained::CheckedExtrinsic::<938 let extrinsic = fp_self_contained::CheckedExtrinsic::<938 AccountId,939 AccountId,939 Call,940 Call,940 SignedExtra,941 SignedExtraScheduler,941 SelfContainedSignedInfo,942 SelfContainedSignedInfo,942 > {943 > {943 signed: CheckedSignature::<AccountId, SignedExtra, SelfContainedSignedInfo>::Signed(944 signed:945 CheckedSignature::<AccountId, SignedExtraScheduler, SelfContainedSignedInfo>::Signed(944 signer.clone().into(),946 signer.clone().into(),945 get_signed_extras(signer.into()),947 get_signed_extras(signer.into()),946 ),948 ),957 count: u32,959 count: u32,958 ) -> Result<(), DispatchError> {960 ) -> Result<(), DispatchError> {959 let dispatch_info = call.get_dispatch_info();961 let dispatch_info = call.get_dispatch_info();960 let fee_charger = ChargeTransactionPayment::new(0);961 let pre = match fee_charger.pre_dispatch(962 let weight: Balance = ChargeTransactionPayment::traditional_fee(0, &dispatch_info, 0)962 &sponsor.clone().into(),963 &call.into(),964 &dispatch_info,965 0,966 ) {967 Ok(p) => p,968 Err(_) => fail!("failed to get pre dispatch info"),963 .saturating_mul(count.into());969 };964970971 let count: u128 = count.into();972 let total_fee: u128 = pre.2.map(|imbalance| imbalance.peek()).unwrap() * count;973 <Balances as NamedReservableCurrency<AccountId>>::reserve_named(965 <Balances as NamedReservableCurrency<AccountId>>::reserve_named(974 &id,966 &id,975 &(sponsor.into()),967 &(sponsor.into()),976 total_fee,968 weight.into(),977 )969 )978 }970 }979971983 call: <T as pallet_unq_scheduler::Config>::Call,975 call: <T as pallet_unq_scheduler::Config>::Call,984 ) -> Result<u128, DispatchError> {976 ) -> Result<u128, DispatchError> {985 let dispatch_info = call.get_dispatch_info();977 let dispatch_info = call.get_dispatch_info();986 let fee_charger = ChargeTransactionPayment::new(0);987 let pre = match fee_charger.pre_dispatch(978 let weight: Balance = ChargeTransactionPayment::traditional_fee(0, &dispatch_info, 0);988 &sponsor.clone().into(),989 &call.into(),990 &dispatch_info,991 0,992 ) {993 Ok(p) => p,994 Err(_) => fail!("failed to get pre dispatch info"),995 };996997 let single_fee: u128 = pre.2.map(|imbalance| imbalance.peek()).unwrap();998999 Ok(979 Ok(1000 <Balances as NamedReservableCurrency<AccountId>>::unreserve_named(980 <Balances as NamedReservableCurrency<AccountId>>::unreserve_named(1001 &id,981 &id,1002 &(sponsor.into()),982 &(sponsor.into()),1003 single_fee,983 weight.into(),1004 ),984 ),1005 )985 )1006 }986 }1184 ChargeTransactionPayment,1164 ChargeTransactionPayment,1185 //pallet_contract_helpers::ContractHelpersExtension<Runtime>,1165 //pallet_contract_helpers::ContractHelpersExtension<Runtime>,1186);1166);1167pub type SignedExtraScheduler = (1168 frame_system::CheckSpecVersion<Runtime>,1169 frame_system::CheckGenesis<Runtime>,1170 frame_system::CheckEra<Runtime>,1171 frame_system::CheckNonce<Runtime>,1172 frame_system::CheckWeight<Runtime>,1173);1187/// Unchecked extrinsic type as expected by this runtime.1174/// Unchecked extrinsic type as expected by this runtime.1188pub type UncheckedExtrinsic =1175pub type UncheckedExtrinsic =1189 fp_self_contained::UncheckedExtrinsic<Address, Call, Signature, SignedExtra>;1176 fp_self_contained::UncheckedExtrinsic<Address, Call, Signature, SignedExtra>;runtime/quartz/src/lib.rsdiffbeforeafterboth34use sp_runtime::{34use sp_runtime::{35 Permill, Perbill, Percent, create_runtime_str, generic, impl_opaque_keys,35 Permill, Perbill, Percent, create_runtime_str, generic, impl_opaque_keys,36 traits::{36 traits::{AccountIdLookup, BlakeTwo256, Block as BlockT, AccountIdConversion, Zero, Member},37 AccountIdLookup, BlakeTwo256, Block as BlockT, AccountIdConversion, Zero, SignedExtension,38 Member,39 },40 transaction_validity::{TransactionSource, TransactionValidity},37 transaction_validity::{TransactionSource, TransactionValidity},41 ApplyExtrinsicResult, RuntimeAppPublic,38 ApplyExtrinsicResult, RuntimeAppPublic,952type ChargeTransactionPayment = pallet_charge_transaction::ChargeTransactionPayment<Runtime>;949type ChargeTransactionPayment = pallet_charge_transaction::ChargeTransactionPayment<Runtime>;953use frame_support::traits::NamedReservableCurrency;950use frame_support::traits::NamedReservableCurrency;954951955fn get_signed_extras(from: <Runtime as frame_system::Config>::AccountId) -> SignedExtra {952fn get_signed_extras(from: <Runtime as frame_system::Config>::AccountId) -> SignedExtraScheduler {956 (953 (957 frame_system::CheckSpecVersion::<Runtime>::new(),954 frame_system::CheckSpecVersion::<Runtime>::new(),958 frame_system::CheckGenesis::<Runtime>::new(),955 frame_system::CheckGenesis::<Runtime>::new(),961 from,958 from,962 )),959 )),963 frame_system::CheckWeight::<Runtime>::new(),960 frame_system::CheckWeight::<Runtime>::new(),964 pallet_charge_transaction::ChargeTransactionPayment::<Runtime>::new(0),961 // sponsoring transaction logic962 // pallet_charge_transaction::ChargeTransactionPayment::<Runtime>::new(0),965 )963 )966}964}967965991 let extrinsic = fp_self_contained::CheckedExtrinsic::<989 let extrinsic = fp_self_contained::CheckedExtrinsic::<992 AccountId,990 AccountId,993 Call,991 Call,994 SignedExtra,992 SignedExtraScheduler,995 SelfContainedSignedInfo,993 SelfContainedSignedInfo,996 > {994 > {997 signed: CheckedSignature::<AccountId, SignedExtra, SelfContainedSignedInfo>::Signed(995 signed:996 CheckedSignature::<AccountId, SignedExtraScheduler, SelfContainedSignedInfo>::Signed(998 signer.clone().into(),997 signer.clone().into(),999 get_signed_extras(signer.into()),998 get_signed_extras(signer.into()),1000 ),999 ),1011 count: u32,1010 count: u32,1012 ) -> Result<(), DispatchError> {1011 ) -> Result<(), DispatchError> {1013 let dispatch_info = call.get_dispatch_info();1012 let dispatch_info = call.get_dispatch_info();1014 let fee_charger = ChargeTransactionPayment::new(0);1015 let pre = match fee_charger.pre_dispatch(1013 let weight: Balance = ChargeTransactionPayment::traditional_fee(0, &dispatch_info, 0)1016 &sponsor.clone().into(),1017 &call.into(),1018 &dispatch_info,1019 0,1020 ) {1021 Ok(p) => p,1022 Err(_) => fail!("failed to get pre dispatch info"),1014 .saturating_mul(count.into());1023 };101510241025 let count: u128 = count.into();1026 let total_fee: u128 = pre.2.map(|imbalance| imbalance.peek()).unwrap() * count;1027 <Balances as NamedReservableCurrency<AccountId>>::reserve_named(1016 <Balances as NamedReservableCurrency<AccountId>>::reserve_named(1028 &id,1017 &id,1029 &(sponsor.into()),1018 &(sponsor.into()),1030 total_fee,1019 weight.into(),1031 )1020 )1032 }1021 }103310221037 call: <T as pallet_unq_scheduler::Config>::Call,1026 call: <T as pallet_unq_scheduler::Config>::Call,1038 ) -> Result<u128, DispatchError> {1027 ) -> Result<u128, DispatchError> {1039 let dispatch_info = call.get_dispatch_info();1028 let dispatch_info = call.get_dispatch_info();1040 let fee_charger = ChargeTransactionPayment::new(0);1041 let pre = match fee_charger.pre_dispatch(1029 let weight: Balance = ChargeTransactionPayment::traditional_fee(0, &dispatch_info, 0);1042 &sponsor.clone().into(),1043 &call.into(),1044 &dispatch_info,1045 0,1046 ) {1047 Ok(p) => p,1048 Err(_) => fail!("failed to get pre dispatch info"),1049 };10501051 let single_fee: u128 = pre.2.map(|imbalance| imbalance.peek()).unwrap();10521053 Ok(1030 Ok(1054 <Balances as NamedReservableCurrency<AccountId>>::unreserve_named(1031 <Balances as NamedReservableCurrency<AccountId>>::unreserve_named(1055 &id,1032 &id,1056 &(sponsor.into()),1033 &(sponsor.into()),1057 single_fee,1034 weight.into(),1058 ),1035 ),1059 )1036 )1060 }1037 }1183 //pallet_contract_helpers::ContractHelpersExtension<Runtime>,1160 //pallet_contract_helpers::ContractHelpersExtension<Runtime>,1184);1161);11621163pub type SignedExtraScheduler = (1164 frame_system::CheckSpecVersion<Runtime>,1165 frame_system::CheckGenesis<Runtime>,1166 frame_system::CheckEra<Runtime>,1167 frame_system::CheckNonce<Runtime>,1168 frame_system::CheckWeight<Runtime>,1169 // pallet_charge_transaction::ChargeTransactionPayment<Runtime>,1170);1185/// Unchecked extrinsic type as expected by this runtime.1171/// Unchecked extrinsic type as expected by this runtime.1186pub type UncheckedExtrinsic =1172pub type UncheckedExtrinsic =1187 fp_self_contained::UncheckedExtrinsic<Address, Call, Signature, SignedExtra>;1173 fp_self_contained::UncheckedExtrinsic<Address, Call, Signature, SignedExtra>;runtime/unique/src/lib.rsdiffbeforeafterboth37 traits::{37 traits::{38 Applyable, BlockNumberProvider, Dispatchable, PostDispatchInfoOf, Saturating,38 Applyable, BlockNumberProvider, Dispatchable, PostDispatchInfoOf, Saturating,39 CheckedConversion, AccountIdLookup, BlakeTwo256, Block as BlockT, AccountIdConversion,39 CheckedConversion, AccountIdLookup, BlakeTwo256, Block as BlockT, AccountIdConversion,40 Zero, Member, SignedExtension,40 Zero, Member,41 },41 },42 transaction_validity::{TransactionSource, TransactionValidity, TransactionValidityError},42 transaction_validity::{TransactionSource, TransactionValidity, TransactionValidityError},43 ApplyExtrinsicResult, RuntimeAppPublic, SaturatedConversion, DispatchErrorWithPostInfo,43 ApplyExtrinsicResult, RuntimeAppPublic, SaturatedConversion, DispatchErrorWithPostInfo,918type ChargeTransactionPayment = pallet_charge_transaction::ChargeTransactionPayment<Runtime>;918type ChargeTransactionPayment = pallet_charge_transaction::ChargeTransactionPayment<Runtime>;919use frame_support::traits::NamedReservableCurrency;919use frame_support::traits::NamedReservableCurrency;920920921fn get_signed_extras(from: <Runtime as frame_system::Config>::AccountId) -> SignedExtra {921fn get_signed_extras(from: <Runtime as frame_system::Config>::AccountId) -> SignedExtraScheduler {922 (922 (923 frame_system::CheckSpecVersion::<Runtime>::new(),923 frame_system::CheckSpecVersion::<Runtime>::new(),924 frame_system::CheckGenesis::<Runtime>::new(),924 frame_system::CheckGenesis::<Runtime>::new(),927 from,927 from,928 )),928 )),929 frame_system::CheckWeight::<Runtime>::new(),929 frame_system::CheckWeight::<Runtime>::new(),930 pallet_charge_transaction::ChargeTransactionPayment::<Runtime>::new(0),930 // sponsoring transaction logic931 // pallet_charge_transaction::ChargeTransactionPayment::<Runtime>::new(0),931 )932 )932}933}933934957 let extrinsic = fp_self_contained::CheckedExtrinsic::<958 let extrinsic = fp_self_contained::CheckedExtrinsic::<958 AccountId,959 AccountId,959 Call,960 Call,960 SignedExtra,961 SignedExtraScheduler,961 SelfContainedSignedInfo,962 SelfContainedSignedInfo,962 > {963 > {963 signed: CheckedSignature::<AccountId, SignedExtra, SelfContainedSignedInfo>::Signed(964 signed:965 CheckedSignature::<AccountId, SignedExtraScheduler, SelfContainedSignedInfo>::Signed(964 signer.clone().into(),966 signer.clone().into(),965 get_signed_extras(signer.into()),967 get_signed_extras(signer.into()),966 ),968 ),977 count: u32,979 count: u32,978 ) -> Result<(), DispatchError> {980 ) -> Result<(), DispatchError> {979 let dispatch_info = call.get_dispatch_info();981 let dispatch_info = call.get_dispatch_info();980 let fee_charger = ChargeTransactionPayment::new(0);981 let pre = match fee_charger.pre_dispatch(982 let weight: Balance = ChargeTransactionPayment::traditional_fee(0, &dispatch_info, 0)982 &sponsor.clone().into(),983 &call.into(),984 &dispatch_info,985 0,986 ) {987 Ok(p) => p,988 Err(_) => fail!("failed to get pre dispatch info"),983 .saturating_mul(count.into());989 };984990991 let count: u128 = count.into();992 let total_fee: u128 = pre.2.map(|imbalance| imbalance.peek()).unwrap() * count;993 <Balances as NamedReservableCurrency<AccountId>>::reserve_named(985 <Balances as NamedReservableCurrency<AccountId>>::reserve_named(994 &id,986 &id,995 &(sponsor.into()),987 &(sponsor.into()),996 total_fee,988 weight.into(),997 )989 )998 }990 }9999911003 call: <T as pallet_unq_scheduler::Config>::Call,995 call: <T as pallet_unq_scheduler::Config>::Call,1004 ) -> Result<u128, DispatchError> {996 ) -> Result<u128, DispatchError> {1005 let dispatch_info = call.get_dispatch_info();997 let dispatch_info = call.get_dispatch_info();1006 let fee_charger = ChargeTransactionPayment::new(0);1007 let pre = match fee_charger.pre_dispatch(998 let weight: Balance = ChargeTransactionPayment::traditional_fee(0, &dispatch_info, 0);1008 &sponsor.clone().into(),1009 &call.into(),1010 &dispatch_info,1011 0,1012 ) {1013 Ok(p) => p,1014 Err(_) => fail!("failed to get pre dispatch info"),1015 };10161017 let single_fee: u128 = pre.2.map(|imbalance| imbalance.peek()).unwrap();10181019 Ok(999 Ok(1020 <Balances as NamedReservableCurrency<AccountId>>::unreserve_named(1000 <Balances as NamedReservableCurrency<AccountId>>::unreserve_named(1021 &id,1001 &id,1022 &(sponsor.into()),1002 &(sponsor.into()),1023 single_fee,1003 weight.into(),1024 ),1004 ),1025 )1005 )1026 }1006 }1173 pallet_charge_transaction::ChargeTransactionPayment<Runtime>,1153 pallet_charge_transaction::ChargeTransactionPayment<Runtime>,1174 //pallet_contract_helpers::ContractHelpersExtension<Runtime>,1154 //pallet_contract_helpers::ContractHelpersExtension<Runtime>,1175);1155);1156pub type SignedExtraScheduler = (1157 frame_system::CheckSpecVersion<Runtime>,1158 frame_system::CheckGenesis<Runtime>,1159 frame_system::CheckEra<Runtime>,1160 frame_system::CheckNonce<Runtime>,1161 frame_system::CheckWeight<Runtime>,1162 // pallet_charge_transaction::ChargeTransactionPayment<Runtime>,1163);1176/// Unchecked extrinsic type as expected by this runtime.1164/// Unchecked extrinsic type as expected by this runtime.1177pub type UncheckedExtrinsic =1165pub type UncheckedExtrinsic =1178 fp_self_contained::UncheckedExtrinsic<Address, Call, Signature, SignedExtra>;1166 fp_self_contained::UncheckedExtrinsic<Address, Call, Signature, SignedExtra>;tests/src/scheduler.test.tsdiffbeforeafterboth454546chai.use(chaiAsPromised);46chai.use(chaiAsPromised);474748describe('Scheduling token and balance transfers', () => {48describe.skip('Scheduling token and balance transfers', () => {49 let alice: IKeyringPair;49 let alice: IKeyringPair;50 let bob: IKeyringPair;50 let bob: IKeyringPair;51 let scheduledIdBase: string;51 let scheduledIdBase: string;