Skip to content

Commit

Permalink
fix(x/intertx): fix ICA integration (#1606)
Browse files Browse the repository at this point in the history
Co-authored-by: Tyler <48813565+technicallyty@users.noreply.github.com>
Co-authored-by: Ryan Christoffersen <12519942+ryanchristo@users.noreply.github.com>
  • Loading branch information
3 people authored Nov 17, 2022
1 parent ecbb6d0 commit 78d6c81
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 19 deletions.
11 changes: 7 additions & 4 deletions x/intertx/client/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,13 @@ func GetTxCmd() *cobra.Command {

func getRegisterAccountCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "register --connection-id <connection-id> --version <version>",
Short: "register an interchain account",
Long: "register an interchain account for the chain corresponding to the connection-id.",
Example: "regen tx intertx register --connection-id channel-10 --version v5",
Use: "register --connection-id <connection-id> --version <version>",
Short: "register an interchain account",
Long: "register an interchain account for the chain corresponding to the connection-id.",
Example: `
regen tx intertx register --connection-id channel-10
regen tx intertx register --connection-id channel-10 --version '{"version":"ics27-1","tx_type":"sdk_multi_msg","encoding":"proto3","host_connection_id":"connection-0","controller_connection_id":"connection-0","address":"regen14zs2x38lmkw4eqvl3lpml5l8crzaxn6mpvh79z"}'
`,
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
Expand Down
10 changes: 0 additions & 10 deletions x/intertx/types/v1/features/msg_register_account.feature
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,6 @@ Feature: MsgRegisterAccount
When the message is validated
Then expect the error "owner: decoding bech32 failed: invalid bech32 string length 3"

Scenario: an error is returned if version is empty
Given the message
"""
{
"owner": "regen16md38uw5z9v4du2dtq4qgake8ewyf36u6qgfza"
}
"""
When the message is validated
Then expect the error "version cannot be empty: invalid request"

Scenario: an error is returned if connection id is empty
Given the message
"""
Expand Down
8 changes: 8 additions & 0 deletions x/intertx/types/v1/init_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package v1

import sdk "github.com/cosmos/cosmos-sdk/types"

func init() {
cfg := sdk.GetConfig()
cfg.SetBech32PrefixForAccount("regen", "regenpub")
}
4 changes: 0 additions & 4 deletions x/intertx/types/v1/msg_register_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ func (m MsgRegisterAccount) ValidateBasic() error {
return sdkerrors.ErrInvalidAddress.Wrapf("owner: %s", err.Error())
}

if m.Version == "" {
return sdkerrors.ErrInvalidRequest.Wrap("version cannot be empty")
}

if m.ConnectionId == "" {
return sdkerrors.ErrInvalidRequest.Wrap("connection_id cannot be empty")
}
Expand Down
25 changes: 24 additions & 1 deletion x/intertx/types/v1/msg_submit_tx.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package v1

import (
"fmt"

proto "github.com/gogo/protobuf/proto"

codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
Expand All @@ -9,6 +13,8 @@ import (

var (
_ legacytx.LegacyMsg = &MsgSubmitTx{}

_ codectypes.UnpackInterfacesMessage = MsgSubmitTx{}
)

// ValidateBasic does a sanity check on the provided data.
Expand Down Expand Up @@ -52,7 +58,7 @@ func (m MsgSubmitTx) Type() string {
// NewMsgSubmitTx creates a new MsgSubmitTx instance
func NewMsgSubmitTx(owner string, connectionID string, msg sdk.Msg) *MsgSubmitTx {

anyMsg, err := codectypes.NewAnyWithValue(msg)
anyMsg, err := PackTxMsgAny(msg)
if err != nil {
panic(err)
}
Expand All @@ -63,3 +69,20 @@ func NewMsgSubmitTx(owner string, connectionID string, msg sdk.Msg) *MsgSubmitTx
Msg: anyMsg,
}
}

// PackTxMsgAny marshals the sdk.Msg payload to a protobuf Any type
func PackTxMsgAny(sdkMsg sdk.Msg) (*codectypes.Any, error) {
msg, ok := sdkMsg.(proto.Message)
if !ok {
return nil, fmt.Errorf("can't proto marshal %T", sdkMsg)
}

return codectypes.NewAnyWithValue(msg)
}

// UnpackInterfaces implements codectypes.UnpackInterfacesMessage
func (msg MsgSubmitTx) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error {
var sdkMsg sdk.Msg

return unpacker.UnpackAny(msg.Msg, &sdkMsg)
}

0 comments on commit 78d6c81

Please sign in to comment.