diff --git a/x/intertx/client/tx.go b/x/intertx/client/tx.go index 21a77f09c4..147343ce62 100644 --- a/x/intertx/client/tx.go +++ b/x/intertx/client/tx.go @@ -45,10 +45,13 @@ func GetTxCmd() *cobra.Command { func getRegisterAccountCmd() *cobra.Command { cmd := &cobra.Command{ - Use: "register --connection-id --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 --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 { diff --git a/x/intertx/types/v1/features/msg_register_account.feature b/x/intertx/types/v1/features/msg_register_account.feature index d1a472559e..c6e46e4ffd 100644 --- a/x/intertx/types/v1/features/msg_register_account.feature +++ b/x/intertx/types/v1/features/msg_register_account.feature @@ -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 """ diff --git a/x/intertx/types/v1/init_test.go b/x/intertx/types/v1/init_test.go new file mode 100644 index 0000000000..4b97be3f8f --- /dev/null +++ b/x/intertx/types/v1/init_test.go @@ -0,0 +1,8 @@ +package v1 + +import sdk "github.com/cosmos/cosmos-sdk/types" + +func init() { + cfg := sdk.GetConfig() + cfg.SetBech32PrefixForAccount("regen", "regenpub") +} diff --git a/x/intertx/types/v1/msg_register_account.go b/x/intertx/types/v1/msg_register_account.go index 87ca3bdbe5..1b82e84c0b 100644 --- a/x/intertx/types/v1/msg_register_account.go +++ b/x/intertx/types/v1/msg_register_account.go @@ -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") } diff --git a/x/intertx/types/v1/msg_submit_tx.go b/x/intertx/types/v1/msg_submit_tx.go index 0ee04382f2..754a18502a 100644 --- a/x/intertx/types/v1/msg_submit_tx.go +++ b/x/intertx/types/v1/msg_submit_tx.go @@ -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" @@ -9,6 +13,8 @@ import ( var ( _ legacytx.LegacyMsg = &MsgSubmitTx{} + + _ codectypes.UnpackInterfacesMessage = MsgSubmitTx{} ) // ValidateBasic does a sanity check on the provided data. @@ -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) } @@ -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) +}