From 72d70ff0073d50035b73b7c5662edca1c08d0776 Mon Sep 17 00:00:00 2001 From: denalimarsh Date: Fri, 5 Jun 2020 22:10:00 -0700 Subject: [PATCH] committee module now compiles --- x/committee/client/cli/tx.go | 34 ++++++++++++--------- x/committee/client/common/query_proposer.go | 5 +-- x/committee/client/rest/tx.go | 15 ++++++--- x/committee/handler.go | 9 +++++- x/committee/types/codec.go | 2 +- x/committee/types/permissions.go | 14 +++++---- 6 files changed, 49 insertions(+), 30 deletions(-) diff --git a/x/committee/client/cli/tx.go b/x/committee/client/cli/tx.go index a2ee640c18..b1ae6f4a31 100644 --- a/x/committee/client/cli/tx.go +++ b/x/committee/client/cli/tx.go @@ -16,8 +16,9 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/version" "github.com/cosmos/cosmos-sdk/x/auth" + authclient "github.com/cosmos/cosmos-sdk/x/auth/client" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" - "github.com/cosmos/cosmos-sdk/x/params" + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types/proposal" "github.com/tendermint/tendermint/crypto" @@ -30,7 +31,7 @@ func GetTxCmd(storeKey string, cdc *codec.Codec) *cobra.Command { Short: "committee governance transactions subcommands", DisableFlagParsing: true, SuggestionsMinimumDistance: 2, - RunE: auth.ValidateCmd, + RunE: client.ValidateCmd, } txCmd.AddCommand(flags.PostCommands( @@ -56,7 +57,7 @@ For example: Example: fmt.Sprintf("%s tx %s submit-proposal 1 your-proposal.json", version.ClientName, types.ModuleName), RunE: func(cmd *cobra.Command, args []string) error { inBuf := bufio.NewReader(cmd.InOrStdin()) - txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(utils.GetTxEncoder(cdc)) + txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(authclient.GetTxEncoder(cdc)) cliCtx := context.NewCLIContext().WithCodec(cdc) // Get proposing address @@ -89,7 +90,7 @@ For example: } // Sign and broadcast message - return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg}) + return authclient.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg}) }, } @@ -106,7 +107,7 @@ func GetCmdVote(cdc *codec.Codec) *cobra.Command { Example: fmt.Sprintf("%s tx %s vote 2", version.ClientName, types.ModuleName), RunE: func(cmd *cobra.Command, args []string) error { inBuf := bufio.NewReader(cmd.InOrStdin()) - txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(utils.GetTxEncoder(cdc)) + txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(authclient.GetTxEncoder(cdc)) cliCtx := context.NewCLIContext().WithCodec(cdc) // Get voting address @@ -125,13 +126,13 @@ func GetCmdVote(cdc *codec.Codec) *cobra.Command { return err } - return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg}) + return authclient.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg}) }, } } // GetGovCmdSubmitProposal returns a command to submit a proposal to the gov module. It is passed to the gov module for use on its command subtree. -func GetGovCmdSubmitProposal(cdc *codec.Codec) *cobra.Command { +func GetGovCmdSubmitProposal(ctx context.CLIContext) *cobra.Command { cmd := &cobra.Command{ Use: "committee [proposal-file] [deposit]", Short: "Submit a governance proposal to change a committee.", @@ -143,12 +144,12 @@ For example, to create or update a committee: and to delete a committee: %s -`, MustGetExampleCommitteeChangeProposal(cdc), MustGetExampleCommitteeDeleteProposal(cdc)), +`, MustGetExampleCommitteeChangeProposal(ctx.Codec), MustGetExampleCommitteeDeleteProposal(ctx.Codec)), Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { inBuf := bufio.NewReader(cmd.InOrStdin()) - txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(utils.GetTxEncoder(cdc)) - cliCtx := context.NewCLIContext().WithCodec(cdc) + txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(authclient.GetTxEncoder(ctx.Codec)) + cliCtx := context.NewCLIContext().WithCodec(ctx.Codec) // Get proposing address proposer := cliCtx.GetFromAddress() @@ -165,7 +166,7 @@ and to delete a committee: return err } var content govtypes.Content - if err := cdc.UnmarshalJSON(bz, &content); err != nil { + if err := ctx.Codec.UnmarshalJSON(bz, &content); err != nil { return err } if err = content.ValidateBasic(); err != nil { @@ -173,14 +174,17 @@ and to delete a committee: } // Build message and run basic validation - msg := govtypes.NewMsgSubmitProposal(content, deposit, proposer) + msg, err := govtypes.NewMsgSubmitProposal(content, deposit, proposer) + if err != nil { + return err + } err = msg.ValidateBasic() if err != nil { return err } // Sign and broadcast message - return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg}) + return authclient.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg}) }, } return cmd @@ -227,10 +231,10 @@ func MustGetExampleCommitteeDeleteProposal(cdc *codec.Codec) string { // MustGetExampleParameterChangeProposal is a helper function to return an example json proposal func MustGetExampleParameterChangeProposal(cdc *codec.Codec) string { - exampleParameterChangeProposal := params.NewParameterChangeProposal( + exampleParameterChangeProposal := paramtypes.NewParameterChangeProposal( "A Title", "A description of this proposal.", - []params.ParamChange{params.NewParamChange("cdp", "SurplusAuctionThreshold", "1000000000")}, + []paramtypes.ParamChange{paramtypes.NewParamChange("cdp", "SurplusAuctionThreshold", "1000000000")}, ) exampleParameterChangeProposalBz, err := cdc.MarshalJSONIndent(exampleParameterChangeProposal, "", " ") if err != nil { diff --git a/x/committee/client/common/query_proposer.go b/x/committee/client/common/query_proposer.go index 32f9bfaab9..1b78c4f078 100644 --- a/x/committee/client/common/query_proposer.go +++ b/x/committee/client/common/query_proposer.go @@ -5,7 +5,7 @@ import ( "github.com/cosmos/cosmos-sdk/client/context" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/auth" + authclient "github.com/cosmos/cosmos-sdk/x/auth/client" "github.com/kava-labs/kava/x/committee/types" ) @@ -41,7 +41,8 @@ func QueryProposer(cliCtx context.CLIContext, proposalID uint64) (Proposer, erro // NOTE: SearchTxs is used to facilitate the txs query which does not currently // support configurable pagination. - searchResult, err := utils.QueryTxsByEvents(cliCtx, events, defaultPage, defaultLimit) + searchResult, err := authclient.QueryTxsByEvents(cliCtx, events, int(defaultPage), int(defaultLimit), "") + if err != nil { return Proposer{}, err } diff --git a/x/committee/client/rest/tx.go b/x/committee/client/rest/tx.go index 9ff56086f8..f6aca250c2 100644 --- a/x/committee/client/rest/tx.go +++ b/x/committee/client/rest/tx.go @@ -9,7 +9,7 @@ import ( "github.com/cosmos/cosmos-sdk/client/context" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/rest" - "github.com/cosmos/cosmos-sdk/x/auth/client" + authclient "github.com/cosmos/cosmos-sdk/x/auth/client" govrest "github.com/cosmos/cosmos-sdk/x/gov/client/rest" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" @@ -62,7 +62,7 @@ func postProposalHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error()) return } - utils.WriteGenerateStdTxResponse(w, cliCtx, req.BaseReq, []sdk.Msg{msg}) + authclient.WriteGenerateStdTxResponse(w, cliCtx, req.BaseReq, []sdk.Msg{msg}) } } @@ -102,7 +102,7 @@ func postVoteHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error()) return } - utils.WriteGenerateStdTxResponse(w, cliCtx, req.BaseReq, []sdk.Msg{msg}) + authclient.WriteGenerateStdTxResponse(w, cliCtx, req.BaseReq, []sdk.Msg{msg}) } } @@ -139,11 +139,16 @@ func postGovProposalHandlerFn(cliCtx context.CLIContext) http.HandlerFunc { } // Create and return a StdTx - msg := govtypes.NewMsgSubmitProposal(req.Content, req.Deposit, req.Proposer) + msg, err := govtypes.NewMsgSubmitProposal(req.Content, req.Deposit, req.Proposer) + if err != nil { + rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error()) + return + } + if err := msg.ValidateBasic(); err != nil { rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error()) return } - utils.WriteGenerateStdTxResponse(w, cliCtx, req.BaseReq, []sdk.Msg{msg}) + authclient.WriteGenerateStdTxResponse(w, cliCtx, req.BaseReq, []sdk.Msg{msg}) } } diff --git a/x/committee/handler.go b/x/committee/handler.go index e643349913..4bd41fd377 100644 --- a/x/committee/handler.go +++ b/x/committee/handler.go @@ -1,6 +1,8 @@ package committee import ( + "encoding/binary" + sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -38,7 +40,12 @@ func handleMsgSubmitProposal(ctx sdk.Context, k keeper.Keeper, msg types.MsgSubm ), ) - return &sdk.Result{Events: ctx.EventManager().Events().ToABCIEvents()}, nil + proposalIDBytes := make([]byte, 32) + binary.LittleEndian.PutUint64(proposalIDBytes, proposalID) + return &sdk.Result{ + Data: proposalIDBytes, + Events: ctx.EventManager().Events().ToABCIEvents(), + }, nil } func handleMsgVote(ctx sdk.Context, k keeper.Keeper, msg types.MsgVote) (*sdk.Result, error) { diff --git a/x/committee/types/codec.go b/x/committee/types/codec.go index 737f9c8ce2..3efe5e8ee0 100644 --- a/x/committee/types/codec.go +++ b/x/committee/types/codec.go @@ -4,7 +4,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" - paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" + paramstypes "github.com/cosmos/cosmos-sdk/x/params/types/proposal" upgrade "github.com/cosmos/cosmos-sdk/x/upgrade" ) diff --git a/x/committee/types/permissions.go b/x/committee/types/permissions.go index 38491c11b9..33c917512a 100644 --- a/x/committee/types/permissions.go +++ b/x/committee/types/permissions.go @@ -4,7 +4,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" - paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" + paramstypes "github.com/cosmos/cosmos-sdk/x/params/types/proposal" upgrade "github.com/cosmos/cosmos-sdk/x/upgrade" bep3types "github.com/kava-labs/kava/x/bep3/types" @@ -16,7 +16,9 @@ import ( func init() { // CommitteeChange/Delete proposals are registered on gov's ModuleCdc (see proposal.go). // But since these proposals contain Permissions, these types also need registering: - govtypes.ModuleCdc.RegisterInterface((*Permission)(nil), nil) + + // TODO: govtypes.ModuleCdc.RegisterInterface is not available + // govtypes.RegisterInterface((*Permission)(nil), nil) govtypes.RegisterProposalTypeCodec(GodPermission{}, "kava/GodPermission") govtypes.RegisterProposalTypeCodec(SimpleParamChangePermission{}, "kava/SimpleParamChangePermission") govtypes.RegisterProposalTypeCodec(TextPermission{}, "kava/TextPermission") @@ -61,7 +63,7 @@ type SimpleParamChangePermission struct { var _ Permission = SimpleParamChangePermission{} func (perm SimpleParamChangePermission) Allows(_ sdk.Context, _ *codec.Codec, _ ParamKeeper, p PubProposal) bool { - proposal, ok := p.(paramstypes.ParameterChangeProposal) + proposal, ok := p.(*paramstypes.ParameterChangeProposal) if !ok { return false } @@ -109,7 +111,7 @@ type TextPermission struct{} var _ Permission = TextPermission{} func (TextPermission) Allows(_ sdk.Context, _ *codec.Codec, _ ParamKeeper, p PubProposal) bool { - _, ok := p.(govtypes.TextProposal) + _, ok := p.(*govtypes.TextProposal) return ok } @@ -131,7 +133,7 @@ type SoftwareUpgradePermission struct{} var _ Permission = SoftwareUpgradePermission{} func (SoftwareUpgradePermission) Allows(_ sdk.Context, _ *codec.Codec, _ ParamKeeper, p PubProposal) bool { - _, ok := p.(upgrade.SoftwareUpgradeProposal) + _, ok := p.(*upgrade.SoftwareUpgradeProposal) return ok } @@ -180,7 +182,7 @@ func (perm SubParamChangePermission) MarshalYAML() (interface{}, error) { func (perm SubParamChangePermission) Allows(ctx sdk.Context, appCdc *codec.Codec, pk ParamKeeper, p PubProposal) bool { // Check pubproposal has correct type - proposal, ok := p.(paramstypes.ParameterChangeProposal) + proposal, ok := p.(*paramstypes.ParameterChangeProposal) if !ok { return false }