1
1
package interchain_accounts
2
2
3
3
import (
4
- "fmt"
5
-
6
4
sdk "github.com/cosmos/cosmos-sdk/types"
7
5
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
8
6
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"
9
7
10
8
"github.com/cosmos/ibc-go/v2/modules/apps/27-interchain-accounts/keeper"
11
- "github.com/cosmos/ibc-go/v2/modules/apps/27-interchain-accounts/types"
12
9
channeltypes "github.com/cosmos/ibc-go/v2/modules/core/04-channel/types"
13
10
porttypes "github.com/cosmos/ibc-go/v2/modules/core/05-port/types"
14
11
ibcexported "github.com/cosmos/ibc-go/v2/modules/core/exported"
15
12
)
16
13
17
- // IBCModule implements the ICS26 callbacks for interchain accounts given the
14
+ // IBCModule implements the ICS26 interface for interchain accounts given the
18
15
// interchain account keeper and underlying application.
19
16
type IBCModule struct {
20
17
keeper keeper.Keeper
@@ -29,7 +26,13 @@ func NewIBCModule(k keeper.Keeper, app porttypes.IBCModule) IBCModule {
29
26
}
30
27
}
31
28
32
- // OnChanOpenInit implements the IBCModule interface
29
+ // OnChanOpenInit implements the IBCModule interface. Interchain Accounts is
30
+ // implemented to act as middleware for connected authentication modules on
31
+ // the controller side. The connected modules may not change the controller side portID or
32
+ // version. They will be allowed to perform custom logic without changing
33
+ // the parameters stored within a channel struct.
34
+ //
35
+ // Controller Chain
33
36
func (im IBCModule ) OnChanOpenInit (
34
37
ctx sdk.Context ,
35
38
order channeltypes.Order ,
@@ -40,10 +43,18 @@ func (im IBCModule) OnChanOpenInit(
40
43
counterparty channeltypes.Counterparty ,
41
44
version string ,
42
45
) error {
43
- return im .keeper .OnChanOpenInit (ctx , order , connectionHops , portID , channelID , chanCap , counterparty , version )
46
+ if err := im .keeper .OnChanOpenInit (ctx , order , connectionHops , portID , channelID , chanCap , counterparty , version ); err != nil {
47
+ return err
48
+ }
49
+
50
+ // call underlying app's OnChanOpenInit callback with the appVersion
51
+ return im .app .OnChanOpenInit (ctx , order , connectionHops , portID , channelID ,
52
+ chanCap , counterparty , version )
44
53
}
45
54
46
55
// OnChanOpenTry implements the IBCModule interface
56
+ //
57
+ // Host Chain
47
58
func (im IBCModule ) OnChanOpenTry (
48
59
ctx sdk.Context ,
49
60
order channeltypes.Order ,
@@ -58,17 +69,30 @@ func (im IBCModule) OnChanOpenTry(
58
69
return im .keeper .OnChanOpenTry (ctx , order , connectionHops , portID , channelID , chanCap , counterparty , version , counterpartyVersion )
59
70
}
60
71
61
- // OnChanOpenAck implements the IBCModule interface
72
+ // OnChanOpenAck implements the IBCModule interface. Interchain Accounts is
73
+ // implemented to act as middleware for connected authentication modules on
74
+ // the controller side. The connected modules may not change the portID or
75
+ // version. They will be allowed to perform custom logic without changing
76
+ // the parameters stored within a channel struct.
77
+ //
78
+ // Controller Chain
62
79
func (im IBCModule ) OnChanOpenAck (
63
80
ctx sdk.Context ,
64
81
portID ,
65
82
channelID string ,
66
83
counterpartyVersion string ,
67
84
) error {
68
- return im .keeper .OnChanOpenAck (ctx , portID , channelID , counterpartyVersion )
85
+ if err := im .keeper .OnChanOpenAck (ctx , portID , channelID , counterpartyVersion ); err != nil {
86
+ return err
87
+ }
88
+
89
+ // call underlying app's OnChanOpenAck callback with the counterparty app version.
90
+ return im .app .OnChanOpenAck (ctx , portID , channelID , counterpartyVersion )
69
91
}
70
92
71
- // OnChanOpenConfirm implements the IBCModule interface
93
+ // OnChanOpenAck implements the IBCModule interface
94
+ //
95
+ // Host Chain
72
96
func (im IBCModule ) OnChanOpenConfirm (
73
97
ctx sdk.Context ,
74
98
portID ,
@@ -97,18 +121,15 @@ func (im IBCModule) OnChanCloseConfirm(
97
121
}
98
122
99
123
// OnRecvPacket implements the IBCModule interface
124
+ //
125
+ // Host Chain
100
126
func (im IBCModule ) OnRecvPacket (
101
127
ctx sdk.Context ,
102
128
packet channeltypes.Packet ,
103
129
_ sdk.AccAddress ,
104
130
) ibcexported.Acknowledgement {
105
131
ack := channeltypes .NewResultAcknowledgement ([]byte {byte (1 )})
106
132
107
- var data types.InterchainAccountPacketData
108
- if err := types .ModuleCdc .UnmarshalJSON (packet .GetData (), & data ); err != nil {
109
- ack = channeltypes .NewErrorAcknowledgement (fmt .Sprintf ("cannot unmarshal ICS-27 interchain account packet data: %s" , err .Error ()))
110
- }
111
-
112
133
// only attempt the application logic if the packet data
113
134
// was successfully decoded
114
135
if ack .Success () {
@@ -123,36 +144,31 @@ func (im IBCModule) OnRecvPacket(
123
144
}
124
145
125
146
// OnAcknowledgementPacket implements the IBCModule interface
147
+ //
148
+ // Controller Chain
126
149
func (im IBCModule ) OnAcknowledgementPacket (
127
150
ctx sdk.Context ,
128
151
packet channeltypes.Packet ,
129
152
acknowledgement []byte ,
130
- _ sdk.AccAddress ,
153
+ relayer sdk.AccAddress ,
131
154
) error {
132
- var ack channeltypes.Acknowledgement
133
-
134
- if err := types .ModuleCdc .UnmarshalJSON (acknowledgement , & ack ); err != nil {
135
- return sdkerrors .Wrapf (sdkerrors .ErrUnknownRequest , "cannot unmarshal ICS-27 interchain account packet acknowledgment: %v" , err )
136
- }
137
- var data types.InterchainAccountPacketData
138
- if err := types .ModuleCdc .UnmarshalJSON (packet .GetData (), & data ); err != nil {
139
- return sdkerrors .Wrapf (sdkerrors .ErrUnknownRequest , "cannot unmarshal ICS-27 interchain account packet data: %s" , err .Error ())
140
- }
141
-
142
- if err := im .keeper .OnAcknowledgementPacket (ctx , packet , data , ack ); err != nil {
143
- return err
144
- }
145
-
146
- return nil
155
+ // call underlying app's OnAcknowledgementPacket callback.
156
+ return im .app .OnAcknowledgementPacket (ctx , packet , acknowledgement , relayer )
147
157
}
148
158
149
159
// OnTimeoutPacket implements the IBCModule interface
160
+ //
161
+ // Controller Chain
150
162
func (im IBCModule ) OnTimeoutPacket (
151
163
ctx sdk.Context ,
152
164
packet channeltypes.Packet ,
153
- _ sdk.AccAddress ,
165
+ relayer sdk.AccAddress ,
154
166
) error {
155
- return im .keeper .OnTimeoutPacket (ctx , packet )
167
+ if err := im .keeper .OnTimeoutPacket (ctx , packet ); err != nil {
168
+ return err
169
+ }
170
+
171
+ return im .app .OnTimeoutPacket (ctx , packet , relayer )
156
172
}
157
173
158
174
// NegotiateAppVersion implements the IBCModule interface
0 commit comments