Skip to content

Commit f5f18fd

Browse files
committed
merge interchain-accounts branch
2 parents 51a487b + e24294c commit f5f18fd

File tree

8 files changed

+133
-298
lines changed

8 files changed

+133
-298
lines changed

docs/ibc/proto-docs.md

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@
1717
- [Query](#ibc.applications.interchain_accounts.v1.Query)
1818

1919
- [ibc/applications/interchain_accounts/v1/types.proto](#ibc/applications/interchain_accounts/v1/types.proto)
20-
- [IBCAccountPacketData](#ibc.applications.interchain_accounts.v1.IBCAccountPacketData)
2120
- [IBCTxBody](#ibc.applications.interchain_accounts.v1.IBCTxBody)
22-
- [IBCTxRaw](#ibc.applications.interchain_accounts.v1.IBCTxRaw)
21+
- [InterchainAccountPacketData](#ibc.applications.interchain_accounts.v1.InterchainAccountPacketData)
2322

2423
- [Type](#ibc.applications.interchain_accounts.v1.Type)
2524

@@ -399,22 +398,6 @@ Query defines the gRPC querier service.
399398

400399

401400

402-
<a name="ibc.applications.interchain_accounts.v1.IBCAccountPacketData"></a>
403-
404-
### IBCAccountPacketData
405-
Packet data is comprised of raw transaction & type of transaction
406-
407-
408-
| Field | Type | Label | Description |
409-
| ----- | ---- | ----- | ----------- |
410-
| `type` | [Type](#ibc.applications.interchain_accounts.v1.Type) | | |
411-
| `data` | [bytes](#bytes) | | |
412-
413-
414-
415-
416-
417-
418401
<a name="ibc.applications.interchain_accounts.v1.IBCTxBody"></a>
419402

420403
### IBCTxBody
@@ -430,15 +413,17 @@ Body of a tx for an ics27 IBC packet
430413

431414

432415

433-
<a name="ibc.applications.interchain_accounts.v1.IBCTxRaw"></a>
416+
<a name="ibc.applications.interchain_accounts.v1.InterchainAccountPacketData"></a>
434417

435-
### IBCTxRaw
436-
Raw tx body
418+
### InterchainAccountPacketData
419+
InterchainAccountPacketData is comprised of araw transaction,type of transaction and optional memo field.
437420

438421

439422
| Field | Type | Label | Description |
440423
| ----- | ---- | ----- | ----------- |
441-
| `body_bytes` | [bytes](#bytes) | | |
424+
| `type` | [Type](#ibc.applications.interchain_accounts.v1.Type) | | |
425+
| `data` | [bytes](#bytes) | | |
426+
| `memo` | [string](#string) | | |
442427

443428

444429

modules/apps/27-interchain-accounts/ibc_module.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func (im IBCModule) OnRecvPacket(
9898
) ibcexported.Acknowledgement {
9999
ack := channeltypes.NewResultAcknowledgement([]byte{byte(1)})
100100

101-
var data types.IBCAccountPacketData
101+
var data types.InterchainAccountPacketData
102102
if err := types.ModuleCdc.UnmarshalJSON(packet.GetData(), &data); err != nil {
103103
ack = channeltypes.NewErrorAcknowledgement(fmt.Sprintf("cannot unmarshal ICS-27 interchain account packet data: %s", err.Error()))
104104
}
@@ -127,7 +127,7 @@ func (im IBCModule) OnAcknowledgementPacket(
127127
if err := types.ModuleCdc.UnmarshalJSON(acknowledgement, &ack); err != nil {
128128
return sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "cannot unmarshal ICS-27 interchain account packet acknowledgment: %v", err)
129129
}
130-
var data types.IBCAccountPacketData
130+
var data types.InterchainAccountPacketData
131131
if err := types.ModuleCdc.UnmarshalJSON(packet.GetData(), &data); err != nil {
132132
return sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "cannot unmarshal ICS-27 interchain account packet data: %s", err.Error())
133133
}

modules/apps/27-interchain-accounts/keeper/keeper.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,7 @@ func (k Keeper) SerializeCosmosTx(cdc codec.BinaryCodec, msgs []sdk.Msg) ([]byte
7373
Messages: msgAnys,
7474
}
7575

76-
txRaw := &types.IBCTxRaw{
77-
BodyBytes: cdc.MustMarshal(txBody),
78-
}
79-
80-
bz, err := cdc.Marshal(txRaw)
76+
bz, err := cdc.Marshal(txBody)
8177
if err != nil {
8278
return nil, err
8379
}

modules/apps/27-interchain-accounts/keeper/relay.go

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515

1616
// TODO: implement middleware functionality, this will allow us to use capabilities to
1717
// manage helper module access to owner addresses they do not have capabilities for
18-
func (k Keeper) TrySendTx(ctx sdk.Context, portID string, data interface{}) ([]byte, error) {
18+
func (k Keeper) TrySendTx(ctx sdk.Context, portID string, data interface{}, memo string) ([]byte, error) {
1919
// Check for the active channel
2020
activeChannelId, found := k.GetActiveChannel(ctx, portID)
2121
if !found {
@@ -30,7 +30,7 @@ func (k Keeper) TrySendTx(ctx sdk.Context, portID string, data interface{}) ([]b
3030
destinationPort := sourceChannelEnd.GetCounterparty().GetPortID()
3131
destinationChannel := sourceChannelEnd.GetCounterparty().GetChannelID()
3232

33-
return k.createOutgoingPacket(ctx, portID, activeChannelId, destinationPort, destinationChannel, data)
33+
return k.createOutgoingPacket(ctx, portID, activeChannelId, destinationPort, destinationChannel, data, memo)
3434
}
3535

3636
func (k Keeper) createOutgoingPacket(
@@ -40,6 +40,7 @@ func (k Keeper) createOutgoingPacket(
4040
destinationPort,
4141
destinationChannel string,
4242
data interface{},
43+
memo string,
4344
) ([]byte, error) {
4445
if data == nil {
4546
return []byte{}, types.ErrInvalidOutgoingData
@@ -72,9 +73,10 @@ func (k Keeper) createOutgoingPacket(
7273
return []byte{}, channeltypes.ErrSequenceSendNotFound
7374
}
7475

75-
packetData := types.IBCAccountPacketData{
76+
packetData := types.InterchainAccountPacketData{
7677
Type: types.EXECUTE_TX,
7778
Data: txBytes,
79+
Memo: memo,
7880
}
7981

8082
// timeoutTimestamp is set to be a max number here so that we never recieve a timeout
@@ -98,17 +100,9 @@ func (k Keeper) createOutgoingPacket(
98100
// DeserializeCosmosTx will unmarshal and unpack a slice of transaction bytes
99101
// into a slice of sdk.Msg's.
100102
func (k Keeper) DeserializeCosmosTx(_ sdk.Context, txBytes []byte) ([]sdk.Msg, error) {
101-
var txRaw types.IBCTxRaw
102-
103-
err := k.cdc.Unmarshal(txBytes, &txRaw)
104-
if err != nil {
105-
return nil, err
106-
}
107-
108103
var txBody types.IBCTxBody
109104

110-
err = k.cdc.Unmarshal(txRaw.BodyBytes, &txBody)
111-
if err != nil {
105+
if err := k.cdc.Unmarshal(txBytes, &txBody); err != nil {
112106
return nil, err
113107
}
114108

@@ -202,7 +196,7 @@ func (k Keeper) ComputeVirtualTxHash(txBytes []byte, seq uint64) []byte {
202196
}
203197

204198
func (k Keeper) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet) error {
205-
var data types.IBCAccountPacketData
199+
var data types.InterchainAccountPacketData
206200

207201
if err := types.ModuleCdc.UnmarshalJSON(packet.GetData(), &data); err != nil {
208202
return sdkerrors.Wrapf(types.ErrUnknownPacketData, "cannot unmarshal ICS-27 interchain account packet data")
@@ -226,7 +220,7 @@ func (k Keeper) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet) error
226220
}
227221
}
228222

229-
func (k Keeper) OnAcknowledgementPacket(ctx sdk.Context, packet channeltypes.Packet, data types.IBCAccountPacketData, ack channeltypes.Acknowledgement) error {
223+
func (k Keeper) OnAcknowledgementPacket(ctx sdk.Context, packet channeltypes.Packet, data types.InterchainAccountPacketData, ack channeltypes.Acknowledgement) error {
230224
switch ack.Response.(type) {
231225
case *channeltypes.Acknowledgement_Error:
232226
if k.hook != nil {
@@ -245,7 +239,7 @@ func (k Keeper) OnAcknowledgementPacket(ctx sdk.Context, packet channeltypes.Pac
245239
}
246240
}
247241

248-
func (k Keeper) OnTimeoutPacket(ctx sdk.Context, packet channeltypes.Packet, data types.IBCAccountPacketData) error {
242+
func (k Keeper) OnTimeoutPacket(ctx sdk.Context, packet channeltypes.Packet, data types.InterchainAccountPacketData) error {
249243
if k.hook != nil {
250244
k.hook.OnTxFailed(ctx, packet.SourcePort, packet.SourceChannel, k.ComputeVirtualTxHash(data.Data, packet.Sequence), data.Data)
251245
}

modules/apps/27-interchain-accounts/keeper/relay_test.go

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ func (suite *KeeperTestSuite) TestTrySendTx() {
8888
suite.SetupTest() // reset
8989
path = NewICAPath(suite.chainA, suite.chainB)
9090
suite.coordinator.SetupConnections(path)
91+
memo := "memo"
9192

9293
err := suite.SetupICAPath(path, TestOwnerAddress)
9394
suite.Require().NoError(err)
@@ -96,7 +97,7 @@ func (suite *KeeperTestSuite) TestTrySendTx() {
9697

9798
tc.malleate()
9899

99-
_, err = suite.chainA.GetSimApp().ICAKeeper.TrySendTx(suite.chainA.GetContext(), portID, msg)
100+
_, err = suite.chainA.GetSimApp().ICAKeeper.TrySendTx(suite.chainA.GetContext(), portID, msg, memo)
100101

101102
if tc.expPass {
102103
suite.Require().NoError(err)
@@ -131,28 +132,15 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() {
131132
txBytes, err := suite.chainA.GetSimApp().ICAKeeper.SerializeCosmosTx(suite.chainA.Codec, []sdk.Msg{msg})
132133
suite.Require().NoError(err)
133134

134-
data := types.IBCAccountPacketData{Type: types.EXECUTE_TX,
135+
data := types.InterchainAccountPacketData{Type: types.EXECUTE_TX,
135136
Data: txBytes}
136137
packetData = data.GetBytes()
137138
}, true,
138139
},
139140
{
140141
"Cannot deserialize txBytes", func() {
141142
txBytes = []byte("invalid tx bytes")
142-
data := types.IBCAccountPacketData{Type: types.EXECUTE_TX,
143-
Data: txBytes}
144-
packetData = data.GetBytes()
145-
}, false,
146-
},
147-
{
148-
"Cannot deserialize txBytes: invalid IBCTxRaw", func() {
149-
txBody := []byte("invalid tx body")
150-
txRaw := &types.IBCTxRaw{
151-
BodyBytes: txBody,
152-
}
153-
154-
txBytes = suite.chainB.Codec.MustMarshal(txRaw)
155-
data := types.IBCAccountPacketData{Type: types.EXECUTE_TX,
143+
data := types.InterchainAccountPacketData{Type: types.EXECUTE_TX,
156144
Data: txBytes}
157145
packetData = data.GetBytes()
158146
}, false,
@@ -162,13 +150,13 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() {
162150
txBytes = []byte{}
163151
// Type here is an ENUM
164152
// Valid type is types.EXECUTE_TX
165-
data := types.IBCAccountPacketData{Type: 100,
153+
data := types.InterchainAccountPacketData{Type: 100,
166154
Data: txBytes}
167155
packetData = data.GetBytes()
168156
}, false,
169157
},
170158
{
171-
"Cannot unmarshal interchain account packet data into types.IBCAccountPacketData", func() {
159+
"Cannot unmarshal interchain account packet data into types.InterchainAccountPacketData", func() {
172160
packetData = []byte{}
173161
}, false,
174162
},
@@ -186,7 +174,7 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() {
186174
// build packet data
187175
txBytes, err := suite.chainA.GetSimApp().ICAKeeper.SerializeCosmosTx(suite.chainA.Codec, []sdk.Msg{msg})
188176
suite.Require().NoError(err)
189-
data := types.IBCAccountPacketData{Type: types.EXECUTE_TX,
177+
data := types.InterchainAccountPacketData{Type: types.EXECUTE_TX,
190178
Data: txBytes}
191179
packetData = data.GetBytes()
192180
}, false,

modules/apps/27-interchain-accounts/types/packet.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ import (
44
sdk "github.com/cosmos/cosmos-sdk/types"
55
)
66

7-
func (packet IBCAccountPacketData) GetBytes() []byte {
7+
func (packet InterchainAccountPacketData) GetBytes() []byte {
88
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&packet))
99
}

0 commit comments

Comments
 (0)