migrate all JSON to new JSON encoder (#4975)

Uses new JSON encoder in #4955 for all JSON. Branched off of #4968.
This commit is contained in:
Erik Grinaker
2020-06-08 14:22:59 +02:00
committed by GitHub
parent ba3a2dde37
commit db8f1b3df3
23 changed files with 89 additions and 79 deletions

View File

@@ -10,6 +10,7 @@ import (
"github.com/tendermint/tendermint/crypto"
tmbytes "github.com/tendermint/tendermint/libs/bytes"
tmjson "github.com/tendermint/tendermint/libs/json"
tmos "github.com/tendermint/tendermint/libs/os"
tmproto "github.com/tendermint/tendermint/proto/types"
tmtime "github.com/tendermint/tendermint/types/time"
@@ -46,7 +47,7 @@ type GenesisDoc struct {
// SaveAs is a utility method for saving GenensisDoc as a JSON file.
func (genDoc *GenesisDoc) SaveAs(file string) error {
genDocBytes, err := cdc.MarshalJSONIndent(genDoc, "", " ")
genDocBytes, err := tmjson.MarshalIndent(genDoc, "", " ")
if err != nil {
return err
}
@@ -104,7 +105,7 @@ func (genDoc *GenesisDoc) ValidateAndComplete() error {
// GenesisDocFromJSON unmarshalls JSON data into a GenesisDoc.
func GenesisDocFromJSON(jsonBlob []byte) (*GenesisDoc, error) {
genDoc := GenesisDoc{}
err := cdc.UnmarshalJSON(jsonBlob, &genDoc)
err := tmjson.Unmarshal(jsonBlob, &genDoc)
if err != nil {
return nil, err
}

View File

@@ -9,6 +9,7 @@ import (
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/crypto/ed25519"
tmjson "github.com/tendermint/tendermint/libs/json"
tmtime "github.com/tendermint/tendermint/types/time"
)
@@ -73,7 +74,7 @@ func TestGenesisGood(t *testing.T) {
ChainID: "abc",
Validators: []GenesisValidator{{pubkey.Address(), pubkey, 10, "myval"}},
}
genDocBytes, err = cdc.MarshalJSON(baseGenDoc)
genDocBytes, err = tmjson.Marshal(baseGenDoc)
assert.NoError(t, err, "error marshalling genDoc")
// test base gendoc and check consensus params were filled
@@ -85,14 +86,14 @@ func TestGenesisGood(t *testing.T) {
assert.NotNil(t, genDoc.Validators[0].Address, "expected validator's address to be filled in")
// create json with consensus params filled
genDocBytes, err = cdc.MarshalJSON(genDoc)
genDocBytes, err = tmjson.Marshal(genDoc)
assert.NoError(t, err, "error marshalling genDoc")
genDoc, err = GenesisDocFromJSON(genDocBytes)
assert.NoError(t, err, "expected no error for valid genDoc json")
// test with invalid consensus params
genDoc.ConsensusParams.Block.MaxBytes = 0
genDocBytes, err = cdc.MarshalJSON(genDoc)
genDocBytes, err = tmjson.Marshal(genDoc)
assert.NoError(t, err, "error marshalling genDoc")
_, err = GenesisDocFromJSON(genDocBytes)
assert.Error(t, err, "expected error for genDoc json with block size of 0")

View File

@@ -10,6 +10,7 @@ import (
"github.com/tendermint/tendermint/crypto/merkle"
"github.com/tendermint/tendermint/libs/bits"
tmbytes "github.com/tendermint/tendermint/libs/bytes"
tmjson "github.com/tendermint/tendermint/libs/json"
tmmath "github.com/tendermint/tendermint/libs/math"
tmproto "github.com/tendermint/tendermint/proto/types"
)
@@ -338,7 +339,7 @@ func (ps *PartSet) MarshalJSON() ([]byte, error) {
ps.mtx.Lock()
defer ps.mtx.Unlock()
return cdc.MarshalJSON(struct {
return tmjson.Marshal(struct {
CountTotal string `json:"count/total"`
PartsBitArray *bits.BitArray `json:"parts_bit_array"`
}{

View File

@@ -7,6 +7,7 @@ import (
"sync"
"github.com/tendermint/tendermint/libs/bits"
tmjson "github.com/tendermint/tendermint/libs/json"
tmproto "github.com/tendermint/tendermint/proto/types"
)
@@ -477,7 +478,7 @@ func (voteSet *VoteSet) StringIndented(indent string) string {
func (voteSet *VoteSet) MarshalJSON() ([]byte, error) {
voteSet.mtx.Lock()
defer voteSet.mtx.Unlock()
return cdc.MarshalJSON(VoteSetJSON{
return tmjson.Marshal(VoteSetJSON{
voteSet.voteStrings(),
voteSet.bitArrayString(),
voteSet.peerMaj23s,