Skip to content

Commit d878a86

Browse files
committed
Alpha transaction payment - in progress
1 parent 2604913 commit d878a86

File tree

1 file changed

+42
-11
lines changed
  • pallets/transaction-fee/src

1 file changed

+42
-11
lines changed

pallets/transaction-fee/src/lib.rs

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,52 @@
22

33
use frame_support::pallet_prelude::*;
44
use 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

1315
use 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

2122
use smallvec::smallvec;
2223
use subtensor_runtime_common::Balance;
2324

2425
pub 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+
2651
pub struct LinearWeightToFee;
2752

2853
impl WeightToFeePolynomial for LinearWeightToFee {
@@ -47,7 +72,7 @@ pub struct FungibleAdapter<F, OU>(PhantomData<(F, OU)>);
4772

4873
impl<T, F, OU> OnChargeTransaction<T> for FungibleAdapter<F, OU>
4974
where
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);
@@ -81,8 +112,8 @@ where
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> {
@@ -98,8 +129,8 @@ where
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

Comments
 (0)