diff --git a/x/slashing/client/cli/tx.go b/x/slashing/client/cli/tx.go new file mode 100644 index 00000000..700c794b --- /dev/null +++ b/x/slashing/client/cli/tx.go @@ -0,0 +1,58 @@ +package cli + +import ( + "cosmossdk.io/core/address" + "github.com/spf13/cobra" + + "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/x/slashing/types" +) + +// NewTxCmd returns a root CLI command handler for all x/slashing transaction commands. +func NewTxCmd(vc address.Codec) *cobra.Command { + slashingTxCmd := &cobra.Command{ + Use: types.ModuleName, + Short: "Slashing transaction subcommands", + DisableFlagParsing: true, + SuggestionsMinimumDistance: 2, + RunE: client.ValidateCmd, + } + + slashingTxCmd.AddCommand(NewUnjailTxCmd(vc)) + return slashingTxCmd +} + +// NewUnjailTxCmd returns a CLI command handler for creating a MsgUnjail transaction. +func NewUnjailTxCmd(vc address.Codec) *cobra.Command { + cmd := &cobra.Command{ + Use: "unjail", + Args: cobra.NoArgs, + Short: "unjail validator previously jailed for downtime", + Long: `unjail a jailed validator: + +$ tx slashing unjail --from mykey +`, + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + valAddr := clientCtx.GetFromAddress() + valAddrStr, err := vc.BytesToString(valAddr) + if err != nil { + return err + + } + + msg := types.NewMsgUnjail(valAddrStr) + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + }, + } + + flags.AddTxFlagsToCmd(cmd) + + return cmd +} diff --git a/x/slashing/module.go b/x/slashing/module.go index 7676cb61..73466f85 100644 --- a/x/slashing/module.go +++ b/x/slashing/module.go @@ -6,6 +6,7 @@ import ( "fmt" "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/spf13/cobra" "cosmossdk.io/core/appmodule" @@ -16,6 +17,7 @@ import ( "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/x/slashing/types" + "github.com/initia-labs/initia/x/slashing/client/cli" "github.com/initia-labs/initia/x/slashing/keeper" ) @@ -77,6 +79,16 @@ func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *r } } +// GetTxCmd returns no root tx command for the mint module. +func (b AppModuleBasic) GetTxCmd() *cobra.Command { + return cli.NewTxCmd(b.cdc.InterfaceRegistry().SigningContext().ValidatorAddressCodec()) +} + +// GetQueryCmd returns the root query command for the mint module. +func (AppModuleBasic) GetQueryCmd() *cobra.Command { + return nil +} + // AppModule implements an application module for the slashing module. type AppModule struct { AppModuleBasic