Skip to content

Commit

Permalink
ica: unspecified type enum for interchain account packet data (#487)
Browse files Browse the repository at this point in the history
* adding unspecified type enum, adding defensive check to ValidateBasic

* Update modules/apps/27-interchain-accounts/types/packet_test.go

Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com>

Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com>
  • Loading branch information
damiannolan and colin-axner authored Oct 13, 2021
1 parent 300f133 commit cd263c7
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 45 deletions.
8 changes: 4 additions & 4 deletions docs/ibc/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -435,13 +435,13 @@ InterchainAccountPacketData is comprised of a raw transaction, type of transacti
<a name="ibc.applications.interchain_accounts.v1.Type"></a>

### Type
The different types of interchain account transactions
EXECUTE_TX is used when sending a TX from the controller side to the host side. The host side will execute the tx on
behalf of the interchain account.
Type defines a classification of message issued from a controller chain to its associated interchain accounts
host

| Name | Number | Description |
| ---- | ------ | ----------- |
| TYPE_EXECUTE_TX_UNSPECIFIED | 0 | Execute message type |
| TYPE_UNSPECIFIED | 0 | Default zero value enumeration |
| TYPE_EXECUTE_TX | 1 | Execute a transaction on an interchain accounts host chain |


<!-- end enums -->
Expand Down
4 changes: 4 additions & 0 deletions modules/apps/27-interchain-accounts/types/packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ const MaxMemoCharLength = 256
// ValidateBasic performs basic validation of the interchain account packet data.
// The memo may be empty.
func (iapd InterchainAccountPacketData) ValidateBasic() error {
if iapd.Type == UNSPECIFIED {
return sdkerrors.Wrap(ErrInvalidOutgoingData, "packet data type cannot be unspecified")
}

if iapd.Data == nil {
return sdkerrors.Wrap(ErrInvalidOutgoingData, "packet data cannot be empty")
}
Expand Down
9 changes: 9 additions & 0 deletions modules/apps/27-interchain-accounts/types/packet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ func (suite *TypesTestSuite) TestValidateBasic() {
},
true,
},
{
"type unspecified",
types.InterchainAccountPacketData{
Type: types.UNSPECIFIED,
Data: []byte("data"),
Memo: "memo",
},
false,
},
{
"empty data",
types.InterchainAccountPacketData{
Expand Down
70 changes: 37 additions & 33 deletions modules/apps/27-interchain-accounts/types/types.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 9 additions & 8 deletions proto/ibc/applications/interchain_accounts/v1/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,25 @@ import "google/protobuf/any.proto";
import "gogoproto/gogo.proto";
option go_package = "github.com/cosmos/ibc-go/v2/modules/apps/27-interchain-accounts/types";

// The different types of interchain account transactions
// EXECUTE_TX is used when sending a TX from the controller side to the host side. The host side will execute the tx on
// behalf of the interchain account.
// Type defines a classification of message issued from a controller chain to its associated interchain accounts
// host
enum Type {
option (gogoproto.goproto_enum_prefix) = false;
// Execute message type
TYPE_EXECUTE_TX_UNSPECIFIED = 0 [(gogoproto.enumvalue_customname) = "EXECUTE_TX"];

// Default zero value enumeration
TYPE_UNSPECIFIED = 0 [(gogoproto.enumvalue_customname) = "UNSPECIFIED"];
// Execute a transaction on an interchain accounts host chain
TYPE_EXECUTE_TX = 1 [(gogoproto.enumvalue_customname) = "EXECUTE_TX"];
}

// InterchainAccountPacketData is comprised of a raw transaction, type of transaction and optional memo field.
message InterchainAccountPacketData {
Type type = 1;
bytes data = 2;
Type type = 1;
bytes data = 2;
string memo = 3;
}

// CosmosTx contains a list of sdk.Msg's. It should be used when sending transactions to an SDK host chain.
message CosmosTx {
repeated google.protobuf.Any messages = 1;
}

0 comments on commit cd263c7

Please sign in to comment.