Skip to content

Commit

Permalink
Make JSONMarshaler methods require proto.Message (cosmos#7054)
Browse files Browse the repository at this point in the history
* Make JSONMarshaler require proto.Message

* Use &msg with MarshalJSON

* Use *LegacyAmino in queriers instead of JSONMarshaler

* Revert ABCIMessageLogs String() and coins tests

* Use LegacyAmino in client/debug and fix subspace tests

* Use LegacyAmino in all legacy queriers and adapt simulation

* Make AminoCodec implement Marshaler and some godoc fixes

* Test fixes

* Remove unrelevant comment

* Use TxConfig.TxJSONEncoder

* Use encoding/json in genutil cli migrate/validate genesis cmds

* Address simulation related comments

* Use JSONMarshaler in cli tests

* Use proto.Message as respType in cli tests

* Use tmjson for tm GenesisDoc

* Update types/module/simulation.go

Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>

* Update types/module/module_test.go

Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>

* Add godoc comments

* Remove unused InsertKeyJSON

* Fix tests

Co-authored-by: Aaron Craelius <aaronc@users.noreply.github.com>
Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>
  • Loading branch information
3 people authored Aug 26, 2020
1 parent 1c5b6cd commit 0f6154e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
4 changes: 1 addition & 3 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ func NewSimApp(
)

app.mm.RegisterInvariants(&app.CrisisKeeper)
app.mm.RegisterRoutes(app.Router(), app.QueryRouter(), codec.NewAminoCodec(encodingConfig.Amino))
app.mm.RegisterRoutes(app.Router(), app.QueryRouter(), encodingConfig.Amino)
app.mm.RegisterQueryServices(app.GRPCQueryRouter())

// add test gRPC service for testing gRPC queries in isolation
Expand Down Expand Up @@ -507,8 +507,6 @@ func (app *SimApp) SimulationManager() *module.SimulationManager {
// API server.
func (app *SimApp) RegisterAPIRoutes(apiSvr *api.Server) {
clientCtx := apiSvr.ClientCtx
// amino is needed here for backwards compatibility of REST routes
clientCtx = clientCtx.WithJSONMarshaler(clientCtx.LegacyAmino)
rpc.RegisterRoutes(clientCtx, apiSvr.Router)
authrest.RegisterTxRoutes(clientCtx, apiSvr.Router)
ModuleBasics.RegisterRESTRoutes(clientCtx, apiSvr.Router)
Expand Down
2 changes: 1 addition & 1 deletion simd/cmd/genaccounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ contain valid denominations. Accounts may optionally be supplied with vesting pa
}

genFile := config.GenesisFile()
appState, genDoc, err := genutiltypes.GenesisStateFromGenFile(depCdc, genFile)
appState, genDoc, err := genutiltypes.GenesisStateFromGenFile(genFile)
if err != nil {
return fmt.Errorf("failed to unmarshal genesis state: %w", err)
}
Expand Down
17 changes: 14 additions & 3 deletions state.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"time"

"github.com/tendermint/tendermint/crypto/secp256k1"
tmjson "github.com/tendermint/tendermint/libs/json"
tmtypes "github.com/tendermint/tendermint/types"

"github.com/cosmos/cosmos-sdk/codec"
Expand Down Expand Up @@ -56,7 +57,10 @@ func AppStateFn(cdc codec.JSONMarshaler, simManager *module.SimulationManager) s
panic(err)
}

cdc.MustUnmarshalJSON(bz, &appParams)
err = json.Unmarshal(bz, &appParams)
if err != nil {
panic(err)
}
appState, simAccs = AppStateRandomizedFn(simManager, r, cdc, accs, genesisTimestamp, appParams)

default:
Expand Down Expand Up @@ -132,10 +136,17 @@ func AppStateFromGenesisFileFn(r io.Reader, cdc codec.JSONMarshaler, genesisFile
}

var genesis tmtypes.GenesisDoc
cdc.MustUnmarshalJSON(bytes, &genesis)
// NOTE: Tendermint uses a custom JSON decoder for GenesisDoc
err = tmjson.Unmarshal(bytes, &genesis)
if err != nil {
panic(err)
}

var appState GenesisState
cdc.MustUnmarshalJSON(genesis.AppState, &appState)
err = json.Unmarshal(genesis.AppState, &appState)
if err != nil {
panic(err)
}

var authGenesis authtypes.GenesisState
if appState[authtypes.ModuleName] != nil {
Expand Down

0 comments on commit 0f6154e

Please sign in to comment.