Replace uses of libs/json with encoding/json. (#7534)

Where possible, replace uses of the custom JSON library with the standard
library. The custom library treats interface and unnamed lteral types
differently, so this change avoids those even where it would probably be safe
to switch them.
This commit is contained in:
M. J. Fromberger
2022-01-08 08:47:26 -08:00
committed by GitHub
parent d5c39f907d
commit 366ab1947a
8 changed files with 21 additions and 19 deletions
+4 -3
View File
@@ -3,6 +3,7 @@ package privval
import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"os"
@@ -72,7 +73,7 @@ func (pvKey FilePVKey) Save() error {
// FilePVLastSignState stores the mutable part of PrivValidator.
type FilePVLastSignState struct {
Height int64 `json:"height"`
Height int64 `json:"height,string"`
Round int32 `json:"round"`
Step int8 `json:"step"`
Signature []byte `json:"signature,omitempty"`
@@ -128,7 +129,7 @@ func (lss *FilePVLastSignState) Save() error {
if outFile == "" {
return errors.New("cannot save FilePVLastSignState: filePath not set")
}
jsonBytes, err := tmjson.MarshalIndent(lss, "", " ")
jsonBytes, err := json.MarshalIndent(lss, "", " ")
if err != nil {
return err
}
@@ -215,7 +216,7 @@ func loadFilePV(keyFilePath, stateFilePath string, loadState bool) (*FilePV, err
if err != nil {
return nil, err
}
err = tmjson.Unmarshal(stateJSONBytes, &pvState)
err = json.Unmarshal(stateJSONBytes, &pvState)
if err != nil {
return nil, fmt.Errorf("error reading PrivValidator state from %v: %w", stateFilePath, err)
}
+3 -2
View File
@@ -3,6 +3,7 @@ package privval
import (
"context"
"encoding/base64"
"encoding/json"
"fmt"
"os"
"testing"
@@ -105,7 +106,7 @@ func TestUnmarshalValidatorState(t *testing.T) {
}`
val := FilePVLastSignState{}
err := tmjson.Unmarshal([]byte(serialized), &val)
err := json.Unmarshal([]byte(serialized), &val)
require.NoError(t, err)
// make sure the values match
@@ -114,7 +115,7 @@ func TestUnmarshalValidatorState(t *testing.T) {
assert.EqualValues(t, val.Step, 1)
// export it and make sure it is the same
out, err := tmjson.Marshal(val)
out, err := json.Marshal(val)
require.NoError(t, err)
assert.JSONEq(t, serialized, string(out))
}