22
33use frame_support:: pallet_prelude:: * ;
44use frame_support:: {
5+ dispatch:: { GetDispatchInfo , PostDispatchInfo } ,
56 traits:: {
6- Imbalance , OnUnbalanced ,
7+ Imbalance , IsSubType , OnUnbalanced ,
78 fungible:: { Balanced , Credit , Debt , Inspect } ,
89 tokens:: { Precision , WithdrawConsequence } ,
10+ UnfilteredDispatchable
911 } ,
1012 weights:: { WeightToFeeCoefficient , WeightToFeeCoefficients , WeightToFeePolynomial } ,
1113} ;
1214
1315use sp_runtime:: {
1416 Perbill , Saturating ,
15- traits:: { DispatchInfoOf , PostDispatchInfoOf } ,
17+ traits:: { Dispatchable , DispatchInfoOf , PostDispatchInfoOf } ,
1618} ;
1719// use substrate_fixed::types::U96F32;
1820// use subtensor_runtime_common::{AlphaCurrency, NetUid};
19- use pallet_transaction_payment:: Config as PTPConfig ;
2021
2122use smallvec:: smallvec;
2223use subtensor_runtime_common:: Balance ;
2324
2425pub use pallet_transaction_payment:: OnChargeTransaction ;
2526
27+ #[ frame_support:: pallet]
28+ pub mod pallet {
29+ use super :: * ;
30+
31+ #[ pallet:: config]
32+ pub trait Config : frame_system:: Config {
33+ type RuntimeCall : Parameter
34+ + Dispatchable < RuntimeOrigin = Self :: RuntimeOrigin , PostInfo = PostDispatchInfo >
35+ + GetDispatchInfo
36+ + From < frame_system:: Call < Self > >
37+ + UnfilteredDispatchable < RuntimeOrigin = Self :: RuntimeOrigin >
38+ + IsSubType < Call < Self > >
39+ + IsType < <Self as frame_system:: Config >:: RuntimeCall > ;
40+ }
41+
42+ #[ pallet:: pallet]
43+ pub struct Pallet < T > ( _ ) ;
44+
45+ // #[pallet::call]
46+ // impl<T: Config> Pallet<T> {
47+ // // You now have access to T::OnChargeTransaction, T::WeightToFee, etc.
48+ // }
49+ }
50+
2651pub struct LinearWeightToFee ;
2752
2853impl WeightToFeePolynomial for LinearWeightToFee {
@@ -47,7 +72,7 @@ pub struct FungibleAdapter<F, OU>(PhantomData<(F, OU)>);
4772
4873impl < T , F , OU > OnChargeTransaction < T > for FungibleAdapter < F , OU >
4974where
50- T : PTPConfig ,
75+ T : crate :: pallet :: Config + frame_system :: Config + pallet_transaction_payment :: Config ,
5176 F : Balanced < T :: AccountId > ,
5277 OU : OnUnbalanced < Credit < T :: AccountId , F > > ,
5378{
@@ -56,12 +81,18 @@ where
5681
5782 fn withdraw_fee (
5883 who : & <T >:: AccountId ,
59- call : & <T >:: RuntimeCall ,
60- _dispatch_info : & DispatchInfoOf < <T >:: RuntimeCall > ,
84+ call : & <T as frame_system :: Config >:: RuntimeCall ,
85+ _dispatch_info : & DispatchInfoOf < <T as frame_system :: Config >:: RuntimeCall > ,
6186 fee : Self :: Balance ,
6287 _tip : Self :: Balance ,
6388 ) -> Result < Self :: LiquidityInfo , TransactionValidityError > {
64- log:: error!( "====================== withdraw_fee. Call = {:?}" , call) ;
89+
90+ match call {
91+ <T as pallet:: Config >:: RuntimeCall :: SubtensorModule ( pallet_subtensor:: Call :: remove_stake { hotkey : _, netuid : _, amount_unstaked : _ } ) => {
92+ log:: error!( "=========== calling remove_stake" ) ;
93+ } ,
94+ _ => { }
95+ }
6596
6697 if fee. is_zero ( ) {
6798 return Ok ( None ) ;
81112
82113 fn can_withdraw_fee (
83114 who : & T :: AccountId ,
84- _call : & T :: RuntimeCall ,
85- _dispatch_info : & DispatchInfoOf < T :: RuntimeCall > ,
115+ _call : & < T as frame_system :: Config > :: RuntimeCall ,
116+ _dispatch_info : & DispatchInfoOf < < T as frame_system :: Config > :: RuntimeCall > ,
86117 fee : Self :: Balance ,
87118 _tip : Self :: Balance ,
88119 ) -> Result < ( ) , TransactionValidityError > {
98129
99130 fn correct_and_deposit_fee (
100131 who : & <T >:: AccountId ,
101- _dispatch_info : & DispatchInfoOf < <T >:: RuntimeCall > ,
102- _post_info : & PostDispatchInfoOf < <T >:: RuntimeCall > ,
132+ _dispatch_info : & DispatchInfoOf < <T as frame_system :: Config >:: RuntimeCall > ,
133+ _post_info : & PostDispatchInfoOf < <T as frame_system :: Config >:: RuntimeCall > ,
103134 corrected_fee : Self :: Balance ,
104135 tip : Self :: Balance ,
105136 already_withdrawn : Self :: LiquidityInfo ,
0 commit comments