Enable proto JSON for genesis (#7000)

* Enable proto JSON for genesis

* Test fixes

* Cleanup

* Cleanup

* Cleanup

* Update CHANGELOG.md

* Protogen

Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>
Co-authored-by: SaReN <sahithnarahari@gmail.com>
This commit is contained in:
Aaron Craelius 2020-08-11 10:22:30 -04:00 committed by GitHub
parent 1744194e71
commit 20c5ee3624
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
71 changed files with 918 additions and 932 deletions

View File

@ -62,6 +62,7 @@ older clients.
* (client/keys) [\#5889](https://github.com/cosmos/cosmos-sdk/pull/5889) Remove `keys update` command. * (client/keys) [\#5889](https://github.com/cosmos/cosmos-sdk/pull/5889) Remove `keys update` command.
* (x/evidence) [\#5952](https://github.com/cosmos/cosmos-sdk/pull/5952) Remove CLI and REST handlers for querying `x/evidence` parameters. * (x/evidence) [\#5952](https://github.com/cosmos/cosmos-sdk/pull/5952) Remove CLI and REST handlers for querying `x/evidence` parameters.
* (server) [\#5982](https://github.com/cosmos/cosmos-sdk/pull/5982) `--pruning` now must be set to `custom` if you want to customise the granular options. * (server) [\#5982](https://github.com/cosmos/cosmos-sdk/pull/5982) `--pruning` now must be set to `custom` if you want to customise the granular options.
* (x/gov) [\#7000](https://github.com/cosmos/cosmos-sdk/pull/7000) `ProposalStatus` is now JSON serialized using its protobuf name, so expect names like `PROPOSAL_STATUS_DEPOSIT_PERIOD` as opposed to `DepositPeriod`.
### API Breaking Changes ### API Breaking Changes
@ -153,6 +154,8 @@ be used to retrieve the actual proposal `Content`. Also the `NewMsgSubmitProposa
* (crypto) [\#6780](https://github.com/cosmos/cosmos-sdk/issues/6780) Move ledger code to its own package. * (crypto) [\#6780](https://github.com/cosmos/cosmos-sdk/issues/6780) Move ledger code to its own package.
* (modules) [\#6834](https://github.com/cosmos/cosmos-sdk/issues/6834) Add `RegisterInterfaces` method to `AppModuleBasic` to support registration of protobuf interface types. * (modules) [\#6834](https://github.com/cosmos/cosmos-sdk/issues/6834) Add `RegisterInterfaces` method to `AppModuleBasic` to support registration of protobuf interface types.
* (modules) [\#6734](https://github.com/cosmos/cosmos-sdk/issues/6834) Add `TxEncodingConfig` parameter to `AppModuleBasic.ValidateGenesis` command to support JSON tx decoding in `genutil`. * (modules) [\#6734](https://github.com/cosmos/cosmos-sdk/issues/6834) Add `TxEncodingConfig` parameter to `AppModuleBasic.ValidateGenesis` command to support JSON tx decoding in `genutil`.
* (genesis) [\#7000](https://github.com/cosmos/cosmos-sdk/pull/7000) The root `GenesisState` is now decoded using `encoding/json` instead of amino so `int64` and `uint64` types are now encoded as integers as opposed to strings.
### Features ### Features

2
go.sum
View File

@ -41,8 +41,6 @@ github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hC
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da h1:8GUt8eRujhVEGZFFEjBj46YV4rDjvGrNxb0KMWYkL2I= github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da h1:8GUt8eRujhVEGZFFEjBj46YV4rDjvGrNxb0KMWYkL2I=
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY= github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=
github.com/armon/go-metrics v0.3.3 h1:a9F4rlj7EWWrbj7BYw8J8+x+ZZkJeqzNyRk8hdPF+ro=
github.com/armon/go-metrics v0.3.3/go.mod h1:4O98XIr/9W0sxpJ8UaYkvjk10Iff7SnFrb4QAOwNTFc=
github.com/armon/go-metrics v0.3.4 h1:Xqf+7f2Vhl9tsqDYmXhnXInUdcrtgpRNpIA15/uldSc= github.com/armon/go-metrics v0.3.4 h1:Xqf+7f2Vhl9tsqDYmXhnXInUdcrtgpRNpIA15/uldSc=
github.com/armon/go-metrics v0.3.4/go.mod h1:4O98XIr/9W0sxpJ8UaYkvjk10Iff7SnFrb4QAOwNTFc= github.com/armon/go-metrics v0.3.4/go.mod h1:4O98XIr/9W0sxpJ8UaYkvjk10Iff7SnFrb4QAOwNTFc=
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=

View File

@ -79,8 +79,6 @@ message Proposal {
// ProposalStatus is a type alias that represents a proposal status as a byte // ProposalStatus is a type alias that represents a proposal status as a byte
enum ProposalStatus { enum ProposalStatus {
option (gogoproto.enum_stringer) = false;
option (gogoproto.goproto_enum_stringer) = false;
option (gogoproto.goproto_enum_prefix) = false; option (gogoproto.goproto_enum_prefix) = false;
// PROPOSAL_STATUS_UNSPECIFIED defines the default propopsal status. // PROPOSAL_STATUS_UNSPECIFIED defines the default propopsal status.

View File

@ -3,6 +3,7 @@ package server
// DONTCOVER // DONTCOVER
import ( import (
"encoding/json"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"os" "os"
@ -10,9 +11,7 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
tmtypes "github.com/tendermint/tendermint/types" tmtypes "github.com/tendermint/tendermint/types"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/server/types" "github.com/cosmos/cosmos-sdk/server/types"
sdk "github.com/cosmos/cosmos-sdk/types" sdk "github.com/cosmos/cosmos-sdk/types"
) )
@ -29,9 +28,6 @@ func ExportCmd(appExporter types.AppExporter, defaultNodeHome string) *cobra.Com
Use: "export", Use: "export",
Short: "Export state to JSON", Short: "Export state to JSON",
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
cdc := clientCtx.JSONMarshaler
serverCtx := GetServerContextFromCmd(cmd) serverCtx := GetServerContextFromCmd(cmd)
config := serverCtx.Config config := serverCtx.Config
@ -94,7 +90,10 @@ func ExportCmd(appExporter types.AppExporter, defaultNodeHome string) *cobra.Com
}, },
} }
encoded, err := codec.MarshalJSONIndent(cdc, doc) // NOTE: for now we're just using standard JSON marshaling for the root GenesisDoc.
// These types are in Tendermint, don't support proto and as far as we know, don't need it.
// All of the protobuf/amino state is inside AppState
encoded, err := json.MarshalIndent(doc, "", " ")
if err != nil { if err != nil {
return err return err
} }

View File

@ -19,7 +19,6 @@ import (
"github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/simapp" "github.com/cosmos/cosmos-sdk/simapp"
"github.com/cosmos/cosmos-sdk/testutil" "github.com/cosmos/cosmos-sdk/testutil"
"github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/errors"
@ -36,14 +35,14 @@ func TestExportCmd_ConsensusParams(t *testing.T) {
} }
db := dbm.NewMemDB() db := dbm.NewMemDB()
app := simapp.NewSimApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, map[int64]bool{}, tempDir, 0) app := simapp.NewSimApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, map[int64]bool{}, tempDir, 0, simapp.MakeEncodingConfig())
serverCtx := NewDefaultContext() serverCtx := NewDefaultContext()
serverCtx.Config.RootDir = tempDir serverCtx.Config.RootDir = tempDir
clientCtx := client.Context{}.WithJSONMarshaler(app.LegacyAmino()) clientCtx := client.Context{}.WithJSONMarshaler(app.AppCodec())
genDoc := newDefaultGenesisDoc(app.LegacyAmino()) genDoc := newDefaultGenesisDoc()
err = saveGenesisFile(genDoc, serverCtx.Config.GenesisFile()) err = saveGenesisFile(genDoc, serverCtx.Config.GenesisFile())
app.InitChain( app.InitChain(
@ -71,7 +70,7 @@ func TestExportCmd_ConsensusParams(t *testing.T) {
require.NoError(t, cmd.ExecuteContext(ctx)) require.NoError(t, cmd.ExecuteContext(ctx))
var exportedGenDoc tmtypes.GenesisDoc var exportedGenDoc tmtypes.GenesisDoc
err = app.LegacyAmino().UnmarshalJSON(output.Bytes(), &exportedGenDoc) err = json.Unmarshal(output.Bytes(), &exportedGenDoc)
if err != nil { if err != nil {
t.Fatalf("error unmarshaling exported genesis doc: %s", err) t.Fatalf("error unmarshaling exported genesis doc: %s", err)
} }
@ -90,10 +89,10 @@ func createConfigFolder(dir string) error {
return os.Mkdir(path.Join(dir, "config"), 0700) return os.Mkdir(path.Join(dir, "config"), 0700)
} }
func newDefaultGenesisDoc(cdc *codec.LegacyAmino) *tmtypes.GenesisDoc { func newDefaultGenesisDoc() *tmtypes.GenesisDoc {
genesisState := simapp.NewDefaultGenesisState() genesisState := simapp.NewDefaultGenesisState()
stateBytes, err := codec.MarshalJSONIndent(cdc, genesisState) stateBytes, err := json.MarshalIndent(genesisState, "", " ")
if err != nil { if err != nil {
panic(err) panic(err)
} }

View File

@ -4,8 +4,6 @@ import (
"io" "io"
"os" "os"
"github.com/cosmos/cosmos-sdk/codec/types"
abci "github.com/tendermint/tendermint/abci/types" abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/libs/log" "github.com/tendermint/tendermint/libs/log"
tmos "github.com/tendermint/tendermint/libs/os" tmos "github.com/tendermint/tendermint/libs/os"
@ -14,7 +12,9 @@ import (
"github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client/rpc" "github.com/cosmos/cosmos-sdk/client/rpc"
"github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/server/api" "github.com/cosmos/cosmos-sdk/server/api"
simappparams "github.com/cosmos/cosmos-sdk/simapp/params"
"github.com/cosmos/cosmos-sdk/std" "github.com/cosmos/cosmos-sdk/std"
"github.com/cosmos/cosmos-sdk/testutil/testdata" "github.com/cosmos/cosmos-sdk/testutil/testdata"
sdk "github.com/cosmos/cosmos-sdk/types" sdk "github.com/cosmos/cosmos-sdk/types"
@ -169,11 +169,10 @@ type SimApp struct {
// NewSimApp returns a reference to an initialized SimApp. // NewSimApp returns a reference to an initialized SimApp.
func NewSimApp( func NewSimApp(
logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest bool, skipUpgradeHeights map[int64]bool, logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest bool, skipUpgradeHeights map[int64]bool,
homePath string, invCheckPeriod uint, baseAppOptions ...func(*baseapp.BaseApp), homePath string, invCheckPeriod uint, encodingConfig simappparams.EncodingConfig, baseAppOptions ...func(*baseapp.BaseApp),
) *SimApp { ) *SimApp {
// TODO: Remove cdc in favor of appCodec once all modules are migrated. // TODO: Remove cdc in favor of appCodec once all modules are migrated.
encodingConfig := MakeEncodingConfig()
appCodec := encodingConfig.Marshaler appCodec := encodingConfig.Marshaler
cdc := encodingConfig.Amino cdc := encodingConfig.Amino
interfaceRegistry := encodingConfig.InterfaceRegistry interfaceRegistry := encodingConfig.InterfaceRegistry
@ -417,7 +416,7 @@ func (app *SimApp) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci.Re
func (app *SimApp) InitChainer(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain { func (app *SimApp) InitChainer(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain {
var genesisState GenesisState var genesisState GenesisState
app.cdc.MustUnmarshalJSON(req.AppStateBytes, &genesisState) app.cdc.MustUnmarshalJSON(req.AppStateBytes, &genesisState)
return app.mm.InitGenesis(ctx, app.cdc, genesisState) return app.mm.InitGenesis(ctx, app.appCodec, genesisState)
} }
// LoadHeight loads a particular height // LoadHeight loads a particular height

View File

@ -15,7 +15,7 @@ import (
func TestSimAppExport(t *testing.T) { func TestSimAppExport(t *testing.T) {
db := dbm.NewMemDB() db := dbm.NewMemDB()
app := NewSimApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0) app := NewSimApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, MakeEncodingConfig())
genesisState := NewDefaultGenesisState() genesisState := NewDefaultGenesisState()
stateBytes, err := codec.MarshalJSONIndent(app.LegacyAmino(), genesisState) stateBytes, err := codec.MarshalJSONIndent(app.LegacyAmino(), genesisState)
@ -31,7 +31,7 @@ func TestSimAppExport(t *testing.T) {
app.Commit() app.Commit()
// Making a new app object with the db, so that initchain hasn't been called // Making a new app object with the db, so that initchain hasn't been called
app2 := NewSimApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0) app2 := NewSimApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, MakeEncodingConfig())
_, _, _, err = app2.ExportAppStateAndValidators(false, []string{}) _, _, _, err = app2.ExportAppStateAndValidators(false, []string{})
require.NoError(t, err, "ExportAppStateAndValidators should not have an error") require.NoError(t, err, "ExportAppStateAndValidators should not have an error")
} }
@ -39,7 +39,7 @@ func TestSimAppExport(t *testing.T) {
// ensure that blocked addresses are properly set in bank keeper // ensure that blocked addresses are properly set in bank keeper
func TestBlockedAddrs(t *testing.T) { func TestBlockedAddrs(t *testing.T) {
db := dbm.NewMemDB() db := dbm.NewMemDB()
app := NewSimApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0) app := NewSimApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, MakeEncodingConfig())
for acc := range maccPerms { for acc := range maccPerms {
require.Equal(t, !allowedReceivingModAcc[acc], app.BankKeeper.BlockedAddr(app.AccountKeeper.GetModuleAddress(acc))) require.Equal(t, !allowedReceivingModAcc[acc], app.BankKeeper.BlockedAddr(app.AccountKeeper.GetModuleAddress(acc)))

View File

@ -7,7 +7,6 @@ import (
abci "github.com/tendermint/tendermint/abci/types" abci "github.com/tendermint/tendermint/abci/types"
tmtypes "github.com/tendermint/tendermint/types" tmtypes "github.com/tendermint/tendermint/types"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types" sdk "github.com/cosmos/cosmos-sdk/types"
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
"github.com/cosmos/cosmos-sdk/x/staking" "github.com/cosmos/cosmos-sdk/x/staking"
@ -28,8 +27,8 @@ func (app *SimApp) ExportAppStateAndValidators(
app.prepForZeroHeightGenesis(ctx, jailWhiteList) app.prepForZeroHeightGenesis(ctx, jailWhiteList)
} }
genState := app.mm.ExportGenesis(ctx, app.cdc) genState := app.mm.ExportGenesis(ctx, app.appCodec)
appState, err = codec.MarshalJSONIndent(app.cdc, genState) appState, err = json.MarshalIndent(genState, "", " ")
if err != nil { if err != nil {
return nil, nil, nil, err return nil, nil, nil, err
} }

View File

@ -2,8 +2,6 @@ package simapp
import ( import (
"encoding/json" "encoding/json"
"github.com/cosmos/cosmos-sdk/std"
) )
// The genesis state of the blockchain is represented here as a map of raw json // The genesis state of the blockchain is represented here as a map of raw json
@ -17,6 +15,6 @@ type GenesisState map[string]json.RawMessage
// NewDefaultGenesisState generates the default state for the application. // NewDefaultGenesisState generates the default state for the application.
func NewDefaultGenesisState() GenesisState { func NewDefaultGenesisState() GenesisState {
cdc := std.MakeCodec(ModuleBasics) encCfg := MakeEncodingConfig()
return ModuleBasics.DefaultGenesis(cdc) return ModuleBasics.DefaultGenesis(encCfg.Marshaler)
} }

View File

@ -26,7 +26,7 @@ func BenchmarkFullAppSimulation(b *testing.B) {
} }
}() }()
app := NewSimApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, FlagPeriodValue, interBlockCacheOpt()) app := NewSimApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, FlagPeriodValue, MakeEncodingConfig(), interBlockCacheOpt())
// run randomized simulation // run randomized simulation
_, simParams, simErr := simulation.SimulateFromSeed( _, simParams, simErr := simulation.SimulateFromSeed(
@ -65,7 +65,7 @@ func BenchmarkInvariants(b *testing.B) {
} }
}() }()
app := NewSimApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, FlagPeriodValue, interBlockCacheOpt()) app := NewSimApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, FlagPeriodValue, MakeEncodingConfig(), interBlockCacheOpt())
// run randomized simulation // run randomized simulation
_, simParams, simErr := simulation.SimulateFromSeed( _, simParams, simErr := simulation.SimulateFromSeed(

View File

@ -67,7 +67,7 @@ func TestFullAppSimulation(t *testing.T) {
require.NoError(t, os.RemoveAll(dir)) require.NoError(t, os.RemoveAll(dir))
}() }()
app := NewSimApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, FlagPeriodValue, fauxMerkleModeOpt) app := NewSimApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, FlagPeriodValue, MakeEncodingConfig(), fauxMerkleModeOpt)
require.Equal(t, "SimApp", app.Name()) require.Equal(t, "SimApp", app.Name())
// run randomized simulation // run randomized simulation
@ -99,7 +99,7 @@ func TestAppImportExport(t *testing.T) {
require.NoError(t, os.RemoveAll(dir)) require.NoError(t, os.RemoveAll(dir))
}() }()
app := NewSimApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, FlagPeriodValue, fauxMerkleModeOpt) app := NewSimApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, FlagPeriodValue, MakeEncodingConfig(), fauxMerkleModeOpt)
require.Equal(t, "SimApp", app.Name()) require.Equal(t, "SimApp", app.Name())
// Run randomized simulation // Run randomized simulation
@ -133,7 +133,7 @@ func TestAppImportExport(t *testing.T) {
require.NoError(t, os.RemoveAll(newDir)) require.NoError(t, os.RemoveAll(newDir))
}() }()
newApp := NewSimApp(log.NewNopLogger(), newDB, nil, true, map[int64]bool{}, DefaultNodeHome, FlagPeriodValue, fauxMerkleModeOpt) newApp := NewSimApp(log.NewNopLogger(), newDB, nil, true, map[int64]bool{}, DefaultNodeHome, FlagPeriodValue, MakeEncodingConfig(), fauxMerkleModeOpt)
require.Equal(t, "SimApp", newApp.Name()) require.Equal(t, "SimApp", newApp.Name())
var genesisState GenesisState var genesisState GenesisState
@ -190,7 +190,7 @@ func TestAppSimulationAfterImport(t *testing.T) {
require.NoError(t, os.RemoveAll(dir)) require.NoError(t, os.RemoveAll(dir))
}() }()
app := NewSimApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, FlagPeriodValue, fauxMerkleModeOpt) app := NewSimApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, FlagPeriodValue, MakeEncodingConfig(), fauxMerkleModeOpt)
require.Equal(t, "SimApp", app.Name()) require.Equal(t, "SimApp", app.Name())
// Run randomized simulation // Run randomized simulation
@ -229,7 +229,7 @@ func TestAppSimulationAfterImport(t *testing.T) {
require.NoError(t, os.RemoveAll(newDir)) require.NoError(t, os.RemoveAll(newDir))
}() }()
newApp := NewSimApp(log.NewNopLogger(), newDB, nil, true, map[int64]bool{}, DefaultNodeHome, FlagPeriodValue, fauxMerkleModeOpt) newApp := NewSimApp(log.NewNopLogger(), newDB, nil, true, map[int64]bool{}, DefaultNodeHome, FlagPeriodValue, MakeEncodingConfig(), fauxMerkleModeOpt)
require.Equal(t, "SimApp", newApp.Name()) require.Equal(t, "SimApp", newApp.Name())
newApp.InitChain(abci.RequestInitChain{ newApp.InitChain(abci.RequestInitChain{
@ -274,7 +274,7 @@ func TestAppStateDeterminism(t *testing.T) {
} }
db := dbm.NewMemDB() db := dbm.NewMemDB()
app := NewSimApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, FlagPeriodValue, interBlockCacheOpt()) app := NewSimApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, FlagPeriodValue, MakeEncodingConfig(), interBlockCacheOpt())
fmt.Printf( fmt.Printf(
"running non-determinism simulation; seed %d: %d/%d, attempt: %d/%d\n", "running non-determinism simulation; seed %d: %d/%d, attempt: %d/%d\n",

View File

@ -6,6 +6,8 @@ import (
"io" "io"
"os" "os"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/spf13/cast" "github.com/spf13/cast"
"github.com/spf13/cobra" "github.com/spf13/cobra"
abci "github.com/tendermint/tendermint/abci/types" abci "github.com/tendermint/tendermint/abci/types"
@ -77,12 +79,12 @@ func init() {
authclient.Codec = encodingConfig.Marshaler authclient.Codec = encodingConfig.Marshaler
rootCmd.AddCommand( rootCmd.AddCommand(
genutilcli.InitCmd(simapp.ModuleBasics, simapp.DefaultNodeHome), withProtoJSON(genutilcli.InitCmd(simapp.ModuleBasics, simapp.DefaultNodeHome)),
genutilcli.CollectGenTxsCmd(banktypes.GenesisBalancesIterator{}, simapp.DefaultNodeHome), withProtoJSON(genutilcli.CollectGenTxsCmd(banktypes.GenesisBalancesIterator{}, simapp.DefaultNodeHome)),
genutilcli.MigrateGenesisCmd(), genutilcli.MigrateGenesisCmd(),
genutilcli.GenTxCmd(simapp.ModuleBasics, encodingConfig.TxConfig, banktypes.GenesisBalancesIterator{}, simapp.DefaultNodeHome), withProtoJSON(genutilcli.GenTxCmd(simapp.ModuleBasics, encodingConfig.TxConfig, banktypes.GenesisBalancesIterator{}, simapp.DefaultNodeHome)),
genutilcli.ValidateGenesisCmd(simapp.ModuleBasics, encodingConfig.TxConfig), withProtoJSON(genutilcli.ValidateGenesisCmd(simapp.ModuleBasics, encodingConfig.TxConfig)),
AddGenesisAccountCmd(simapp.DefaultNodeHome), withProtoJSON(AddGenesisAccountCmd(simapp.DefaultNodeHome)),
tmcli.NewCompletionCmd(rootCmd, true), tmcli.NewCompletionCmd(rootCmd, true),
testnetCmd(simapp.ModuleBasics, banktypes.GenesisBalancesIterator{}), testnetCmd(simapp.ModuleBasics, banktypes.GenesisBalancesIterator{}),
debug.Cmd(), debug.Cmd(),
@ -171,6 +173,7 @@ func newApp(logger log.Logger, db dbm.DB, traceStore io.Writer, appOpts serverty
logger, db, traceStore, true, skipUpgradeHeights, logger, db, traceStore, true, skipUpgradeHeights,
cast.ToString(appOpts.Get(flags.FlagHome)), cast.ToString(appOpts.Get(flags.FlagHome)),
cast.ToUint(appOpts.Get(server.FlagInvCheckPeriod)), cast.ToUint(appOpts.Get(server.FlagInvCheckPeriod)),
encodingConfig,
baseapp.SetPruning(pruningOpts), baseapp.SetPruning(pruningOpts),
baseapp.SetMinGasPrices(cast.ToString(appOpts.Get(server.FlagMinGasPrices))), baseapp.SetMinGasPrices(cast.ToString(appOpts.Get(server.FlagMinGasPrices))),
baseapp.SetHaltHeight(cast.ToUint64(appOpts.Get(server.FlagHaltHeight))), baseapp.SetHaltHeight(cast.ToUint64(appOpts.Get(server.FlagHaltHeight))),
@ -184,16 +187,42 @@ func exportAppStateAndTMValidators(
logger log.Logger, db dbm.DB, traceStore io.Writer, height int64, forZeroHeight bool, jailWhiteList []string, logger log.Logger, db dbm.DB, traceStore io.Writer, height int64, forZeroHeight bool, jailWhiteList []string,
) (json.RawMessage, []tmtypes.GenesisValidator, *abci.ConsensusParams, error) { ) (json.RawMessage, []tmtypes.GenesisValidator, *abci.ConsensusParams, error) {
encCfg := simapp.MakeEncodingConfig()
encCfg.Marshaler = codec.NewProtoCodec(encCfg.InterfaceRegistry)
var simApp *simapp.SimApp var simApp *simapp.SimApp
if height != -1 { if height != -1 {
simApp = simapp.NewSimApp(logger, db, traceStore, false, map[int64]bool{}, "", uint(1)) simApp = simapp.NewSimApp(logger, db, traceStore, false, map[int64]bool{}, "", uint(1), encCfg)
if err := simApp.LoadHeight(height); err != nil { if err := simApp.LoadHeight(height); err != nil {
return nil, nil, nil, err return nil, nil, nil, err
} }
} else { } else {
simApp = simapp.NewSimApp(logger, db, traceStore, true, map[int64]bool{}, "", uint(1)) simApp = simapp.NewSimApp(logger, db, traceStore, true, map[int64]bool{}, "", uint(1), encCfg)
} }
return simApp.ExportAppStateAndValidators(forZeroHeight, jailWhiteList) return simApp.ExportAppStateAndValidators(forZeroHeight, jailWhiteList)
} }
// This is a temporary command middleware to enable proto JSON marshaling for testing.
// Once proto JSON works everywhere we can remove this and set ProtoCodec as default
func withProtoJSON(command *cobra.Command) *cobra.Command {
existing := command.PersistentPreRunE
if existing != nil {
command.PersistentPreRunE = func(cmd *cobra.Command, args []string) error {
err := existing(cmd, args)
if err != nil {
return err
}
return setProtoJSON(cmd, args)
}
} else {
command.PersistentPreRunE = setProtoJSON
}
return command
}
func setProtoJSON(cmd *cobra.Command, _ []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
clientCtx = clientCtx.WithJSONMarshaler(codec.NewProtoCodec(clientCtx.InterfaceRegistry))
return client.SetCmdClientContext(cmd, clientCtx)
}

View File

@ -3,6 +3,7 @@ package simapp
import ( import (
"bytes" "bytes"
"encoding/hex" "encoding/hex"
"encoding/json"
"fmt" "fmt"
"strconv" "strconv"
"testing" "testing"
@ -48,7 +49,7 @@ var DefaultConsensusParams = &abci.ConsensusParams{
// Setup initializes a new SimApp. A Nop logger is set in SimApp. // Setup initializes a new SimApp. A Nop logger is set in SimApp.
func Setup(isCheckTx bool) *SimApp { func Setup(isCheckTx bool) *SimApp {
db := dbm.NewMemDB() db := dbm.NewMemDB()
app := NewSimApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, DefaultNodeHome, 5) app := NewSimApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, DefaultNodeHome, 5, MakeEncodingConfig())
if !isCheckTx { if !isCheckTx {
// init chain must be called to stop deliverState from being nil // init chain must be called to stop deliverState from being nil
genesisState := NewDefaultGenesisState() genesisState := NewDefaultGenesisState()
@ -76,7 +77,7 @@ func Setup(isCheckTx bool) *SimApp {
// account. A Nop logger is set in SimApp. // account. A Nop logger is set in SimApp.
func SetupWithGenesisValSet(t *testing.T, valSet *tmtypes.ValidatorSet, genAccs []authtypes.GenesisAccount, balances ...banktypes.Balance) *SimApp { func SetupWithGenesisValSet(t *testing.T, valSet *tmtypes.ValidatorSet, genAccs []authtypes.GenesisAccount, balances ...banktypes.Balance) *SimApp {
db := dbm.NewMemDB() db := dbm.NewMemDB()
app := NewSimApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, DefaultNodeHome, 5) app := NewSimApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, DefaultNodeHome, 5, MakeEncodingConfig())
genesisState := NewDefaultGenesisState() genesisState := NewDefaultGenesisState()
@ -150,13 +151,13 @@ func SetupWithGenesisValSet(t *testing.T, valSet *tmtypes.ValidatorSet, genAccs
// accounts and possible balances. // accounts and possible balances.
func SetupWithGenesisAccounts(genAccs []authtypes.GenesisAccount, balances ...banktypes.Balance) *SimApp { func SetupWithGenesisAccounts(genAccs []authtypes.GenesisAccount, balances ...banktypes.Balance) *SimApp {
db := dbm.NewMemDB() db := dbm.NewMemDB()
app := NewSimApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0) app := NewSimApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, MakeEncodingConfig())
// initialize the chain with the passed in genesis accounts // initialize the chain with the passed in genesis accounts
genesisState := NewDefaultGenesisState() genesisState := NewDefaultGenesisState()
authGenesis := authtypes.NewGenesisState(authtypes.DefaultParams(), genAccs) authGenesis := authtypes.NewGenesisState(authtypes.DefaultParams(), genAccs)
genesisState[authtypes.ModuleName] = app.LegacyAmino().MustMarshalJSON(authGenesis) genesisState[authtypes.ModuleName] = app.AppCodec().MustMarshalJSON(authGenesis)
totalSupply := sdk.NewCoins() totalSupply := sdk.NewCoins()
for _, b := range balances { for _, b := range balances {
@ -164,9 +165,9 @@ func SetupWithGenesisAccounts(genAccs []authtypes.GenesisAccount, balances ...ba
} }
bankGenesis := banktypes.NewGenesisState(banktypes.DefaultGenesisState().Params, balances, totalSupply, []banktypes.Metadata{}) bankGenesis := banktypes.NewGenesisState(banktypes.DefaultGenesisState().Params, balances, totalSupply, []banktypes.Metadata{})
genesisState[banktypes.ModuleName] = app.LegacyAmino().MustMarshalJSON(bankGenesis) genesisState[banktypes.ModuleName] = app.AppCodec().MustMarshalJSON(bankGenesis)
stateBytes, err := codec.MarshalJSONIndent(app.LegacyAmino(), genesisState) stateBytes, err := json.MarshalIndent(genesisState, "", " ")
if err != nil { if err != nil {
panic(err) panic(err)
} }

View File

@ -53,6 +53,7 @@ type AppConstructor = func(val Validator) servertypes.Application
func NewSimApp(val Validator) servertypes.Application { func NewSimApp(val Validator) servertypes.Application {
return simapp.NewSimApp( return simapp.NewSimApp(
val.Ctx.Logger, dbm.NewMemDB(), nil, true, make(map[int64]bool), val.Ctx.Config.RootDir, 0, val.Ctx.Logger, dbm.NewMemDB(), nil, true, make(map[int64]bool), val.Ctx.Config.RootDir, 0,
simapp.MakeEncodingConfig(),
baseapp.SetPruning(storetypes.NewPruningOptionsFromString(val.AppConfig.Pruning)), baseapp.SetPruning(storetypes.NewPruningOptionsFromString(val.AppConfig.Pruning)),
baseapp.SetMinGasPrices(val.AppConfig.MinGasPrices), baseapp.SetMinGasPrices(val.AppConfig.MinGasPrices),
) )

View File

@ -1,6 +1,7 @@
package network package network
import ( import (
"encoding/json"
"path/filepath" "path/filepath"
"time" "time"
@ -13,7 +14,6 @@ import (
"github.com/tendermint/tendermint/types" "github.com/tendermint/tendermint/types"
tmtime "github.com/tendermint/tendermint/types/time" tmtime "github.com/tendermint/tendermint/types/time"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/server/api" "github.com/cosmos/cosmos-sdk/server/api"
servergrpc "github.com/cosmos/cosmos-sdk/server/grpc" servergrpc "github.com/cosmos/cosmos-sdk/server/grpc"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
@ -142,16 +142,16 @@ func initGenFiles(cfg Config, genAccounts []authtypes.GenesisAccount, genBalance
} }
authGenState.Accounts = accounts authGenState.Accounts = accounts
cfg.GenesisState[authtypes.ModuleName] = cfg.Codec.MustMarshalJSON(authGenState) cfg.GenesisState[authtypes.ModuleName] = cfg.Codec.MustMarshalJSON(&authGenState)
// set the balances in the genesis state // set the balances in the genesis state
var bankGenState banktypes.GenesisState var bankGenState banktypes.GenesisState
cfg.Codec.MustUnmarshalJSON(cfg.GenesisState[banktypes.ModuleName], &bankGenState) cfg.Codec.MustUnmarshalJSON(cfg.GenesisState[banktypes.ModuleName], &bankGenState)
bankGenState.Balances = genBalances bankGenState.Balances = genBalances
cfg.GenesisState[banktypes.ModuleName] = cfg.Codec.MustMarshalJSON(bankGenState) cfg.GenesisState[banktypes.ModuleName] = cfg.Codec.MustMarshalJSON(&bankGenState)
appGenStateJSON, err := codec.MarshalJSONIndent(cfg.Codec, cfg.GenesisState) appGenStateJSON, err := json.MarshalIndent(cfg.GenesisState, "", " ")
if err != nil { if err != nil {
return err return err
} }

View File

@ -28,7 +28,7 @@ func InitGenesis(ctx sdk.Context, ak keeper.AccountKeeper, data types.GenesisSta
} }
// ExportGenesis returns a GenesisState for a given context and keeper // ExportGenesis returns a GenesisState for a given context and keeper
func ExportGenesis(ctx sdk.Context, ak keeper.AccountKeeper) types.GenesisState { func ExportGenesis(ctx sdk.Context, ak keeper.AccountKeeper) *types.GenesisState {
params := ak.GetParams(ctx) params := ak.GetParams(ctx)
var genAccounts types.GenesisAccounts var genAccounts types.GenesisAccounts

View File

@ -26,6 +26,13 @@ func RegisterInterfaces(registry types.InterfaceRegistry) {
&BaseAccount{}, &BaseAccount{},
&ModuleAccount{}, &ModuleAccount{},
) )
registry.RegisterInterface(
"cosmos.auth.GenesisAccount",
(*GenesisAccount)(nil),
&BaseAccount{},
&ModuleAccount{},
)
} }
// RegisterKeyTypeCodec registers an external concrete type defined in // RegisterKeyTypeCodec registers an external concrete type defined in
@ -37,7 +44,7 @@ func RegisterKeyTypeCodec(o interface{}, name string) {
var ( var (
amino = codec.New() amino = codec.New()
ModuleCdc = codec.NewHybridCodec(amino, types.NewInterfaceRegistry()) ModuleCdc = codec.NewAminoCodec(amino)
) )
func init() { func init() {

View File

@ -5,6 +5,6 @@ import (
) )
var ( var (
app = simapp.Setup(false) app = simapp.Setup(false)
appCodec, _ = simapp.MakeCodecs() appCodec, legacyAmino = simapp.MakeCodecs()
) )

View File

@ -14,12 +14,12 @@ import (
var _ types.UnpackInterfacesMessage = GenesisState{} var _ types.UnpackInterfacesMessage = GenesisState{}
// NewGenesisState - Create a new genesis state // NewGenesisState - Create a new genesis state
func NewGenesisState(params Params, accounts GenesisAccounts) GenesisState { func NewGenesisState(params Params, accounts GenesisAccounts) *GenesisState {
genAccounts, err := PackAccounts(accounts) genAccounts, err := PackAccounts(accounts)
if err != nil { if err != nil {
panic(err) panic(err)
} }
return GenesisState{ return &GenesisState{
Params: params, Params: params,
Accounts: genAccounts, Accounts: genAccounts,
} }
@ -38,7 +38,7 @@ func (g GenesisState) UnpackInterfaces(unpacker types.AnyUnpacker) error {
} }
// DefaultGenesisState - Return a default genesis state // DefaultGenesisState - Return a default genesis state
func DefaultGenesisState() GenesisState { func DefaultGenesisState() *GenesisState {
return NewGenesisState(DefaultParams(), GenesisAccounts{}) return NewGenesisState(DefaultParams(), GenesisAccounts{})
} }

View File

@ -27,12 +27,20 @@ func RegisterInterfaces(registry types.InterfaceRegistry) {
&DelayedVestingAccount{}, &DelayedVestingAccount{},
&PeriodicVestingAccount{}, &PeriodicVestingAccount{},
) )
registry.RegisterImplementations( registry.RegisterImplementations(
(*authtypes.AccountI)(nil), (*authtypes.AccountI)(nil),
&DelayedVestingAccount{}, &DelayedVestingAccount{},
&ContinuousVestingAccount{}, &ContinuousVestingAccount{},
&PeriodicVestingAccount{}, &PeriodicVestingAccount{},
) )
registry.RegisterImplementations(
(*authtypes.GenesisAccount)(nil),
&DelayedVestingAccount{},
&ContinuousVestingAccount{},
&PeriodicVestingAccount{},
)
} }
var amino = codec.New() var amino = codec.New()

View File

@ -34,7 +34,7 @@ func (k BaseKeeper) InitGenesis(ctx sdk.Context, genState types.GenesisState) {
} }
// ExportGenesis returns the bank module's genesis state. // ExportGenesis returns the bank module's genesis state.
func (k BaseKeeper) ExportGenesis(ctx sdk.Context) types.GenesisState { func (k BaseKeeper) ExportGenesis(ctx sdk.Context) *types.GenesisState {
return types.NewGenesisState( return types.NewGenesisState(
k.GetParams(ctx), k.GetParams(ctx),
k.GetAccountsBalances(ctx), k.GetAccountsBalances(ctx),

View File

@ -23,7 +23,7 @@ type Keeper interface {
SendKeeper SendKeeper
InitGenesis(sdk.Context, types.GenesisState) InitGenesis(sdk.Context, types.GenesisState)
ExportGenesis(sdk.Context) types.GenesisState ExportGenesis(sdk.Context) *types.GenesisState
GetSupply(ctx sdk.Context) exported.SupplyI GetSupply(ctx sdk.Context) exported.SupplyI
SetSupply(ctx sdk.Context, supply exported.SupplyI) SetSupply(ctx sdk.Context, supply exported.SupplyI)

View File

@ -46,8 +46,8 @@ func ValidateGenesis(data GenesisState) error {
} }
// NewGenesisState creates a new genesis state. // NewGenesisState creates a new genesis state.
func NewGenesisState(params Params, balances []Balance, supply sdk.Coins, denomMetaData []Metadata) GenesisState { func NewGenesisState(params Params, balances []Balance, supply sdk.Coins, denomMetaData []Metadata) *GenesisState {
return GenesisState{ return &GenesisState{
Params: params, Params: params,
Balances: balances, Balances: balances,
Supply: supply, Supply: supply,
@ -56,20 +56,20 @@ func NewGenesisState(params Params, balances []Balance, supply sdk.Coins, denomM
} }
// DefaultGenesisState returns a default bank module genesis state. // DefaultGenesisState returns a default bank module genesis state.
func DefaultGenesisState() GenesisState { func DefaultGenesisState() *GenesisState {
return NewGenesisState(DefaultParams(), []Balance{}, DefaultSupply().GetTotal(), []Metadata{}) return NewGenesisState(DefaultParams(), []Balance{}, DefaultSupply().GetTotal(), []Metadata{})
} }
// GetGenesisStateFromAppState returns x/bank GenesisState given raw application // GetGenesisStateFromAppState returns x/bank GenesisState given raw application
// genesis state. // genesis state.
func GetGenesisStateFromAppState(cdc codec.JSONMarshaler, appState map[string]json.RawMessage) GenesisState { func GetGenesisStateFromAppState(cdc codec.JSONMarshaler, appState map[string]json.RawMessage) *GenesisState {
var genesisState GenesisState var genesisState GenesisState
if appState[ModuleName] != nil { if appState[ModuleName] != nil {
cdc.MustUnmarshalJSON(appState[ModuleName], &genesisState) cdc.MustUnmarshalJSON(appState[ModuleName], &genesisState)
} }
return genesisState return &genesisState
} }
// GenesisAccountIterator implements genesis account iteration. // GenesisAccountIterator implements genesis account iteration.

View File

@ -19,7 +19,7 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState)
} }
// ExportGenesis returns the capability module's exported genesis. // ExportGenesis returns the capability module's exported genesis.
func ExportGenesis(ctx sdk.Context, k keeper.Keeper) types.GenesisState { func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState {
index := k.GetLatestIndex(ctx) index := k.GetLatestIndex(ctx)
owners := []types.GenesisOwners{} owners := []types.GenesisOwners{}
@ -36,7 +36,7 @@ func ExportGenesis(ctx sdk.Context, k keeper.Keeper) types.GenesisState {
owners = append(owners, genOwner) owners = append(owners, genOwner)
} }
return types.GenesisState{ return &types.GenesisState{
Index: index, Index: index,
Owners: owners, Owners: owners,
} }

View File

@ -9,8 +9,8 @@ import (
const DefaultIndex uint64 = 1 const DefaultIndex uint64 = 1
// DefaultGenesis returns the default Capability genesis state // DefaultGenesis returns the default Capability genesis state
func DefaultGenesis() GenesisState { func DefaultGenesis() *GenesisState {
return GenesisState{ return &GenesisState{
Index: DefaultIndex, Index: DefaultIndex,
Owners: []GenesisOwners{}, Owners: []GenesisOwners{},
} }

View File

@ -120,7 +120,7 @@ func TestValidateGenesis(t *testing.T) {
for _, tc := range testCases { for _, tc := range testCases {
tc := tc tc := tc
genState := DefaultGenesis() genState := DefaultGenesis()
tc.malleate(&genState) tc.malleate(genState)
err := genState.Validate() err := genState.Validate()
if tc.expPass { if tc.expPass {
require.NoError(t, err, tc.name) require.NoError(t, err, tc.name)

View File

@ -28,7 +28,7 @@ var (
func createTestApp() (*simapp.SimApp, sdk.Context, []sdk.AccAddress) { func createTestApp() (*simapp.SimApp, sdk.Context, []sdk.AccAddress) {
db := dbm.NewMemDB() db := dbm.NewMemDB()
app := simapp.NewSimApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, simapp.DefaultNodeHome, 1) app := simapp.NewSimApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, simapp.DefaultNodeHome, 1, simapp.MakeEncodingConfig())
ctx := app.NewContext(true, abci.Header{}) ctx := app.NewContext(true, abci.Header{})
constantFee := sdk.NewInt64Coin(sdk.DefaultBondDenom, 10) constantFee := sdk.NewInt64Coin(sdk.DefaultBondDenom, 10)

View File

@ -6,12 +6,12 @@ import (
) )
// new crisis genesis // new crisis genesis
func (k Keeper) InitGenesis(ctx sdk.Context, data types.GenesisState) { func (k Keeper) InitGenesis(ctx sdk.Context, data *types.GenesisState) {
k.SetConstantFee(ctx, data.ConstantFee) k.SetConstantFee(ctx, data.ConstantFee)
} }
// ExportGenesis returns a GenesisState for a given context and keeper. // ExportGenesis returns a GenesisState for a given context and keeper.
func (k Keeper) ExportGenesis(ctx sdk.Context) types.GenesisState { func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState {
constantFee := k.GetConstantFee(ctx) constantFee := k.GetConstantFee(ctx)
return types.NewGenesisState(constantFee) return types.NewGenesisState(constantFee)
} }

View File

@ -50,7 +50,7 @@ func (AppModuleBasic) ValidateGenesis(cdc codec.JSONMarshaler, config client.TxE
return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err) return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err)
} }
return types.ValidateGenesis(data) return types.ValidateGenesis(&data)
} }
// RegisterRESTRoutes registers no REST routes for the crisis module. // RegisterRESTRoutes registers no REST routes for the crisis module.
@ -118,7 +118,7 @@ func (am AppModule) RegisterQueryService(grpc.Server) {}
func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, data json.RawMessage) []abci.ValidatorUpdate { func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, data json.RawMessage) []abci.ValidatorUpdate {
var genesisState types.GenesisState var genesisState types.GenesisState
cdc.MustUnmarshalJSON(data, &genesisState) cdc.MustUnmarshalJSON(data, &genesisState)
am.keeper.InitGenesis(ctx, genesisState) am.keeper.InitGenesis(ctx, &genesisState)
am.keeper.AssertInvariants(ctx) am.keeper.AssertInvariants(ctx)
return []abci.ValidatorUpdate{} return []abci.ValidatorUpdate{}
} }

View File

@ -7,21 +7,21 @@ import (
) )
// NewGenesisState creates a new GenesisState object // NewGenesisState creates a new GenesisState object
func NewGenesisState(constantFee sdk.Coin) GenesisState { func NewGenesisState(constantFee sdk.Coin) *GenesisState {
return GenesisState{ return &GenesisState{
ConstantFee: constantFee, ConstantFee: constantFee,
} }
} }
// DefaultGenesisState creates a default GenesisState object // DefaultGenesisState creates a default GenesisState object
func DefaultGenesisState() GenesisState { func DefaultGenesisState() *GenesisState {
return GenesisState{ return &GenesisState{
ConstantFee: sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(1000)), ConstantFee: sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(1000)),
} }
} }
// ValidateGenesis - validate crisis genesis data // ValidateGenesis - validate crisis genesis data
func ValidateGenesis(data GenesisState) error { func ValidateGenesis(data *GenesisState) error {
if !data.ConstantFee.IsPositive() { if !data.ConstantFee.IsPositive() {
return fmt.Errorf("constant fee must be positive: %s", data.ConstantFee) return fmt.Errorf("constant fee must be positive: %s", data.ConstantFee)
} }

View File

@ -60,7 +60,7 @@ func (k Keeper) InitGenesis(ctx sdk.Context, data types.GenesisState) {
} }
// ExportGenesis returns a GenesisState for a given context and keeper. // ExportGenesis returns a GenesisState for a given context and keeper.
func (k Keeper) ExportGenesis(ctx sdk.Context) types.GenesisState { func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState {
feePool := k.GetFeePool(ctx) feePool := k.GetFeePool(ctx)
params := k.GetParams(ctx) params := k.GetParams(ctx)

View File

@ -59,7 +59,7 @@ func (AppModuleBasic) ValidateGenesis(cdc codec.JSONMarshaler, config sdkclient.
return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err) return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err)
} }
return types.ValidateGenesis(data) return types.ValidateGenesis(&data)
} }
// RegisterRESTRoutes registers the REST routes for the distribution module. // RegisterRESTRoutes registers the REST routes for the distribution module.

View File

@ -8,9 +8,9 @@ func NewGenesisState(
params Params, fp FeePool, dwis []DelegatorWithdrawInfo, pp sdk.ConsAddress, r []ValidatorOutstandingRewardsRecord, params Params, fp FeePool, dwis []DelegatorWithdrawInfo, pp sdk.ConsAddress, r []ValidatorOutstandingRewardsRecord,
acc []ValidatorAccumulatedCommissionRecord, historical []ValidatorHistoricalRewardsRecord, acc []ValidatorAccumulatedCommissionRecord, historical []ValidatorHistoricalRewardsRecord,
cur []ValidatorCurrentRewardsRecord, dels []DelegatorStartingInfoRecord, slashes []ValidatorSlashEventRecord, cur []ValidatorCurrentRewardsRecord, dels []DelegatorStartingInfoRecord, slashes []ValidatorSlashEventRecord,
) GenesisState { ) *GenesisState {
return GenesisState{ return &GenesisState{
Params: params, Params: params,
FeePool: fp, FeePool: fp,
DelegatorWithdrawInfos: dwis, DelegatorWithdrawInfos: dwis,
@ -25,8 +25,8 @@ func NewGenesisState(
} }
// get raw genesis raw message for testing // get raw genesis raw message for testing
func DefaultGenesisState() GenesisState { func DefaultGenesisState() *GenesisState {
return GenesisState{ return &GenesisState{
FeePool: InitialFeePool(), FeePool: InitialFeePool(),
Params: DefaultParams(), Params: DefaultParams(),
DelegatorWithdrawInfos: []DelegatorWithdrawInfo{}, DelegatorWithdrawInfos: []DelegatorWithdrawInfo{},
@ -41,7 +41,7 @@ func DefaultGenesisState() GenesisState {
} }
// ValidateGenesis validates the genesis state of distribution genesis input // ValidateGenesis validates the genesis state of distribution genesis input
func ValidateGenesis(gs GenesisState) error { func ValidateGenesis(gs *GenesisState) error {
if err := gs.Params.ValidateBasic(); err != nil { if err := gs.Params.ValidateBasic(); err != nil {
return err return err
} }

View File

@ -14,7 +14,7 @@ import (
// InitGenesis initializes the evidence module's state from a provided genesis // InitGenesis initializes the evidence module's state from a provided genesis
// state. // state.
func InitGenesis(ctx sdk.Context, k keeper.Keeper, gs types.GenesisState) { func InitGenesis(ctx sdk.Context, k keeper.Keeper, gs *types.GenesisState) {
if err := gs.Validate(); err != nil { if err := gs.Validate(); err != nil {
panic(fmt.Sprintf("failed to validate %s genesis state: %s", types.ModuleName, err)) panic(fmt.Sprintf("failed to validate %s genesis state: %s", types.ModuleName, err))
} }
@ -33,7 +33,7 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, gs types.GenesisState) {
} }
// ExportGenesis returns the evidence module's exported genesis. // ExportGenesis returns the evidence module's exported genesis.
func ExportGenesis(ctx sdk.Context, k keeper.Keeper) types.GenesisState { func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState {
e := k.GetAllEvidence(ctx) e := k.GetAllEvidence(ctx)
evidence := make([]*codectypes.Any, len(e)) evidence := make([]*codectypes.Any, len(e))
for i, evi := range e { for i, evi := range e {
@ -47,7 +47,7 @@ func ExportGenesis(ctx sdk.Context, k keeper.Keeper) types.GenesisState {
} }
evidence[i] = any evidence[i] = any
} }
return types.GenesisState{ return &types.GenesisState{
Evidence: evidence, Evidence: evidence,
} }
} }

View File

@ -34,7 +34,7 @@ func (suite *GenesisTestSuite) SetupTest() {
func (suite *GenesisTestSuite) TestInitGenesis() { func (suite *GenesisTestSuite) TestInitGenesis() {
var ( var (
genesisState types.GenesisState genesisState *types.GenesisState
testEvidence []exported.Evidence testEvidence []exported.Evidence
pk = ed25519.GenPrivKey() pk = ed25519.GenPrivKey()
) )

View File

@ -160,7 +160,7 @@ func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, bz jso
panic(fmt.Sprintf("failed to unmarshal %s genesis state: %s", types.ModuleName, err)) panic(fmt.Sprintf("failed to unmarshal %s genesis state: %s", types.ModuleName, err))
} }
InitGenesis(ctx, am.keeper, gs) InitGenesis(ctx, am.keeper, &gs)
return []abci.ValidatorUpdate{} return []abci.ValidatorUpdate{}
} }

View File

@ -12,7 +12,7 @@ import (
var _ types.UnpackInterfacesMessage = GenesisState{} var _ types.UnpackInterfacesMessage = GenesisState{}
// NewGenesisState creates a new genesis state for the evidence module. // NewGenesisState creates a new genesis state for the evidence module.
func NewGenesisState(e []exported.Evidence) GenesisState { func NewGenesisState(e []exported.Evidence) *GenesisState {
evidence := make([]*types.Any, len(e)) evidence := make([]*types.Any, len(e))
for i, evi := range e { for i, evi := range e {
msg, ok := evi.(proto.Message) msg, ok := evi.(proto.Message)
@ -25,14 +25,14 @@ func NewGenesisState(e []exported.Evidence) GenesisState {
} }
evidence[i] = any evidence[i] = any
} }
return GenesisState{ return &GenesisState{
Evidence: evidence, Evidence: evidence,
} }
} }
// DefaultGenesisState returns the evidence module's default genesis state. // DefaultGenesisState returns the evidence module's default genesis state.
func DefaultGenesisState() GenesisState { func DefaultGenesisState() *GenesisState {
return GenesisState{ return &GenesisState{
Evidence: []*types.Any{}, Evidence: []*types.Any{},
} }
} }

View File

@ -59,7 +59,7 @@ func TestNewGenesisState(t *testing.T) {
func TestGenesisStateValidate(t *testing.T) { func TestGenesisStateValidate(t *testing.T) {
var ( var (
genesisState types.GenesisState genesisState *types.GenesisState
testEvidence []exported.Evidence testEvidence []exported.Evidence
pk = ed25519.GenPrivKey() pk = ed25519.GenPrivKey()
) )
@ -104,7 +104,7 @@ func TestGenesisStateValidate(t *testing.T) {
{ {
"expected evidence", "expected evidence",
func() { func() {
genesisState = types.GenesisState{ genesisState = &types.GenesisState{
Evidence: []*codectypes.Any{{}}, Evidence: []*codectypes.Any{{}},
} }
}, },

View File

@ -88,7 +88,7 @@ $ %s gentx my-key-name --home=/path/to/home/dir --keyring-backend=os --chain-id=
} }
var genesisState map[string]json.RawMessage var genesisState map[string]json.RawMessage
if err = cdc.UnmarshalJSON(genDoc.AppState, &genesisState); err != nil { if err = json.Unmarshal(genDoc.AppState, &genesisState); err != nil {
return errors.Wrap(err, "failed to unmarshal genesis state") return errors.Wrap(err, "failed to unmarshal genesis state")
} }

View File

@ -22,7 +22,7 @@ func QueryGenesisTxs(clientCtx client.Context, w http.ResponseWriter) {
return return
} }
appState, err := types.GenesisStateFromGenDoc(clientCtx.LegacyAmino, *resultGenesis.Genesis) appState, err := types.GenesisStateFromGenDoc(*resultGenesis.Genesis)
if err != nil { if err != nil {
rest.WriteErrorResponse( rest.WriteErrorResponse(
w, http.StatusInternalServerError, w, http.StatusInternalServerError,

View File

@ -45,7 +45,7 @@ func GenAppStateFromConfig(cdc codec.JSONMarshaler, txEncodingConfig client.TxEn
} }
// create the app state // create the app state
appGenesisState, err := types.GenesisStateFromGenDoc(cdc, genDoc) appGenesisState, err := types.GenesisStateFromGenDoc(genDoc)
if err != nil { if err != nil {
return appState, err return appState, err
} }
@ -55,7 +55,7 @@ func GenAppStateFromConfig(cdc codec.JSONMarshaler, txEncodingConfig client.TxEn
return appState, err return appState, err
} }
appState, err = codec.MarshalJSONIndent(cdc, appGenesisState) appState, err = json.MarshalIndent(appGenesisState, "", " ")
if err != nil { if err != nil {
return appState, err return appState, err
} }
@ -81,7 +81,7 @@ func CollectTxs(cdc codec.JSONMarshaler, txJSONDecoder sdk.TxDecoder, moniker, g
// prepare a map of all balances in genesis state to then validate // prepare a map of all balances in genesis state to then validate
// against the validators addresses // against the validators addresses
var appState map[string]json.RawMessage var appState map[string]json.RawMessage
if err := cdc.UnmarshalJSON(genDoc.AppState, &appState); err != nil { if err := json.Unmarshal(genDoc.AppState, &appState); err != nil {
return appGenTxs, persistentPeers, err return appGenTxs, persistentPeers, err
} }

View File

@ -49,7 +49,7 @@ func (b AppModuleBasic) ValidateGenesis(cdc codec.JSONMarshaler, txEncodingConfi
return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err) return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err)
} }
return types.ValidateGenesis(data, txEncodingConfig.TxJSONDecoder()) return types.ValidateGenesis(&data, txEncodingConfig.TxJSONDecoder())
} }
// RegisterRESTRoutes registers the REST routes for the genutil module. // RegisterRESTRoutes registers the REST routes for the genutil module.

View File

@ -14,26 +14,26 @@ import (
) )
// NewGenesisState creates a new GenesisState object // NewGenesisState creates a new GenesisState object
func NewGenesisState(genTxs []json.RawMessage) GenesisState { func NewGenesisState(genTxs []json.RawMessage) *GenesisState {
// Ensure genTxs is never nil, https://github.com/cosmos/cosmos-sdk/issues/5086 // Ensure genTxs is never nil, https://github.com/cosmos/cosmos-sdk/issues/5086
if len(genTxs) == 0 { if len(genTxs) == 0 {
genTxs = make([]json.RawMessage, 0) genTxs = make([]json.RawMessage, 0)
} }
return GenesisState{ return &GenesisState{
GenTxs: genTxs, GenTxs: genTxs,
} }
} }
// DefaultGenesisState returns the genutil module's default genesis state. // DefaultGenesisState returns the genutil module's default genesis state.
func DefaultGenesisState() GenesisState { func DefaultGenesisState() *GenesisState {
return GenesisState{ return &GenesisState{
GenTxs: []json.RawMessage{}, GenTxs: []json.RawMessage{},
} }
} }
// NewGenesisStateFromTx creates a new GenesisState object // NewGenesisStateFromTx creates a new GenesisState object
// from auth transactions // from auth transactions
func NewGenesisStateFromTx(txJSONEncoder sdk.TxEncoder, genTxs []sdk.Tx) GenesisState { func NewGenesisStateFromTx(txJSONEncoder sdk.TxEncoder, genTxs []sdk.Tx) *GenesisState {
genTxsBz := make([]json.RawMessage, len(genTxs)) genTxsBz := make([]json.RawMessage, len(genTxs))
for i, genTx := range genTxs { for i, genTx := range genTxs {
var err error var err error
@ -46,17 +46,17 @@ func NewGenesisStateFromTx(txJSONEncoder sdk.TxEncoder, genTxs []sdk.Tx) Genesis
} }
// GetGenesisStateFromAppState gets the genutil genesis state from the expected app state // GetGenesisStateFromAppState gets the genutil genesis state from the expected app state
func GetGenesisStateFromAppState(cdc codec.JSONMarshaler, appState map[string]json.RawMessage) GenesisState { func GetGenesisStateFromAppState(cdc codec.JSONMarshaler, appState map[string]json.RawMessage) *GenesisState {
var genesisState GenesisState var genesisState GenesisState
if appState[ModuleName] != nil { if appState[ModuleName] != nil {
cdc.MustUnmarshalJSON(appState[ModuleName], &genesisState) cdc.MustUnmarshalJSON(appState[ModuleName], &genesisState)
} }
return genesisState return &genesisState
} }
// SetGenesisStateInAppState sets the genutil genesis state within the expected app state // SetGenesisStateInAppState sets the genutil genesis state within the expected app state
func SetGenesisStateInAppState( func SetGenesisStateInAppState(
cdc codec.JSONMarshaler, appState map[string]json.RawMessage, genesisState GenesisState, cdc codec.JSONMarshaler, appState map[string]json.RawMessage, genesisState *GenesisState,
) map[string]json.RawMessage { ) map[string]json.RawMessage {
genesisStateBz := cdc.MustMarshalJSON(genesisState) genesisStateBz := cdc.MustMarshalJSON(genesisState)
@ -68,10 +68,9 @@ func SetGenesisStateInAppState(
// for the application. // for the application.
// //
// NOTE: The pubkey input is this machines pubkey. // NOTE: The pubkey input is this machines pubkey.
func GenesisStateFromGenDoc(cdc codec.JSONMarshaler, genDoc tmtypes.GenesisDoc, func GenesisStateFromGenDoc(genDoc tmtypes.GenesisDoc) (genesisState map[string]json.RawMessage, err error) {
) (genesisState map[string]json.RawMessage, err error) {
if err = cdc.UnmarshalJSON(genDoc.AppState, &genesisState); err != nil { if err = json.Unmarshal(genDoc.AppState, &genesisState); err != nil {
return genesisState, err return genesisState, err
} }
return genesisState, nil return genesisState, nil
@ -92,12 +91,12 @@ func GenesisStateFromGenFile(cdc codec.JSONMarshaler, genFile string) (genesisSt
return genesisState, genDoc, err return genesisState, genDoc, err
} }
genesisState, err = GenesisStateFromGenDoc(cdc, *genDoc) genesisState, err = GenesisStateFromGenDoc(*genDoc)
return genesisState, genDoc, err return genesisState, genDoc, err
} }
// ValidateGenesis validates GenTx transactions // ValidateGenesis validates GenTx transactions
func ValidateGenesis(genesisState GenesisState, txJSONDecoder sdk.TxDecoder) error { func ValidateGenesis(genesisState *GenesisState, txJSONDecoder sdk.TxDecoder) error {
for i, genTx := range genesisState.GenTxs { for i, genTx := range genesisState.GenTxs {
var tx sdk.Tx var tx sdk.Tx
tx, err := txJSONDecoder(genTx) tx, err := txJSONDecoder(genTx)

View File

@ -44,6 +44,7 @@ func NormalizeProposalStatus(status string) string {
return "Passed" return "Passed"
case "Rejected", "rejected": case "Rejected", "rejected":
return "Rejected" return "Rejected"
default:
return status
} }
return ""
} }

View File

@ -9,7 +9,7 @@ import (
) )
// InitGenesis - store genesis parameters // InitGenesis - store genesis parameters
func InitGenesis(ctx sdk.Context, ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper, data types.GenesisState) { func InitGenesis(ctx sdk.Context, ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper, data *types.GenesisState) {
k.SetProposalID(ctx, data.StartingProposalID) k.SetProposalID(ctx, data.StartingProposalID)
k.SetDepositParams(ctx, data.DepositParams) k.SetDepositParams(ctx, data.DepositParams)
k.SetVotingParams(ctx, data.VotingParams) k.SetVotingParams(ctx, data.VotingParams)
@ -52,7 +52,7 @@ func InitGenesis(ctx sdk.Context, ak types.AccountKeeper, bk types.BankKeeper, k
} }
// ExportGenesis - output genesis parameters // ExportGenesis - output genesis parameters
func ExportGenesis(ctx sdk.Context, k keeper.Keeper) types.GenesisState { func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState {
startingProposalID, _ := k.GetProposalID(ctx) startingProposalID, _ := k.GetProposalID(ctx)
depositParams := k.GetDepositParams(ctx) depositParams := k.GetDepositParams(ctx)
votingParams := k.GetVotingParams(ctx) votingParams := k.GetVotingParams(ctx)
@ -69,7 +69,7 @@ func ExportGenesis(ctx sdk.Context, k keeper.Keeper) types.GenesisState {
proposalsVotes = append(proposalsVotes, votes...) proposalsVotes = append(proposalsVotes, votes...)
} }
return types.GenesisState{ return &types.GenesisState{
StartingProposalID: startingProposalID, StartingProposalID: startingProposalID,
Deposits: proposalsDeposits, Deposits: proposalsDeposits,
Votes: proposalsVotes, Votes: proposalsVotes,

View File

@ -1,6 +1,7 @@
package gov_test package gov_test
import ( import (
"encoding/json"
"testing" "testing"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
@ -8,7 +9,6 @@ import (
"github.com/tendermint/tendermint/libs/log" "github.com/tendermint/tendermint/libs/log"
dbm "github.com/tendermint/tm-db" dbm "github.com/tendermint/tm-db"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/simapp" "github.com/cosmos/cosmos-sdk/simapp"
"github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/auth"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
@ -61,13 +61,13 @@ func TestImportExportQueues(t *testing.T) {
genesisState[banktypes.ModuleName] = app.AppCodec().MustMarshalJSON(bankGenState) genesisState[banktypes.ModuleName] = app.AppCodec().MustMarshalJSON(bankGenState)
genesisState[types.ModuleName] = app.AppCodec().MustMarshalJSON(govGenState) genesisState[types.ModuleName] = app.AppCodec().MustMarshalJSON(govGenState)
stateBytes, err := codec.MarshalJSONIndent(app.LegacyAmino(), genesisState) stateBytes, err := json.MarshalIndent(genesisState, "", " ")
if err != nil { if err != nil {
panic(err) panic(err)
} }
db := dbm.NewMemDB() db := dbm.NewMemDB()
app2 := simapp.NewSimApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, simapp.DefaultNodeHome, 0) app2 := simapp.NewSimApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, simapp.DefaultNodeHome, 0, simapp.MakeEncodingConfig())
app2.InitChain( app2.InitChain(
abci.RequestInitChain{ abci.RequestInitChain{

View File

@ -2,6 +2,7 @@ package keeper_test
import ( import (
"errors" "errors"
"fmt"
"strings" "strings"
"testing" "testing"
"time" "time"
@ -128,14 +129,16 @@ func TestGetProposalsFiltered(t *testing.T) {
{types.NewQueryProposalsParams(1, 50, types.StatusVotingPeriod, nil, nil), 50}, {types.NewQueryProposalsParams(1, 50, types.StatusVotingPeriod, nil, nil), 50},
} }
for _, tc := range testCases { for i, tc := range testCases {
proposals := app.GovKeeper.GetProposalsFiltered(ctx, tc.params) t.Run(fmt.Sprintf("Test Case %d", i), func(t *testing.T) {
require.Len(t, proposals, tc.expectedNumResults) proposals := app.GovKeeper.GetProposalsFiltered(ctx, tc.params)
require.Len(t, proposals, tc.expectedNumResults)
for _, p := range proposals { for _, p := range proposals {
if len(tc.params.ProposalStatus.String()) != 0 { if types.ValidProposalStatus(tc.params.ProposalStatus) {
require.Equal(t, tc.params.ProposalStatus, p.Status) require.Equal(t, tc.params.ProposalStatus, p.Status)
}
} }
} })
} }
} }

View File

@ -70,7 +70,7 @@ func (AppModuleBasic) ValidateGenesis(cdc codec.JSONMarshaler, config client.TxE
return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err) return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err)
} }
return types.ValidateGenesis(data) return types.ValidateGenesis(&data)
} }
// RegisterRESTRoutes registers the REST routes for the gov module. // RegisterRESTRoutes registers the REST routes for the gov module.
@ -160,7 +160,7 @@ func (am AppModule) RegisterQueryService(server grpc.Server) {
func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, data json.RawMessage) []abci.ValidatorUpdate { func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, data json.RawMessage) []abci.ValidatorUpdate {
var genesisState types.GenesisState var genesisState types.GenesisState
cdc.MustUnmarshalJSON(data, &genesisState) cdc.MustUnmarshalJSON(data, &genesisState)
InitGenesis(ctx, am.accountKeeper, am.bankKeeper, am.keeper, genesisState) InitGenesis(ctx, am.accountKeeper, am.bankKeeper, am.keeper, &genesisState)
return []abci.ValidatorUpdate{} return []abci.ValidatorUpdate{}
} }

View File

@ -8,8 +8,8 @@ import (
) )
// NewGenesisState creates a new genesis state for the governance module // NewGenesisState creates a new genesis state for the governance module
func NewGenesisState(startingProposalID uint64, dp DepositParams, vp VotingParams, tp TallyParams) GenesisState { func NewGenesisState(startingProposalID uint64, dp DepositParams, vp VotingParams, tp TallyParams) *GenesisState {
return GenesisState{ return &GenesisState{
StartingProposalID: startingProposalID, StartingProposalID: startingProposalID,
DepositParams: dp, DepositParams: dp,
VotingParams: vp, VotingParams: vp,
@ -18,7 +18,7 @@ func NewGenesisState(startingProposalID uint64, dp DepositParams, vp VotingParam
} }
// DefaultGenesisState defines the default governance genesis state // DefaultGenesisState defines the default governance genesis state
func DefaultGenesisState() GenesisState { func DefaultGenesisState() *GenesisState {
return NewGenesisState( return NewGenesisState(
DefaultStartingProposalID, DefaultStartingProposalID,
DefaultDepositParams(), DefaultDepositParams(),
@ -43,7 +43,7 @@ func (data GenesisState) Empty() bool {
} }
// ValidateGenesis checks if parameters are within valid ranges // ValidateGenesis checks if parameters are within valid ranges
func ValidateGenesis(data GenesisState) error { func ValidateGenesis(data *GenesisState) error {
threshold := data.TallyParams.Threshold threshold := data.TallyParams.Threshold
if threshold.IsNegative() || threshold.GT(sdk.OneDec()) { if threshold.IsNegative() || threshold.GT(sdk.OneDec()) {
return fmt.Errorf("governance vote threshold should be positive and less or equal to one, is %s", return fmt.Errorf("governance vote threshold should be positive and less or equal to one, is %s",

View File

@ -105,6 +105,10 @@ var ProposalStatus_value = map[string]int32{
"PROPOSAL_STATUS_FAILED": 5, "PROPOSAL_STATUS_FAILED": 5,
} }
func (x ProposalStatus) String() string {
return proto.EnumName(ProposalStatus_name, int32(x))
}
func (ProposalStatus) EnumDescriptor() ([]byte, []int) { func (ProposalStatus) EnumDescriptor() ([]byte, []int) {
return fileDescriptor_6e82113c1a9a4b7c, []int{1} return fileDescriptor_6e82113c1a9a4b7c, []int{1}
} }
@ -448,94 +452,95 @@ func init() {
func init() { proto.RegisterFile("cosmos/gov/v1beta1/gov.proto", fileDescriptor_6e82113c1a9a4b7c) } func init() { proto.RegisterFile("cosmos/gov/v1beta1/gov.proto", fileDescriptor_6e82113c1a9a4b7c) }
var fileDescriptor_6e82113c1a9a4b7c = []byte{ var fileDescriptor_6e82113c1a9a4b7c = []byte{
// 1392 bytes of a gzipped FileDescriptorProto // 1395 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x57, 0x3f, 0x6c, 0xdb, 0xc6, 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x57, 0x41, 0x6c, 0xdb, 0xd4,
0x17, 0x16, 0xe5, 0x7f, 0xf1, 0x49, 0xb6, 0x99, 0xb3, 0x7f, 0xb6, 0xcc, 0x5f, 0x4a, 0x32, 0x6c, 0x1b, 0x8f, 0xd3, 0xb4, 0x5d, 0x5f, 0xd2, 0xd6, 0x7b, 0xed, 0xbf, 0x4d, 0xfd, 0x1f, 0xb6, 0x67,
0x50, 0x18, 0x41, 0x22, 0x27, 0x2e, 0x50, 0xa0, 0x09, 0x50, 0x44, 0xb4, 0x98, 0x44, 0x45, 0x20, 0x26, 0x54, 0x4d, 0x5b, 0xba, 0x15, 0x09, 0x89, 0x4d, 0x42, 0x8b, 0x1b, 0x6f, 0x0b, 0x9a, 0x92,
0x09, 0x14, 0xa3, 0x20, 0xe9, 0x40, 0xd0, 0x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x6a, 0x9a, 0xc4,
0x68, 0xec, 0x99, 0x2d, 0xe4, 0xb7, 0x1b, 0x24, 0x33, 0x19, 0xf6, 0x27, 0x9d, 0x54, 0xc3, 0x08, 0x6a, 0x36, 0x77, 0xcd, 0x36, 0xf2, 0x3b, 0x4d, 0x92, 0x4d, 0x85, 0xfd, 0x49, 0x27, 0xd5, 0x30,
0xf2, 0xf4, 0x30, 0x4d, 0x3d, 0x1f, 0x48, 0x7c, 0xd4, 0x93, 0x56, 0x69, 0x91, 0x51, 0x22, 0x45, 0x82, 0x3c, 0x3d, 0x4c, 0x53, 0xcf, 0x07, 0x12, 0x1f, 0xf6, 0xa5, 0x15, 0x5a, 0x64, 0x94, 0x48,
0xe7, 0xc3, 0x60, 0x0c, 0x04, 0x3f, 0x00, 0x29, 0xbf, 0xbd, 0xe5, 0x3a, 0xc4, 0x0c, 0x4c, 0x91, 0xd1, 0xf9, 0x30, 0x18, 0x03, 0xc1, 0xf7, 0x40, 0xda, 0xef, 0x6c, 0xba, 0x0e, 0x31, 0x03, 0x53,
0x99, 0x0a, 0x4b, 0x09, 0x23, 0x52, 0x18, 0x91, 0x63, 0x54, 0x91, 0x55, 0x61, 0x97, 0x2d, 0x06, 0x64, 0x27, 0xc3, 0x52, 0xc2, 0x88, 0x14, 0x46, 0xe4, 0x18, 0x55, 0x64, 0x55, 0xd8, 0x65, 0x8b,
0x56, 0x1e, 0xbf, 0x90, 0x38, 0x1d, 0xd0, 0x48, 0x00, 0x80, 0x0e, 0xe0, 0xd9, 0x65, 0x31, 0x91, 0x81, 0x95, 0xc7, 0xcf, 0x25, 0x4e, 0x07, 0x34, 0x12, 0x00, 0xa0, 0x03, 0x78, 0x76, 0x59, 0x4c,
0x67, 0xd3, 0x0a, 0xd3, 0xa7, 0x56, 0x78, 0x93, 0x55, 0x58, 0xa1, 0x15, 0x86, 0x19, 0x68, 0x99, 0xe4, 0xd9, 0xb4, 0xc2, 0xd4, 0xa9, 0x15, 0x5e, 0x67, 0x15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bd, 0x10, 0x13, 0x9f, 0xec, 0x8b, 0x89, 0xbd, 0x7d,
0x07, 0x22, 0xf7, 0xfb, 0x81, 0xc8, 0x3d, 0x7e, 0x25, 0x26, 0x9e, 0xbe, 0x12, 0x13, 0xcf, 0x5f, 0x91, 0x7b, 0xba, 0x2f, 0x72, 0xbf, 0xef, 0x8b, 0xdc, 0xe3, 0x97, 0x62, 0xe2, 0xe9, 0x4b, 0x31,
0x89, 0x89, 0x07, 0xff, 0x3c, 0xe9, 0x76, 0xc3, 0xdf, 0x5a, 0xe1, 0x9d, 0xdd, 0x9a, 0x0e, 0x87, 0xf1, 0xec, 0xa5, 0x98, 0x78, 0xf0, 0xcf, 0x13, 0x6e, 0x27, 0xfc, 0x8d, 0x15, 0xde, 0xd5, 0xcd,
0xc3, 0xdb, 0x7f, 0x07, 0x00, 0x00, 0xff, 0xff, 0xc9, 0x24, 0xef, 0x4e, 0x86, 0x0d, 0x00, 0x00, 0xa9, 0x70, 0x28, 0xbc, 0xf9, 0x77, 0x00, 0x00, 0x00, 0xff, 0xff, 0x4f, 0x85, 0xd1, 0x2a, 0x7e,
0x0d, 0x00, 0x00,
} }
func (this *TextProposal) Equal(that interface{}) bool { func (this *TextProposal) Equal(that interface{}) bool {

View File

@ -1,7 +1,6 @@
package types package types
import ( import (
"encoding/json"
"fmt" "fmt"
"strings" "strings"
"time" "time"
@ -137,28 +136,11 @@ type (
// ProposalStatusFromString turns a string into a ProposalStatus // ProposalStatusFromString turns a string into a ProposalStatus
func ProposalStatusFromString(str string) (ProposalStatus, error) { func ProposalStatusFromString(str string) (ProposalStatus, error) {
switch str { num, ok := ProposalStatus_value[str]
case "DepositPeriod": if !ok {
return StatusDepositPeriod, nil return StatusNil, fmt.Errorf("'%s' is not a valid proposal status", str)
case "VotingPeriod":
return StatusVotingPeriod, nil
case "Passed":
return StatusPassed, nil
case "Rejected":
return StatusRejected, nil
case "Failed":
return StatusFailed, nil
case "":
return StatusNil, nil
default:
return ProposalStatus(0xff), fmt.Errorf("'%s' is not a valid proposal status", str)
} }
return ProposalStatus(num), nil
} }
// ValidProposalStatus returns true if the proposal status is valid and false // ValidProposalStatus returns true if the proposal status is valid and false
@ -185,51 +167,6 @@ func (status *ProposalStatus) Unmarshal(data []byte) error {
return nil return nil
} }
// MarshalJSON Marshals to JSON using string representation of the status
func (status ProposalStatus) MarshalJSON() ([]byte, error) {
return json.Marshal(status.String())
}
// UnmarshalJSON Unmarshals from JSON assuming Bech32 encoding
func (status *ProposalStatus) UnmarshalJSON(data []byte) error {
var s string
err := json.Unmarshal(data, &s)
if err != nil {
return err
}
bz2, err := ProposalStatusFromString(s)
if err != nil {
return err
}
*status = bz2
return nil
}
// String implements the Stringer interface.
func (status ProposalStatus) String() string {
switch status {
case StatusDepositPeriod:
return "DepositPeriod"
case StatusVotingPeriod:
return "VotingPeriod"
case StatusPassed:
return "Passed"
case StatusRejected:
return "Rejected"
case StatusFailed:
return "Failed"
default:
return ""
}
}
// Format implements the fmt.Formatter interface. // Format implements the fmt.Formatter interface.
// nolint: errcheck // nolint: errcheck
func (status ProposalStatus) Format(s fmt.State, verb rune) { func (status ProposalStatus) Format(s fmt.State, verb rune) {

View File

@ -8,13 +8,13 @@ import (
) )
func TestProposalStatus_Format(t *testing.T) { func TestProposalStatus_Format(t *testing.T) {
statusDepositPeriod, _ := ProposalStatusFromString("DepositPeriod") statusDepositPeriod, _ := ProposalStatusFromString("PROPOSAL_STATUS_DEPOSIT_PERIOD")
tests := []struct { tests := []struct {
pt ProposalStatus pt ProposalStatus
sprintFArgs string sprintFArgs string
expectedStringOutput string expectedStringOutput string
}{ }{
{statusDepositPeriod, "%s", "DepositPeriod"}, {statusDepositPeriod, "%s", "PROPOSAL_STATUS_DEPOSIT_PERIOD"},
{statusDepositPeriod, "%v", "1"}, {statusDepositPeriod, "%v", "1"},
} }
for _, tt := range tests { for _, tt := range tests {

View File

@ -31,8 +31,8 @@ func InitGenesis(ctx sdk.Context, keeper keeper.Keeper, state types.GenesisState
} }
// ExportGenesis exports transfer module's portID into its geneis state // ExportGenesis exports transfer module's portID into its geneis state
func ExportGenesis(ctx sdk.Context, keeper keeper.Keeper) types.GenesisState { func ExportGenesis(ctx sdk.Context, keeper keeper.Keeper) *types.GenesisState {
return types.GenesisState{ return &types.GenesisState{
PortID: keeper.GetPort(ctx), PortID: keeper.GetPort(ctx),
} }
} }

View File

@ -5,8 +5,8 @@ import (
) )
// DefaultGenesisState returns a GenesisState with "transfer" as the default PortID. // DefaultGenesisState returns a GenesisState with "transfer" as the default PortID.
func DefaultGenesisState() GenesisState { func DefaultGenesisState() *GenesisState {
return GenesisState{ return &GenesisState{
PortID: PortID, PortID: PortID,
} }
} }

View File

@ -11,7 +11,7 @@ import (
func TestValidateGenesis(t *testing.T) { func TestValidateGenesis(t *testing.T) {
testCases := []struct { testCases := []struct {
name string name string
genState types.GenesisState genState *types.GenesisState
expPass bool expPass bool
}{ }{
{ {
@ -21,14 +21,14 @@ func TestValidateGenesis(t *testing.T) {
}, },
{ {
"valid genesis", "valid genesis",
types.GenesisState{ &types.GenesisState{
PortID: "portidone", PortID: "portidone",
}, },
true, true,
}, },
{ {
"invalid client", "invalid client",
types.GenesisState{ &types.GenesisState{
PortID: "(INVALIDPORT)", PortID: "(INVALIDPORT)",
}, },
false, false,

View File

@ -11,15 +11,15 @@ import (
// InitGenesis initializes the ibc state from a provided genesis // InitGenesis initializes the ibc state from a provided genesis
// state. // state.
func InitGenesis(ctx sdk.Context, k keeper.Keeper, createLocalhost bool, gs types.GenesisState) { func InitGenesis(ctx sdk.Context, k keeper.Keeper, createLocalhost bool, gs *types.GenesisState) {
client.InitGenesis(ctx, k.ClientKeeper, gs.ClientGenesis) client.InitGenesis(ctx, k.ClientKeeper, gs.ClientGenesis)
connection.InitGenesis(ctx, k.ConnectionKeeper, gs.ConnectionGenesis) connection.InitGenesis(ctx, k.ConnectionKeeper, gs.ConnectionGenesis)
channel.InitGenesis(ctx, k.ChannelKeeper, gs.ChannelGenesis) channel.InitGenesis(ctx, k.ChannelKeeper, gs.ChannelGenesis)
} }
// ExportGenesis returns the ibc exported genesis. // ExportGenesis returns the ibc exported genesis.
func ExportGenesis(ctx sdk.Context, k keeper.Keeper) types.GenesisState { func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState {
return types.GenesisState{ return &types.GenesisState{
ClientGenesis: client.ExportGenesis(ctx, k.ClientKeeper), ClientGenesis: client.ExportGenesis(ctx, k.ClientKeeper),
ConnectionGenesis: connection.ExportGenesis(ctx, k.ConnectionKeeper), ConnectionGenesis: connection.ExportGenesis(ctx, k.ConnectionKeeper),
ChannelGenesis: channel.ExportGenesis(ctx, k.ChannelKeeper), ChannelGenesis: channel.ExportGenesis(ctx, k.ChannelKeeper),

View File

@ -23,7 +23,7 @@ import (
func (suite *IBCTestSuite) TestValidateGenesis() { func (suite *IBCTestSuite) TestValidateGenesis() {
testCases := []struct { testCases := []struct {
name string name string
genState types.GenesisState genState *types.GenesisState
expPass bool expPass bool
}{ }{
{ {
@ -33,7 +33,7 @@ func (suite *IBCTestSuite) TestValidateGenesis() {
}, },
{ {
name: "valid genesis", name: "valid genesis",
genState: types.GenesisState{ genState: &types.GenesisState{
ClientGenesis: clienttypes.NewGenesisState( ClientGenesis: clienttypes.NewGenesisState(
[]clienttypes.GenesisClientState{ []clienttypes.GenesisClientState{
clienttypes.NewGenesisClientState( clienttypes.NewGenesisClientState(
@ -93,7 +93,7 @@ func (suite *IBCTestSuite) TestValidateGenesis() {
}, },
{ {
name: "invalid client genesis", name: "invalid client genesis",
genState: types.GenesisState{ genState: &types.GenesisState{
ClientGenesis: clienttypes.NewGenesisState( ClientGenesis: clienttypes.NewGenesisState(
[]clienttypes.GenesisClientState{ []clienttypes.GenesisClientState{
clienttypes.NewGenesisClientState( clienttypes.NewGenesisClientState(
@ -112,7 +112,7 @@ func (suite *IBCTestSuite) TestValidateGenesis() {
}, },
{ {
name: "invalid connection genesis", name: "invalid connection genesis",
genState: types.GenesisState{ genState: &types.GenesisState{
ClientGenesis: clienttypes.DefaultGenesisState(), ClientGenesis: clienttypes.DefaultGenesisState(),
ConnectionGenesis: connectiontypes.NewGenesisState( ConnectionGenesis: connectiontypes.NewGenesisState(
[]connectiontypes.IdentifiedConnection{ []connectiontypes.IdentifiedConnection{
@ -127,7 +127,7 @@ func (suite *IBCTestSuite) TestValidateGenesis() {
}, },
{ {
name: "invalid channel genesis", name: "invalid channel genesis",
genState: types.GenesisState{ genState: &types.GenesisState{
ClientGenesis: clienttypes.DefaultGenesisState(), ClientGenesis: clienttypes.DefaultGenesisState(),
ConnectionGenesis: connectiontypes.DefaultGenesisState(), ConnectionGenesis: connectiontypes.DefaultGenesisState(),
ChannelGenesis: channeltypes.GenesisState{ ChannelGenesis: channeltypes.GenesisState{
@ -154,7 +154,7 @@ func (suite *IBCTestSuite) TestValidateGenesis() {
func (suite *IBCTestSuite) TestInitGenesis() { func (suite *IBCTestSuite) TestInitGenesis() {
testCases := []struct { testCases := []struct {
name string name string
genState types.GenesisState genState *types.GenesisState
}{ }{
{ {
name: "default", name: "default",
@ -162,7 +162,7 @@ func (suite *IBCTestSuite) TestInitGenesis() {
}, },
{ {
name: "valid genesis", name: "valid genesis",
genState: types.GenesisState{ genState: &types.GenesisState{
ClientGenesis: clienttypes.NewGenesisState( ClientGenesis: clienttypes.NewGenesisState(
[]clienttypes.GenesisClientState{ []clienttypes.GenesisClientState{
clienttypes.NewGenesisClientState( clienttypes.NewGenesisClientState(
@ -254,7 +254,7 @@ func (suite *HandlerTestSuite) TestExportGenesis() {
tc.malleate() tc.malleate()
var gs types.GenesisState var gs *types.GenesisState
suite.NotPanics(func() { suite.NotPanics(func() {
gs = ibc.ExportGenesis(suite.chainA.GetContext(), *suite.chainA.App.IBCKeeper) gs = ibc.ExportGenesis(suite.chainA.GetContext(), *suite.chainA.App.IBCKeeper)
}) })
@ -266,8 +266,8 @@ func (suite *HandlerTestSuite) TestExportGenesis() {
suite.NotPanics(func() { suite.NotPanics(func() {
cdc := codec.NewProtoCodec(suite.chainA.App.InterfaceRegistry()) cdc := codec.NewProtoCodec(suite.chainA.App.InterfaceRegistry())
genState := cdc.MustMarshalJSON(&gs) genState := cdc.MustMarshalJSON(gs)
cdc.MustUnmarshalJSON(genState, &gs) cdc.MustUnmarshalJSON(genState, gs)
}) })
// init genesis based on marshal and unmarshal // init genesis based on marshal and unmarshal

View File

@ -137,7 +137,7 @@ func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, bz jso
if err != nil { if err != nil {
panic(fmt.Sprintf("failed to unmarshal %s genesis state: %s", host.ModuleName, err)) panic(fmt.Sprintf("failed to unmarshal %s genesis state: %s", host.ModuleName, err))
} }
InitGenesis(ctx, *am.keeper, am.createLocalhost, gs) InitGenesis(ctx, *am.keeper, am.createLocalhost, &gs)
return []abci.ValidatorUpdate{} return []abci.ValidatorUpdate{}
} }

View File

@ -10,8 +10,8 @@ import (
var _ codectypes.UnpackInterfacesMessage = GenesisState{} var _ codectypes.UnpackInterfacesMessage = GenesisState{}
// DefaultGenesisState returns the ibc module's default genesis state. // DefaultGenesisState returns the ibc module's default genesis state.
func DefaultGenesisState() GenesisState { func DefaultGenesisState() *GenesisState {
return GenesisState{ return &GenesisState{
ClientGenesis: clienttypes.DefaultGenesisState(), ClientGenesis: clienttypes.DefaultGenesisState(),
ConnectionGenesis: connectiontypes.DefaultGenesisState(), ConnectionGenesis: connectiontypes.DefaultGenesisState(),
ChannelGenesis: channeltypes.DefaultGenesisState(), ChannelGenesis: channeltypes.DefaultGenesisState(),
@ -25,7 +25,7 @@ func (gs GenesisState) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error {
// Validate performs basic genesis state validation returning an error upon any // Validate performs basic genesis state validation returning an error upon any
// failure. // failure.
func (gs GenesisState) Validate() error { func (gs *GenesisState) Validate() error {
if err := gs.ClientGenesis.Validate(); err != nil { if err := gs.ClientGenesis.Validate(); err != nil {
return err return err
} }

View File

@ -7,14 +7,14 @@ import (
) )
// InitGenesis new mint genesis // InitGenesis new mint genesis
func InitGenesis(ctx sdk.Context, keeper keeper.Keeper, ak types.AccountKeeper, data types.GenesisState) { func InitGenesis(ctx sdk.Context, keeper keeper.Keeper, ak types.AccountKeeper, data *types.GenesisState) {
keeper.SetMinter(ctx, data.Minter) keeper.SetMinter(ctx, data.Minter)
keeper.SetParams(ctx, data.Params) keeper.SetParams(ctx, data.Params)
ak.GetModuleAccount(ctx, types.ModuleName) ak.GetModuleAccount(ctx, types.ModuleName)
} }
// ExportGenesis returns a GenesisState for a given context and keeper. // ExportGenesis returns a GenesisState for a given context and keeper.
func ExportGenesis(ctx sdk.Context, keeper keeper.Keeper) types.GenesisState { func ExportGenesis(ctx sdk.Context, keeper keeper.Keeper) *types.GenesisState {
minter := keeper.GetMinter(ctx) minter := keeper.GetMinter(ctx)
params := keeper.GetParams(ctx) params := keeper.GetParams(ctx)
return types.NewGenesisState(minter, params) return types.NewGenesisState(minter, params)

View File

@ -128,7 +128,7 @@ func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, data j
var genesisState types.GenesisState var genesisState types.GenesisState
cdc.MustUnmarshalJSON(data, &genesisState) cdc.MustUnmarshalJSON(data, &genesisState)
InitGenesis(ctx, am.keeper, am.authKeeper, genesisState) InitGenesis(ctx, am.keeper, am.authKeeper, &genesisState)
return []abci.ValidatorUpdate{} return []abci.ValidatorUpdate{}
} }

View File

@ -1,16 +1,16 @@
package types package types
// NewGenesisState creates a new GenesisState object // NewGenesisState creates a new GenesisState object
func NewGenesisState(minter Minter, params Params) GenesisState { func NewGenesisState(minter Minter, params Params) *GenesisState {
return GenesisState{ return &GenesisState{
Minter: minter, Minter: minter,
Params: params, Params: params,
} }
} }
// DefaultGenesisState creates a default GenesisState object // DefaultGenesisState creates a default GenesisState object
func DefaultGenesisState() GenesisState { func DefaultGenesisState() *GenesisState {
return GenesisState{ return &GenesisState{
Minter: DefaultInitialMinter(), Minter: DefaultInitialMinter(),
Params: DefaultParams(), Params: DefaultParams(),
} }

View File

@ -9,7 +9,7 @@ import (
// InitGenesis initialize default parameters // InitGenesis initialize default parameters
// and the keeper's address to pubkey map // and the keeper's address to pubkey map
func InitGenesis(ctx sdk.Context, keeper keeper.Keeper, stakingKeeper types.StakingKeeper, data types.GenesisState) { func InitGenesis(ctx sdk.Context, keeper keeper.Keeper, stakingKeeper types.StakingKeeper, data *types.GenesisState) {
stakingKeeper.IterateValidators(ctx, stakingKeeper.IterateValidators(ctx,
func(index int64, validator exported.ValidatorI) bool { func(index int64, validator exported.ValidatorI) bool {
keeper.AddPubkey(ctx, validator.GetConsPubKey()) keeper.AddPubkey(ctx, validator.GetConsPubKey())
@ -41,7 +41,7 @@ func InitGenesis(ctx sdk.Context, keeper keeper.Keeper, stakingKeeper types.Stak
// ExportGenesis writes the current store values // ExportGenesis writes the current store values
// to a genesis file, which can be imported again // to a genesis file, which can be imported again
// with InitGenesis // with InitGenesis
func ExportGenesis(ctx sdk.Context, keeper keeper.Keeper) (data types.GenesisState) { func ExportGenesis(ctx sdk.Context, keeper keeper.Keeper) (data *types.GenesisState) {
params := keeper.GetParams(ctx) params := keeper.GetParams(ctx)
signingInfos := make([]types.SigningInfo, 0) signingInfos := make([]types.SigningInfo, 0)
missedBlocks := make([]types.ValidatorMissedBlocks, 0) missedBlocks := make([]types.ValidatorMissedBlocks, 0)

View File

@ -141,8 +141,8 @@ func (am AppModule) RegisterQueryService(server grpc.Server) {
// no validator updates. // no validator updates.
func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, data json.RawMessage) []abci.ValidatorUpdate { func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, data json.RawMessage) []abci.ValidatorUpdate {
var genesisState types.GenesisState var genesisState types.GenesisState
types.ModuleCdc.MustUnmarshalJSON(data, &genesisState) cdc.MustUnmarshalJSON(data, &genesisState)
InitGenesis(ctx, am.keeper, am.stakingKeeper, genesisState) InitGenesis(ctx, am.keeper, am.stakingKeeper, &genesisState)
return []abci.ValidatorUpdate{} return []abci.ValidatorUpdate{}
} }

View File

@ -10,9 +10,9 @@ import (
// NewGenesisState creates a new GenesisState object // NewGenesisState creates a new GenesisState object
func NewGenesisState( func NewGenesisState(
params Params, signingInfos []SigningInfo, missedBlocks []ValidatorMissedBlocks, params Params, signingInfos []SigningInfo, missedBlocks []ValidatorMissedBlocks,
) GenesisState { ) *GenesisState {
return GenesisState{ return &GenesisState{
Params: params, Params: params,
SigningInfos: signingInfos, SigningInfos: signingInfos,
MissedBlocks: missedBlocks, MissedBlocks: missedBlocks,
@ -28,8 +28,8 @@ func NewMissedBlock(index int64, missed bool) MissedBlock {
} }
// DefaultGenesisState - default GenesisState used by Cosmos Hub // DefaultGenesisState - default GenesisState used by Cosmos Hub
func DefaultGenesisState() GenesisState { func DefaultGenesisState() *GenesisState {
return GenesisState{ return &GenesisState{
Params: DefaultParams(), Params: DefaultParams(),
SigningInfos: []SigningInfo{}, SigningInfos: []SigningInfo{},
MissedBlocks: []ValidatorMissedBlocks{}, MissedBlocks: []ValidatorMissedBlocks{},

View File

@ -19,7 +19,7 @@ import (
// Returns final validator set after applying all declaration and delegations // Returns final validator set after applying all declaration and delegations
func InitGenesis( func InitGenesis(
ctx sdk.Context, keeper keeper.Keeper, accountKeeper types.AccountKeeper, ctx sdk.Context, keeper keeper.Keeper, accountKeeper types.AccountKeeper,
bankKeeper types.BankKeeper, data types.GenesisState, bankKeeper types.BankKeeper, data *types.GenesisState,
) (res []abci.ValidatorUpdate) { ) (res []abci.ValidatorUpdate) {
bondedTokens := sdk.ZeroInt() bondedTokens := sdk.ZeroInt()
notBondedTokens := sdk.ZeroInt() notBondedTokens := sdk.ZeroInt()
@ -147,7 +147,7 @@ func InitGenesis(
// ExportGenesis returns a GenesisState for a given context and keeper. The // ExportGenesis returns a GenesisState for a given context and keeper. The
// GenesisState will contain the pool, params, validators, and bonds found in // GenesisState will contain the pool, params, validators, and bonds found in
// the keeper. // the keeper.
func ExportGenesis(ctx sdk.Context, keeper keeper.Keeper) types.GenesisState { func ExportGenesis(ctx sdk.Context, keeper keeper.Keeper) *types.GenesisState {
var unbondingDelegations []types.UnbondingDelegation var unbondingDelegations []types.UnbondingDelegation
keeper.IterateUnbondingDelegations(ctx, func(_ int64, ubd types.UnbondingDelegation) (stop bool) { keeper.IterateUnbondingDelegations(ctx, func(_ int64, ubd types.UnbondingDelegation) (stop bool) {
@ -169,7 +169,7 @@ func ExportGenesis(ctx sdk.Context, keeper keeper.Keeper) types.GenesisState {
return false return false
}) })
return types.GenesisState{ return &types.GenesisState{
Params: keeper.GetParams(ctx), Params: keeper.GetParams(ctx),
LastTotalPower: keeper.GetLastTotalPower(ctx), LastTotalPower: keeper.GetLastTotalPower(ctx),
LastValidatorPowers: lastValidatorPowers, LastValidatorPowers: lastValidatorPowers,
@ -199,7 +199,7 @@ func WriteValidators(ctx sdk.Context, keeper keeper.Keeper) (vals []tmtypes.Gene
// ValidateGenesis validates the provided staking genesis state to ensure the // ValidateGenesis validates the provided staking genesis state to ensure the
// expected invariants holds. (i.e. params in correct bounds, no duplicate validators) // expected invariants holds. (i.e. params in correct bounds, no duplicate validators)
func ValidateGenesis(data types.GenesisState) error { func ValidateGenesis(data *types.GenesisState) error {
if err := validateGenesisStateValidators(data.Validators); err != nil { if err := validateGenesisStateValidators(data.Validators); err != nil {
return err return err
} }

View File

@ -161,7 +161,7 @@ func TestValidateGenesis(t *testing.T) {
tt := tt tt := tt
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
genesisState := types.DefaultGenesisState() genesisState := types.DefaultGenesisState()
tt.mutate(&genesisState) tt.mutate(genesisState)
if tt.wantErr { if tt.wantErr {
assert.Error(t, staking.ValidateGenesis(genesisState)) assert.Error(t, staking.ValidateGenesis(genesisState))
} else { } else {

View File

@ -65,7 +65,7 @@ func (AppModuleBasic) ValidateGenesis(cdc codec.JSONMarshaler, config client.TxE
return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err) return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err)
} }
return ValidateGenesis(data) return ValidateGenesis(&data)
} }
// RegisterRESTRoutes registers the REST routes for the staking module. // RegisterRESTRoutes registers the REST routes for the staking module.
@ -141,7 +141,7 @@ func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONMarshaler, data j
cdc.MustUnmarshalJSON(data, &genesisState) cdc.MustUnmarshalJSON(data, &genesisState)
return InitGenesis(ctx, am.keeper, am.accountKeeper, am.bankKeeper, genesisState) return InitGenesis(ctx, am.keeper, am.accountKeeper, am.bankKeeper, &genesisState)
} }
// ExportGenesis returns the exported genesis state as raw bytes for the staking // ExportGenesis returns the exported genesis state as raw bytes for the staking

View File

@ -7,8 +7,8 @@ import (
) )
// NewGenesisState creates a new GenesisState instanc e // NewGenesisState creates a new GenesisState instanc e
func NewGenesisState(params Params, validators []Validator, delegations []Delegation) GenesisState { func NewGenesisState(params Params, validators []Validator, delegations []Delegation) *GenesisState {
return GenesisState{ return &GenesisState{
Params: params, Params: params,
Validators: validators, Validators: validators,
Delegations: delegations, Delegations: delegations,
@ -16,20 +16,20 @@ func NewGenesisState(params Params, validators []Validator, delegations []Delega
} }
// DefaultGenesisState gets the raw genesis raw message for testing // DefaultGenesisState gets the raw genesis raw message for testing
func DefaultGenesisState() GenesisState { func DefaultGenesisState() *GenesisState {
return GenesisState{ return &GenesisState{
Params: DefaultParams(), Params: DefaultParams(),
} }
} }
// GetGenesisStateFromAppState returns x/staking GenesisState given raw application // GetGenesisStateFromAppState returns x/staking GenesisState given raw application
// genesis state. // genesis state.
func GetGenesisStateFromAppState(cdc *codec.LegacyAmino, appState map[string]json.RawMessage) GenesisState { func GetGenesisStateFromAppState(cdc *codec.LegacyAmino, appState map[string]json.RawMessage) *GenesisState {
var genesisState GenesisState var genesisState GenesisState
if appState[ModuleName] != nil { if appState[ModuleName] != nil {
cdc.MustUnmarshalJSON(appState[ModuleName], &genesisState) cdc.MustUnmarshalJSON(appState[ModuleName], &genesisState)
} }
return genesisState return &genesisState
} }

File diff suppressed because it is too large Load Diff

View File

@ -38,7 +38,7 @@ var s TestSuite
func setupTest(height int64, skip map[int64]bool) TestSuite { func setupTest(height int64, skip map[int64]bool) TestSuite {
db := dbm.NewMemDB() db := dbm.NewMemDB()
app := simapp.NewSimApp(log.NewNopLogger(), db, nil, true, skip, simapp.DefaultNodeHome, 0) app := simapp.NewSimApp(log.NewNopLogger(), db, nil, true, skip, simapp.DefaultNodeHome, 0, simapp.MakeEncodingConfig())
genesisState := simapp.NewDefaultGenesisState() genesisState := simapp.NewDefaultGenesisState()
stateBytes, err := codec.MarshalJSONIndent(app.LegacyAmino(), genesisState) stateBytes, err := codec.MarshalJSONIndent(app.LegacyAmino(), genesisState)
if err != nil { if err != nil {