Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Make JSONMarshaler methods require proto.Message #7054

Merged
merged 27 commits into from
Aug 26, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
97c59de
Make JSONMarshaler require proto.Message
blushi Aug 13, 2020
8f43ba6
Use &msg with MarshalJSON
blushi Aug 13, 2020
b6dd69b
Use *LegacyAmino in queriers instead of JSONMarshaler
blushi Aug 13, 2020
3af5055
Revert ABCIMessageLogs String() and coins tests
blushi Aug 13, 2020
282cc28
Use LegacyAmino in client/debug and fix subspace tests
blushi Aug 13, 2020
f572cd3
Merge branch 'master' into marie/6982-json-marshaler-proto
blushi Aug 13, 2020
3f68d9a
Use LegacyAmino in all legacy queriers and adapt simulation
blushi Aug 14, 2020
8ed3b64
Merge branch 'master' into marie/6982-json-marshaler-proto
blushi Aug 14, 2020
2d452d4
Make AminoCodec implement Marshaler and some godoc fixes
blushi Aug 14, 2020
fa96cfe
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk into ma…
aaronc Aug 17, 2020
28db5ea
Test fixes
aaronc Aug 17, 2020
2b65f5a
Remove unrelevant comment
blushi Aug 19, 2020
48103b9
Merge branch 'master' into marie/6982-json-marshaler-proto
blushi Aug 19, 2020
b4da972
Use TxConfig.TxJSONEncoder
blushi Aug 19, 2020
ecc133a
Use encoding/json in genutil cli migrate/validate genesis cmds
blushi Aug 19, 2020
7e6d09d
Address simulation related comments
blushi Aug 19, 2020
abfdd22
Use JSONMarshaler in cli tests
blushi Aug 19, 2020
a3e394e
Use proto.Message as respType in cli tests
blushi Aug 20, 2020
e5f88e1
Merge branch 'master' into marie/6982-json-marshaler-proto
blushi Aug 20, 2020
7665df4
Use tmjson for tm GenesisDoc
blushi Aug 24, 2020
8ab0066
Merge branch 'master' into marie/6982-json-marshaler-proto
blushi Aug 24, 2020
12754cd
Update types/module/simulation.go
blushi Aug 25, 2020
17ea317
Update types/module/module_test.go
blushi Aug 25, 2020
4121810
Add godoc comments
blushi Aug 26, 2020
4aa1d08
Remove unused InsertKeyJSON
blushi Aug 26, 2020
5060ae3
Merge branch 'master' into marie/6982-json-marshaler-proto
blushi Aug 26, 2020
0cff5ca
Fix tests
blushi Aug 26, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Make AminoCodec implement Marshaler and some godoc fixes
  • Loading branch information
blushi committed Aug 14, 2020
commit 2d452d48cc38281315b7c9f03942f434017cc179
2 changes: 1 addition & 1 deletion codec/amino.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/cosmos/cosmos-sdk/codec/types"
)

// deprecated: Codec defines a wrapper for an Amino codec that properly handles protobuf
// deprecated: LegacyAmino defines a wrapper for an Amino codec that properly handles protobuf
// types with Any's
type LegacyAmino struct {
Amino *amino.Codec
Expand Down
20 changes: 19 additions & 1 deletion codec/amino_codec.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package codec

import "github.com/gogo/protobuf/proto"

// AminoCodec defines a codec that utilizes Codec for both binary and JSON
// encoding.
type AminoCodec struct {
*LegacyAmino
}

var _ BinaryMarshaler = &AminoCodec{}
var _ Marshaler = &AminoCodec{}

func NewAminoCodec(codec *LegacyAmino) *AminoCodec {
return &AminoCodec{LegacyAmino: codec}
Expand Down Expand Up @@ -43,3 +45,19 @@ func (ac *AminoCodec) UnmarshalBinaryLengthPrefixed(bz []byte, ptr ProtoMarshale
func (ac *AminoCodec) MustUnmarshalBinaryLengthPrefixed(bz []byte, ptr ProtoMarshaler) {
ac.LegacyAmino.MustUnmarshalBinaryLengthPrefixed(bz, ptr)
}

func (ac *AminoCodec) MarshalJSON(o proto.Message) ([]byte, error) {
blushi marked this conversation as resolved.
Show resolved Hide resolved
return ac.LegacyAmino.MarshalJSON(o)
}

func (ac *AminoCodec) MustMarshalJSON(o proto.Message) []byte {
return ac.LegacyAmino.MustMarshalJSON(o)
}

func (ac *AminoCodec) UnmarshalJSON(bz []byte, ptr proto.Message) error {
return ac.LegacyAmino.UnmarshalJSON(bz, ptr)
}

func (ac *AminoCodec) MustUnmarshalJSON(bz []byte, ptr proto.Message) {
ac.LegacyAmino.MustUnmarshalJSON(bz, ptr)
}
2 changes: 1 addition & 1 deletion simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ func (app *SimApp) BlockedAddrs() map[string]bool {
return blockedAddrs
}

// Codec returns SimApp's codec.
// LegacyAmino returns SimApp's legacy amino codec.
//
// NOTE: This is solely to be used for testing purposes as it may be desirable
// for modules to register their own custom testing types.
Expand Down
1 change: 1 addition & 0 deletions simapp/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ func AppStateRandomizedFn(
simState := &module.SimulationState{
AppParams: appParams,
Cdc: cdc,
LegacyAmino: legacyAmino,
blushi marked this conversation as resolved.
Show resolved Hide resolved
Rand: r,
GenState: genesisState,
Accounts: accs,
Expand Down
6 changes: 3 additions & 3 deletions x/auth/keeper/querier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ func TestQueryAccount(t *testing.T) {
require.Error(t, err)
require.Nil(t, res)

req.Data = legacyQuerierCdc.MustMarshalJSON(types.QueryAccountRequest{Address: []byte("")})
req.Data = legacyQuerierCdc.MustMarshalJSON(&types.QueryAccountRequest{Address: []byte("")})
res, err = querier(ctx, path, req)
require.Error(t, err)
require.Nil(t, res)

_, _, addr := testdata.KeyTestPubAddr()
req.Data = legacyQuerierCdc.MustMarshalJSON(types.QueryAccountRequest{Address: addr})
req.Data = legacyQuerierCdc.MustMarshalJSON(&types.QueryAccountRequest{Address: addr})
res, err = querier(ctx, path, req)
require.Error(t, err)
require.Nil(t, res)
Expand All @@ -60,6 +60,6 @@ func TestQueryAccount(t *testing.T) {
require.NotNil(t, res)

var account types.AccountI
err2 := legacyQuerierCdc.UnmarshalJSON(res, &account)
err2 := legacyQuerierCdc.LegacyAmino.UnmarshalJSON(res, &account)
require.Nil(t, err2)
}
2 changes: 1 addition & 1 deletion x/bank/simulation/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func ParamChanges(r *rand.Rand) []simtypes.ParamChange {
return []simtypes.ParamChange{
simulation.NewSimParamChange(types.ModuleName, string(types.KeySendEnabled),
func(r *rand.Rand) string {
return fmt.Sprintf("%s", types.ModuleCdc.MustMarshalJSON(RandomGenesisSendParams(r)))
return fmt.Sprintf("%s", types.ModuleCdc.LegacyAmino.MustMarshalJSON(RandomGenesisSendParams(r)))
blushi marked this conversation as resolved.
Show resolved Hide resolved
},
),
simulation.NewSimParamChange(types.ModuleName, string(types.KeyDefaultSendEnabled),
Expand Down