Skip to content

Commit

Permalink
add ordering at ica account creation (#276)
Browse files Browse the repository at this point in the history
  • Loading branch information
beer-1 authored Oct 4, 2024
1 parent 1298e7f commit 02b3968
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 37 deletions.
2 changes: 2 additions & 0 deletions proto/initia/intertx/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import "amino/amino.proto";
import "cosmos/msg/v1/msg.proto";
import "gogoproto/gogo.proto";
import "google/protobuf/any.proto";
import "ibc/core/channel/v1/channel.proto";

option go_package = "github.com/initia-labs/initia/x/intertx/types";

Expand All @@ -30,6 +31,7 @@ message MsgRegisterAccount {
string owner = 1;
string connection_id = 2 [(gogoproto.moretags) = "yaml:\"connection_id\""];
string version = 3;
ibc.core.channel.v1.Order ordering = 4;
}

// MsgRegisterAccountResponse defines the response for Msg/RegisterAccount
Expand Down
4 changes: 4 additions & 0 deletions x/intertx/client/cli/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,19 @@ const (
FlagConnectionID = "connection-id"
// The controller chain channel version
FlagVersion = "version"
// Set the ordering of the channel to ordered
FlagOrdered = "ordered"
)

// common flagsets to add to various functions
var (
fsConnectionID = flag.NewFlagSet("", flag.ContinueOnError)
fsVersion = flag.NewFlagSet("", flag.ContinueOnError)
fsOrdered = flag.NewFlagSet("", flag.ContinueOnError)
)

func init() {
fsConnectionID.String(FlagConnectionID, "", "Connection ID")
fsVersion.String(FlagVersion, "", "Version")
fsOrdered.Bool(FlagOrdered, false, "Set the ordering of the channel to ordered")
}
8 changes: 8 additions & 0 deletions x/intertx/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (
"github.com/cosmos/cosmos-sdk/client/tx"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"

channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types"
)

// GetTxCmd creates and returns the intertx tx command
Expand Down Expand Up @@ -55,6 +57,11 @@ func getRegisterAccountCmd(ac address.Codec) *cobra.Command {
viper.GetString(FlagVersion),
)

ordered := viper.GetBool(FlagOrdered)
if ordered {
msg.Ordering = channeltypes.ORDERED
}

if err := msg.Validate(ac); err != nil {
return err
}
Expand All @@ -65,6 +72,7 @@ func getRegisterAccountCmd(ac address.Codec) *cobra.Command {

cmd.Flags().AddFlagSet(fsConnectionID)
cmd.Flags().AddFlagSet(fsVersion)
cmd.Flags().AddFlagSet(fsOrdered)
_ = cmd.MarkFlagRequired(FlagConnectionID)

flags.AddTxFlagsToCmd(cmd)
Expand Down
2 changes: 2 additions & 0 deletions x/intertx/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ func (k msgServer) RegisterAccount(goCtx context.Context, msg *types.MsgRegister
ctx := sdk.UnwrapSDKContext(goCtx)

icaMsg := icacontrollertypes.NewMsgRegisterInterchainAccount(msg.ConnectionId, msg.Owner, msg.Version)
icaMsg.Ordering = msg.Ordering

if _, err := k.icaControllerMsgServer.RegisterInterchainAccount(ctx, icaMsg); err != nil {
return nil, err
}
Expand Down
1 change: 1 addition & 0 deletions x/intertx/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ func (suite *KeeperTestSuite) TestRegisterInterchainAccount() {

msgSrv := keeper.NewMsgServerImpl(*GetICAApp(suite.chainA).GetICAAuthKeeper())
msg := types.NewMsgRegisterAccount(owner, path.EndpointA.ConnectionID, path.EndpointA.ChannelConfig.Version)
msg.Ordering = channeltypes.ORDERED

res, err := msgSrv.RegisterAccount(sdk.WrapSDKContext(suite.chainA.GetContext()), msg)

Expand Down
106 changes: 69 additions & 37 deletions x/intertx/types/tx.pb.go

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

0 comments on commit 02b3968

Please sign in to comment.