diff --git a/pallets/duniter-account/src/lib.rs b/pallets/duniter-account/src/lib.rs index ddd56e0addf284638668be629f5a1b5e7e077374..03eec0d4e05bc74fbd8750c85f0cb0240d630b53 100644 --- a/pallets/duniter-account/src/lib.rs +++ b/pallets/duniter-account/src/lib.rs @@ -320,6 +320,16 @@ where type Balance = BalanceOf<T>; type LiquidityInfo = Option<Credit<T::AccountId, T::Currency>>; + fn can_withdraw_fee( + who: &T::AccountId, + call: &T::RuntimeCall, + dispatch_info: &DispatchInfoOf<T::RuntimeCall>, + fee: Self::Balance, + tip: Self::Balance, + ) -> Result<(), TransactionValidityError> { + T::InnerOnChargeTransaction::can_withdraw_fee(who, call, dispatch_info, fee, tip) + } + fn withdraw_fee( who: &T::AccountId, call: &T::RuntimeCall, diff --git a/pallets/oneshot-account/src/check_nonce.rs b/pallets/oneshot-account/src/check_nonce.rs index 3d792e53b130a94d77800ad806b6d6fa2dc35e77..63968eddb7a09e457fd8223e8c52358bba070e23 100644 --- a/pallets/oneshot-account/src/check_nonce.rs +++ b/pallets/oneshot-account/src/check_nonce.rs @@ -17,15 +17,19 @@ use crate::Config; use codec::{Decode, Encode}; -use frame_support::{dispatch::DispatchInfo, traits::IsSubType}; +use frame_support::{dispatch::DispatchInfo, pallet_prelude::Weight, traits::IsSubType}; //use frame_system::Config; use scale_info::{ prelude::fmt::{Debug, Formatter}, TypeInfo, }; use sp_runtime::{ - traits::{DispatchInfoOf, Dispatchable, SignedExtension}, - transaction_validity::{TransactionValidity, TransactionValidityError}, + traits::{ + AsSystemOriginSigner, DispatchInfoOf, Dispatchable, PostDispatchInfoOf, + TransactionExtension, ValidateResult, + }, + transaction_validity::{TransactionSource, TransactionValidityError}, + DispatchResult, }; /// Wrapper around `frame_system::CheckNonce<T>`. @@ -51,46 +55,71 @@ impl<T: Config> Debug for CheckNonce<T> { } } -impl<T: Config + TypeInfo> SignedExtension for CheckNonce<T> +impl<T: Config + TypeInfo> TransactionExtension<T::RuntimeCall> for CheckNonce<T> where - T::RuntimeCall: Dispatchable<Info = DispatchInfo> + IsSubType<crate::Call<T>>, + T::RuntimeCall: Dispatchable<Info = DispatchInfo>, + <T::RuntimeCall as Dispatchable>::RuntimeOrigin: AsSystemOriginSigner<T::AccountId> + Clone, + T::RuntimeCall: IsSubType<crate::Call<T>>, { - type AccountId = <T as frame_system::Config>::AccountId; - type AdditionalSigned = (); - type Call = <T as frame_system::Config>::RuntimeCall; - type Pre = (); + type Implicit = (); + type Pre = <frame_system::CheckNonce<T> as TransactionExtension<T::RuntimeCall>>::Pre; + type Val = <frame_system::CheckNonce<T> as TransactionExtension<T::RuntimeCall>>::Val; const IDENTIFIER: &'static str = "CheckNonce"; - fn additional_signed(&self) -> Result<(), TransactionValidityError> { - self.0.additional_signed() + fn validate( + &self, + origin: <T as frame_system::Config>::RuntimeOrigin, + call: &T::RuntimeCall, + info: &DispatchInfoOf<T::RuntimeCall>, + len: usize, + self_implicit: Self::Implicit, + inherited_implication: &impl Encode, + source: TransactionSource, + ) -> ValidateResult<Self::Val, T::RuntimeCall> { + self.0.validate( + origin, + call, + info, + len, + self_implicit, + inherited_implication, + source, + ) } - fn pre_dispatch( + fn weight(&self, origin: &T::RuntimeCall) -> Weight { + self.0.weight(origin) + } + + fn prepare( self, - who: &Self::AccountId, - call: &Self::Call, - info: &DispatchInfoOf<Self::Call>, + val: Self::Val, + origin: &T::RuntimeOrigin, + call: &T::RuntimeCall, + info: &DispatchInfoOf<T::RuntimeCall>, len: usize, - ) -> Result<(), TransactionValidityError> { + ) -> Result<Self::Pre, TransactionValidityError> { if let Some( crate::Call::consume_oneshot_account { .. } | crate::Call::consume_oneshot_account_with_remaining { .. }, ) = call.is_sub_type() { - Ok(()) + Ok(Self::Pre::NonceChecked) } else { - self.0.pre_dispatch(who, call, info, len) + self.0.prepare(val, origin, call, info, len) } } - fn validate( - &self, - who: &Self::AccountId, - call: &Self::Call, - info: &DispatchInfoOf<Self::Call>, + fn post_dispatch_details( + pre: Self::Pre, + info: &DispatchInfo, + post_info: &PostDispatchInfoOf<T::RuntimeCall>, len: usize, - ) -> TransactionValidity { - self.0.validate(who, call, info, len) + result: &DispatchResult, + ) -> Result<Weight, TransactionValidityError> { + <frame_system::CheckNonce<T> as TransactionExtension<T::RuntimeCall>>::post_dispatch_details( + pre, info, post_info, len, result, + ) } } diff --git a/pallets/oneshot-account/src/lib.rs b/pallets/oneshot-account/src/lib.rs index 42adac55a8fce9bd6cb629c506c2b6424c2d6980..dc54c7637b58efb3e61da927215f99fe8166eb1e 100644 --- a/pallets/oneshot-account/src/lib.rs +++ b/pallets/oneshot-account/src/lib.rs @@ -136,7 +136,7 @@ pub mod pallet { /// /// Origin account is kept alive. #[pallet::call_index(0)] - #[pallet::weight(T::WeightInfo::create_oneshot_account())] + #[pallet::weight(<T as pallet::Config>::WeightInfo::create_oneshot_account())] pub fn create_oneshot_account( origin: OriginFor<T>, dest: <T::Lookup as StaticLookup>::Source, @@ -177,7 +177,7 @@ pub mod pallet { /// - `dest`: The destination account. /// - `dest_is_oneshot`: If set to `true`, then a oneshot account is created at `dest`. Else, `dest` has to be an existing account. #[pallet::call_index(1)] - #[pallet::weight(T::WeightInfo::consume_oneshot_account())] + #[pallet::weight(<T as pallet::Config>::WeightInfo::consume_oneshot_account())] pub fn consume_oneshot_account( origin: OriginFor<T>, block_height: BlockNumberFor<T>, @@ -237,7 +237,7 @@ pub mod pallet { /// - `dest2_is_oneshot`: If set to `true`, then a oneshot account is created at `dest2`. Else, `dest2` has to be an existing account. /// - `balance1`: The amount transfered to `dest`, the leftover being transfered to `dest2`. #[pallet::call_index(2)] - #[pallet::weight(T::WeightInfo::consume_oneshot_account_with_remaining())] + #[pallet::weight(<T as pallet::Config>::WeightInfo::consume_oneshot_account_with_remaining())] pub fn consume_oneshot_account_with_remaining( origin: OriginFor<T>, block_height: BlockNumberFor<T>, @@ -339,6 +339,16 @@ where type Balance = BalanceOf<T>; type LiquidityInfo = Option<Credit<T::AccountId, T::Currency>>; + fn can_withdraw_fee( + who: &T::AccountId, + call: &T::RuntimeCall, + dispatch_info: &DispatchInfoOf<T::RuntimeCall>, + fee: Self::Balance, + tip: Self::Balance, + ) -> Result<(), TransactionValidityError> { + T::InnerOnChargeTransaction::can_withdraw_fee(who, call, dispatch_info, fee, tip) + } + fn withdraw_fee( who: &T::AccountId, call: &T::RuntimeCall, diff --git a/pallets/upgrade-origin/src/lib.rs b/pallets/upgrade-origin/src/lib.rs index d98c21f84b3f2870ff4ecff6f91d84c923881a3f..b9d0e047973841854a7485ddd545618bb1fab0f8 100644 --- a/pallets/upgrade-origin/src/lib.rs +++ b/pallets/upgrade-origin/src/lib.rs @@ -86,7 +86,7 @@ pub mod pallet { let dispatch_info = call.get_dispatch_info(); ( T::WeightInfo::dispatch_as_root() - .saturating_add(dispatch_info.weight), + .saturating_add(dispatch_info.call_weight).saturating_add(dispatch_info.extension_weight), dispatch_info.class, ) })] diff --git a/runtime/g1/src/lib.rs b/runtime/g1/src/lib.rs index 8dccda2f1d873a1b5e7b754f712e7b69b7cf16b1..7f8314c50ee9a1a89e776f14fbea7009bf2eb6a0 100644 --- a/runtime/g1/src/lib.rs +++ b/runtime/g1/src/lib.rs @@ -113,9 +113,9 @@ pub fn native_version() -> NativeVersion { pub type Block = sp_runtime::generic::Block<Header, UncheckedExtrinsic>; /// Unchecked extrinsic type as expected by this runtime. pub type UncheckedExtrinsic = - generic::UncheckedExtrinsic<Address, RuntimeCall, Signature, SignedExtra>; -/// The SignedExtension to the basic transaction logic. -pub type SignedExtra = ( + generic::UncheckedExtrinsic<Address, RuntimeCall, Signature, TxExtension>; +/// The `TransactionExtension` to the basic transaction logic. +pub type TxExtension = ( frame_system::CheckNonZeroSender<Runtime>, frame_system::CheckSpecVersion<Runtime>, frame_system::CheckTxVersion<Runtime>, diff --git a/runtime/gdev/src/lib.rs b/runtime/gdev/src/lib.rs index 4b7d0427887bc85146940e9d8be33f516533e325..0ab65024fb1b4271ad32bac6d1ff605b32e0d44d 100644 --- a/runtime/gdev/src/lib.rs +++ b/runtime/gdev/src/lib.rs @@ -113,9 +113,9 @@ pub fn native_version() -> NativeVersion { pub type Block = sp_runtime::generic::Block<Header, UncheckedExtrinsic>; /// Unchecked extrinsic type as expected by this runtime. pub type UncheckedExtrinsic = - generic::UncheckedExtrinsic<Address, RuntimeCall, Signature, SignedExtra>; -/// The SignedExtension to the basic transaction logic. -pub type SignedExtra = ( + generic::UncheckedExtrinsic<Address, RuntimeCall, Signature, TxExtension>; +/// The `TransactionExtension` to the basic transaction logic. +pub type TxExtension = ( frame_system::CheckNonZeroSender<Runtime>, frame_system::CheckSpecVersion<Runtime>, frame_system::CheckTxVersion<Runtime>, diff --git a/runtime/gtest/src/lib.rs b/runtime/gtest/src/lib.rs index 842fc6a387814272075a72aad5a8ee5ca3508b6c..0a0c4f0991a8859dc3a78a5ecaab94743361a715 100644 --- a/runtime/gtest/src/lib.rs +++ b/runtime/gtest/src/lib.rs @@ -112,9 +112,9 @@ pub fn native_version() -> NativeVersion { pub type Block = sp_runtime::generic::Block<Header, UncheckedExtrinsic>; /// Unchecked extrinsic type as expected by this runtime. pub type UncheckedExtrinsic = - generic::UncheckedExtrinsic<Address, RuntimeCall, Signature, SignedExtra>; -/// The SignedExtension to the basic transaction logic. -pub type SignedExtra = ( + generic::UncheckedExtrinsic<Address, RuntimeCall, Signature, TxExtension>; +/// The `TransactionExtension` to the basic transaction logic. +pub type TxExtension = ( frame_system::CheckNonZeroSender<Runtime>, frame_system::CheckSpecVersion<Runtime>, frame_system::CheckTxVersion<Runtime>,