-
Notifications
You must be signed in to change notification settings - Fork 4
/
keeper.go
88 lines (75 loc) · 2.85 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
package keeper
import (
"fmt"
"github.com/Carina-labs/nova/x/icacontrol/types"
"github.com/cosmos/cosmos-sdk/codec"
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"
icacontrollerkeeper "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/controller/keeper"
ibcchanneltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/keeper"
host "github.com/cosmos/ibc-go/v3/modules/core/24-host"
"github.com/tendermint/tendermint/libs/log"
)
type Keeper struct {
cdc codec.Codec
storeKey sdk.StoreKey
authKeeper types.AccountKeeper
scopedKeeper capabilitykeeper.ScopedKeeper
IcaControllerKeeper icacontrollerkeeper.Keeper
hooks types.ICAHooks
paramSpace paramtypes.Subspace
channelKeeper ibcchanneltypes.Keeper
}
func NewKeeper(cdc codec.Codec, storeKey sdk.StoreKey, ak types.AccountKeeper, iaKeeper icacontrollerkeeper.Keeper, scopedKeeper capabilitykeeper.ScopedKeeper, paramStore paramtypes.Subspace, channelKeeper ibcchanneltypes.Keeper) Keeper {
if addr := ak.GetModuleAddress(types.ModuleName); addr == nil {
panic(fmt.Sprintf("%s module account has not been set", types.ModuleName))
}
if !paramStore.HasKeyTable() {
paramStore = paramStore.WithKeyTable(types.ParamKeyTable())
}
return Keeper{
cdc: cdc,
storeKey: storeKey,
authKeeper: ak,
scopedKeeper: scopedKeeper,
paramSpace: paramStore,
IcaControllerKeeper: iaKeeper,
channelKeeper: channelKeeper,
}
}
// Logger returns the application logger, scoped to the associated module
func (k Keeper) Logger(ctx sdk.Context) log.Logger {
return ctx.Logger().With("module", fmt.Sprintf("x/%s-%s", host.ModuleName, types.ModuleName))
}
// ClaimCapability claims the channel capability passed via the OnOpenChanInit callback
func (k *Keeper) ClaimCapability(ctx sdk.Context, cap *capabilitytypes.Capability, name string) error {
return k.scopedKeeper.ClaimCapability(ctx, cap, name)
}
// SetHooks set the epoch hooks
func (k *Keeper) SetHooks(eh types.ICAHooks) *Keeper {
if k.hooks != nil {
panic("cannot set ICA hooks twice")
}
k.hooks = eh
return k
}
func (k Keeper) IsValidKeyManager(ctx sdk.Context, address string) bool {
params := k.GetParams(ctx)
for i := range params.ControllerKeyManager {
if params.ControllerKeyManager[i] == address {
return true
}
}
return false
}
func (k Keeper) GetConnectionId(ctx sdk.Context, portId string) (string, error) {
icas := k.IcaControllerKeeper.GetAllInterchainAccounts(ctx)
for _, ica := range icas {
if ica.PortId == portId {
return ica.ConnectionId, nil
}
}
return "", fmt.Errorf("portId %s has no associated connectionId", portId)
}