-
Notifications
You must be signed in to change notification settings - Fork 41
/
keeper.go
104 lines (91 loc) · 3.26 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
92
93
94
95
96
97
98
99
100
101
102
103
104
package keeper
import (
"fmt"
"github.com/cometbft/cometbft/libs/log"
"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"
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
host "github.com/cosmos/ibc-go/v7/modules/core/24-host"
"github.com/tendermint/spn/x/monitoringp/types"
)
type (
Keeper struct {
cdc codec.BinaryCodec
portKey []byte
storeKey storetypes.StoreKey
memKey storetypes.StoreKey
paramstore paramtypes.Subspace
stakingKeeper types.StakingKeeper
scopedKeeper capabilitykeeper.ScopedKeeper
clientKeeper types.ClientKeeper
portKeeper types.PortKeeper
connectionKeeper types.ConnectionKeeper
channelKeeper types.ChannelKeeper
}
)
func NewKeeper(
cdc codec.BinaryCodec,
storeKey,
memKey storetypes.StoreKey,
ps paramtypes.Subspace,
stakingKeeper types.StakingKeeper,
clientKeeper types.ClientKeeper,
connectionKeeper types.ConnectionKeeper,
channelKeeper types.ChannelKeeper,
portKeeper types.PortKeeper,
scopedKeeper capabilitykeeper.ScopedKeeper,
) *Keeper {
// set KeyTable if it has not already been set
if !ps.HasKeyTable() {
ps = ps.WithKeyTable(types.ParamKeyTable())
}
return &Keeper{
cdc: cdc,
portKey: types.PortKey,
storeKey: storeKey,
memKey: memKey,
paramstore: ps,
stakingKeeper: stakingKeeper,
scopedKeeper: scopedKeeper,
clientKeeper: clientKeeper,
portKeeper: portKeeper,
connectionKeeper: connectionKeeper,
channelKeeper: channelKeeper,
}
}
func (k Keeper) Logger(ctx sdk.Context) log.Logger {
return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName))
}
// IsBound checks if the module is already bound to the desired port
func (k Keeper) IsBound(ctx sdk.Context, portID string) bool {
_, ok := k.scopedKeeper.GetCapability(ctx, host.PortPath(portID))
return ok
}
// BindPort defines a wrapper function for the ort Keeper's function in
// order to expose it to module's InitGenesis function
func (k Keeper) BindPort(ctx sdk.Context, portID string) error {
c := k.portKeeper.BindPort(ctx, portID)
return k.ClaimCapability(ctx, c, host.PortPath(portID))
}
// GetPort returns the portID for the module. Used in ExportGenesis
func (k Keeper) GetPort(ctx sdk.Context) string {
store := ctx.KVStore(k.storeKey)
return string(store.Get(k.portKey))
}
// SetPort sets the portID for the module. Used in InitGenesis
func (k Keeper) SetPort(ctx sdk.Context, portID string) {
store := ctx.KVStore(k.storeKey)
store.Set(k.portKey, []byte(portID))
}
// AuthenticateCapability wraps the scopedKeeper's AuthenticateCapability function
func (k Keeper) AuthenticateCapability(ctx sdk.Context, c *capabilitytypes.Capability, name string) bool {
return k.scopedKeeper.AuthenticateCapability(ctx, c, name)
}
// ClaimCapability allows the transfer module that can claim a capability that IBC module
// passes to it
func (k Keeper) ClaimCapability(ctx sdk.Context, c *capabilitytypes.Capability, name string) error {
return k.scopedKeeper.ClaimCapability(ctx, c, name)
}