From 0404f85d8e264222046e57d2d5ba97d8e24e74c3 Mon Sep 17 00:00:00 2001 From: nhpd Date: Mon, 15 Jul 2024 13:54:06 +0400 Subject: [PATCH 1/7] tmp: remove manual tx's --- app/app.go | 11 +- x/adminmodule/client/cli/helper.go | 44 ----- x/adminmodule/client/cli/query.go | 2 - x/adminmodule/client/cli/query_admins.go | 43 ----- .../client/cli/query_archived_proposals.go | 73 -------- x/adminmodule/client/cli/tx.go | 12 -- x/adminmodule/client/cli/tx_add_admin.go | 45 ----- .../client/cli/tx_client_update_proposal.go | 59 ------- x/adminmodule/client/cli/tx_delete_admin.go | 44 ----- .../client/cli/tx_ibc_upgrade_proposal.go | 116 ------------- .../cli/tx_software_upgrade_proposal.go | 158 ------------------ .../cli/tx_submit_param_change_proposal.go | 83 --------- .../client/cli/tx_submit_proposal.go | 102 ----------- x/adminmodule/client/proposal_handlers.go | 33 ++-- 14 files changed, 19 insertions(+), 806 deletions(-) delete mode 100644 x/adminmodule/client/cli/helper.go delete mode 100644 x/adminmodule/client/cli/query_admins.go delete mode 100644 x/adminmodule/client/cli/query_archived_proposals.go delete mode 100644 x/adminmodule/client/cli/tx_add_admin.go delete mode 100644 x/adminmodule/client/cli/tx_client_update_proposal.go delete mode 100644 x/adminmodule/client/cli/tx_delete_admin.go delete mode 100644 x/adminmodule/client/cli/tx_ibc_upgrade_proposal.go delete mode 100644 x/adminmodule/client/cli/tx_software_upgrade_proposal.go delete mode 100644 x/adminmodule/client/cli/tx_submit_param_change_proposal.go delete mode 100644 x/adminmodule/client/cli/tx_submit_proposal.go diff --git a/app/app.go b/app/app.go index f914411..54024fc 100644 --- a/app/app.go +++ b/app/app.go @@ -31,7 +31,6 @@ import ( upgradetypes "cosmossdk.io/x/upgrade/types" tmjson "github.com/cometbft/cometbft/libs/json" adminmodulemodule "github.com/cosmos/admin-module/v2/x/adminmodule" - adminmoduleclient "github.com/cosmos/admin-module/v2/x/adminmodule/client" adminmodulemodulekeeper "github.com/cosmos/admin-module/v2/x/adminmodule/keeper" adminmodulemoduletypes "github.com/cosmos/admin-module/v2/x/adminmodule/types" "github.com/cosmos/cosmos-sdk/baseapp" @@ -134,11 +133,11 @@ var ( vesting.AppModuleBasic{}, // this line is used by starport scaffolding # stargate/app/moduleBasic adminmodulemodule.NewAppModuleBasic( - adminmoduleclient.ParamChangeProposalHandler, - adminmoduleclient.SoftwareUpgradeProposalHandler, - adminmoduleclient.CancelUpgradeProposalHandler, - adminmoduleclient.IBCClientUpdateProposalHandler, - adminmoduleclient.IBCClientUpgradeProposalHandler, + //adminmoduleclient.ParamChangeProposalHandler, + //adminmoduleclient.SoftwareUpgradeProposalHandler, + //adminmoduleclient.CancelUpgradeProposalHandler, + //adminmoduleclient.IBCClientUpdateProposalHandler, + //adminmoduleclient.IBCClientUpgradeProposalHandler, ), ) diff --git a/x/adminmodule/client/cli/helper.go b/x/adminmodule/client/cli/helper.go deleted file mode 100644 index 8fa504e..0000000 --- a/x/adminmodule/client/cli/helper.go +++ /dev/null @@ -1,44 +0,0 @@ -package cli - -import ( - "encoding/json" - "fmt" - "os" - "path/filepath" - - "github.com/spf13/pflag" - - gcutils "github.com/cosmos/cosmos-sdk/x/gov/client/utils" -) - -func parseSubmitProposalFlags(fs *pflag.FlagSet) (*proposal, error) { - proposal := &proposal{} - proposalFile, _ := fs.GetString(FlagProposal) - - if proposalFile == "" { - proposalType, _ := fs.GetString(FlagProposalType) - - proposal.Title, _ = fs.GetString(FlagTitle) - proposal.Description, _ = fs.GetString(FlagDescription) - proposal.Type = gcutils.NormalizeProposalType(proposalType) - return proposal, nil - } - - for _, flag := range ProposalFlags { - if v, _ := fs.GetString(flag); v != "" { - return nil, fmt.Errorf("--%s flag provided alongside --proposal, which is a noop", flag) - } - } - - contents, err := os.ReadFile(filepath.Clean(proposalFile)) - if err != nil { - return nil, err - } - - err = json.Unmarshal(contents, proposal) - if err != nil { - return nil, err - } - - return proposal, nil -} diff --git a/x/adminmodule/client/cli/query.go b/x/adminmodule/client/cli/query.go index bb1f9f9..d7dd448 100644 --- a/x/adminmodule/client/cli/query.go +++ b/x/adminmodule/client/cli/query.go @@ -26,7 +26,5 @@ func GetQueryCmd(queryRoute string) *cobra.Command { // this line is used by starport scaffolding # 1 - cmd.AddCommand(CmdAdmins(), CmdArchivedProposals(), CmdArchivedProposalsLegacy()) - return cmd } diff --git a/x/adminmodule/client/cli/query_admins.go b/x/adminmodule/client/cli/query_admins.go deleted file mode 100644 index 0f06c52..0000000 --- a/x/adminmodule/client/cli/query_admins.go +++ /dev/null @@ -1,43 +0,0 @@ -package cli - -import ( - "strconv" - - "github.com/spf13/cobra" - - "github.com/cosmos/admin-module/v2/x/adminmodule/types" - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/client/flags" -) - -var _ = strconv.Itoa(0) - -func CmdAdmins() *cobra.Command { - cmd := &cobra.Command{ - Use: "admins", - Short: "Query admins", - Args: cobra.ExactArgs(0), - RunE: func(cmd *cobra.Command, args []string) error { - - clientCtx, err := client.GetClientTxContext(cmd) - if err != nil { - return err - } - - queryClient := types.NewQueryClient(clientCtx) - - params := &types.QueryAdminsRequest{} - - res, err := queryClient.Admins(cmd.Context(), params) - if err != nil { - return err - } - - return clientCtx.PrintProto(res) - }, - } - - flags.AddQueryFlagsToCmd(cmd) - - return cmd -} diff --git a/x/adminmodule/client/cli/query_archived_proposals.go b/x/adminmodule/client/cli/query_archived_proposals.go deleted file mode 100644 index 0416266..0000000 --- a/x/adminmodule/client/cli/query_archived_proposals.go +++ /dev/null @@ -1,73 +0,0 @@ -package cli - -import ( - "strconv" - - "github.com/spf13/cobra" - - "github.com/cosmos/admin-module/v2/x/adminmodule/types" - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/client/flags" -) - -var _ = strconv.Itoa(0) - -func CmdArchivedProposals() *cobra.Command { - cmd := &cobra.Command{ - Use: "archivedproposals", - Short: "Query archived proposals", - Args: cobra.ExactArgs(0), - RunE: func(cmd *cobra.Command, args []string) error { - - clientCtx, err := client.GetClientTxContext(cmd) - if err != nil { - return err - } - - queryClient := types.NewQueryClient(clientCtx) - - params := &types.QueryArchivedProposalsRequest{} - - res, err := queryClient.ArchivedProposals(cmd.Context(), params) - if err != nil { - return err - } - - return clientCtx.PrintProto(res) - }, - } - - flags.AddQueryFlagsToCmd(cmd) - - return cmd -} - -func CmdArchivedProposalsLegacy() *cobra.Command { - cmd := &cobra.Command{ - Use: "archivedproposalslegacy", - Short: "Query archived proposals legacy", - Args: cobra.ExactArgs(0), - RunE: func(cmd *cobra.Command, args []string) error { - - clientCtx, err := client.GetClientTxContext(cmd) - if err != nil { - return err - } - - queryClient := types.NewQueryClient(clientCtx) - - params := &types.QueryArchivedProposalsLegacyRequest{} - - res, err := queryClient.ArchivedProposalsLegacy(cmd.Context(), params) - if err != nil { - return err - } - - return clientCtx.PrintProto(res) - }, - } - - flags.AddQueryFlagsToCmd(cmd) - - return cmd -} diff --git a/x/adminmodule/client/cli/tx.go b/x/adminmodule/client/cli/tx.go index 032db2c..8f8f75e 100644 --- a/x/adminmodule/client/cli/tx.go +++ b/x/adminmodule/client/cli/tx.go @@ -7,7 +7,6 @@ import ( "github.com/cosmos/admin-module/v2/x/adminmodule/types" "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/client/flags" ) // GetTxCmd returns the transaction commands for this module @@ -20,17 +19,6 @@ func GetTxCmd(propCmds []*cobra.Command) *cobra.Command { RunE: client.ValidateCmd, } - cmd.AddCommand(CmdDeleteAdmin()) - - cmd.AddCommand(CmdAddAdmin()) - - cmdSubmitProp := CmdSubmitProposal() - for _, propCmd := range propCmds { - flags.AddTxFlagsToCmd(propCmd) - cmdSubmitProp.AddCommand(propCmd) - } - - cmd.AddCommand(cmdSubmitProp) // this line is used by starport scaffolding # 1 return cmd diff --git a/x/adminmodule/client/cli/tx_add_admin.go b/x/adminmodule/client/cli/tx_add_admin.go deleted file mode 100644 index aef46fa..0000000 --- a/x/adminmodule/client/cli/tx_add_admin.go +++ /dev/null @@ -1,45 +0,0 @@ -package cli - -import ( - "strconv" - - "github.com/spf13/cobra" - - "github.com/cosmos/admin-module/v2/x/adminmodule/types" - "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" -) - -var _ = strconv.Itoa(0) - -func CmdAddAdmin() *cobra.Command { - cmd := &cobra.Command{ - Use: "add-admin [admin]", - Short: "Broadcast message AddAdmin", - Args: cobra.ExactArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - - clientCtx, err := client.GetClientTxContext(cmd) - if err != nil { - return err - } - - newAdmin, err := sdk.AccAddressFromBech32(args[0]) - if err != nil { - return err - } - - msg := types.NewMsgAddAdmin(clientCtx.GetFromAddress(), newAdmin) - if err := msg.ValidateBasic(); err != nil { - return err - } - return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) - }, - } - - flags.AddTxFlagsToCmd(cmd) - - return cmd -} diff --git a/x/adminmodule/client/cli/tx_client_update_proposal.go b/x/adminmodule/client/cli/tx_client_update_proposal.go deleted file mode 100644 index c636507..0000000 --- a/x/adminmodule/client/cli/tx_client_update_proposal.go +++ /dev/null @@ -1,59 +0,0 @@ -package cli - -import ( - "github.com/cosmos/admin-module/v2/x/adminmodule/types" - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/client/tx" - clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" - "github.com/spf13/cobra" -) - -func NewCmdSubmitUpdateClientProposal() *cobra.Command { - cmd := &cobra.Command{ - Use: "update-client [subject-client-id] [substitute-client-id] (--title [title] | --description [description]) [flags]", - Args: cobra.ExactArgs(2), - Short: "Submit an update IBC client proposal", - Long: "Submit an update IBC client proposal along with an initial deposit.\n" + - "Please specify a subject client identifier you want to update..\n" + - "Please specify the substitute client the subject client will be updated to.", - RunE: func(cmd *cobra.Command, args []string) error { - clientCtx, err := client.GetClientTxContext(cmd) - if err != nil { - return err - } - - title, err := cmd.Flags().GetString(FlagTitle) - if err != nil { - return err - } - - description, err := cmd.Flags().GetString(FlagDescription) - if err != nil { - return err - } - - subjectClientID := args[0] - substituteClientID := args[1] - - content := clienttypes.NewClientUpdateProposal(title, description, subjectClientID, substituteClientID) - - from := clientCtx.GetFromAddress() - - msg, err := types.NewMsgSubmitProposalLegacy(content, from) - if err != nil { - return err - } - - if err = msg.ValidateBasic(); err != nil { - return err - } - - return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) - }, - } - - cmd.Flags().String(FlagTitle, "", "title of proposal") - cmd.Flags().String(FlagDescription, "", "description of proposal") - - return cmd -} diff --git a/x/adminmodule/client/cli/tx_delete_admin.go b/x/adminmodule/client/cli/tx_delete_admin.go deleted file mode 100644 index 5cc342b..0000000 --- a/x/adminmodule/client/cli/tx_delete_admin.go +++ /dev/null @@ -1,44 +0,0 @@ -package cli - -import ( - "strconv" - - "github.com/spf13/cobra" - - "github.com/cosmos/admin-module/v2/x/adminmodule/types" - "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" -) - -var _ = strconv.Itoa(0) - -func CmdDeleteAdmin() *cobra.Command { - cmd := &cobra.Command{ - Use: "delete-admin [admin]", - Short: "Broadcast message DeleteAdmin", - Args: cobra.ExactArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - clientCtx, err := client.GetClientTxContext(cmd) - if err != nil { - return err - } - - removeAdmin, err := sdk.AccAddressFromBech32(args[0]) - if err != nil { - return err - } - - msg := types.NewMsgDeleteAdmin(clientCtx.GetFromAddress(), removeAdmin) - if err := msg.ValidateBasic(); err != nil { - return err - } - return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) - }, - } - - flags.AddTxFlagsToCmd(cmd) - - return cmd -} diff --git a/x/adminmodule/client/cli/tx_ibc_upgrade_proposal.go b/x/adminmodule/client/cli/tx_ibc_upgrade_proposal.go deleted file mode 100644 index 4432378..0000000 --- a/x/adminmodule/client/cli/tx_ibc_upgrade_proposal.go +++ /dev/null @@ -1,116 +0,0 @@ -package cli - -import ( - "fmt" - "os" - "strconv" - - "github.com/spf13/cobra" - - upgradetypes "cosmossdk.io/x/upgrade/types" - "github.com/cosmos/admin-module/v2/x/adminmodule/types" - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/client/tx" - "github.com/cosmos/cosmos-sdk/codec" - clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" - "github.com/cosmos/ibc-go/v8/modules/core/exported" -) - -// NewCmdSubmitUpgradeProposal implements a command handler for submitting an upgrade IBC client proposal transaction. -func NewCmdSubmitIbcClientUpgradeProposal() *cobra.Command { - cmd := &cobra.Command{ - Use: "ibc-upgrade [name] [height] [path/to/upgraded_client_state.json] (--title [title] | --description [description]) [flags]", - Args: cobra.ExactArgs(3), - Short: "Submit an IBC upgrade proposal", - Long: "Submit an IBC client breaking upgrade proposal along with an initial deposit.\n" + - "The client state specified is the upgraded client state representing the upgraded chain\n" + - `Example Upgraded Client State JSON: -{ - "@type":"/ibc.lightclients.tendermint.v1.ClientState", - "chain_id":"testchain1", - "unbonding_period":"1814400s", - "latest_height":{"revision_number":"0","revision_height":"2"}, - "proof_specs":[{"leaf_spec":{"hash":"SHA256","prehash_key":"NO_HASH","prehash_value":"SHA256","length":"VAR_PROTO","prefix":"AA=="},"inner_spec":{"child_order":[0,1],"child_size":33,"min_prefix_length":4,"max_prefix_length":12,"empty_child":null,"hash":"SHA256"},"max_depth":0,"min_depth":0},{"leaf_spec":{"hash":"SHA256","prehash_key":"NO_HASH","prehash_value":"SHA256","length":"VAR_PROTO","prefix":"AA=="},"inner_spec":{"child_order":[0,1],"child_size":32,"min_prefix_length":1,"max_prefix_length":1,"empty_child":null,"hash":"SHA256"},"max_depth":0,"min_depth":0}], - "upgrade_path":["upgrade","upgradedIBCState"], -} - `, - RunE: func(cmd *cobra.Command, args []string) error { - clientCtx, err := client.GetClientTxContext(cmd) - if err != nil { - return err - } - cdc := codec.NewProtoCodec(clientCtx.InterfaceRegistry) - - title, err := cmd.Flags().GetString(FlagTitle) - if err != nil { - return err - } - - description, err := cmd.Flags().GetString(FlagDescription) - if err != nil { - return err - } - - name := args[0] - - height, err := strconv.ParseInt(args[1], 10, 64) - if err != nil { - return err - } - - plan := upgradetypes.Plan{ - Name: name, - Height: height, - } - - clientState, err := tryUnmarshallClientState(cdc, args[2]) - if err != nil { - return err - } - - if err != nil { - return err - } - - content, err := clienttypes.NewUpgradeProposal(title, description, plan, clientState) - if err != nil { - return err - } - - from := clientCtx.GetFromAddress() - - msg, err := types.NewMsgSubmitProposalLegacy(content, from) - if err != nil { - return err - } - - if err = msg.ValidateBasic(); err != nil { - return err - } - - return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) - }, - } - - cmd.Flags().String(FlagTitle, "", "title of proposal") - cmd.Flags().String(FlagDescription, "", "description of proposal") - - return cmd -} - -func tryUnmarshallClientState(cdc *codec.ProtoCodec, clientStateOrFileName string) (exported.ClientState, error) { - var clientState exported.ClientState - - if err := cdc.UnmarshalInterfaceJSON([]byte(clientStateOrFileName), &clientState); err != nil { - contents, err := os.ReadFile(clientStateOrFileName) - if err != nil { - return nil, fmt.Errorf("neither JSON input nor path to .json file for client state were provided: %w", err) - } - - if err = cdc.UnmarshalInterfaceJSON(contents, &clientState); err != nil { - return nil, err - } - - } - return clientState, nil -} diff --git a/x/adminmodule/client/cli/tx_software_upgrade_proposal.go b/x/adminmodule/client/cli/tx_software_upgrade_proposal.go deleted file mode 100644 index e146123..0000000 --- a/x/adminmodule/client/cli/tx_software_upgrade_proposal.go +++ /dev/null @@ -1,158 +0,0 @@ -package cli - -import ( - "fmt" - "time" - - "github.com/spf13/cobra" - - upgradetypes "cosmossdk.io/x/upgrade/types" - "github.com/cosmos/admin-module/v2/x/adminmodule/types" - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/client/tx" - "github.com/cosmos/cosmos-sdk/x/gov/client/cli" - govv1types "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" -) - -const ( - // TimeFormat specifies ISO UTC format for submitting the time for a new upgrade proposal - TimeFormat = "2006-01-02T15:04:05Z" - - FlagUpgradeHeight = "upgrade-height" - FlagUpgradeTime = "upgrade-time" - FlagUpgradeInfo = "upgrade-info" -) - -// NewCmdSubmitUpgradeProposal implements a command handler for submitting a software upgrade proposal transaction. -func NewCmdSubmitUpgradeProposal() *cobra.Command { - cmd := &cobra.Command{ - Use: "software-upgrade [name] (--upgrade-height [height] | --upgrade-time [time]) (--upgrade-info [info]) [flags]", - Args: cobra.ExactArgs(1), - Short: "Submit a software upgrade proposal", - Long: "Submit a software upgrade.\n" + - "Please specify a unique name and height OR time for the upgrade to take effect.\n" + - "You may include info to reference a binary download link, in a format compatible with: https://github.com/cosmos/cosmos-sdk/tree/master/cosmovisor", - RunE: func(cmd *cobra.Command, args []string) error { - clientCtx, err := client.GetClientTxContext(cmd) - if err != nil { - return err - } - name := args[0] - content, err := parseArgsToContent(cmd, name) - if err != nil { - return err - } - - from := clientCtx.GetFromAddress() - - msg, err := types.NewMsgSubmitProposalLegacy(content, from) - if err != nil { - return err - } - - if err = msg.ValidateBasic(); err != nil { - return err - } - - return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) - }, - } - - cmd.Flags().String(cli.FlagTitle, "", "title of proposal") - cmd.Flags().String(cli.FlagDescription, "", "description of proposal") - cmd.Flags().Int64(FlagUpgradeHeight, 0, "The height at which the upgrade must happen (not to be used together with --upgrade-time)") - cmd.Flags().String(FlagUpgradeTime, "", fmt.Sprintf("The time at which the upgrade must happen (ex. %s) (not to be used together with --upgrade-height)", TimeFormat)) - cmd.Flags().String(FlagUpgradeInfo, "", "Optional info for the planned upgrade such as commit hash, etc.") - - return cmd -} - -// NewCmdSubmitCancelUpgradeProposal implements a command handler for submitting a software upgrade cancel proposal transaction. -func NewCmdSubmitCancelUpgradeProposal() *cobra.Command { - cmd := &cobra.Command{ - Use: "cancel-software-upgrade [flags]", - Args: cobra.ExactArgs(0), - Short: "Cancel the current software upgrade proposal", - Long: "Cancel a software upgrade.", - RunE: func(cmd *cobra.Command, args []string) error { - clientCtx, err := client.GetClientTxContext(cmd) - if err != nil { - return err - } - from := clientCtx.GetFromAddress() - - title, err := cmd.Flags().GetString(cli.FlagTitle) - if err != nil { - return err - } - - description, err := cmd.Flags().GetString(cli.FlagDescription) - if err != nil { - return err - } - - content := upgradetypes.NewCancelSoftwareUpgradeProposal(title, description) - - msg, err := types.NewMsgSubmitProposalLegacy(content, from) - if err != nil { - return err - } - - if err = msg.ValidateBasic(); err != nil { - return err - } - - return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) - }, - } - - cmd.Flags().String(cli.FlagTitle, "", "title of proposal") - cmd.Flags().String(cli.FlagDescription, "", "description of proposal") - _ = cmd.MarkFlagRequired(cli.FlagTitle) - _ = cmd.MarkFlagRequired(cli.FlagDescription) - - return cmd -} - -func parseArgsToContent(cmd *cobra.Command, name string) (govv1types.Content, error) { - title, err := cmd.Flags().GetString(cli.FlagTitle) - if err != nil { - return nil, err - } - - description, err := cmd.Flags().GetString(cli.FlagDescription) - if err != nil { - return nil, err - } - - height, err := cmd.Flags().GetInt64(FlagUpgradeHeight) - if err != nil { - return nil, err - } - - timeStr, err := cmd.Flags().GetString(FlagUpgradeTime) - if err != nil { - return nil, err - } - - if height != 0 && len(timeStr) != 0 { - return nil, fmt.Errorf("only one of --upgrade-time or --upgrade-height should be specified") - } - - var upgradeTime time.Time - if len(timeStr) != 0 { - upgradeTime, err = time.Parse(TimeFormat, timeStr) - if err != nil { - return nil, err - } - } - - info, err := cmd.Flags().GetString(FlagUpgradeInfo) - if err != nil { - return nil, err - } - - plan := upgradetypes.Plan{Name: name, Time: upgradeTime, Height: height, Info: info} - content := upgradetypes.NewSoftwareUpgradeProposal(title, description, plan) - return content, nil -} diff --git a/x/adminmodule/client/cli/tx_submit_param_change_proposal.go b/x/adminmodule/client/cli/tx_submit_param_change_proposal.go deleted file mode 100644 index 735f726..0000000 --- a/x/adminmodule/client/cli/tx_submit_param_change_proposal.go +++ /dev/null @@ -1,83 +0,0 @@ -package cli - -import ( - "fmt" - "strings" - - "github.com/spf13/cobra" - - "github.com/cosmos/admin-module/v2/x/adminmodule/types" - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/client/tx" - "github.com/cosmos/cosmos-sdk/version" - paramscutils "github.com/cosmos/cosmos-sdk/x/params/client/utils" - paramproposal "github.com/cosmos/cosmos-sdk/x/params/types/proposal" -) - -// NewSubmitParamChangeProposalTxCmd returns a CLI command handler for creating -// a parameter change proposal governance transaction. -func NewSubmitParamChangeProposalTxCmd() *cobra.Command { - return &cobra.Command{ - Use: "param-change [proposal-file]", - Args: cobra.ExactArgs(1), - Short: "Submit a parameter change proposal", - Long: strings.TrimSpace( - fmt.Sprintf(`Submit a parameter proposal . -The proposal details must be supplied via a JSON file. For values that contains -objects, only non-empty fields will be updated. - -IMPORTANT: Currently parameter changes are evaluated but not validated, so it is -very important that any "value" change is valid (ie. correct type and within bounds) -for its respective parameter, eg. "MaxValidators" should be an integer and not a decimal. - -Proper vetting of a parameter change proposal should prevent this from happening -(no deposits should occur during the governance process), but it should be noted -regardless. - -Example: -$ %s tx adminmodule submit-proposal param-change --from= - -Where proposal.json contains: - -{ - "title": "Staking Param Change", - "description": "Update max validators", - "changes": [ - { - "subspace": "staking", - "key": "MaxValidators", - "value": 105 - } - ] -} -`, - version.AppName, - ), - ), - RunE: func(cmd *cobra.Command, args []string) error { - clientCtx, err := client.GetClientTxContext(cmd) - if err != nil { - return err - } - proposal, err := paramscutils.ParseParamChangeProposalJSON(clientCtx.LegacyAmino, args[0]) - if err != nil { - return err - } - - from := clientCtx.GetFromAddress() - content := paramproposal.NewParameterChangeProposal( - proposal.Title, proposal.Description, proposal.Changes.ToParamChanges(), - ) - - msg, err := types.NewMsgSubmitProposalLegacy(content, from) - if err != nil { - return err - } - if err := msg.ValidateBasic(); err != nil { - return err - } - - return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) - }, - } -} diff --git a/x/adminmodule/client/cli/tx_submit_proposal.go b/x/adminmodule/client/cli/tx_submit_proposal.go deleted file mode 100644 index 404f8de..0000000 --- a/x/adminmodule/client/cli/tx_submit_proposal.go +++ /dev/null @@ -1,102 +0,0 @@ -package cli - -import ( - "fmt" - "strconv" - "strings" - - "github.com/spf13/cobra" - - "github.com/cosmos/admin-module/v2/x/adminmodule/types" - "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" - govv1types "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" -) - -var _ = strconv.Itoa(0) - -// Proposal flags -const ( - FlagTitle = "title" - FlagDescription = "description" - FlagProposalType = "type" - FlagProposal = "proposal" -) - -type proposal struct { - Title string - Description string - Type string -} - -// ProposalFlags defines the core required fields of a proposal. It is used to -// verify that these values are not provided in conjunction with a JSON proposal -// file. -var ProposalFlags = []string{ - FlagTitle, - FlagDescription, - FlagProposalType, -} - -func CmdSubmitProposal() *cobra.Command { - cmd := &cobra.Command{ - Use: "submit-proposal", - Short: "Submit a proposal", - Long: strings.TrimSpace( - fmt.Sprintf(`Submit a proposal. -Proposal title, description, type and can be given directly or through a proposal JSON file. - -Example: -$ %s adminmodule submit-proposal --proposal="path/to/proposal.json" --from mykey - -Where proposal.json contains: - -{ - "title": "Test Proposal", - "description": "My awesome proposal", - "type": "Text" -} - -Which is equivalent to: - -$ %s tx adminmodule submit-proposal --title="Test Proposal" --description="My awesome proposal" --type="Text" --from mykey -`, - version.AppName, version.AppName, - ), - ), - RunE: func(cmd *cobra.Command, args []string) error { - clientCtx, err := client.GetClientTxContext(cmd) - if err != nil { - return err - } - - proposal, err := parseSubmitProposalFlags(cmd.Flags()) - if err != nil { - return fmt.Errorf("failed to parse proposal: %w", err) - } - - content, _ := govv1types.ContentFromProposalType(proposal.Title, proposal.Description, proposal.Type) - - msg, err := types.NewMsgSubmitProposalLegacy(content, clientCtx.GetFromAddress()) - if err != nil { - return fmt.Errorf("invalid message: %w", err) - } - - if err = msg.ValidateBasic(); err != nil { - return fmt.Errorf("message validation failed: %w", err) - } - - return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) - }, - } - - cmd.Flags().String(FlagTitle, "", "The proposal title") - cmd.Flags().String(FlagDescription, "", "The proposal description") - cmd.Flags().String(FlagProposalType, "", "The proposal Type") - cmd.Flags().String(FlagProposal, "", "Proposal file path (if this path is given, other proposal flags are ignored)") - flags.AddTxFlagsToCmd(cmd) - - return cmd -} diff --git a/x/adminmodule/client/proposal_handlers.go b/x/adminmodule/client/proposal_handlers.go index 2ead31d..9773de5 100644 --- a/x/adminmodule/client/proposal_handlers.go +++ b/x/adminmodule/client/proposal_handlers.go @@ -1,21 +1,16 @@ package client -import ( - "github.com/cosmos/admin-module/v2/x/adminmodule/client/cli" - govclient "github.com/cosmos/cosmos-sdk/x/gov/client" -) - -// Param change proposal handler. -var ParamChangeProposalHandler = govclient.NewProposalHandler(cli.NewSubmitParamChangeProposalTxCmd) - -// Software upgrade proposal handler. -var SoftwareUpgradeProposalHandler = govclient.NewProposalHandler(cli.NewCmdSubmitUpgradeProposal) - -// Cancel software upgrade proposal handler. -var CancelUpgradeProposalHandler = govclient.NewProposalHandler(cli.NewCmdSubmitCancelUpgradeProposal) - -// IBC Client upgrade proposal handler. -var IBCClientUpgradeProposalHandler = govclient.NewProposalHandler(cli.NewCmdSubmitIbcClientUpgradeProposal) - -// IBC Client update proposal handler. -var IBCClientUpdateProposalHandler = govclient.NewProposalHandler(cli.NewCmdSubmitUpdateClientProposal) +//// Param change proposal handler. +//var ParamChangeProposalHandler = govclient.NewProposalHandler(cli.NewSubmitParamChangeProposalTxCmd) +// +//// Software upgrade proposal handler. +//var SoftwareUpgradeProposalHandler = govclient.NewProposalHandler(cli.NewCmdSubmitUpgradeProposal) +// +//// Cancel software upgrade proposal handler. +//var CancelUpgradeProposalHandler = govclient.NewProposalHandler(cli.NewCmdSubmitCancelUpgradeProposal) +// +//// IBC Client upgrade proposal handler. +//var IBCClientUpgradeProposalHandler = govclient.NewProposalHandler(cli.NewCmdSubmitIbcClientUpgradeProposal) +// +//// IBC Client update proposal handler. +//var IBCClientUpdateProposalHandler = govclient.NewProposalHandler(cli.NewCmdSubmitUpdateClientProposal) From 16ec389c7afba875604792750ea72a038e0e5c98 Mon Sep 17 00:00:00 2001 From: nhpd Date: Mon, 15 Jul 2024 19:45:44 +0400 Subject: [PATCH 2/7] tmp 2 --- x/adminmodule/module.go | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/x/adminmodule/module.go b/x/adminmodule/module.go index aad7278..a6a9581 100644 --- a/x/adminmodule/module.go +++ b/x/adminmodule/module.go @@ -8,12 +8,9 @@ import ( // this line is used by starport scaffolding # 1 "cosmossdk.io/core/appmodule" - "github.com/grpc-ecosystem/grpc-gateway/runtime" - "github.com/spf13/cobra" - abci "github.com/cometbft/cometbft/abci/types" + "github.com/grpc-ecosystem/grpc-gateway/runtime" - "github.com/cosmos/admin-module/v2/x/adminmodule/client/cli" "github.com/cosmos/admin-module/v2/x/adminmodule/keeper" "github.com/cosmos/admin-module/v2/x/adminmodule/types" "github.com/cosmos/cosmos-sdk/client" @@ -87,18 +84,18 @@ func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *r } // GetTxCmd returns the capability module's root tx command. -func (a AppModuleBasic) GetTxCmd() *cobra.Command { - proposalCLIHandlers := make([]*cobra.Command, 0, len(a.proposalHandlers)) - for _, proposalHandler := range a.proposalHandlers { - proposalCLIHandlers = append(proposalCLIHandlers, proposalHandler.CLIHandler()) - } - return cli.GetTxCmd(proposalCLIHandlers) -} +//func (a AppModuleBasic) GetTxCmd() *cobra.Command { +// proposalCLIHandlers := make([]*cobra.Command, 0, len(a.proposalHandlers)) +// for _, proposalHandler := range a.proposalHandlers { +// proposalCLIHandlers = append(proposalCLIHandlers, proposalHandler.CLIHandler()) +// } +// return cli.GetTxCmd(proposalCLIHandlers) +//} // GetQueryCmd returns the capability module's root query command. -func (AppModuleBasic) GetQueryCmd() *cobra.Command { - return cli.GetQueryCmd(types.StoreKey) -} +//func (AppModuleBasic) GetQueryCmd() *cobra.Command { +// return cli.GetQueryCmd(types.StoreKey) +//} // ---------------------------------------------------------------------------- // AppModule From 1f27b07d98f270520c26c09c85085eabaeaa8306 Mon Sep 17 00:00:00 2001 From: nhpd Date: Tue, 16 Jul 2024 13:47:38 +0400 Subject: [PATCH 3/7] add autocli enhance command --- x/adminmodule/autocli.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 x/adminmodule/autocli.go diff --git a/x/adminmodule/autocli.go b/x/adminmodule/autocli.go new file mode 100644 index 0000000..3a56e0f --- /dev/null +++ b/x/adminmodule/autocli.go @@ -0,0 +1,20 @@ +package adminmodule + +import ( + autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" +) + +func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions { + return &autocliv1.ModuleOptions{ + Query: &autocliv1.ServiceCommandDescriptor{ + //Service: _Query_serviceDesc.ServiceName, + RpcCommandOptions: []*autocliv1.RpcCommandOptions{}, + EnhanceCustomCommand: true, + }, + Tx: &autocliv1.ServiceCommandDescriptor{ + //Service: _Msg_ServiceDesc.ServiceName, + RpcCommandOptions: []*autocliv1.RpcCommandOptions{}, + EnhanceCustomCommand: true, + }, + } +} From 4fd3225fdc61f29d43cdd0cda2aaf540837a1a40 Mon Sep 17 00:00:00 2001 From: nhpd Date: Tue, 16 Jul 2024 13:47:50 +0400 Subject: [PATCH 4/7] Revert "tmp: remove manual tx's" This reverts commit 0404f85d8e264222046e57d2d5ba97d8e24e74c3. --- app/app.go | 11 +- x/adminmodule/client/cli/helper.go | 44 +++++ x/adminmodule/client/cli/query.go | 2 + x/adminmodule/client/cli/query_admins.go | 43 +++++ .../client/cli/query_archived_proposals.go | 73 ++++++++ x/adminmodule/client/cli/tx.go | 12 ++ x/adminmodule/client/cli/tx_add_admin.go | 45 +++++ .../client/cli/tx_client_update_proposal.go | 59 +++++++ x/adminmodule/client/cli/tx_delete_admin.go | 44 +++++ .../client/cli/tx_ibc_upgrade_proposal.go | 116 +++++++++++++ .../cli/tx_software_upgrade_proposal.go | 158 ++++++++++++++++++ .../cli/tx_submit_param_change_proposal.go | 83 +++++++++ .../client/cli/tx_submit_proposal.go | 102 +++++++++++ x/adminmodule/client/proposal_handlers.go | 33 ++-- 14 files changed, 806 insertions(+), 19 deletions(-) create mode 100644 x/adminmodule/client/cli/helper.go create mode 100644 x/adminmodule/client/cli/query_admins.go create mode 100644 x/adminmodule/client/cli/query_archived_proposals.go create mode 100644 x/adminmodule/client/cli/tx_add_admin.go create mode 100644 x/adminmodule/client/cli/tx_client_update_proposal.go create mode 100644 x/adminmodule/client/cli/tx_delete_admin.go create mode 100644 x/adminmodule/client/cli/tx_ibc_upgrade_proposal.go create mode 100644 x/adminmodule/client/cli/tx_software_upgrade_proposal.go create mode 100644 x/adminmodule/client/cli/tx_submit_param_change_proposal.go create mode 100644 x/adminmodule/client/cli/tx_submit_proposal.go diff --git a/app/app.go b/app/app.go index 54024fc..f914411 100644 --- a/app/app.go +++ b/app/app.go @@ -31,6 +31,7 @@ import ( upgradetypes "cosmossdk.io/x/upgrade/types" tmjson "github.com/cometbft/cometbft/libs/json" adminmodulemodule "github.com/cosmos/admin-module/v2/x/adminmodule" + adminmoduleclient "github.com/cosmos/admin-module/v2/x/adminmodule/client" adminmodulemodulekeeper "github.com/cosmos/admin-module/v2/x/adminmodule/keeper" adminmodulemoduletypes "github.com/cosmos/admin-module/v2/x/adminmodule/types" "github.com/cosmos/cosmos-sdk/baseapp" @@ -133,11 +134,11 @@ var ( vesting.AppModuleBasic{}, // this line is used by starport scaffolding # stargate/app/moduleBasic adminmodulemodule.NewAppModuleBasic( - //adminmoduleclient.ParamChangeProposalHandler, - //adminmoduleclient.SoftwareUpgradeProposalHandler, - //adminmoduleclient.CancelUpgradeProposalHandler, - //adminmoduleclient.IBCClientUpdateProposalHandler, - //adminmoduleclient.IBCClientUpgradeProposalHandler, + adminmoduleclient.ParamChangeProposalHandler, + adminmoduleclient.SoftwareUpgradeProposalHandler, + adminmoduleclient.CancelUpgradeProposalHandler, + adminmoduleclient.IBCClientUpdateProposalHandler, + adminmoduleclient.IBCClientUpgradeProposalHandler, ), ) diff --git a/x/adminmodule/client/cli/helper.go b/x/adminmodule/client/cli/helper.go new file mode 100644 index 0000000..8fa504e --- /dev/null +++ b/x/adminmodule/client/cli/helper.go @@ -0,0 +1,44 @@ +package cli + +import ( + "encoding/json" + "fmt" + "os" + "path/filepath" + + "github.com/spf13/pflag" + + gcutils "github.com/cosmos/cosmos-sdk/x/gov/client/utils" +) + +func parseSubmitProposalFlags(fs *pflag.FlagSet) (*proposal, error) { + proposal := &proposal{} + proposalFile, _ := fs.GetString(FlagProposal) + + if proposalFile == "" { + proposalType, _ := fs.GetString(FlagProposalType) + + proposal.Title, _ = fs.GetString(FlagTitle) + proposal.Description, _ = fs.GetString(FlagDescription) + proposal.Type = gcutils.NormalizeProposalType(proposalType) + return proposal, nil + } + + for _, flag := range ProposalFlags { + if v, _ := fs.GetString(flag); v != "" { + return nil, fmt.Errorf("--%s flag provided alongside --proposal, which is a noop", flag) + } + } + + contents, err := os.ReadFile(filepath.Clean(proposalFile)) + if err != nil { + return nil, err + } + + err = json.Unmarshal(contents, proposal) + if err != nil { + return nil, err + } + + return proposal, nil +} diff --git a/x/adminmodule/client/cli/query.go b/x/adminmodule/client/cli/query.go index d7dd448..bb1f9f9 100644 --- a/x/adminmodule/client/cli/query.go +++ b/x/adminmodule/client/cli/query.go @@ -26,5 +26,7 @@ func GetQueryCmd(queryRoute string) *cobra.Command { // this line is used by starport scaffolding # 1 + cmd.AddCommand(CmdAdmins(), CmdArchivedProposals(), CmdArchivedProposalsLegacy()) + return cmd } diff --git a/x/adminmodule/client/cli/query_admins.go b/x/adminmodule/client/cli/query_admins.go new file mode 100644 index 0000000..0f06c52 --- /dev/null +++ b/x/adminmodule/client/cli/query_admins.go @@ -0,0 +1,43 @@ +package cli + +import ( + "strconv" + + "github.com/spf13/cobra" + + "github.com/cosmos/admin-module/v2/x/adminmodule/types" + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" +) + +var _ = strconv.Itoa(0) + +func CmdAdmins() *cobra.Command { + cmd := &cobra.Command{ + Use: "admins", + Short: "Query admins", + Args: cobra.ExactArgs(0), + RunE: func(cmd *cobra.Command, args []string) error { + + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + queryClient := types.NewQueryClient(clientCtx) + + params := &types.QueryAdminsRequest{} + + res, err := queryClient.Admins(cmd.Context(), params) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} diff --git a/x/adminmodule/client/cli/query_archived_proposals.go b/x/adminmodule/client/cli/query_archived_proposals.go new file mode 100644 index 0000000..0416266 --- /dev/null +++ b/x/adminmodule/client/cli/query_archived_proposals.go @@ -0,0 +1,73 @@ +package cli + +import ( + "strconv" + + "github.com/spf13/cobra" + + "github.com/cosmos/admin-module/v2/x/adminmodule/types" + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" +) + +var _ = strconv.Itoa(0) + +func CmdArchivedProposals() *cobra.Command { + cmd := &cobra.Command{ + Use: "archivedproposals", + Short: "Query archived proposals", + Args: cobra.ExactArgs(0), + RunE: func(cmd *cobra.Command, args []string) error { + + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + queryClient := types.NewQueryClient(clientCtx) + + params := &types.QueryArchivedProposalsRequest{} + + res, err := queryClient.ArchivedProposals(cmd.Context(), params) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} + +func CmdArchivedProposalsLegacy() *cobra.Command { + cmd := &cobra.Command{ + Use: "archivedproposalslegacy", + Short: "Query archived proposals legacy", + Args: cobra.ExactArgs(0), + RunE: func(cmd *cobra.Command, args []string) error { + + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + queryClient := types.NewQueryClient(clientCtx) + + params := &types.QueryArchivedProposalsLegacyRequest{} + + res, err := queryClient.ArchivedProposalsLegacy(cmd.Context(), params) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} diff --git a/x/adminmodule/client/cli/tx.go b/x/adminmodule/client/cli/tx.go index 8f8f75e..032db2c 100644 --- a/x/adminmodule/client/cli/tx.go +++ b/x/adminmodule/client/cli/tx.go @@ -7,6 +7,7 @@ import ( "github.com/cosmos/admin-module/v2/x/adminmodule/types" "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" ) // GetTxCmd returns the transaction commands for this module @@ -19,6 +20,17 @@ func GetTxCmd(propCmds []*cobra.Command) *cobra.Command { RunE: client.ValidateCmd, } + cmd.AddCommand(CmdDeleteAdmin()) + + cmd.AddCommand(CmdAddAdmin()) + + cmdSubmitProp := CmdSubmitProposal() + for _, propCmd := range propCmds { + flags.AddTxFlagsToCmd(propCmd) + cmdSubmitProp.AddCommand(propCmd) + } + + cmd.AddCommand(cmdSubmitProp) // this line is used by starport scaffolding # 1 return cmd diff --git a/x/adminmodule/client/cli/tx_add_admin.go b/x/adminmodule/client/cli/tx_add_admin.go new file mode 100644 index 0000000..aef46fa --- /dev/null +++ b/x/adminmodule/client/cli/tx_add_admin.go @@ -0,0 +1,45 @@ +package cli + +import ( + "strconv" + + "github.com/spf13/cobra" + + "github.com/cosmos/admin-module/v2/x/adminmodule/types" + "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" +) + +var _ = strconv.Itoa(0) + +func CmdAddAdmin() *cobra.Command { + cmd := &cobra.Command{ + Use: "add-admin [admin]", + Short: "Broadcast message AddAdmin", + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + newAdmin, err := sdk.AccAddressFromBech32(args[0]) + if err != nil { + return err + } + + msg := types.NewMsgAddAdmin(clientCtx.GetFromAddress(), newAdmin) + if err := msg.ValidateBasic(); err != nil { + return err + } + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + }, + } + + flags.AddTxFlagsToCmd(cmd) + + return cmd +} diff --git a/x/adminmodule/client/cli/tx_client_update_proposal.go b/x/adminmodule/client/cli/tx_client_update_proposal.go new file mode 100644 index 0000000..c636507 --- /dev/null +++ b/x/adminmodule/client/cli/tx_client_update_proposal.go @@ -0,0 +1,59 @@ +package cli + +import ( + "github.com/cosmos/admin-module/v2/x/adminmodule/types" + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/tx" + clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" + "github.com/spf13/cobra" +) + +func NewCmdSubmitUpdateClientProposal() *cobra.Command { + cmd := &cobra.Command{ + Use: "update-client [subject-client-id] [substitute-client-id] (--title [title] | --description [description]) [flags]", + Args: cobra.ExactArgs(2), + Short: "Submit an update IBC client proposal", + Long: "Submit an update IBC client proposal along with an initial deposit.\n" + + "Please specify a subject client identifier you want to update..\n" + + "Please specify the substitute client the subject client will be updated to.", + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + title, err := cmd.Flags().GetString(FlagTitle) + if err != nil { + return err + } + + description, err := cmd.Flags().GetString(FlagDescription) + if err != nil { + return err + } + + subjectClientID := args[0] + substituteClientID := args[1] + + content := clienttypes.NewClientUpdateProposal(title, description, subjectClientID, substituteClientID) + + from := clientCtx.GetFromAddress() + + msg, err := types.NewMsgSubmitProposalLegacy(content, from) + if err != nil { + return err + } + + if err = msg.ValidateBasic(); err != nil { + return err + } + + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + }, + } + + cmd.Flags().String(FlagTitle, "", "title of proposal") + cmd.Flags().String(FlagDescription, "", "description of proposal") + + return cmd +} diff --git a/x/adminmodule/client/cli/tx_delete_admin.go b/x/adminmodule/client/cli/tx_delete_admin.go new file mode 100644 index 0000000..5cc342b --- /dev/null +++ b/x/adminmodule/client/cli/tx_delete_admin.go @@ -0,0 +1,44 @@ +package cli + +import ( + "strconv" + + "github.com/spf13/cobra" + + "github.com/cosmos/admin-module/v2/x/adminmodule/types" + "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" +) + +var _ = strconv.Itoa(0) + +func CmdDeleteAdmin() *cobra.Command { + cmd := &cobra.Command{ + Use: "delete-admin [admin]", + Short: "Broadcast message DeleteAdmin", + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + removeAdmin, err := sdk.AccAddressFromBech32(args[0]) + if err != nil { + return err + } + + msg := types.NewMsgDeleteAdmin(clientCtx.GetFromAddress(), removeAdmin) + if err := msg.ValidateBasic(); err != nil { + return err + } + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + }, + } + + flags.AddTxFlagsToCmd(cmd) + + return cmd +} diff --git a/x/adminmodule/client/cli/tx_ibc_upgrade_proposal.go b/x/adminmodule/client/cli/tx_ibc_upgrade_proposal.go new file mode 100644 index 0000000..4432378 --- /dev/null +++ b/x/adminmodule/client/cli/tx_ibc_upgrade_proposal.go @@ -0,0 +1,116 @@ +package cli + +import ( + "fmt" + "os" + "strconv" + + "github.com/spf13/cobra" + + upgradetypes "cosmossdk.io/x/upgrade/types" + "github.com/cosmos/admin-module/v2/x/adminmodule/types" + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/tx" + "github.com/cosmos/cosmos-sdk/codec" + clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" + "github.com/cosmos/ibc-go/v8/modules/core/exported" +) + +// NewCmdSubmitUpgradeProposal implements a command handler for submitting an upgrade IBC client proposal transaction. +func NewCmdSubmitIbcClientUpgradeProposal() *cobra.Command { + cmd := &cobra.Command{ + Use: "ibc-upgrade [name] [height] [path/to/upgraded_client_state.json] (--title [title] | --description [description]) [flags]", + Args: cobra.ExactArgs(3), + Short: "Submit an IBC upgrade proposal", + Long: "Submit an IBC client breaking upgrade proposal along with an initial deposit.\n" + + "The client state specified is the upgraded client state representing the upgraded chain\n" + + `Example Upgraded Client State JSON: +{ + "@type":"/ibc.lightclients.tendermint.v1.ClientState", + "chain_id":"testchain1", + "unbonding_period":"1814400s", + "latest_height":{"revision_number":"0","revision_height":"2"}, + "proof_specs":[{"leaf_spec":{"hash":"SHA256","prehash_key":"NO_HASH","prehash_value":"SHA256","length":"VAR_PROTO","prefix":"AA=="},"inner_spec":{"child_order":[0,1],"child_size":33,"min_prefix_length":4,"max_prefix_length":12,"empty_child":null,"hash":"SHA256"},"max_depth":0,"min_depth":0},{"leaf_spec":{"hash":"SHA256","prehash_key":"NO_HASH","prehash_value":"SHA256","length":"VAR_PROTO","prefix":"AA=="},"inner_spec":{"child_order":[0,1],"child_size":32,"min_prefix_length":1,"max_prefix_length":1,"empty_child":null,"hash":"SHA256"},"max_depth":0,"min_depth":0}], + "upgrade_path":["upgrade","upgradedIBCState"], +} + `, + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + cdc := codec.NewProtoCodec(clientCtx.InterfaceRegistry) + + title, err := cmd.Flags().GetString(FlagTitle) + if err != nil { + return err + } + + description, err := cmd.Flags().GetString(FlagDescription) + if err != nil { + return err + } + + name := args[0] + + height, err := strconv.ParseInt(args[1], 10, 64) + if err != nil { + return err + } + + plan := upgradetypes.Plan{ + Name: name, + Height: height, + } + + clientState, err := tryUnmarshallClientState(cdc, args[2]) + if err != nil { + return err + } + + if err != nil { + return err + } + + content, err := clienttypes.NewUpgradeProposal(title, description, plan, clientState) + if err != nil { + return err + } + + from := clientCtx.GetFromAddress() + + msg, err := types.NewMsgSubmitProposalLegacy(content, from) + if err != nil { + return err + } + + if err = msg.ValidateBasic(); err != nil { + return err + } + + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + }, + } + + cmd.Flags().String(FlagTitle, "", "title of proposal") + cmd.Flags().String(FlagDescription, "", "description of proposal") + + return cmd +} + +func tryUnmarshallClientState(cdc *codec.ProtoCodec, clientStateOrFileName string) (exported.ClientState, error) { + var clientState exported.ClientState + + if err := cdc.UnmarshalInterfaceJSON([]byte(clientStateOrFileName), &clientState); err != nil { + contents, err := os.ReadFile(clientStateOrFileName) + if err != nil { + return nil, fmt.Errorf("neither JSON input nor path to .json file for client state were provided: %w", err) + } + + if err = cdc.UnmarshalInterfaceJSON(contents, &clientState); err != nil { + return nil, err + } + + } + return clientState, nil +} diff --git a/x/adminmodule/client/cli/tx_software_upgrade_proposal.go b/x/adminmodule/client/cli/tx_software_upgrade_proposal.go new file mode 100644 index 0000000..e146123 --- /dev/null +++ b/x/adminmodule/client/cli/tx_software_upgrade_proposal.go @@ -0,0 +1,158 @@ +package cli + +import ( + "fmt" + "time" + + "github.com/spf13/cobra" + + upgradetypes "cosmossdk.io/x/upgrade/types" + "github.com/cosmos/admin-module/v2/x/adminmodule/types" + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/tx" + "github.com/cosmos/cosmos-sdk/x/gov/client/cli" + govv1types "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" +) + +const ( + // TimeFormat specifies ISO UTC format for submitting the time for a new upgrade proposal + TimeFormat = "2006-01-02T15:04:05Z" + + FlagUpgradeHeight = "upgrade-height" + FlagUpgradeTime = "upgrade-time" + FlagUpgradeInfo = "upgrade-info" +) + +// NewCmdSubmitUpgradeProposal implements a command handler for submitting a software upgrade proposal transaction. +func NewCmdSubmitUpgradeProposal() *cobra.Command { + cmd := &cobra.Command{ + Use: "software-upgrade [name] (--upgrade-height [height] | --upgrade-time [time]) (--upgrade-info [info]) [flags]", + Args: cobra.ExactArgs(1), + Short: "Submit a software upgrade proposal", + Long: "Submit a software upgrade.\n" + + "Please specify a unique name and height OR time for the upgrade to take effect.\n" + + "You may include info to reference a binary download link, in a format compatible with: https://github.com/cosmos/cosmos-sdk/tree/master/cosmovisor", + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + name := args[0] + content, err := parseArgsToContent(cmd, name) + if err != nil { + return err + } + + from := clientCtx.GetFromAddress() + + msg, err := types.NewMsgSubmitProposalLegacy(content, from) + if err != nil { + return err + } + + if err = msg.ValidateBasic(); err != nil { + return err + } + + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + }, + } + + cmd.Flags().String(cli.FlagTitle, "", "title of proposal") + cmd.Flags().String(cli.FlagDescription, "", "description of proposal") + cmd.Flags().Int64(FlagUpgradeHeight, 0, "The height at which the upgrade must happen (not to be used together with --upgrade-time)") + cmd.Flags().String(FlagUpgradeTime, "", fmt.Sprintf("The time at which the upgrade must happen (ex. %s) (not to be used together with --upgrade-height)", TimeFormat)) + cmd.Flags().String(FlagUpgradeInfo, "", "Optional info for the planned upgrade such as commit hash, etc.") + + return cmd +} + +// NewCmdSubmitCancelUpgradeProposal implements a command handler for submitting a software upgrade cancel proposal transaction. +func NewCmdSubmitCancelUpgradeProposal() *cobra.Command { + cmd := &cobra.Command{ + Use: "cancel-software-upgrade [flags]", + Args: cobra.ExactArgs(0), + Short: "Cancel the current software upgrade proposal", + Long: "Cancel a software upgrade.", + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + from := clientCtx.GetFromAddress() + + title, err := cmd.Flags().GetString(cli.FlagTitle) + if err != nil { + return err + } + + description, err := cmd.Flags().GetString(cli.FlagDescription) + if err != nil { + return err + } + + content := upgradetypes.NewCancelSoftwareUpgradeProposal(title, description) + + msg, err := types.NewMsgSubmitProposalLegacy(content, from) + if err != nil { + return err + } + + if err = msg.ValidateBasic(); err != nil { + return err + } + + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + }, + } + + cmd.Flags().String(cli.FlagTitle, "", "title of proposal") + cmd.Flags().String(cli.FlagDescription, "", "description of proposal") + _ = cmd.MarkFlagRequired(cli.FlagTitle) + _ = cmd.MarkFlagRequired(cli.FlagDescription) + + return cmd +} + +func parseArgsToContent(cmd *cobra.Command, name string) (govv1types.Content, error) { + title, err := cmd.Flags().GetString(cli.FlagTitle) + if err != nil { + return nil, err + } + + description, err := cmd.Flags().GetString(cli.FlagDescription) + if err != nil { + return nil, err + } + + height, err := cmd.Flags().GetInt64(FlagUpgradeHeight) + if err != nil { + return nil, err + } + + timeStr, err := cmd.Flags().GetString(FlagUpgradeTime) + if err != nil { + return nil, err + } + + if height != 0 && len(timeStr) != 0 { + return nil, fmt.Errorf("only one of --upgrade-time or --upgrade-height should be specified") + } + + var upgradeTime time.Time + if len(timeStr) != 0 { + upgradeTime, err = time.Parse(TimeFormat, timeStr) + if err != nil { + return nil, err + } + } + + info, err := cmd.Flags().GetString(FlagUpgradeInfo) + if err != nil { + return nil, err + } + + plan := upgradetypes.Plan{Name: name, Time: upgradeTime, Height: height, Info: info} + content := upgradetypes.NewSoftwareUpgradeProposal(title, description, plan) + return content, nil +} diff --git a/x/adminmodule/client/cli/tx_submit_param_change_proposal.go b/x/adminmodule/client/cli/tx_submit_param_change_proposal.go new file mode 100644 index 0000000..735f726 --- /dev/null +++ b/x/adminmodule/client/cli/tx_submit_param_change_proposal.go @@ -0,0 +1,83 @@ +package cli + +import ( + "fmt" + "strings" + + "github.com/spf13/cobra" + + "github.com/cosmos/admin-module/v2/x/adminmodule/types" + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/tx" + "github.com/cosmos/cosmos-sdk/version" + paramscutils "github.com/cosmos/cosmos-sdk/x/params/client/utils" + paramproposal "github.com/cosmos/cosmos-sdk/x/params/types/proposal" +) + +// NewSubmitParamChangeProposalTxCmd returns a CLI command handler for creating +// a parameter change proposal governance transaction. +func NewSubmitParamChangeProposalTxCmd() *cobra.Command { + return &cobra.Command{ + Use: "param-change [proposal-file]", + Args: cobra.ExactArgs(1), + Short: "Submit a parameter change proposal", + Long: strings.TrimSpace( + fmt.Sprintf(`Submit a parameter proposal . +The proposal details must be supplied via a JSON file. For values that contains +objects, only non-empty fields will be updated. + +IMPORTANT: Currently parameter changes are evaluated but not validated, so it is +very important that any "value" change is valid (ie. correct type and within bounds) +for its respective parameter, eg. "MaxValidators" should be an integer and not a decimal. + +Proper vetting of a parameter change proposal should prevent this from happening +(no deposits should occur during the governance process), but it should be noted +regardless. + +Example: +$ %s tx adminmodule submit-proposal param-change --from= + +Where proposal.json contains: + +{ + "title": "Staking Param Change", + "description": "Update max validators", + "changes": [ + { + "subspace": "staking", + "key": "MaxValidators", + "value": 105 + } + ] +} +`, + version.AppName, + ), + ), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + proposal, err := paramscutils.ParseParamChangeProposalJSON(clientCtx.LegacyAmino, args[0]) + if err != nil { + return err + } + + from := clientCtx.GetFromAddress() + content := paramproposal.NewParameterChangeProposal( + proposal.Title, proposal.Description, proposal.Changes.ToParamChanges(), + ) + + msg, err := types.NewMsgSubmitProposalLegacy(content, from) + if err != nil { + return err + } + if err := msg.ValidateBasic(); err != nil { + return err + } + + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + }, + } +} diff --git a/x/adminmodule/client/cli/tx_submit_proposal.go b/x/adminmodule/client/cli/tx_submit_proposal.go new file mode 100644 index 0000000..404f8de --- /dev/null +++ b/x/adminmodule/client/cli/tx_submit_proposal.go @@ -0,0 +1,102 @@ +package cli + +import ( + "fmt" + "strconv" + "strings" + + "github.com/spf13/cobra" + + "github.com/cosmos/admin-module/v2/x/adminmodule/types" + "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" + govv1types "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" +) + +var _ = strconv.Itoa(0) + +// Proposal flags +const ( + FlagTitle = "title" + FlagDescription = "description" + FlagProposalType = "type" + FlagProposal = "proposal" +) + +type proposal struct { + Title string + Description string + Type string +} + +// ProposalFlags defines the core required fields of a proposal. It is used to +// verify that these values are not provided in conjunction with a JSON proposal +// file. +var ProposalFlags = []string{ + FlagTitle, + FlagDescription, + FlagProposalType, +} + +func CmdSubmitProposal() *cobra.Command { + cmd := &cobra.Command{ + Use: "submit-proposal", + Short: "Submit a proposal", + Long: strings.TrimSpace( + fmt.Sprintf(`Submit a proposal. +Proposal title, description, type and can be given directly or through a proposal JSON file. + +Example: +$ %s adminmodule submit-proposal --proposal="path/to/proposal.json" --from mykey + +Where proposal.json contains: + +{ + "title": "Test Proposal", + "description": "My awesome proposal", + "type": "Text" +} + +Which is equivalent to: + +$ %s tx adminmodule submit-proposal --title="Test Proposal" --description="My awesome proposal" --type="Text" --from mykey +`, + version.AppName, version.AppName, + ), + ), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + proposal, err := parseSubmitProposalFlags(cmd.Flags()) + if err != nil { + return fmt.Errorf("failed to parse proposal: %w", err) + } + + content, _ := govv1types.ContentFromProposalType(proposal.Title, proposal.Description, proposal.Type) + + msg, err := types.NewMsgSubmitProposalLegacy(content, clientCtx.GetFromAddress()) + if err != nil { + return fmt.Errorf("invalid message: %w", err) + } + + if err = msg.ValidateBasic(); err != nil { + return fmt.Errorf("message validation failed: %w", err) + } + + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + }, + } + + cmd.Flags().String(FlagTitle, "", "The proposal title") + cmd.Flags().String(FlagDescription, "", "The proposal description") + cmd.Flags().String(FlagProposalType, "", "The proposal Type") + cmd.Flags().String(FlagProposal, "", "Proposal file path (if this path is given, other proposal flags are ignored)") + flags.AddTxFlagsToCmd(cmd) + + return cmd +} diff --git a/x/adminmodule/client/proposal_handlers.go b/x/adminmodule/client/proposal_handlers.go index 9773de5..2ead31d 100644 --- a/x/adminmodule/client/proposal_handlers.go +++ b/x/adminmodule/client/proposal_handlers.go @@ -1,16 +1,21 @@ package client -//// Param change proposal handler. -//var ParamChangeProposalHandler = govclient.NewProposalHandler(cli.NewSubmitParamChangeProposalTxCmd) -// -//// Software upgrade proposal handler. -//var SoftwareUpgradeProposalHandler = govclient.NewProposalHandler(cli.NewCmdSubmitUpgradeProposal) -// -//// Cancel software upgrade proposal handler. -//var CancelUpgradeProposalHandler = govclient.NewProposalHandler(cli.NewCmdSubmitCancelUpgradeProposal) -// -//// IBC Client upgrade proposal handler. -//var IBCClientUpgradeProposalHandler = govclient.NewProposalHandler(cli.NewCmdSubmitIbcClientUpgradeProposal) -// -//// IBC Client update proposal handler. -//var IBCClientUpdateProposalHandler = govclient.NewProposalHandler(cli.NewCmdSubmitUpdateClientProposal) +import ( + "github.com/cosmos/admin-module/v2/x/adminmodule/client/cli" + govclient "github.com/cosmos/cosmos-sdk/x/gov/client" +) + +// Param change proposal handler. +var ParamChangeProposalHandler = govclient.NewProposalHandler(cli.NewSubmitParamChangeProposalTxCmd) + +// Software upgrade proposal handler. +var SoftwareUpgradeProposalHandler = govclient.NewProposalHandler(cli.NewCmdSubmitUpgradeProposal) + +// Cancel software upgrade proposal handler. +var CancelUpgradeProposalHandler = govclient.NewProposalHandler(cli.NewCmdSubmitCancelUpgradeProposal) + +// IBC Client upgrade proposal handler. +var IBCClientUpgradeProposalHandler = govclient.NewProposalHandler(cli.NewCmdSubmitIbcClientUpgradeProposal) + +// IBC Client update proposal handler. +var IBCClientUpdateProposalHandler = govclient.NewProposalHandler(cli.NewCmdSubmitUpdateClientProposal) From 02335cde39af43134cf00fb68b1eb0bf6ae5ea44 Mon Sep 17 00:00:00 2001 From: nhpd Date: Tue, 16 Jul 2024 13:53:32 +0400 Subject: [PATCH 5/7] test: enhance set to true, and remove queries and txs --- x/adminmodule/client/cli/query.go | 2 -- x/adminmodule/client/cli/tx.go | 4 ---- x/adminmodule/module.go | 22 ++++++++++++---------- 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/x/adminmodule/client/cli/query.go b/x/adminmodule/client/cli/query.go index bb1f9f9..d7dd448 100644 --- a/x/adminmodule/client/cli/query.go +++ b/x/adminmodule/client/cli/query.go @@ -26,7 +26,5 @@ func GetQueryCmd(queryRoute string) *cobra.Command { // this line is used by starport scaffolding # 1 - cmd.AddCommand(CmdAdmins(), CmdArchivedProposals(), CmdArchivedProposalsLegacy()) - return cmd } diff --git a/x/adminmodule/client/cli/tx.go b/x/adminmodule/client/cli/tx.go index 032db2c..281e115 100644 --- a/x/adminmodule/client/cli/tx.go +++ b/x/adminmodule/client/cli/tx.go @@ -20,10 +20,6 @@ func GetTxCmd(propCmds []*cobra.Command) *cobra.Command { RunE: client.ValidateCmd, } - cmd.AddCommand(CmdDeleteAdmin()) - - cmd.AddCommand(CmdAddAdmin()) - cmdSubmitProp := CmdSubmitProposal() for _, propCmd := range propCmds { flags.AddTxFlagsToCmd(propCmd) diff --git a/x/adminmodule/module.go b/x/adminmodule/module.go index a6a9581..126a158 100644 --- a/x/adminmodule/module.go +++ b/x/adminmodule/module.go @@ -5,6 +5,8 @@ import ( "context" "encoding/json" "fmt" + "github.com/cosmos/admin-module/v2/x/adminmodule/client/cli" + "github.com/spf13/cobra" // this line is used by starport scaffolding # 1 "cosmossdk.io/core/appmodule" @@ -84,18 +86,18 @@ func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *r } // GetTxCmd returns the capability module's root tx command. -//func (a AppModuleBasic) GetTxCmd() *cobra.Command { -// proposalCLIHandlers := make([]*cobra.Command, 0, len(a.proposalHandlers)) -// for _, proposalHandler := range a.proposalHandlers { -// proposalCLIHandlers = append(proposalCLIHandlers, proposalHandler.CLIHandler()) -// } -// return cli.GetTxCmd(proposalCLIHandlers) -//} +func (a AppModuleBasic) GetTxCmd() *cobra.Command { + proposalCLIHandlers := make([]*cobra.Command, 0, len(a.proposalHandlers)) + for _, proposalHandler := range a.proposalHandlers { + proposalCLIHandlers = append(proposalCLIHandlers, proposalHandler.CLIHandler()) + } + return cli.GetTxCmd(proposalCLIHandlers) +} // GetQueryCmd returns the capability module's root query command. -//func (AppModuleBasic) GetQueryCmd() *cobra.Command { -// return cli.GetQueryCmd(types.StoreKey) -//} +func (AppModuleBasic) GetQueryCmd() *cobra.Command { + return cli.GetQueryCmd(types.StoreKey) +} // ---------------------------------------------------------------------------- // AppModule From c4b55d77ee0b5c4d0c96a523e4405c39bd1f38b4 Mon Sep 17 00:00:00 2001 From: nhpd Date: Tue, 16 Jul 2024 15:24:16 +0400 Subject: [PATCH 6/7] add serviceName --- go.mod | 3 +- x/adminmodule/autocli.go | 44 +++++++++++++++++++++--- x/adminmodule/client/cli/query_admins.go | 43 ----------------------- 3 files changed, 42 insertions(+), 48 deletions(-) delete mode 100644 x/adminmodule/client/cli/query_admins.go diff --git a/go.mod b/go.mod index f51c01c..e96389d 100644 --- a/go.mod +++ b/go.mod @@ -21,6 +21,8 @@ require ( ) require ( + cosmossdk.io/api v0.7.2 + cosmossdk.io/client/v2 v2.0.0-beta.1 cosmossdk.io/core v0.11.0 cosmossdk.io/errors v1.0.1 cosmossdk.io/log v1.3.0 @@ -45,7 +47,6 @@ require ( cloud.google.com/go/compute/metadata v0.2.3 // indirect cloud.google.com/go/iam v1.1.5 // indirect cloud.google.com/go/storage v1.35.1 // indirect - cosmossdk.io/api v0.7.2 // indirect cosmossdk.io/collections v0.4.0 // indirect cosmossdk.io/depinject v1.0.0-alpha.4 // indirect cosmossdk.io/x/tx v0.13.0 // indirect diff --git a/x/adminmodule/autocli.go b/x/adminmodule/autocli.go index 3a56e0f..a899116 100644 --- a/x/adminmodule/autocli.go +++ b/x/adminmodule/autocli.go @@ -2,18 +2,54 @@ package adminmodule import ( autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" + "cosmossdk.io/client/v2/autocli" ) +var _ autocli.HasAutoCLIConfig = AppModule{} + func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions { return &autocliv1.ModuleOptions{ Query: &autocliv1.ServiceCommandDescriptor{ - //Service: _Query_serviceDesc.ServiceName, - RpcCommandOptions: []*autocliv1.RpcCommandOptions{}, + Service: "cosmos.adminmodule.adminmodule.Query", + RpcCommandOptions: []*autocliv1.RpcCommandOptions{ + { + RpcMethod: "Admins", + Use: "admins", + Short: "Query list of admins", + }, + { + RpcMethod: "ArchivedProposals", + Use: "archivedproposals", + Short: "Query archived proposals", + }, + { + RpcMethod: "ArchivedProposalsLegacy", + Use: "archivedproposalslegacy", + Short: "Query legacy archived proposals", + }, + }, EnhanceCustomCommand: true, }, Tx: &autocliv1.ServiceCommandDescriptor{ - //Service: _Msg_ServiceDesc.ServiceName, - RpcCommandOptions: []*autocliv1.RpcCommandOptions{}, + Service: "cosmos.adminmodule.adminmodule.Msg", + RpcCommandOptions: []*autocliv1.RpcCommandOptions{ + { + RpcMethod: "DeleteAdmin", + Use: "delete-admin [admin]", + Short: "Delete admin", + PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "admin"}}, + }, + { + RpcMethod: "AddAdmin", + Use: "add-admin [admin]", + Short: "Add new admin", + PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "admin"}}, + }, + { + RpcMethod: "SubmitProposalLegacy", + Skip: true, // TODO: do we need to remove it? Was it here before? + }, + }, EnhanceCustomCommand: true, }, } diff --git a/x/adminmodule/client/cli/query_admins.go b/x/adminmodule/client/cli/query_admins.go deleted file mode 100644 index 0f06c52..0000000 --- a/x/adminmodule/client/cli/query_admins.go +++ /dev/null @@ -1,43 +0,0 @@ -package cli - -import ( - "strconv" - - "github.com/spf13/cobra" - - "github.com/cosmos/admin-module/v2/x/adminmodule/types" - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/client/flags" -) - -var _ = strconv.Itoa(0) - -func CmdAdmins() *cobra.Command { - cmd := &cobra.Command{ - Use: "admins", - Short: "Query admins", - Args: cobra.ExactArgs(0), - RunE: func(cmd *cobra.Command, args []string) error { - - clientCtx, err := client.GetClientTxContext(cmd) - if err != nil { - return err - } - - queryClient := types.NewQueryClient(clientCtx) - - params := &types.QueryAdminsRequest{} - - res, err := queryClient.Admins(cmd.Context(), params) - if err != nil { - return err - } - - return clientCtx.PrintProto(res) - }, - } - - flags.AddQueryFlagsToCmd(cmd) - - return cmd -} From 7a28e650a430a239503367f36086a4ffe88222a1 Mon Sep 17 00:00:00 2001 From: nhpd Date: Tue, 16 Jul 2024 16:13:23 +0400 Subject: [PATCH 7/7] cleanup --- x/adminmodule/autocli.go | 2 +- x/adminmodule/client/cli/query.go | 30 -------- .../client/cli/query_archived_proposals.go | 73 ------------------- x/adminmodule/client/cli/tx_add_admin.go | 45 ------------ x/adminmodule/client/cli/tx_delete_admin.go | 44 ----------- .../client/cli/tx_ibc_upgrade_proposal.go | 2 +- x/adminmodule/module.go | 5 -- 7 files changed, 2 insertions(+), 199 deletions(-) delete mode 100644 x/adminmodule/client/cli/query.go delete mode 100644 x/adminmodule/client/cli/query_archived_proposals.go delete mode 100644 x/adminmodule/client/cli/tx_add_admin.go delete mode 100644 x/adminmodule/client/cli/tx_delete_admin.go diff --git a/x/adminmodule/autocli.go b/x/adminmodule/autocli.go index a899116..4d7ea4d 100644 --- a/x/adminmodule/autocli.go +++ b/x/adminmodule/autocli.go @@ -47,7 +47,7 @@ func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions { }, { RpcMethod: "SubmitProposalLegacy", - Skip: true, // TODO: do we need to remove it? Was it here before? + Skip: true, }, }, EnhanceCustomCommand: true, diff --git a/x/adminmodule/client/cli/query.go b/x/adminmodule/client/cli/query.go deleted file mode 100644 index d7dd448..0000000 --- a/x/adminmodule/client/cli/query.go +++ /dev/null @@ -1,30 +0,0 @@ -package cli - -import ( - "fmt" - // "strings" - - "github.com/spf13/cobra" - - "github.com/cosmos/cosmos-sdk/client" - // "github.com/cosmos/cosmos-sdk/client/flags" - // sdk "github.com/cosmos/cosmos-sdk/types" - - "github.com/cosmos/admin-module/v2/x/adminmodule/types" -) - -// GetQueryCmd returns the cli query commands for this module -func GetQueryCmd(queryRoute string) *cobra.Command { - // Group adminmodule queries under a subcommand - cmd := &cobra.Command{ - Use: types.ModuleName, - Short: fmt.Sprintf("Querying commands for the %s module", types.ModuleName), - DisableFlagParsing: true, - SuggestionsMinimumDistance: 2, - RunE: client.ValidateCmd, - } - - // this line is used by starport scaffolding # 1 - - return cmd -} diff --git a/x/adminmodule/client/cli/query_archived_proposals.go b/x/adminmodule/client/cli/query_archived_proposals.go deleted file mode 100644 index 0416266..0000000 --- a/x/adminmodule/client/cli/query_archived_proposals.go +++ /dev/null @@ -1,73 +0,0 @@ -package cli - -import ( - "strconv" - - "github.com/spf13/cobra" - - "github.com/cosmos/admin-module/v2/x/adminmodule/types" - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/client/flags" -) - -var _ = strconv.Itoa(0) - -func CmdArchivedProposals() *cobra.Command { - cmd := &cobra.Command{ - Use: "archivedproposals", - Short: "Query archived proposals", - Args: cobra.ExactArgs(0), - RunE: func(cmd *cobra.Command, args []string) error { - - clientCtx, err := client.GetClientTxContext(cmd) - if err != nil { - return err - } - - queryClient := types.NewQueryClient(clientCtx) - - params := &types.QueryArchivedProposalsRequest{} - - res, err := queryClient.ArchivedProposals(cmd.Context(), params) - if err != nil { - return err - } - - return clientCtx.PrintProto(res) - }, - } - - flags.AddQueryFlagsToCmd(cmd) - - return cmd -} - -func CmdArchivedProposalsLegacy() *cobra.Command { - cmd := &cobra.Command{ - Use: "archivedproposalslegacy", - Short: "Query archived proposals legacy", - Args: cobra.ExactArgs(0), - RunE: func(cmd *cobra.Command, args []string) error { - - clientCtx, err := client.GetClientTxContext(cmd) - if err != nil { - return err - } - - queryClient := types.NewQueryClient(clientCtx) - - params := &types.QueryArchivedProposalsLegacyRequest{} - - res, err := queryClient.ArchivedProposalsLegacy(cmd.Context(), params) - if err != nil { - return err - } - - return clientCtx.PrintProto(res) - }, - } - - flags.AddQueryFlagsToCmd(cmd) - - return cmd -} diff --git a/x/adminmodule/client/cli/tx_add_admin.go b/x/adminmodule/client/cli/tx_add_admin.go deleted file mode 100644 index aef46fa..0000000 --- a/x/adminmodule/client/cli/tx_add_admin.go +++ /dev/null @@ -1,45 +0,0 @@ -package cli - -import ( - "strconv" - - "github.com/spf13/cobra" - - "github.com/cosmos/admin-module/v2/x/adminmodule/types" - "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" -) - -var _ = strconv.Itoa(0) - -func CmdAddAdmin() *cobra.Command { - cmd := &cobra.Command{ - Use: "add-admin [admin]", - Short: "Broadcast message AddAdmin", - Args: cobra.ExactArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - - clientCtx, err := client.GetClientTxContext(cmd) - if err != nil { - return err - } - - newAdmin, err := sdk.AccAddressFromBech32(args[0]) - if err != nil { - return err - } - - msg := types.NewMsgAddAdmin(clientCtx.GetFromAddress(), newAdmin) - if err := msg.ValidateBasic(); err != nil { - return err - } - return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) - }, - } - - flags.AddTxFlagsToCmd(cmd) - - return cmd -} diff --git a/x/adminmodule/client/cli/tx_delete_admin.go b/x/adminmodule/client/cli/tx_delete_admin.go deleted file mode 100644 index 5cc342b..0000000 --- a/x/adminmodule/client/cli/tx_delete_admin.go +++ /dev/null @@ -1,44 +0,0 @@ -package cli - -import ( - "strconv" - - "github.com/spf13/cobra" - - "github.com/cosmos/admin-module/v2/x/adminmodule/types" - "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" -) - -var _ = strconv.Itoa(0) - -func CmdDeleteAdmin() *cobra.Command { - cmd := &cobra.Command{ - Use: "delete-admin [admin]", - Short: "Broadcast message DeleteAdmin", - Args: cobra.ExactArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - clientCtx, err := client.GetClientTxContext(cmd) - if err != nil { - return err - } - - removeAdmin, err := sdk.AccAddressFromBech32(args[0]) - if err != nil { - return err - } - - msg := types.NewMsgDeleteAdmin(clientCtx.GetFromAddress(), removeAdmin) - if err := msg.ValidateBasic(); err != nil { - return err - } - return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) - }, - } - - flags.AddTxFlagsToCmd(cmd) - - return cmd -} diff --git a/x/adminmodule/client/cli/tx_ibc_upgrade_proposal.go b/x/adminmodule/client/cli/tx_ibc_upgrade_proposal.go index 4432378..994fdc3 100644 --- a/x/adminmodule/client/cli/tx_ibc_upgrade_proposal.go +++ b/x/adminmodule/client/cli/tx_ibc_upgrade_proposal.go @@ -16,7 +16,7 @@ import ( "github.com/cosmos/ibc-go/v8/modules/core/exported" ) -// NewCmdSubmitUpgradeProposal implements a command handler for submitting an upgrade IBC client proposal transaction. +// NewCmdSubmitIbcClientUpgradeProposal implements a command handler for submitting an upgrade IBC client proposal transaction. func NewCmdSubmitIbcClientUpgradeProposal() *cobra.Command { cmd := &cobra.Command{ Use: "ibc-upgrade [name] [height] [path/to/upgraded_client_state.json] (--title [title] | --description [description]) [flags]", diff --git a/x/adminmodule/module.go b/x/adminmodule/module.go index 126a158..49ebde8 100644 --- a/x/adminmodule/module.go +++ b/x/adminmodule/module.go @@ -94,11 +94,6 @@ func (a AppModuleBasic) GetTxCmd() *cobra.Command { return cli.GetTxCmd(proposalCLIHandlers) } -// GetQueryCmd returns the capability module's root query command. -func (AppModuleBasic) GetQueryCmd() *cobra.Command { - return cli.GetQueryCmd(types.StoreKey) -} - // ---------------------------------------------------------------------------- // AppModule // ----------------------------------------------------------------------------