Skip to content

Commit

Permalink
committee module now compiles
Browse files Browse the repository at this point in the history
  • Loading branch information
denalimarsh committed Jun 6, 2020
1 parent 162057f commit 72d70ff
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 30 deletions.
34 changes: 19 additions & 15 deletions x/committee/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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(
Expand All @@ -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
Expand Down Expand Up @@ -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})
},
}

Expand All @@ -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
Expand All @@ -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.",
Expand All @@ -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()
Expand All @@ -165,22 +166,25 @@ 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 {
return err
}

// 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
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 3 additions & 2 deletions x/committee/client/common/query_proposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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
}
Expand Down
15 changes: 10 additions & 5 deletions x/committee/client/rest/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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})
}
}

Expand Down Expand Up @@ -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})
}
}

Expand Down Expand Up @@ -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})
}
}
9 changes: 8 additions & 1 deletion x/committee/handler.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package committee

import (
"encoding/binary"

sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"

Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion x/committee/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
14 changes: 8 additions & 6 deletions x/committee/types/permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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")
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}

Expand All @@ -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
}

Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 72d70ff

Please sign in to comment.