@@ -9,10 +9,10 @@ import (
9
9
sdk "github.com/cosmos/cosmos-sdk/types"
10
10
capabilitykeeper "github.com/cosmos/cosmos-sdk/x/capability/keeper"
11
11
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"
12
- host "github.com/cosmos/ibc-go/modules/core/24-host"
13
12
"github.com/tendermint/tendermint/libs/log"
14
13
15
14
"github.com/cosmos/ibc-go/modules/apps/27-interchain-accounts/types"
15
+ host "github.com/cosmos/ibc-go/modules/core/24-host"
16
16
)
17
17
18
18
// Keeper defines the IBC transfer keeper
@@ -49,6 +49,7 @@ func NewKeeper(
49
49
}
50
50
}
51
51
52
+ // SerializeCosmosTx marshals data to bytes using the provided codec
52
53
func (k Keeper ) SerializeCosmosTx (cdc codec.BinaryCodec , data interface {}) ([]byte , error ) {
53
54
msgs := make ([]sdk.Msg , 0 )
54
55
switch data := data .(type ) {
@@ -86,68 +87,63 @@ func (k Keeper) SerializeCosmosTx(cdc codec.BinaryCodec, data interface{}) ([]by
86
87
return bz , nil
87
88
}
88
89
90
+ // Logger returns the application logger, scoped to the associated module
89
91
func (k Keeper ) Logger (ctx sdk.Context ) log.Logger {
90
92
return ctx .Logger ().With ("module" , fmt .Sprintf ("x/%s-%s" , host .ModuleName , types .ModuleName ))
91
93
}
92
94
93
- // IsBound checks if the interchain account module is already bound to the desired port
94
- func (k Keeper ) IsBound (ctx sdk.Context , portID string ) bool {
95
- _ , ok := k . scopedKeeper . GetCapability ( ctx , host . PortPath ( portID ) )
96
- return ok
95
+ // GetPort returns the portID for the interchain accounts module. Used in ExportGenesis
96
+ func (k Keeper ) GetPort (ctx sdk.Context ) string {
97
+ store := ctx . KVStore ( k . storeKey )
98
+ return string ( store . Get ([] byte ( types . PortKey )))
97
99
}
98
100
99
- // BindPort defines a wrapper function for the port Keeper's BindPort function in
100
- // order to expose it to module's InitGenesis function
101
- func (k Keeper ) BindPort (ctx sdk.Context , portID string ) error {
102
- // Set the portID into our store so we can retrieve it later
101
+ // BindPort stores the provided portID and binds to it, returning the associated capability
102
+ func (k Keeper ) BindPort (ctx sdk.Context , portID string ) * capabilitytypes.Capability {
103
103
store := ctx .KVStore (k .storeKey )
104
104
store .Set ([]byte (types .PortKey ), []byte (portID ))
105
105
106
- cap := k .portKeeper .BindPort (ctx , portID )
107
- return k .ClaimCapability (ctx , cap , host .PortPath (portID ))
106
+ return k .portKeeper .BindPort (ctx , portID )
108
107
}
109
108
110
- // GetPort returns the portID for the interchain accounts module. Used in ExportGenesis
111
- func (k Keeper ) GetPort (ctx sdk.Context ) string {
112
- store := ctx . KVStore ( k . storeKey )
113
- return string ( store . Get ([] byte ( types . PortKey )))
109
+ // IsBound checks if the interchain account module is already bound to the desired port
110
+ func (k Keeper ) IsBound (ctx sdk.Context , portID string ) bool {
111
+ _ , ok := k . scopedKeeper . GetCapability ( ctx , host . PortPath ( portID ) )
112
+ return ok
114
113
}
115
114
116
- // ClaimCapability allows the transfer module that can claim a capability that IBC module
117
- // passes to it
118
- func (k Keeper ) ClaimCapability (ctx sdk.Context , cap * capabilitytypes.Capability , name string ) error {
119
- return k .scopedKeeper .ClaimCapability (ctx , cap , name )
115
+ // AuthenticateCapability wraps the scopedKeeper's AuthenticateCapability function
116
+ func (k Keeper ) AuthenticateCapability (ctx sdk.Context , cap * capabilitytypes.Capability , name string ) bool {
117
+ return k .scopedKeeper .AuthenticateCapability (ctx , cap , name )
120
118
}
121
119
122
- func (k Keeper ) SetActiveChannel (ctx sdk.Context , portId , channelId string ) error {
123
- store := ctx .KVStore (k .storeKey )
124
-
125
- key := types .KeyActiveChannel (portId )
126
- store .Set (key , []byte (channelId ))
127
- return nil
120
+ // ClaimCapability wraps the scopedKeeper's ClaimCapability function
121
+ func (k Keeper ) ClaimCapability (ctx sdk.Context , cap * capabilitytypes.Capability , name string ) error {
122
+ return k .scopedKeeper .ClaimCapability (ctx , cap , name )
128
123
}
129
124
125
+ // GetActiveChannel retrieves the active channelID from the store keyed by the provided portID
130
126
func (k Keeper ) GetActiveChannel (ctx sdk.Context , portId string ) (string , bool ) {
131
127
store := ctx .KVStore (k .storeKey )
132
128
key := types .KeyActiveChannel (portId )
129
+
133
130
if ! store .Has (key ) {
134
131
return "" , false
135
132
}
136
133
137
- activeChannel := string (store .Get (key ))
138
- return activeChannel , true
134
+ return string (store .Get (key )), true
139
135
}
140
136
141
- // IsActiveChannel returns true if there exists an active channel for
142
- // the provided portID and false otherwise.
143
- func (k Keeper ) IsActiveChannel (ctx sdk.Context , portId string ) bool {
144
- _ , found := k .GetActiveChannel (ctx , portId )
145
- return found
137
+ // SetActiveChannel stores the active channelID, keyed by the provided portID
138
+ func (k Keeper ) SetActiveChannel (ctx sdk.Context , portID , channelID string ) {
139
+ store := ctx .KVStore (k .storeKey )
140
+ store .Set (types .KeyActiveChannel (portID ), []byte (channelID ))
146
141
}
147
142
148
- // AuthenticateCapability wraps the scopedKeeper's AuthenticateCapability function
149
- func (k Keeper ) AuthenticateCapability (ctx sdk.Context , cap * capabilitytypes.Capability , name string ) bool {
150
- return k .scopedKeeper .AuthenticateCapability (ctx , cap , name )
143
+ // IsActiveChannel returns true if there exists an active channel for the provided portID, otherwise false
144
+ func (k Keeper ) IsActiveChannel (ctx sdk.Context , portID string ) bool {
145
+ _ , ok := k .GetActiveChannel (ctx , portID )
146
+ return ok
151
147
}
152
148
153
149
// GetInterchainAccountAddress retrieves the InterchainAccount address from the store keyed by the provided portID
0 commit comments