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

Cosmos 0.37.5 Modules [PLEASE DON'T MERGE IT, JUST FOR EXP PURPOSE] #1081

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
56 changes: 56 additions & 0 deletions params/alias.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// nolint
// autogenerated code using github.com/rigelrozanski/multitool
// aliases generated for the following subdirectories:
// ALIASGEN: github.com/cosmos/cosmos-sdk/x/params/subspace
// ALIASGEN: github.com/cosmos/cosmos-sdk/x/params/types
package params

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

const (
StoreKey = subspace.StoreKey
TStoreKey = subspace.TStoreKey
TestParamStore = subspace.TestParamStore
DefaultCodespace = types.DefaultCodespace
CodeUnknownSubspace = types.CodeUnknownSubspace
CodeSettingParameter = types.CodeSettingParameter
CodeEmptyData = types.CodeEmptyData
ModuleName = types.ModuleName
RouterKey = types.RouterKey
ProposalTypeChange = types.ProposalTypeChange
)

var (
// functions aliases
NewSubspace = subspace.NewSubspace
NewKeyTable = subspace.NewKeyTable
DefaultTestComponents = subspace.DefaultTestComponents
RegisterCodec = types.RegisterCodec
ErrUnknownSubspace = types.ErrUnknownSubspace
ErrSettingParameter = types.ErrSettingParameter
ErrEmptyChanges = types.ErrEmptyChanges
ErrEmptySubspace = types.ErrEmptySubspace
ErrEmptyKey = types.ErrEmptyKey
ErrEmptyValue = types.ErrEmptyValue
NewParameterChangeProposal = types.NewParameterChangeProposal
NewParamChange = types.NewParamChange
NewParamChangeWithSubkey = types.NewParamChangeWithSubkey
ValidateChanges = types.ValidateChanges

// variable aliases
ModuleCdc = types.ModuleCdc
)

type (
ParamSetPair = subspace.ParamSetPair
ParamSetPairs = subspace.ParamSetPairs
ParamSet = subspace.ParamSet
Subspace = subspace.Subspace
ReadOnlySubspace = subspace.ReadOnlySubspace
KeyTable = subspace.KeyTable
ParameterChangeProposal = types.ParameterChangeProposal
ParamChange = types.ParamChange
)
5 changes: 0 additions & 5 deletions params/client/cli/flags.go

This file was deleted.

37 changes: 11 additions & 26 deletions params/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,19 @@ import (
"fmt"
"strings"

"github.com/maticnetwork/heimdall/helper"
"github.com/spf13/cobra"
"github.com/spf13/viper"

"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/version"

govTypes "github.com/maticnetwork/heimdall/gov/types"
paramscutils "github.com/maticnetwork/heimdall/params/client/utils"
"github.com/maticnetwork/heimdall/params/types"
hmTypes "github.com/maticnetwork/heimdall/types"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/auth/client/utils"
"github.com/cosmos/cosmos-sdk/x/gov"
paramscutils "github.com/cosmos/cosmos-sdk/x/params/client/utils"
"github.com/cosmos/cosmos-sdk/x/params/types"
)

var logger = helper.Logger.With("module", "params/client/cli")

// GetCmdSubmitProposal implements a command handler for submitting a parameter
// change proposal transaction.
func GetCmdSubmitProposal(cdc *codec.Codec) *cobra.Command {
Expand Down Expand Up @@ -58,8 +54,8 @@ Where proposal.json contains:
],
"deposit": [
{
"denom": "matic",
"amount": "1000000000000000000"
"denom": "stake",
"amount": "10000"
}
]
}
Expand All @@ -68,36 +64,25 @@ Where proposal.json contains:
),
),
RunE: func(cmd *cobra.Command, args []string) error {
txBldr := auth.NewTxBuilderFromCLI().WithTxEncoder(utils.GetTxEncoder(cdc))
cliCtx := context.NewCLIContext().WithCodec(cdc)

proposal, err := paramscutils.ParseParamChangeProposalJSON(cdc, args[0])
if err != nil {
return err
}

validatorID := viper.GetUint64(FlagValidatorID)
if validatorID == 0 {
return fmt.Errorf("Valid validator ID required")
}

from := helper.GetFromAddress(cliCtx)
from := cliCtx.GetFromAddress()
content := types.NewParameterChangeProposal(proposal.Title, proposal.Description, proposal.Changes.ToParamChanges())

// create submit proposal
msg := govTypes.NewMsgSubmitProposal(content, proposal.Deposit, from, hmTypes.NewValidatorID(validatorID))
msg := gov.NewMsgSubmitProposal(content, proposal.Deposit, from)
if err := msg.ValidateBasic(); err != nil {
return err
}

return helper.BroadcastMsgsWithCLI(cliCtx, []sdk.Msg{msg})
return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg})
},
}

cmd.Flags().Int(FlagValidatorID, 0, "--validator-id=<validator ID here>")

if err := cmd.MarkFlagRequired(FlagValidatorID); err != nil {
logger.Error("GetCmdSubmitProposal | MarkFlagRequired | FlagValidatorID", "Error", err)
}

return cmd
}
6 changes: 3 additions & 3 deletions params/client/proposal_handler.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package client

import (
govclient "github.com/maticnetwork/heimdall/gov/client"
"github.com/maticnetwork/heimdall/params/client/cli"
"github.com/maticnetwork/heimdall/params/client/rest"
govclient "github.com/cosmos/cosmos-sdk/x/gov/client"
"github.com/cosmos/cosmos-sdk/x/params/client/cli"
"github.com/cosmos/cosmos-sdk/x/params/client/rest"
)

// param change proposal handler
Expand Down
25 changes: 12 additions & 13 deletions params/client/rest/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,26 @@ import (

"github.com/cosmos/cosmos-sdk/client/context"
sdk "github.com/cosmos/cosmos-sdk/types"

restClient "github.com/maticnetwork/heimdall/client/rest"
govRest "github.com/maticnetwork/heimdall/gov/client/rest"
govTypes "github.com/maticnetwork/heimdall/gov/types"
paramsUtils "github.com/maticnetwork/heimdall/params/client/utils"
paramsTypes "github.com/maticnetwork/heimdall/params/types"
"github.com/maticnetwork/heimdall/types/rest"
"github.com/cosmos/cosmos-sdk/types/rest"
"github.com/cosmos/cosmos-sdk/x/auth/client/utils"
"github.com/cosmos/cosmos-sdk/x/gov"
govrest "github.com/cosmos/cosmos-sdk/x/gov/client/rest"
"github.com/cosmos/cosmos-sdk/x/params"
paramscutils "github.com/cosmos/cosmos-sdk/x/params/client/utils"
)

// ProposalRESTHandler returns a ProposalRESTHandler that exposes the param
// change REST handler with a given sub-route.
func ProposalRESTHandler(cliCtx context.CLIContext) govRest.ProposalRESTHandler {
return govRest.ProposalRESTHandler{
func ProposalRESTHandler(cliCtx context.CLIContext) govrest.ProposalRESTHandler {
return govrest.ProposalRESTHandler{
SubRoute: "param_change",
Handler: postProposalHandlerFn(cliCtx),
}
}

func postProposalHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req paramsUtils.ParamChangeProposalReq
var req paramscutils.ParamChangeProposalReq
if !rest.ReadRESTReq(w, r, cliCtx.Codec, &req) {
return
}
Expand All @@ -35,14 +34,14 @@ func postProposalHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return
}

content := paramsTypes.NewParameterChangeProposal(req.Title, req.Description, req.Changes.ToParamChanges())
content := params.NewParameterChangeProposal(req.Title, req.Description, req.Changes.ToParamChanges())

msg := govTypes.NewMsgSubmitProposal(content, req.Deposit, req.Proposer, req.Validator)
msg := gov.NewMsgSubmitProposal(content, req.Deposit, req.Proposer)
if err := msg.ValidateBasic(); err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
}

restClient.WriteGenerateStdTxResponse(w, cliCtx, req.BaseReq, []sdk.Msg{msg})
utils.WriteGenerateStdTxResponse(w, cliCtx, req.BaseReq, []sdk.Msg{msg})
}
}
40 changes: 18 additions & 22 deletions params/client/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ import (

"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/maticnetwork/heimdall/params/types"
hmTypes "github.com/maticnetwork/heimdall/types"
"github.com/maticnetwork/heimdall/types/rest"
"github.com/cosmos/cosmos-sdk/types/rest"
"github.com/cosmos/cosmos-sdk/x/params"
)

type (
Expand All @@ -22,49 +20,47 @@ type (
ParamChangeJSON struct {
Subspace string `json:"subspace" yaml:"subspace"`
Key string `json:"key" yaml:"key"`
Subkey string `json:"subkey,omitempty" yaml:"subkey,omitempty"`
Value json.RawMessage `json:"value" yaml:"value"`
}

// ParamChangeProposalJSON defines a ParameterChangeProposal with a deposit used
// to parse parameter change proposals from a JSON file.
ParamChangeProposalJSON struct {
Title string `json:"title" yaml:"title"`
Description string `json:"description" yaml:"description"`
Changes ParamChangesJSON `json:"changes" yaml:"changes"`
Deposit sdk.Coins `json:"deposit" yaml:"deposit"`
Validator hmTypes.ValidatorID `json:"validator" yaml:"validator"`
Title string `json:"title" yaml:"title"`
Description string `json:"description" yaml:"description"`
Changes ParamChangesJSON `json:"changes" yaml:"changes"`
Deposit sdk.Coins `json:"deposit" yaml:"deposit"`
}

// ParamChangeProposalReq defines a parameter change proposal request body.
ParamChangeProposalReq struct {
BaseReq rest.BaseReq `json:"base_req" yaml:"base_req"`

Title string `json:"title" yaml:"title"`
Description string `json:"description" yaml:"description"`
Changes ParamChangesJSON `json:"changes" yaml:"changes"`
Proposer hmTypes.HeimdallAddress `json:"proposer" yaml:"proposer"`
Deposit sdk.Coins `json:"deposit" yaml:"deposit"`
Validator hmTypes.ValidatorID `json:"validator" yaml:"validator"`
Title string `json:"title" yaml:"title"`
Description string `json:"description" yaml:"description"`
Changes ParamChangesJSON `json:"changes" yaml:"changes"`
Proposer sdk.AccAddress `json:"proposer" yaml:"proposer"`
Deposit sdk.Coins `json:"deposit" yaml:"deposit"`
}
)

func NewParamChangeJSON(subspace string, key string, value json.RawMessage) ParamChangeJSON {
return ParamChangeJSON{subspace, key, value}
func NewParamChangeJSON(subspace, key, subkey string, value json.RawMessage) ParamChangeJSON {
return ParamChangeJSON{subspace, key, subkey, value}
}

// ToParamChange converts a ParamChangeJSON object to ParamChange.
func (pcj ParamChangeJSON) ToParamChange() types.ParamChange {
return types.NewParamChange(pcj.Subspace, pcj.Key, string(pcj.Value))
func (pcj ParamChangeJSON) ToParamChange() params.ParamChange {
return params.NewParamChangeWithSubkey(pcj.Subspace, pcj.Key, pcj.Subkey, string(pcj.Value))
}

// ToParamChanges converts a slice of ParamChangeJSON objects to a slice of
// ParamChange.
func (pcj ParamChangesJSON) ToParamChanges() []types.ParamChange {
res := make([]types.ParamChange, len(pcj))
func (pcj ParamChangesJSON) ToParamChanges() []params.ParamChange {
res := make([]params.ParamChange, len(pcj))
for i, pc := range pcj {
res[i] = pc.ToParamChange()
}

return res
}

Expand Down
13 changes: 6 additions & 7 deletions params/client/utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,28 @@ import (
)

func TestNewParamChangeJSON(t *testing.T) {
t.Parallel()

pcj := NewParamChangeJSON("subspace", "key", json.RawMessage(`{}`))
pcj := NewParamChangeJSON("subspace", "key", "subkey", json.RawMessage(`{}`))
require.Equal(t, "subspace", pcj.Subspace)
require.Equal(t, "key", pcj.Key)
require.Equal(t, "subkey", pcj.Subkey)
require.Equal(t, json.RawMessage(`{}`), pcj.Value)
}

func TestToParamChanges(t *testing.T) {
t.Parallel()

pcj1 := NewParamChangeJSON("subspace", "key1", json.RawMessage(`{}`))
pcj2 := NewParamChangeJSON("subspace", "key2", json.RawMessage(`{}`))
pcj1 := NewParamChangeJSON("subspace", "key1", "", json.RawMessage(`{}`))
pcj2 := NewParamChangeJSON("subspace", "key2", "", json.RawMessage(`{}`))
pcjs := ParamChangesJSON{pcj1, pcj2}

paramChanges := pcjs.ToParamChanges()
require.Len(t, paramChanges, 2)

require.Equal(t, paramChanges[0].Subspace, pcj1.Subspace)
require.Equal(t, paramChanges[0].Key, pcj1.Key)
require.Equal(t, paramChanges[0].Subkey, pcj1.Subkey)
require.Equal(t, paramChanges[0].Value, string(pcj1.Value))

require.Equal(t, paramChanges[1].Subspace, pcj2.Subspace)
require.Equal(t, paramChanges[1].Key, pcj2.Key)
require.Equal(t, paramChanges[1].Subkey, pcj2.Subkey)
require.Equal(t, paramChanges[1].Value, string(pcj2.Value))
}
18 changes: 9 additions & 9 deletions params/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (

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

"github.com/maticnetwork/heimdall/params/subspace"
"github.com/maticnetwork/heimdall/params/types"
"github.com/tendermint/tendermint/libs/log"
)

Expand All @@ -17,7 +17,7 @@ type Keeper struct {
key sdk.StoreKey
tkey sdk.StoreKey
codespace sdk.CodespaceType
spaces map[string]*subspace.Subspace
spaces map[string]*Subspace
}

// NewKeeper constructs a params keeper
Expand All @@ -27,7 +27,7 @@ func NewKeeper(cdc *codec.Codec, key *sdk.KVStoreKey, tkey *sdk.TransientStoreKe
key: key,
tkey: tkey,
codespace: codespace,
spaces: make(map[string]*subspace.Subspace),
spaces: make(map[string]*Subspace),
}

return k
Expand All @@ -38,8 +38,8 @@ func (k Keeper) Logger(ctx sdk.Context) log.Logger {
return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName))
}

// Subspace allocate subspace used for keepers
func (k Keeper) Subspace(s string) subspace.Subspace {
// Allocate subspace used for keepers
func (k Keeper) Subspace(s string) Subspace {
_, ok := k.spaces[s]
if ok {
panic("subspace already occupied")
Expand All @@ -55,11 +55,11 @@ func (k Keeper) Subspace(s string) subspace.Subspace {
return space
}

// GetSubspace existing substore from keeper
func (k Keeper) GetSubspace(s string) (subspace.Subspace, bool) {
// Get existing substore from keeper
func (k Keeper) GetSubspace(s string) (Subspace, bool) {
space, ok := k.spaces[s]
if !ok {
return subspace.Subspace{}, false
return Subspace{}, false
}
return *space, ok
}
Loading
Loading