-
Notifications
You must be signed in to change notification settings - Fork 17
/
keeper.go
104 lines (90 loc) · 3.3 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 (
"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"
host "github.com/cosmos/ibc-go/modules/core/24-host"
authkeeper "github.com/datachainlab/cross/x/core/auth/keeper"
authtypes "github.com/datachainlab/cross/x/core/auth/types"
initiatorkeeper "github.com/datachainlab/cross/x/core/initiator/keeper"
"github.com/datachainlab/cross/x/core/router"
txtypes "github.com/datachainlab/cross/x/core/tx/types"
"github.com/datachainlab/cross/x/core/types"
xcctypes "github.com/datachainlab/cross/x/core/xcc/types"
"github.com/datachainlab/cross/x/packets"
)
type Keeper struct {
m codec.Codec
portKeeper types.PortKeeper
channelKeeper types.ChannelKeeper
scopedKeeper capabilitykeeper.ScopedKeeper
router router.Router
initiatorKeeper initiatorkeeper.Keeper
authKeeper authkeeper.Keeper
}
func NewKeeper(
cdc codec.Codec, initiatorStoreKey, authStoreKey sdk.StoreKey,
channelKeeper types.ChannelKeeper, portKeeper types.PortKeeper, scopedKeeper capabilitykeeper.ScopedKeeper,
packetMiddleware packets.PacketMiddleware, xccResolver xcctypes.XCCResolver, txRunner txtypes.TxRunner, router router.Router,
) Keeper {
packetSendKeeper := packets.NewPacketSendKeeper(
cdc,
channelKeeper,
portKeeper,
scopedKeeper,
)
authKeeper := authkeeper.NewKeeper(
cdc, authStoreKey, channelKeeper, packetSendKeeper, packetMiddleware,
xccResolver,
)
initiatorKeeper := initiatorkeeper.NewKeeper(
cdc, initiatorStoreKey, channelKeeper,
authKeeper,
packetSendKeeper,
packetMiddleware,
xccResolver,
txRunner,
)
authKeeper.SetTxManager(initiatorKeeper)
router.AddRoute(authtypes.PacketType, authKeeper)
return Keeper{
m: cdc,
portKeeper: portKeeper,
channelKeeper: channelKeeper,
scopedKeeper: scopedKeeper,
router: router,
initiatorKeeper: initiatorKeeper,
authKeeper: authKeeper,
}
}
func (k Keeper) InitiatorKeeper() initiatorkeeper.Keeper {
return k.initiatorKeeper
}
func (k Keeper) AuthKeeper() authkeeper.Keeper {
return k.authKeeper
}
// IsBound checks if the transfer 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
}
// GetPort returns portID
func (k Keeper) GetPort(ctx sdk.Context) string {
return types.PortID
}
// 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 {
cap := k.portKeeper.BindPort(ctx, portID)
return k.ClaimCapability(ctx, cap, host.PortPath(portID))
}
// ClaimCapability allows the transfer module that can claim a capability that IBC module
// passes to it
func (k Keeper) ClaimCapability(ctx sdk.Context, cap *capabilitytypes.Capability, name string) error {
return k.scopedKeeper.ClaimCapability(ctx, cap, name)
}
// AuthenticateCapability wraps the scopedKeeper's AuthenticateCapability function
func (k Keeper) AuthenticateCapability(ctx sdk.Context, cap *capabilitytypes.Capability, name string) bool {
return k.scopedKeeper.AuthenticateCapability(ctx, cap, name)
}