|
1 |
| -use super::{Balances, Runtime, Treasury}; |
| 1 | +use super::{Authorship, Balances, Runtime, Treasury}; |
2 | 2 | use frame_support::traits::{fungible::Inspect, Currency, Imbalance, OnUnbalanced};
|
3 | 3 | use node_primitives::{AccountId, Balance};
|
4 | 4 | use pallet_balances::{NegativeImbalance, PositiveImbalance};
|
| 5 | +use pallet_evm::{EVMCurrencyAdapter, OnChargeEVMTransaction}; |
5 | 6 |
|
6 | 7 | pub struct EvmCurrency;
|
7 | 8 |
|
@@ -51,6 +52,44 @@ impl OnUnbalanced<NegativeImbalance<Runtime>> for EvmDealWithFees {
|
51 | 52 | }
|
52 | 53 | }
|
53 | 54 |
|
| 55 | +impl OnChargeEVMTransaction<Runtime> for EvmDealWithFees { |
| 56 | + type LiquidityInfo = Option<NegativeImbalance<Runtime>>; |
| 57 | + |
| 58 | + fn withdraw_fee( |
| 59 | + who: &sp_core::H160, |
| 60 | + fee: sp_core::U256, |
| 61 | + ) -> Result<Self::LiquidityInfo, pallet_evm::Error<Runtime>> { |
| 62 | + <EVMCurrencyAdapter<EvmCurrency, Self> as OnChargeEVMTransaction<Runtime>>::withdraw_fee( |
| 63 | + who, fee, |
| 64 | + ) |
| 65 | + } |
| 66 | + |
| 67 | + fn correct_and_deposit_fee( |
| 68 | + who: &sp_core::H160, |
| 69 | + corrected_fee: sp_core::U256, |
| 70 | + base_fee: sp_core::U256, |
| 71 | + already_withdrawn: Self::LiquidityInfo, |
| 72 | + ) -> Self::LiquidityInfo { |
| 73 | + <EVMCurrencyAdapter<EvmCurrency, Self> as OnChargeEVMTransaction<Runtime>>::correct_and_deposit_fee( |
| 74 | + who, |
| 75 | + corrected_fee, |
| 76 | + base_fee, |
| 77 | + already_withdrawn, |
| 78 | + ) |
| 79 | + } |
| 80 | + |
| 81 | + fn pay_priority_fee(tip: Self::LiquidityInfo) { |
| 82 | + if let Some(tip) = tip { |
| 83 | + match Authorship::author() { |
| 84 | + Some(author) => { |
| 85 | + let _ = EvmCurrency::deposit_creating(&author, tip.peek()); |
| 86 | + } |
| 87 | + None => Self::on_unbalanced(tip), |
| 88 | + } |
| 89 | + } |
| 90 | + } |
| 91 | +} |
| 92 | + |
54 | 93 | impl Currency<AccountId> for EvmCurrency {
|
55 | 94 | type Balance = Balance;
|
56 | 95 |
|
|
0 commit comments