@@ -3,9 +3,13 @@ package keeper
3
3
4
4
import (
5
5
// "github.com/NibiruChain/nibiru/x/evm"
6
+ "math/big"
7
+
8
+ "github.com/NibiruChain/nibiru/x/evm"
6
9
"github.com/cosmos/cosmos-sdk/codec"
7
10
storetypes "github.com/cosmos/cosmos-sdk/store/types"
8
11
sdk "github.com/cosmos/cosmos-sdk/types"
12
+ gethcommon "github.com/ethereum/go-ethereum/common"
9
13
)
10
14
11
15
type Keeper struct {
@@ -20,6 +24,8 @@ type Keeper struct {
20
24
21
25
// the address capable of executing a MsgUpdateParams message. Typically, this should be the x/gov module account.
22
26
authority sdk.AccAddress
27
+
28
+ bankKeeper evm.BankKeeper
23
29
}
24
30
25
31
func NewKeeper (
@@ -38,3 +44,24 @@ func NewKeeper(
38
44
EvmState : NewEvmState (cdc , storeKey , transientKey ),
39
45
}
40
46
}
47
+
48
+ // GetEvmGasBalance: Implements `evm.EVMKeeper` from
49
+ // "github.com/NibiruChain/nibiru/app/ante/evm": Load account's balance of gas
50
+ // tokens for EVM execution
51
+ func (k * Keeper ) GetEvmGasBalance (ctx sdk.Context , addr gethcommon.Address ) * big.Int {
52
+ cosmosAddr := sdk .AccAddress (addr .Bytes ())
53
+ evmParams := k .GetParams (ctx )
54
+ evmDenom := evmParams .GetEvmDenom ()
55
+ // if node is pruned, params is empty. Return invalid value
56
+ if evmDenom == "" {
57
+ return big .NewInt (- 1 )
58
+ }
59
+ coin := k .bankKeeper .GetBalance (ctx , cosmosAddr , evmDenom )
60
+ return coin .Amount .BigInt ()
61
+ }
62
+
63
+ // GetParams returns the total set of evm parameters.
64
+ func (k Keeper ) GetParams (ctx sdk.Context ) (params evm.Params ) {
65
+ params , _ = k .EvmState .ModuleParams .Get (ctx )
66
+ return params
67
+ }
0 commit comments