diff --git a/x/ibcratelimit/client/cli/tx.go b/x/ibcratelimit/client/cli/tx.go new file mode 100644 index 0000000000..ce43f99f67 --- /dev/null +++ b/x/ibcratelimit/client/cli/tx.go @@ -0,0 +1,78 @@ +package cli + +import ( + "fmt" + + "github.com/spf13/cobra" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/client/tx" + sdk "github.com/cosmos/cosmos-sdk/types" + sdktx "github.com/cosmos/cosmos-sdk/types/tx" + "github.com/cosmos/cosmos-sdk/version" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + govcli "github.com/cosmos/cosmos-sdk/x/gov/client/cli" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" + + "github.com/provenance-io/provenance/x/ibcratelimit" +) + +// NewTxCmd is the top-level command for oracle CLI transactions. +func NewTxCmd() *cobra.Command { + txCmd := &cobra.Command{ + Use: ibcratelimit.ModuleName, + Aliases: []string{"rl"}, + Short: "Transaction commands for the ibcratelimit module", + DisableFlagParsing: true, + SuggestionsMinimumDistance: 2, + RunE: client.ValidateCmd, + } + + txCmd.AddCommand( + GetCmdParamsUpdate(), + ) + + return txCmd +} + +// GetCmdParamsUpdate is a command to update the params of the module's rate limiter. +func GetCmdParamsUpdate() *cobra.Command { + cmd := &cobra.Command{ + Use: "update-params
", + Short: "Update the module's params", + Long: "Submit an update params via governance proposal along with an initial deposit.", + Args: cobra.ExactArgs(1), + Aliases: []string{"u"}, + Example: fmt.Sprintf(`%[1]s tx ratelimitedibc update-params pb1skjwj5whet0lpe65qaq4rpq03hjxlwd9nf39lk --deposit 50000nhash`, version.AppName), + RunE: func(cmd *cobra.Command, args []string) (err error) { + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + authority := authtypes.NewModuleAddress(govtypes.ModuleName) + + msg := ibcratelimit.NewMsgGovUpdateParamsRequest( + authority.String(), + args[0], + ) + + proposal, govErr := govcli.ReadGovPropFlags(clientCtx, cmd.Flags()) + if govErr != nil { + return govErr + } + proposal.Messages, govErr = sdktx.SetMsgs([]sdk.Msg{msg}) + if govErr != nil { + return govErr + } + + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), proposal) + }, + } + + govcli.AddGovPropFlagsToCmd(cmd) + flags.AddTxFlagsToCmd(cmd) + + return cmd +} diff --git a/x/ibcratelimit/module/module.go b/x/ibcratelimit/module/module.go index 43448ab4f8..4ce3c67075 100644 --- a/x/ibcratelimit/module/module.go +++ b/x/ibcratelimit/module/module.go @@ -82,7 +82,7 @@ func (b AppModuleBasic) GetQueryCmd() *cobra.Command { // GetTxCmd returns the transaction commands for the ibcratelimit module func (b AppModuleBasic) GetTxCmd() *cobra.Command { - return nil + return ibcratelimitcli.NewTxCmd() } // AppModule implements the sdk.AppModule interface diff --git a/x/ibcratelimit/msgs.go b/x/ibcratelimit/msgs.go index 0283e6ee83..5c67a7da73 100644 --- a/x/ibcratelimit/msgs.go +++ b/x/ibcratelimit/msgs.go @@ -11,6 +11,13 @@ var AllRequestMsgs = []sdk.Msg{ (*MsgGovUpdateParamsRequest)(nil), } +func NewMsgGovUpdateParamsRequest(authority, ratelimiter string) *MsgGovUpdateParamsRequest { + return &MsgGovUpdateParamsRequest{ + Authority: authority, + Params: NewParams(ratelimiter), + } +} + func (m MsgGovUpdateParamsRequest) ValidateBasic() error { errs := make([]error, 0, 2) if _, err := sdk.AccAddressFromBech32(m.Authority); err != nil {