diff --git a/CHANGELOG_PENDING.md b/CHANGELOG_PENDING.md index 620a98472..d0e555d96 100644 --- a/CHANGELOG_PENDING.md +++ b/CHANGELOG_PENDING.md @@ -39,6 +39,7 @@ Friendly reminder, we have a [bug bounty program](https://hackerone.com/tendermi - [light] \#4964 `light` reactor migration to Protobuf encoding - [store] \#4778 Transition store module to protobuf encoding - `BlockStoreStateJSON` is now `BlockStoreState` and is encoded as binary in the database + - [rpc] \#4968 JSON encoding is now handled by `libs/json`, not Amino - Apps diff --git a/cmd/tendermint/commands/codec.go b/cmd/tendermint/commands/codec.go deleted file mode 100644 index 041b9e9ce..000000000 --- a/cmd/tendermint/commands/codec.go +++ /dev/null @@ -1,13 +0,0 @@ -package commands - -import ( - amino "github.com/tendermint/go-amino" - - cryptoamino "github.com/tendermint/tendermint/crypto/encoding/amino" -) - -var cdc = amino.NewCodec() - -func init() { - cryptoamino.RegisterAmino(cdc) -} diff --git a/cmd/tendermint/commands/gen_validator.go b/cmd/tendermint/commands/gen_validator.go index 572bc974f..41020a5be 100644 --- a/cmd/tendermint/commands/gen_validator.go +++ b/cmd/tendermint/commands/gen_validator.go @@ -5,6 +5,7 @@ import ( "github.com/spf13/cobra" + tmjson "github.com/tendermint/tendermint/libs/json" "github.com/tendermint/tendermint/privval" ) @@ -18,7 +19,7 @@ var GenValidatorCmd = &cobra.Command{ func genValidator(cmd *cobra.Command, args []string) { pv := privval.GenFilePV("", "") - jsbz, err := cdc.MarshalJSON(pv) + jsbz, err := tmjson.Marshal(pv) if err != nil { panic(err) } diff --git a/cmd/tendermint/commands/probe_upnp.go b/cmd/tendermint/commands/probe_upnp.go index 35c3c354d..9ac35fd50 100644 --- a/cmd/tendermint/commands/probe_upnp.go +++ b/cmd/tendermint/commands/probe_upnp.go @@ -5,6 +5,7 @@ import ( "github.com/spf13/cobra" + tmjson "github.com/tendermint/tendermint/libs/json" "github.com/tendermint/tendermint/p2p/upnp" ) @@ -21,7 +22,7 @@ func probeUpnp(cmd *cobra.Command, args []string) error { fmt.Println("Probe failed: ", err) } else { fmt.Println("Probe success!") - jsonBytes, err := cdc.MarshalJSON(capabilities) + jsonBytes, err := tmjson.Marshal(capabilities) if err != nil { return err } diff --git a/cmd/tendermint/commands/show_validator.go b/cmd/tendermint/commands/show_validator.go index fef458a2f..e3980743a 100644 --- a/cmd/tendermint/commands/show_validator.go +++ b/cmd/tendermint/commands/show_validator.go @@ -5,6 +5,7 @@ import ( "github.com/spf13/cobra" + tmjson "github.com/tendermint/tendermint/libs/json" tmos "github.com/tendermint/tendermint/libs/os" "github.com/tendermint/tendermint/privval" ) @@ -29,7 +30,7 @@ func showValidator(cmd *cobra.Command, args []string) error { return fmt.Errorf("can't get pubkey: %w", err) } - bz, err := cdc.MarshalJSON(pubKey) + bz, err := tmjson.Marshal(pubKey) if err != nil { return fmt.Errorf("failed to marshal private validator pubkey: %w", err) } diff --git a/consensus/reactor.go b/consensus/reactor.go index 432791209..01a435035 100644 --- a/consensus/reactor.go +++ b/consensus/reactor.go @@ -12,6 +12,7 @@ import ( cstypes "github.com/tendermint/tendermint/consensus/types" "github.com/tendermint/tendermint/libs/bits" tmevents "github.com/tendermint/tendermint/libs/events" + tmjson "github.com/tendermint/tendermint/libs/json" "github.com/tendermint/tendermint/libs/log" "github.com/tendermint/tendermint/p2p" tmproto "github.com/tendermint/tendermint/proto/types" @@ -953,12 +954,12 @@ func (ps *PeerState) GetRoundState() *cstypes.PeerRoundState { return &prs } -// ToJSON returns a json of PeerState, marshalled using go-amino. +// ToJSON returns a json of PeerState. func (ps *PeerState) ToJSON() ([]byte, error) { ps.mtx.Lock() defer ps.mtx.Unlock() - return cdc.MarshalJSON(ps) + return tmjson.Marshal(ps) } // GetHeight returns an atomic snapshot of the PeerRoundState's height @@ -1393,6 +1394,18 @@ func RegisterMessages(cdc *amino.Codec) { cdc.RegisterConcrete(&VoteSetBitsMessage{}, "tendermint/VoteSetBits", nil) } +func init() { + tmjson.RegisterType(&NewRoundStepMessage{}, "tendermint/NewRoundStepMessage") + tmjson.RegisterType(&NewValidBlockMessage{}, "tendermint/NewValidBlockMessage") + tmjson.RegisterType(&ProposalMessage{}, "tendermint/Proposal") + tmjson.RegisterType(&ProposalPOLMessage{}, "tendermint/ProposalPOL") + tmjson.RegisterType(&BlockPartMessage{}, "tendermint/BlockPart") + tmjson.RegisterType(&VoteMessage{}, "tendermint/Vote") + tmjson.RegisterType(&HasVoteMessage{}, "tendermint/HasVote") + tmjson.RegisterType(&VoteSetMaj23Message{}, "tendermint/VoteSetMaj23") + tmjson.RegisterType(&VoteSetBitsMessage{}, "tendermint/VoteSetBits") +} + func decodeMsg(bz []byte) (msg Message, err error) { err = cdc.UnmarshalBinaryBare(bz, &msg) return diff --git a/consensus/state.go b/consensus/state.go index 85da7190f..924ffbefa 100644 --- a/consensus/state.go +++ b/consensus/state.go @@ -17,6 +17,7 @@ import ( cstypes "github.com/tendermint/tendermint/consensus/types" tmevents "github.com/tendermint/tendermint/libs/events" "github.com/tendermint/tendermint/libs/fail" + tmjson "github.com/tendermint/tendermint/libs/json" "github.com/tendermint/tendermint/libs/log" tmmath "github.com/tendermint/tendermint/libs/math" tmos "github.com/tendermint/tendermint/libs/os" @@ -235,18 +236,18 @@ func (cs *State) GetRoundState() *cstypes.RoundState { return &rs } -// GetRoundStateJSON returns a json of RoundState, marshalled using go-amino. +// GetRoundStateJSON returns a json of RoundState. func (cs *State) GetRoundStateJSON() ([]byte, error) { cs.mtx.RLock() defer cs.mtx.RUnlock() - return cdc.MarshalJSON(cs.RoundState) + return tmjson.Marshal(cs.RoundState) } // GetRoundStateSimpleJSON returns a json of RoundStateSimple, marshalled using go-amino. func (cs *State) GetRoundStateSimpleJSON() ([]byte, error) { cs.mtx.RLock() defer cs.mtx.RUnlock() - return cdc.MarshalJSON(cs.RoundState.RoundStateSimple()) + return tmjson.Marshal(cs.RoundState.RoundStateSimple()) } // GetValidators returns a copy of the current validators. diff --git a/consensus/types/height_vote_set.go b/consensus/types/height_vote_set.go index 42eb2265e..5304bf994 100644 --- a/consensus/types/height_vote_set.go +++ b/consensus/types/height_vote_set.go @@ -6,6 +6,7 @@ import ( "strings" "sync" + tmjson "github.com/tendermint/tendermint/libs/json" tmmath "github.com/tendermint/tendermint/libs/math" "github.com/tendermint/tendermint/p2p" tmproto "github.com/tendermint/tendermint/proto/types" @@ -237,9 +238,7 @@ func (hvs *HeightVoteSet) StringIndented(indent string) string { func (hvs *HeightVoteSet) MarshalJSON() ([]byte, error) { hvs.mtx.Lock() defer hvs.mtx.Unlock() - - allVotes := hvs.toAllRoundVotes() - return cdc.MarshalJSON(allVotes) + return tmjson.Marshal(hvs.toAllRoundVotes()) } func (hvs *HeightVoteSet) toAllRoundVotes() []roundVotes { diff --git a/consensus/wal.go b/consensus/wal.go index 3fdae5f8f..215bfd1bd 100644 --- a/consensus/wal.go +++ b/consensus/wal.go @@ -11,6 +11,7 @@ import ( amino "github.com/tendermint/go-amino" auto "github.com/tendermint/tendermint/libs/autofile" + tmjson "github.com/tendermint/tendermint/libs/json" "github.com/tendermint/tendermint/libs/log" tmos "github.com/tendermint/tendermint/libs/os" "github.com/tendermint/tendermint/libs/service" @@ -55,6 +56,12 @@ func RegisterWALMessages(cdc *amino.Codec) { cdc.RegisterConcrete(EndHeightMessage{}, "tendermint/wal/EndHeightMessage", nil) } +func init() { + tmjson.RegisterType(msgInfo{}, "tendermint/wal/MsgInfo") + tmjson.RegisterType(timeoutInfo{}, "tendermint/wal/TimeoutInfo") + tmjson.RegisterType(EndHeightMessage{}, "tendermint/wal/EndHeightMessage") +} + //-------------------------------------------------------- // Simple write-ahead logger diff --git a/crypto/encoding/amino/encode_test.go b/crypto/encoding/amino/encode_test.go index a867ea68e..18908369a 100644 --- a/crypto/encoding/amino/encode_test.go +++ b/crypto/encoding/amino/encode_test.go @@ -14,6 +14,7 @@ import ( "github.com/tendermint/tendermint/crypto/multisig" "github.com/tendermint/tendermint/crypto/secp256k1" "github.com/tendermint/tendermint/crypto/sr25519" + tmjson "github.com/tendermint/tendermint/libs/json" ) type AminoMarshal interface { @@ -39,9 +40,9 @@ func checkAminoBinary(t *testing.T, src, dst interface{}, size int) { require.Nil(t, err, "%+v", err) } -func checkAminoJSON(t *testing.T, src interface{}, dst interface{}, isNil bool) { +func checkJSON(t *testing.T, src interface{}, dst interface{}, isNil bool) { // Marshal to JSON bytes. - js, err := cdc.MarshalJSON(src) + js, err := tmjson.Marshal(src) require.Nil(t, err, "%+v", err) if isNil { assert.Equal(t, string(js), `null`) @@ -50,7 +51,7 @@ func checkAminoJSON(t *testing.T, src interface{}, dst interface{}, isNil bool) assert.Contains(t, string(js), `"value":`) } // Unmarshal. - err = cdc.UnmarshalJSON(js, dst) + err = tmjson.Unmarshal(js, dst) require.Nil(t, err, "%+v", err) } @@ -85,7 +86,7 @@ func TestKeyEncodings(t *testing.T) { var priv2, priv3 crypto.PrivKey checkAminoBinary(t, tc.privKey, &priv2, tc.privSize) assert.EqualValues(t, tc.privKey, priv2, "tc #%d", tcIndex) - checkAminoJSON(t, tc.privKey, &priv3, false) // TODO also check Prefix bytes. + checkJSON(t, tc.privKey, &priv3, false) // TODO also check Prefix bytes. assert.EqualValues(t, tc.privKey, priv3, "tc #%d", tcIndex) // Check (de/en)codings of Signatures. @@ -100,7 +101,7 @@ func TestKeyEncodings(t *testing.T) { var pub2, pub3 crypto.PubKey checkAminoBinary(t, pubKey, &pub2, tc.pubSize) assert.EqualValues(t, pubKey, pub2, "tc #%d", tcIndex) - checkAminoJSON(t, pubKey, &pub3, false) // TODO also check Prefix bytes. + checkJSON(t, pubKey, &pub3, false) // TODO also check Prefix bytes. assert.EqualValues(t, pubKey, pub3, "tc #%d", tcIndex) } } @@ -109,17 +110,17 @@ func TestNilEncodings(t *testing.T) { // Check nil Signature. var a, b []byte - checkAminoJSON(t, &a, &b, true) + checkJSON(t, &a, &b, true) assert.EqualValues(t, a, b) // Check nil PubKey. var c, d crypto.PubKey - checkAminoJSON(t, &c, &d, true) + checkJSON(t, &c, &d, true) assert.EqualValues(t, c, d) // Check nil PrivKey. var e, f crypto.PrivKey - checkAminoJSON(t, &e, &f, true) + checkJSON(t, &e, &f, true) assert.EqualValues(t, e, f) } diff --git a/crypto/secp256k1/encoding.go b/crypto/secp256k1/encoding.go index bc9a40121..3ea0b7947 100644 --- a/crypto/secp256k1/encoding.go +++ b/crypto/secp256k1/encoding.go @@ -2,7 +2,9 @@ package secp256k1 import ( amino "github.com/tendermint/go-amino" + "github.com/tendermint/tendermint/crypto" + tmjson "github.com/tendermint/tendermint/libs/json" ) const ( @@ -20,4 +22,7 @@ func init() { cdc.RegisterInterface((*crypto.PrivKey)(nil), nil) cdc.RegisterConcrete(PrivKey{}, PrivKeyAminoName, nil) + + tmjson.RegisterType(PubKey{}, PubKeyAminoName) + tmjson.RegisterType(PrivKey{}, PrivKeyAminoName) } diff --git a/crypto/sr25519/encoding.go b/crypto/sr25519/encoding.go index 26a67c3ea..a914e1b7d 100644 --- a/crypto/sr25519/encoding.go +++ b/crypto/sr25519/encoding.go @@ -2,7 +2,9 @@ package sr25519 import ( "github.com/tendermint/go-amino" + "github.com/tendermint/tendermint/crypto" + tmjson "github.com/tendermint/tendermint/libs/json" ) var _ crypto.PrivKey = PrivKey{} @@ -26,4 +28,7 @@ func init() { cdc.RegisterInterface((*crypto.PrivKey)(nil), nil) cdc.RegisterConcrete(PrivKey{}, PrivKeyAminoName, nil) + + tmjson.RegisterType(PubKey{}, PubKeyAminoName) + tmjson.RegisterType(PrivKey{}, PrivKeyAminoName) } diff --git a/node/node.go b/node/node.go index 4d963510c..97e6e37c0 100644 --- a/node/node.go +++ b/node/node.go @@ -25,6 +25,7 @@ import ( cs "github.com/tendermint/tendermint/consensus" "github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/evidence" + tmjson "github.com/tendermint/tendermint/libs/json" "github.com/tendermint/tendermint/libs/log" tmpubsub "github.com/tendermint/tendermint/libs/pubsub" "github.com/tendermint/tendermint/libs/service" @@ -1293,7 +1294,7 @@ func loadGenesisDoc(db dbm.DB) (*types.GenesisDoc, error) { return nil, errors.New("genesis doc not found") } var genDoc *types.GenesisDoc - err = cdc.UnmarshalJSON(b, &genDoc) + err = tmjson.Unmarshal(b, &genDoc) if err != nil { panic(fmt.Sprintf("Failed to load genesis doc due to unmarshaling error: %v (bytes: %X)", err, b)) } @@ -1302,7 +1303,7 @@ func loadGenesisDoc(db dbm.DB) (*types.GenesisDoc, error) { // panics if failed to marshal the given genesis document func saveGenesisDoc(db dbm.DB, genDoc *types.GenesisDoc) { - b, err := cdc.MarshalJSON(genDoc) + b, err := tmjson.Marshal(genDoc) if err != nil { panic(fmt.Sprintf("Failed to save genesis doc due to marshaling error: %v", err)) } diff --git a/p2p/key.go b/p2p/key.go index 84dec3f1a..f0f3dfd03 100644 --- a/p2p/key.go +++ b/p2p/key.go @@ -8,6 +8,7 @@ import ( "github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/crypto/ed25519" + tmjson "github.com/tendermint/tendermint/libs/json" tmos "github.com/tendermint/tendermint/libs/os" ) @@ -74,7 +75,7 @@ func LoadNodeKey(filePath string) (*NodeKey, error) { return nil, err } nodeKey := new(NodeKey) - err = cdc.UnmarshalJSON(jsonBytes, nodeKey) + err = tmjson.Unmarshal(jsonBytes, nodeKey) if err != nil { return nil, err } @@ -83,7 +84,7 @@ func LoadNodeKey(filePath string) (*NodeKey, error) { // SaveAs persists the NodeKey to filePath. func (nodeKey *NodeKey) SaveAs(filePath string) error { - jsonBytes, err := cdc.MarshalJSON(nodeKey) + jsonBytes, err := tmjson.Marshal(nodeKey) if err != nil { return err } diff --git a/privval/file.go b/privval/file.go index 5666a50fd..06c0073de 100644 --- a/privval/file.go +++ b/privval/file.go @@ -10,6 +10,7 @@ import ( "github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/crypto/ed25519" tmbytes "github.com/tendermint/tendermint/libs/bytes" + tmjson "github.com/tendermint/tendermint/libs/json" tmos "github.com/tendermint/tendermint/libs/os" "github.com/tendermint/tendermint/libs/tempfile" tmproto "github.com/tendermint/tendermint/proto/types" @@ -55,7 +56,7 @@ func (pvKey FilePVKey) Save() { panic("cannot save PrivValidator key: filePath not set") } - jsonBytes, err := cdc.MarshalJSONIndent(pvKey, "", " ") + jsonBytes, err := tmjson.MarshalIndent(pvKey, "", " ") if err != nil { panic(err) } @@ -126,7 +127,7 @@ func (lss *FilePVLastSignState) Save() { if outFile == "" { panic("cannot save FilePVLastSignState: filePath not set") } - jsonBytes, err := cdc.MarshalJSONIndent(lss, "", " ") + jsonBytes, err := tmjson.MarshalIndent(lss, "", " ") if err != nil { panic(err) } @@ -187,7 +188,7 @@ func loadFilePV(keyFilePath, stateFilePath string, loadState bool) *FilePV { tmos.Exit(err.Error()) } pvKey := FilePVKey{} - err = cdc.UnmarshalJSON(keyJSONBytes, &pvKey) + err = tmjson.Unmarshal(keyJSONBytes, &pvKey) if err != nil { tmos.Exit(fmt.Sprintf("Error reading PrivValidator key from %v: %v\n", keyFilePath, err)) } @@ -203,7 +204,7 @@ func loadFilePV(keyFilePath, stateFilePath string, loadState bool) *FilePV { if err != nil { tmos.Exit(err.Error()) } - err = cdc.UnmarshalJSON(stateJSONBytes, &pvState) + err = tmjson.Unmarshal(stateJSONBytes, &pvState) if err != nil { tmos.Exit(fmt.Sprintf("Error reading PrivValidator state from %v: %v\n", stateFilePath, err)) } @@ -406,8 +407,8 @@ func checkVotesOnlyDifferByTimestamp(lastSignBytes, newSignBytes []byte) (time.T now := tmtime.Now() lastVote.Timestamp = now newVote.Timestamp = now - lastVoteBytes, _ := cdc.MarshalJSON(lastVote) - newVoteBytes, _ := cdc.MarshalJSON(newVote) + lastVoteBytes, _ := tmjson.Marshal(lastVote) + newVoteBytes, _ := tmjson.Marshal(newVote) return lastTime, bytes.Equal(newVoteBytes, lastVoteBytes) } diff --git a/privval/file_test.go b/privval/file_test.go index b118ac869..540e952a5 100644 --- a/privval/file_test.go +++ b/privval/file_test.go @@ -12,6 +12,7 @@ import ( "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/crypto/ed25519" + tmjson "github.com/tendermint/tendermint/libs/json" tmproto "github.com/tendermint/tendermint/proto/types" "github.com/tendermint/tendermint/types" tmtime "github.com/tendermint/tendermint/types/time" @@ -99,7 +100,7 @@ func TestUnmarshalValidatorState(t *testing.T) { }` val := FilePVLastSignState{} - err := cdc.UnmarshalJSON([]byte(serialized), &val) + err := tmjson.Unmarshal([]byte(serialized), &val) require.Nil(err, "%+v", err) // make sure the values match @@ -108,7 +109,7 @@ func TestUnmarshalValidatorState(t *testing.T) { assert.EqualValues(val.Step, 1) // export it and make sure it is the same - out, err := cdc.MarshalJSON(val) + out, err := tmjson.Marshal(val) require.Nil(err, "%+v", err) assert.JSONEq(serialized, string(out)) } @@ -138,7 +139,7 @@ func TestUnmarshalValidatorKey(t *testing.T) { }`, addr, pubB64, privB64) val := FilePVKey{} - err := cdc.UnmarshalJSON([]byte(serialized), &val) + err := tmjson.Unmarshal([]byte(serialized), &val) require.Nil(err, "%+v", err) // make sure the values match @@ -147,7 +148,7 @@ func TestUnmarshalValidatorKey(t *testing.T) { assert.EqualValues(privKey, val.PrivKey) // export it and make sure it is the same - out, err := cdc.MarshalJSON(val) + out, err := tmjson.Marshal(val) require.Nil(err, "%+v", err) assert.JSONEq(serialized, string(out)) } diff --git a/scripts/json2wal/main.go b/scripts/json2wal/main.go index a23dc5d57..ef98977d9 100644 --- a/scripts/json2wal/main.go +++ b/scripts/json2wal/main.go @@ -14,20 +14,11 @@ import ( "os" "strings" - amino "github.com/tendermint/go-amino" - cs "github.com/tendermint/tendermint/consensus" + tmjson "github.com/tendermint/tendermint/libs/json" "github.com/tendermint/tendermint/types" ) -var cdc = amino.NewCodec() - -func init() { - cs.RegisterMessages(cdc) - cs.RegisterWALMessages(cdc) - types.RegisterBlockAmino(cdc) -} - func main() { if len(os.Args) < 3 { fmt.Fprintln(os.Stderr, "missing arguments: Usage:json2wal ") @@ -65,7 +56,7 @@ func main() { } var msg cs.TimedWALMessage - err = cdc.UnmarshalJSON(msgJSON, &msg) + err = tmjson.Unmarshal(msgJSON, &msg) if err != nil { panic(fmt.Errorf("failed to unmarshal json: %v", err)) } diff --git a/scripts/wal2json/main.go b/scripts/wal2json/main.go index 181f40c75..123c103a2 100644 --- a/scripts/wal2json/main.go +++ b/scripts/wal2json/main.go @@ -12,20 +12,10 @@ import ( "io" "os" - amino "github.com/tendermint/go-amino" - cs "github.com/tendermint/tendermint/consensus" - "github.com/tendermint/tendermint/types" + tmjson "github.com/tendermint/tendermint/libs/json" ) -var cdc = amino.NewCodec() - -func init() { - cs.RegisterMessages(cdc) - cs.RegisterWALMessages(cdc) - types.RegisterBlockAmino(cdc) -} - func main() { if len(os.Args) < 2 { fmt.Println("missing one argument: ") @@ -47,7 +37,7 @@ func main() { panic(fmt.Errorf("failed to decode msg: %v", err)) } - json, err := cdc.MarshalJSON(msg) + json, err := tmjson.Marshal(msg) if err != nil { panic(fmt.Errorf("failed to marshal msg: %v", err)) } diff --git a/test/app/grpc_client.go b/test/app/grpc_client.go index 88e4650ab..73022aaf8 100644 --- a/test/app/grpc_client.go +++ b/test/app/grpc_client.go @@ -7,8 +7,7 @@ import ( "context" - amino "github.com/tendermint/go-amino" - + tmjson "github.com/tendermint/tendermint/libs/json" coregrpc "github.com/tendermint/tendermint/rpc/grpc" ) @@ -34,7 +33,7 @@ func main() { os.Exit(1) } - bz, err := amino.NewCodec().MarshalJSON(res) + bz, err := tmjson.Marshal(res) if err != nil { fmt.Println(err) os.Exit(1) diff --git a/types/genesis.go b/types/genesis.go index 216827b3f..d5924fe3e 100644 --- a/types/genesis.go +++ b/types/genesis.go @@ -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 } diff --git a/types/genesis_test.go b/types/genesis_test.go index ee713a6e7..a56bfaa65 100644 --- a/types/genesis_test.go +++ b/types/genesis_test.go @@ -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") diff --git a/types/part_set.go b/types/part_set.go index 0cf319b6e..bb05ce1cd 100644 --- a/types/part_set.go +++ b/types/part_set.go @@ -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"` }{ diff --git a/types/vote_set.go b/types/vote_set.go index 443077292..f874dd5ab 100644 --- a/types/vote_set.go +++ b/types/vote_set.go @@ -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,