Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

R4R: Parameter Change Proposal #3880

Closed
wants to merge 89 commits into from
Closed
Show file tree
Hide file tree
Changes from 84 commits
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
8fbe541
in progress
mossid Mar 1, 2019
19b04db
in progres
mossid Mar 1, 2019
4fdabb1
fix test in progress
mossid Mar 1, 2019
ec133ef
fix test
mossid Mar 1, 2019
aac536d
fix lint
mossid Mar 1, 2019
cd0eb03
Update x/gov/endblocker.go
alexanderbez Mar 1, 2019
d6b1e53
Update x/gov/endblocker.go
alexanderbez Mar 1, 2019
6b13eb7
address comments
mossid Mar 2, 2019
502bfc9
fix integration test
mossid Mar 2, 2019
afa4038
Merge branch 'joon/3570-split-proposal-interface' of github.com:cosmo…
mossid Mar 2, 2019
dcea8ef
add SoftwareUpgradeProposal
mossid Mar 3, 2019
31bda27
Update x/gov/endblocker.go
alexanderbez Mar 1, 2019
0e58adb
Update x/gov/endblocker.go
alexanderbez Mar 1, 2019
e2ec4fe
Merge branch 'joon/3570-split-proposal-interface' of github.com:cosmo…
mossid Mar 4, 2019
90c1d7c
add to codec
mossid Mar 4, 2019
a03bcc8
add pending
mossid Mar 4, 2019
ea820cf
Merge branch 'develop' into joon/3570-split-proposal-interface
mossid Mar 8, 2019
c0a556a
expose SubmitProposal(), fix ProposalEqual()
mossid Mar 8, 2019
43dcee0
fix test, add docs
mossid Mar 11, 2019
0f998cb
Merge branch 'develop' into joon/3570-split-proposal-interface
mossid Mar 14, 2019
d9ea2d1
in progress
mossid Mar 3, 2019
a9011be
fix tests
mossid Mar 4, 2019
3442ec5
implement params.NewProposalHandler in progress
mossid Mar 4, 2019
322c95c
in progress
mossid Mar 11, 2019
a3e89b2
fix SubmitParameterChangeProposal
mossid Mar 11, 2019
f4a7c47
move to gov/proposal, writing test in progress
mossid Mar 11, 2019
e6f8d97
writing test in progress
mossid Mar 12, 2019
9beca06
fix test
mossid Mar 12, 2019
8ba2eda
in progress
mossid Mar 14, 2019
b9cead1
write test in progress
mossid Mar 14, 2019
ba6b52a
fix lint
mossid Mar 14, 2019
f1b2192
rm SubmitForm, fix lint
mossid Mar 14, 2019
7cb7d4f
Update x/gov/test_common.go
cwgoes Mar 15, 2019
3fc1cb3
Merge branch 'joon/3570-split-proposal-interface' of github.com:cosmo…
mossid Mar 18, 2019
e80c27b
Update x/gov/client/rest/rest.go
fedekunze Mar 18, 2019
47aae50
Update x/gov/errors/errors.go
fedekunze Mar 18, 2019
ea1a9aa
Update x/params/contents.go
fedekunze Mar 18, 2019
79080c1
Update x/params/msgs.go
fedekunze Mar 18, 2019
3f8b67d
Update x/gov/keeper.go
fedekunze Mar 18, 2019
06b1325
Update x/gov/keeper.go
fedekunze Mar 18, 2019
18265bf
add legacy
mossid Mar 18, 2019
373c81b
add legacy test
mossid Mar 18, 2019
8173a73
Merge branch 'joon/3565-parameter-change-proposal-2' of github.com:co…
mossid Mar 18, 2019
cbd38b4
Update x/gov/keeper.go
fedekunze Mar 18, 2019
e9d7fcc
address comments in progress
mossid Mar 18, 2019
542f83d
Merge branch 'develop' into joon/3565-parameter-change-proposal-2
mossid Mar 18, 2019
fbd5ac8
Merge branch 'develop' into joon/3565-parameter-change-proposal-2
mossid Mar 18, 2019
2aaf227
Merge branch 'joon/3565-parameter-change-proposal-2' of github.com:co…
mossid Mar 18, 2019
b20bfb1
rm legacy
mossid Mar 19, 2019
f5ecc4e
Update x/gov/msgs.go
fedekunze Mar 19, 2019
77a8bc6
address comments in progress
mossid Mar 19, 2019
f29f1a5
address comments in progress
mossid Mar 19, 2019
031da7c
fix lint
mossid Mar 19, 2019
d68f935
addressing comments in progress
mossid Mar 22, 2019
ae7bcb3
address commtnes
mossid Mar 22, 2019
330a7ae
Update x/gov/handler.go
alexanderbez Mar 22, 2019
7735a05
in progress
mossid Mar 25, 2019
bb90b15
Merge branch 'develop' into joon/3565-parameter-change-proposal-2
mossid Mar 25, 2019
55626e6
fix sim
mossid Mar 25, 2019
869e90c
Update x/gov/handler.go
alexanderbez Mar 25, 2019
7521116
address comments
mossid Mar 25, 2019
5f78daa
Merge branch 'joon/3565-parameter-change-proposal-2' of github.com:co…
mossid Mar 25, 2019
bd4a849
add genesis migration
mossid Mar 25, 2019
d1d67b5
fix test
mossid Mar 25, 2019
a63d24f
Apply suggestions from code review
rigelrozanski Mar 26, 2019
81458a9
apply requests
mossid Mar 26, 2019
9eaaf3d
apply comments
mossid Mar 26, 2019
dd0e476
rm startingProposalID
mossid Mar 26, 2019
8fbbd5e
Update x/gov/keeper.go
alexanderbez Mar 26, 2019
dc21c9c
apply comments
mossid Mar 27, 2019
dd5adad
Merge branch 'joon/3565-parameter-change-proposal-2' of github.com:co…
mossid Mar 27, 2019
765ec24
rm abstract rename legacy
mossid Mar 27, 2019
0893103
revert json encoding change for encoding compat
mossid Apr 3, 2019
f13b696
Apply suggestions from code review
fedekunze Apr 8, 2019
7a8f90b
add test
mossid Apr 10, 2019
d806275
rename MsgSubmitParameterChangeProposal -> MsgSubmitProposal
mossid Apr 10, 2019
b05ebdb
Apply suggestions from code review
alexanderbez Apr 10, 2019
244ad53
Merge branch 'develop' of github.com:cosmos/cosmos-sdk into joon/3565…
mossid Apr 10, 2019
ded0fcf
unifying msg form, add validatebasic to content
mossid Apr 10, 2019
a7edcbe
Merge branch 'joon/3565-parameter-change-proposal-2' of github.com:co…
mossid Apr 10, 2019
0820bea
unify msg into gov
mossid Apr 10, 2019
008b6f2
Merge branch 'develop' of github.com:cosmos/cosmos-sdk into joon/3565…
mossid Apr 10, 2019
b098315
add rest/cli, address comments
mossid Apr 12, 2019
d7056b7
mistake
mossid Apr 12, 2019
ebdd392
gobot
mossid Apr 12, 2019
901cf44
Apply suggestions from code review
fedekunze Apr 12, 2019
a784ee9
address comments
mossid Apr 12, 2019
6b4cbda
rename to ParameterChangeProposal, fix test
mossid Apr 12, 2019
93b9dda
Merge branch 'develop' into joon/3565-parameter-change-proposal-2
alexanderbez Apr 16, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions cmd/gaia/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func NewGaiaApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest,
tkeyParams: sdk.NewTransientStoreKey(params.TStoreKey),
}

app.paramsKeeper = params.NewKeeper(app.cdc, app.keyParams, app.tkeyParams)
app.paramsKeeper = params.NewKeeper(app.cdc, app.keyParams, app.tkeyParams, params.DefaultCodespace)

// define the accountKeeper
app.accountKeeper = auth.NewAccountKeeper(
Expand Down Expand Up @@ -138,7 +138,8 @@ func NewGaiaApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest,
&stakingKeeper, app.paramsKeeper.Subspace(slashing.DefaultParamspace),
slashing.DefaultCodespace,
)
app.govKeeper = gov.NewKeeper(
var grouter gov.Router
mossid marked this conversation as resolved.
Show resolved Hide resolved
app.govKeeper, grouter = gov.NewKeeper(
mossid marked this conversation as resolved.
Show resolved Hide resolved
app.cdc,
app.keyGov,
app.paramsKeeper, app.paramsKeeper.Subspace(gov.DefaultParamspace), app.bankKeeper, &stakingKeeper,
Expand Down Expand Up @@ -180,6 +181,10 @@ func NewGaiaApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest,
AddRoute(staking.QuerierRoute, staking.NewQuerier(app.stakingKeeper, app.cdc)).
AddRoute(mint.QuerierRoute, mint.NewQuerier(app.mintKeeper))

grouter.
mossid marked this conversation as resolved.
Show resolved Hide resolved
AddRoute(gov.RouterKey, gov.ProposalHandler).
AddRoute(params.RouterKey, params.NewProposalHandler(app.paramsKeeper))

// initialize BaseApp
app.MountStores(app.keyMain, app.keyAccount, app.keyStaking, app.keyMint, app.keyDistr,
app.keySlashing, app.keyGov, app.keyFeeCollection, app.keyParams,
Expand Down
8 changes: 6 additions & 2 deletions cmd/gaia/cmd/gaiacli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
gv "github.com/cosmos/cosmos-sdk/x/gov"
gov "github.com/cosmos/cosmos-sdk/x/gov/client/rest"
mintrest "github.com/cosmos/cosmos-sdk/x/mint/client/rest"
params "github.com/cosmos/cosmos-sdk/x/params/client/rest"
sl "github.com/cosmos/cosmos-sdk/x/slashing"
slashing "github.com/cosmos/cosmos-sdk/x/slashing/client/rest"
st "github.com/cosmos/cosmos-sdk/x/staking"
Expand All @@ -43,6 +44,7 @@ import (
distClient "github.com/cosmos/cosmos-sdk/x/distribution/client"
govClient "github.com/cosmos/cosmos-sdk/x/gov/client"
mintclient "github.com/cosmos/cosmos-sdk/x/mint/client"
paramcmd "github.com/cosmos/cosmos-sdk/x/params/client/cli"
slashingclient "github.com/cosmos/cosmos-sdk/x/slashing/client"
stakingclient "github.com/cosmos/cosmos-sdk/x/staking/client"

Expand Down Expand Up @@ -70,7 +72,9 @@ func main() {
// Module clients hold cli commnads (tx,query) and lcd routes
// TODO: Make the lcd command take a list of ModuleClient
mc := []sdk.ModuleClients{
govClient.NewModuleClient(gv.StoreKey, cdc),
govClient.NewModuleClient(gv.StoreKey, cdc,
paramcmd.GetCmdSubmitProposal(cdc),
),
distClient.NewModuleClient(distcmd.StoreKey, cdc),
stakingclient.NewModuleClient(st.StoreKey, cdc),
mintclient.NewModuleClient(mint.StoreKey, cdc),
Expand Down Expand Up @@ -175,7 +179,7 @@ func registerRoutes(rs *lcd.RestServer) {
dist.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc, distcmd.StoreKey)
staking.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc, rs.KeyBase)
slashing.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc, rs.KeyBase)
gov.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc)
gov.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc, params.PropHandler(rs.CliCtx, rs.Cdc))
mintrest.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc)
}

Expand Down
Binary file added cmd/gaia/cmd/gaiadebug/gaiadebug
Binary file not shown.
2 changes: 1 addition & 1 deletion cmd/gaia/cmd/gaiadebug/hack.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func NewGaiaApp(logger log.Logger, db dbm.DB, baseAppOptions ...func(*bam.BaseAp
tkeyParams: sdk.NewTransientStoreKey(params.TStoreKey),
}

app.paramsKeeper = params.NewKeeper(app.cdc, app.keyParams, app.tkeyParams)
app.paramsKeeper = params.NewKeeper(app.cdc, app.keyParams, app.tkeyParams, params.DefaultCodespace)

// define the accountKeeper
app.accountKeeper = auth.NewAccountKeeper(
Expand Down
2 changes: 1 addition & 1 deletion types/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func MakeTag(k string, v string) Tag {
//__________________________________________________

// common tags
var (
const (
TagAction = "action"
TagCategory = "category"
TagSender = "sender"
Expand Down
6 changes: 3 additions & 3 deletions x/auth/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

codec "github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/params"
"github.com/cosmos/cosmos-sdk/x/params/subspace"
)

const (
Expand Down Expand Up @@ -40,14 +40,14 @@ type AccountKeeper struct {
// The codec codec for binary encoding/decoding of accounts.
cdc *codec.Codec

paramSubspace params.Subspace
paramSubspace subspace.Subspace
}

// NewAccountKeeper returns a new sdk.AccountKeeper that uses go-amino to
// (binary) encode and decode concrete sdk.Accounts.
// nolint
func NewAccountKeeper(
cdc *codec.Codec, key sdk.StoreKey, paramstore params.Subspace, proto func() Account,
cdc *codec.Codec, key sdk.StoreKey, paramstore subspace.Subspace, proto func() Account,
) AccountKeeper {

return AccountKeeper{
Expand Down
12 changes: 6 additions & 6 deletions x/auth/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"strings"

"github.com/cosmos/cosmos-sdk/x/params"
"github.com/cosmos/cosmos-sdk/x/params/subspace"
)

// DefaultParamspace defines the default auth module parameter subspace
Expand All @@ -29,7 +29,7 @@ var (
KeySigVerifyCostSecp256k1 = []byte("SigVerifyCostSecp256k1")
)

var _ params.ParamSet = &Params{}
var _ subspace.ParamSet = &Params{}

// Params defines the parameters for the auth module.
type Params struct {
Expand All @@ -41,15 +41,15 @@ type Params struct {
}

// ParamKeyTable for auth module
func ParamKeyTable() params.KeyTable {
return params.NewKeyTable().RegisterParamSet(&Params{})
func ParamKeyTable() subspace.KeyTable {
return subspace.NewKeyTable().RegisterParamSet(&Params{})
}

// ParamSetPairs implements the ParamSet interface and returns all the key/value pairs
// pairs of auth module's parameters.
// nolint
func (p *Params) ParamSetPairs() params.ParamSetPairs {
return params.ParamSetPairs{
func (p *Params) ParamSetPairs() subspace.ParamSetPairs {
return subspace.ParamSetPairs{
{KeyMaxMemoCharacters, &p.MaxMemoCharacters},
{KeyTxSigLimit, &p.TxSigLimit},
{KeyTxSizeCostPerByte, &p.TxSizeCostPerByte},
Expand Down
10 changes: 5 additions & 5 deletions x/auth/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/store"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/params"
subspace "github.com/cosmos/cosmos-sdk/x/params/subspace"
)

type testInput struct {
Expand All @@ -29,8 +29,8 @@ func setupTestInput() testInput {

authCapKey := sdk.NewKVStoreKey("authCapKey")
fckCapKey := sdk.NewKVStoreKey("fckCapKey")
keyParams := sdk.NewKVStoreKey("params")
tkeyParams := sdk.NewTransientStoreKey("transient_params")
keyParams := sdk.NewKVStoreKey("subspace")
tkeyParams := sdk.NewTransientStoreKey("transient_subspace")

ms := store.NewCommitMultiStore(db)
ms.MountStoreWithDB(authCapKey, sdk.StoreTypeIAVL, db)
Expand All @@ -39,8 +39,8 @@ func setupTestInput() testInput {
ms.MountStoreWithDB(tkeyParams, sdk.StoreTypeTransient, db)
ms.LoadLatestVersion()

pk := params.NewKeeper(cdc, keyParams, tkeyParams)
ak := NewAccountKeeper(cdc, authCapKey, pk.Subspace(DefaultParamspace), ProtoBaseAccount)
ps := subspace.NewSubspace(cdc, keyParams, tkeyParams, DefaultParamspace)
ak := NewAccountKeeper(cdc, authCapKey, ps, ProtoBaseAccount)
fck := NewFeeCollectionKeeper(cdc, fckCapKey)
ctx := sdk.NewContext(ms, abci.Header{ChainID: "test-chain-id"}, false, log.NewNopLogger())

Expand Down
2 changes: 1 addition & 1 deletion x/bank/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func setupTestInput() testInput {
ms.MountStoreWithDB(tkeyParams, sdk.StoreTypeTransient, db)
ms.LoadLatestVersion()

pk := params.NewKeeper(cdc, keyParams, tkeyParams)
pk := params.NewKeeper(cdc, keyParams, tkeyParams, params.DefaultCodespace)
ak := auth.NewAccountKeeper(
cdc, authCapKey, pk.Subspace(auth.DefaultParamspace), auth.ProtoBaseAccount,
)
Expand Down
2 changes: 1 addition & 1 deletion x/distribution/keeper/test_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func CreateTestInputAdvanced(t *testing.T, isCheckTx bool, initPower int64,
require.Nil(t, err)

cdc := MakeTestCodec()
pk := params.NewKeeper(cdc, keyParams, tkeyParams)
pk := params.NewKeeper(cdc, keyParams, tkeyParams, params.DefaultCodespace)

ctx := sdk.NewContext(ms, abci.Header{ChainID: "foochainid"}, isCheckTx, log.NewNopLogger())
accountKeeper := auth.NewAccountKeeper(cdc, keyAcc, pk.Subspace(auth.DefaultParamspace), auth.ProtoBaseAccount)
Expand Down
10 changes: 9 additions & 1 deletion x/gov/client/cli/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,23 @@ import (
govClientUtils "github.com/cosmos/cosmos-sdk/x/gov/client/utils"
)

func readProposalType() string {
return govClientUtils.NormalizeProposalType(viper.GetString(flagProposalType))
}

func parseSubmitProposalFlags() (*proposal, error) {
proposal := &proposal{}
proposalFile := viper.GetString(flagProposal)

if proposalFile == "" {
proposal.Title = viper.GetString(flagTitle)
proposal.Description = viper.GetString(flagDescription)
proposal.Type = govClientUtils.NormalizeProposalType(viper.GetString(flagProposalType))
proposal.Type = readProposalType()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious to learn why? Wasn't the inline call enough? I can't find any other place where readProposalType() is used

proposal.Deposit = viper.GetString(flagDeposit)

if proposal.Type == "" {
return nil, fmt.Errorf("Invalid ProposalType %s was given", flagProposalType)
}
return proposal, nil
}

Expand Down
9 changes: 5 additions & 4 deletions x/gov/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,13 @@ $ gaiacli gov submit-proposal --title="Test Proposal" --description="My awesome
return err
}

proposalType, err := gov.ProposalTypeFromString(proposal.Type)
if err != nil {
return err
if !gov.IsValidProposalType(proposal.Type) {
return fmt.Errorf("Invalid proposal type %s", proposal.Type)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto. From the line above I'd have expected something like "proposal content is empty"

}
content := gov.ContentFromProposalType(proposal.Title, proposal.Description, proposal.Type)

msg := gov.NewMsgSubmitProposal(content, from, amount)

msg := gov.NewMsgSubmitProposal(proposal.Title, proposal.Description, proposalType, from, amount)
err = msg.ValidateBasic()
if err != nil {
return err
Expand Down
12 changes: 9 additions & 3 deletions x/gov/client/module_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ import (
type ModuleClient struct {
storeKey string
cdc *amino.Codec
pcmds []*cobra.Command
}

func NewModuleClient(storeKey string, cdc *amino.Codec) ModuleClient {
return ModuleClient{storeKey, cdc}
func NewModuleClient(storeKey string, cdc *amino.Codec, pcmds ...*cobra.Command) ModuleClient {
return ModuleClient{storeKey, cdc, pcmds}
}

// GetQueryCmd returns the cli query commands for this module
Expand Down Expand Up @@ -49,10 +50,15 @@ func (mc ModuleClient) GetTxCmd() *cobra.Command {
Short: "Governance transactions subcommands",
}

propcmd := govCli.GetCmdSubmitProposal(mc.cdc)
for _, pcmd := range mc.pcmds {
propcmd.AddCommand(pcmd)
}

govTxCmd.AddCommand(client.PostCommands(
govCli.GetCmdDeposit(mc.storeKey, mc.cdc),
govCli.GetCmdVote(mc.storeKey, mc.cdc),
govCli.GetCmdSubmitProposal(mc.cdc),
propcmd,
)...)

return govTxCmd
Expand Down
24 changes: 19 additions & 5 deletions x/gov/client/rest/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/gov"
gcutils "github.com/cosmos/cosmos-sdk/x/gov/client/utils"
govClientUtils "github.com/cosmos/cosmos-sdk/x/gov/client/utils"
goverr "github.com/cosmos/cosmos-sdk/x/gov/errors"
)

// REST Variable names
Expand All @@ -29,7 +30,14 @@ const (
)

// RegisterRoutes - Central function to define routes that get registered by the main application
func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *codec.Codec) {
func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *codec.Codec,
phs ...PropHandler) {

propsub := r.PathPrefix("/gov/proposals").Subrouter()
for _, ph := range phs {
propsub.HandleFunc("/"+ph.Name, ph.Handler).Methods("POST")
}

r.HandleFunc("/gov/proposals", postProposalHandlerFn(cdc, cliCtx)).Methods("POST")
r.HandleFunc(fmt.Sprintf("/gov/proposals/{%s}/deposits", RestProposalID), depositHandlerFn(cdc, cliCtx)).Methods("POST")
r.HandleFunc(fmt.Sprintf("/gov/proposals/{%s}/votes", RestProposalID), voteHandlerFn(cdc, cliCtx)).Methods("POST")
Expand Down Expand Up @@ -76,6 +84,11 @@ type VoteReq struct {
Option string `json:"option"` // option from OptionSet chosen by the voter
}

type PropHandler struct {
Name string
Handler func(http.ResponseWriter, *http.Request)
}

func postProposalHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req PostProposalReq
Expand All @@ -88,14 +101,15 @@ func postProposalHandlerFn(cdc *codec.Codec, cliCtx context.CLIContext) http.Han
return
}

proposalType, err := gov.ProposalTypeFromString(govClientUtils.NormalizeProposalType(req.ProposalType))
if err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
proposalType := govClientUtils.NormalizeProposalType(req.ProposalType)
if !gov.IsValidProposalType(proposalType) {
rest.WriteErrorResponse(w, http.StatusBadRequest, goverr.ErrInvalidProposalType(gov.DefaultCodespace, req.ProposalType).Error())
return
}

// create the message
msg := gov.NewMsgSubmitProposal(req.Title, req.Description, proposalType, req.Proposer, req.InitialDeposit)
content := gov.ContentFromProposalType(req.Title, req.Description, proposalType)
msg := gov.NewMsgSubmitProposal(content, req.Proposer, req.InitialDeposit)
if err := msg.ValidateBasic(); err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
Expand Down
11 changes: 7 additions & 4 deletions x/gov/client/utils/utils.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package utils

import (
"github.com/cosmos/cosmos-sdk/x/gov"
"github.com/cosmos/cosmos-sdk/x/params"
)

// NormalizeVoteOption - normalize user specified vote option
func NormalizeVoteOption(option string) string {
switch option {
Expand All @@ -19,11 +24,9 @@ func NormalizeVoteOption(option string) string {
func NormalizeProposalType(proposalType string) string {
switch proposalType {
case "Text", "text":
return "Text"
case "ParameterChange", "parameter_change":
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this shouldn't be deleted

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Each proposal content type is managed by the module where it is defined, but still sending the tx to the governance handler.

return "ParameterChange"
return gov.ProposalTypeText
case "SoftwareUpgrade", "software_upgrade":
return "SoftwareUpgrade"
return gov.ProposalTypeSoftwareUpgrade
}
return ""
}
Expand Down
3 changes: 2 additions & 1 deletion x/gov/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package gov

import (
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/x/gov/proposal"
)

var msgCdc = codec.New()
Expand All @@ -12,7 +13,7 @@ func RegisterCodec(cdc *codec.Codec) {
cdc.RegisterConcrete(MsgDeposit{}, "cosmos-sdk/MsgDeposit", nil)
cdc.RegisterConcrete(MsgVote{}, "cosmos-sdk/MsgVote", nil)

cdc.RegisterInterface((*ProposalContent)(nil), nil)
proposal.RegisterCodec(cdc)
cdc.RegisterConcrete(TextProposal{}, "gov/TextProposal", nil)
cdc.RegisterConcrete(SoftwareUpgradeProposal{}, "gov/SoftwareUpgradeProposal", nil)
}
Expand Down
Loading