-
Notifications
You must be signed in to change notification settings - Fork 13
/
keeper.go
91 lines (80 loc) · 2.92 KB
/
keeper.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package keeper
import (
"github.com/cosmos/cosmos-sdk/codec"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
capabilitykeeper "github.com/cosmos/cosmos-sdk/x/capability/keeper"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
ibctransferkeeper "github.com/cosmos/ibc-go/v6/modules/apps/transfer/keeper"
transfertypes "github.com/cosmos/ibc-go/v6/modules/apps/transfer/types"
porttypes "github.com/cosmos/ibc-go/v6/modules/core/05-port/types"
host "github.com/cosmos/ibc-go/v6/modules/core/24-host"
"github.com/tendermint/tendermint/libs/log"
"github.com/functionx/fx-core/v7/x/ibc/applications/transfer/types"
)
// Keeper defines the IBC fungible transfer keeper
type Keeper struct {
ibctransferkeeper.Keeper
storeKey storetypes.StoreKey
cdc codec.Codec
paramSpace paramtypes.Subspace
ics4Wrapper porttypes.ICS4Wrapper
channelKeeper transfertypes.ChannelKeeper
portKeeper transfertypes.PortKeeper
authKeeper transfertypes.AccountKeeper
bankKeeper transfertypes.BankKeeper
scopedKeeper capabilitykeeper.ScopedKeeper
erc20Keeper types.Erc20Keeper
evmKeeper types.EvmKeeper
router *types.Router
refundHook types.RefundHook
}
// NewKeeper creates a new IBC transfer Keeper instance
func NewKeeper(keeper ibctransferkeeper.Keeper,
cdc codec.Codec, key storetypes.StoreKey, paramSpace paramtypes.Subspace,
ics4Wrapper porttypes.ICS4Wrapper, channelKeeper transfertypes.ChannelKeeper, portKeeper transfertypes.PortKeeper,
authKeeper transfertypes.AccountKeeper, bankKeeper transfertypes.BankKeeper, scopedKeeper capabilitykeeper.ScopedKeeper,
) Keeper {
// ensure ibc transfer module account is set
if addr := authKeeper.GetModuleAddress(types.ModuleName); addr == nil {
panic("the FX IBC transfer module account has not been set")
}
return Keeper{
Keeper: keeper,
cdc: cdc,
storeKey: key,
paramSpace: paramSpace,
ics4Wrapper: ics4Wrapper,
channelKeeper: channelKeeper,
portKeeper: portKeeper,
authKeeper: authKeeper,
bankKeeper: bankKeeper,
scopedKeeper: scopedKeeper,
}
}
// SetRouter sets the Router in IBC Transfer Keeper and seals it. The method panics if
// there is an existing router that's already sealed.
func (k Keeper) SetRouter(rtr types.Router) Keeper {
if k.router != nil && k.router.Sealed() {
panic("cannot reset a sealed router")
}
k.router = &rtr
k.router.Seal()
return k
}
func (k Keeper) SetRefundHook(hook types.RefundHook) Keeper {
k.refundHook = hook
return k
}
func (k Keeper) SetErc20Keeper(erc20Keeper types.Erc20Keeper) Keeper {
k.erc20Keeper = erc20Keeper
return k
}
func (k Keeper) SetEvmKeeper(evmKeeper types.EvmKeeper) Keeper {
k.evmKeeper = evmKeeper
return k
}
// Logger returns a module-specific logger.
func (k Keeper) Logger(ctx sdk.Context) log.Logger {
return ctx.Logger().With("module", "x/"+host.ModuleName+"-"+types.CompatibleModuleName)
}