From 5a6b26e729e1c71d07d9b4048eb72df177f93a1d Mon Sep 17 00:00:00 2001 From: vuong177 Date: Mon, 19 Jun 2023 18:42:37 +0700 Subject: [PATCH] update cli --- x/transfermiddleware/client/cli/tx.go | 71 +++++++++++++++++++++++++++ x/transfermiddleware/module.go | 2 +- x/transfermiddleware/types/msg.go | 6 ++- 3 files changed, 76 insertions(+), 3 deletions(-) create mode 100644 x/transfermiddleware/client/cli/tx.go diff --git a/x/transfermiddleware/client/cli/tx.go b/x/transfermiddleware/client/cli/tx.go new file mode 100644 index 000000000..630573e2e --- /dev/null +++ b/x/transfermiddleware/client/cli/tx.go @@ -0,0 +1,71 @@ +package cli + +import ( + "fmt" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/client/tx" + "github.com/cosmos/cosmos-sdk/version" + "github.com/notional-labs/centauri/v3/x/transfermiddleware/types" + "github.com/spf13/cobra" +) + +// GetTxCmd returns the tx commands for router +func GetTxCmd() *cobra.Command { + txCmd := &cobra.Command{ + Use: "transfermiddleware", + DisableFlagParsing: true, + SuggestionsMinimumDistance: 2, + Short: "Registry and remove IBC dotsama chain infomation", + Long: "Registry and remove IBC dotsama chain infomation", + } + + txCmd.AddCommand( + RegistryDotSamaChain(), + ) + + return txCmd +} + +// RegistryDotSamaChain returns the command handler for registry dotsame token info. +func RegistryDotSamaChain() *cobra.Command { + cmd := &cobra.Command{ + Use: "registry", + Short: "registry dotsama chain infomation", + Long: "registry dotsama chain infomation", + Args: cobra.MatchAll(cobra.ExactArgs(4), cobra.OnlyValidArgs), + Example: fmt.Sprintf("%s tx transfermiddleware registry [ibc_denom] [native_denom] [asset_id] [channel_id]", version.AppName), + RunE: func(cmd *cobra.Command, args []string) error { + ibcDenom := args[0] + nativeDenom := args[1] + assetID := args[2] + channelID := args[3] + + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + fromAddress := clientCtx.GetFromAddress().String() + + msg := types.NewMsgAddParachainIBCTokenInfo( + fromAddress, + ibcDenom, + nativeDenom, + assetID, + channelID, + ) + + if err := msg.ValidateBasic(); err != nil { + return err + } + + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + }, + } + + flags.AddTxFlagsToCmd(cmd) + + return cmd +} diff --git a/x/transfermiddleware/module.go b/x/transfermiddleware/module.go index 6574cc5a7..7704f11de 100644 --- a/x/transfermiddleware/module.go +++ b/x/transfermiddleware/module.go @@ -58,7 +58,7 @@ func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *r // GetTxCmd implements AppModuleBasic interface func (AppModuleBasic) GetTxCmd() *cobra.Command { - return cli.NewTxCmd() + return cli.GetTxCmd() } // GetQueryCmd implements AppModuleBasic interface diff --git a/x/transfermiddleware/types/msg.go b/x/transfermiddleware/types/msg.go index 9ab7930ad..2732f14f1 100644 --- a/x/transfermiddleware/types/msg.go +++ b/x/transfermiddleware/types/msg.go @@ -12,14 +12,16 @@ var _ sdk.Msg = &MsgAddParachainIBCTokenInfo{} func NewMsgAddParachainIBCTokenInfo( authority string, ibcDenom string, - channelID string, nativeDenom string, + assetID string, + channelID string, ) *MsgAddParachainIBCTokenInfo { return &MsgAddParachainIBCTokenInfo{ Authority: authority, IbcDenom: ibcDenom, - ChannelId: channelID, NativeDenom: nativeDenom, + AssetId: assetID, + ChannelId: channelID, } }