1
// Copyright (C) Moondance Labs Ltd.
2
// This file is part of Tanssi.
3

            
4
// Tanssi is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8

            
9
// Tanssi is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13

            
14
// You should have received a copy of the GNU General Public License
15
// along with Tanssi.  If not, see <http://www.gnu.org/licenses/>.
16

            
17
#[macro_export]
18
macro_rules! impl_on_charge_evm_transaction {
19
	{} => {
20
		pub struct OnChargeEVMTransaction<OU>(sp_std::marker::PhantomData<OU>);
21
		impl<T, OU> OnChargeEVMTransactionT<T> for OnChargeEVMTransaction<OU>
22
		where
23
			T: pallet_evm::Config,
24
			T::Currency: Balanced<pallet_evm::AccountIdOf<T>>,
25
			OU: OnUnbalanced<Credit<pallet_evm::AccountIdOf<T>, T::Currency>>,
26
			U256: UniqueSaturatedInto<<T::Currency as Inspect<pallet_evm::AccountIdOf<T>>>::Balance>,
27
			T::AddressMapping: pallet_evm::AddressMapping<T::AccountId>,
28

            
29
		{
30
			type LiquidityInfo =  Option<Credit<pallet_evm::AccountIdOf<T>, T::Currency>>;
31

            
32
			fn withdraw_fee(who: &H160, fee: U256) -> Result<Self::LiquidityInfo, pallet_evm::Error<T>> {
33
				EVMFungibleAdapter::<<T as pallet_evm::Config>::Currency, ()>::withdraw_fee(who, fee)
34
			}
35

            
36
			fn correct_and_deposit_fee(
37
				who: &H160,
38
				corrected_fee: U256,
39
				base_fee: U256,
40
				already_withdrawn: Self::LiquidityInfo,
41
			) -> Self::LiquidityInfo {
42
				<EVMFungibleAdapter<<T as pallet_evm::Config>::Currency, OU> as OnChargeEVMTransactionT<
43
					T,
44
				>>::correct_and_deposit_fee(who, corrected_fee, base_fee, already_withdrawn)
45
			}
46

            
47
			fn pay_priority_fee(tip: Self::LiquidityInfo) {
48
				if let Some(tip) = tip {
49
					OU::on_unbalanced(tip);
50
				}
51
			}
52
		}
53
	}
54
}