forked from AstraProtocol/astra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
evm_hooks.go
53 lines (44 loc) · 1.47 KB
/
evm_hooks.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package keeper
import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/dungtt-astra/astra/v3/cmd/config"
"github.com/ethereum/go-ethereum/core"
ethtypes "github.com/ethereum/go-ethereum/core/types"
evmtypes "github.com/dungtt-astra/astra/v3/x/feeburn/types"
)
var _ evmtypes.EvmHooks = Hooks{}
// Hooks wrapper struct for fees keeper
type Hooks struct {
k Keeper
}
// Hooks return the wrapper hooks struct for the Keeper
func (k Keeper) Hooks() Hooks {
return Hooks{k}
}
// PostTxProcessing is a wrapper for calling the EVM PostTxProcessing hook on
// the module keeper
func (h Hooks) PostTxProcessing(ctx sdk.Context, msg core.Message, receipt *ethtypes.Receipt) error {
return h.k.PostTxProcessing(ctx, msg, receipt)
}
// PostTxProcessing implements EvmHooks.PostTxProcessing. After each successful
// interaction with a registered contract, the contract deployer (or, if set,
// the withdraw address) receives a share from the transaction fees paid by the
// transaction sender.
func (k Keeper) PostTxProcessing(
ctx sdk.Context,
msg core.Message,
receipt *ethtypes.Receipt,
) error {
// check if the fees are globally enabled
params := k.GetParams(ctx)
if !params.EnableFeeBurn {
return nil
}
totalFeeAmount := sdk.NewIntFromUint64(receipt.GasUsed).Mul(sdk.NewIntFromBigInt(msg.GasPrice()))
totalFees := sdk.Coins{{Denom: config.BaseDenom, Amount: totalFeeAmount}}
err := k.BurnFee(ctx, k.bankKeeper, totalFees, params)
if err != nil {
return err
}
return nil
}