Lots of updates to use new go-crypto / json style

This commit is contained in:
Ethan Frey
2017-03-21 22:46:15 +01:00
committed by Ethan Buchman
parent 516e78ea54
commit e325ffc681
7 changed files with 41 additions and 31 deletions

View File

@@ -1,11 +1,11 @@
package types
import (
"encoding/json"
"time"
. "github.com/tendermint/go-common"
"github.com/tendermint/go-crypto"
"github.com/tendermint/go-wire"
)
//------------------------------------------------------------
@@ -31,14 +31,18 @@ type GenesisDoc struct {
// Utility method for saving GenensisDoc as JSON file.
func (genDoc *GenesisDoc) SaveAs(file string) error {
genDocBytes := wire.JSONBytesPretty(genDoc)
genDocBytes, err := json.Marshal(genDoc)
if err != nil {
return err
}
return WriteFile(file, genDocBytes, 0644)
}
//------------------------------------------------------------
// Make genesis state from file
func GenesisDocFromJSON(jsonBlob []byte) (genDoc *GenesisDoc, err error) {
wire.ReadJSONPtr(&genDoc, jsonBlob, &err)
return
func GenesisDocFromJSON(jsonBlob []byte) (*GenesisDoc, error) {
genDoc := GenesisDoc{}
err := json.Unmarshal(jsonBlob, &genDoc)
return &genDoc, err
}

View File

@@ -2,6 +2,7 @@ package types
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io/ioutil"
@@ -10,7 +11,6 @@ import (
. "github.com/tendermint/go-common"
"github.com/tendermint/go-crypto"
"github.com/tendermint/go-wire"
)
const (
@@ -96,13 +96,14 @@ func LoadPrivValidator(filePath string) *PrivValidator {
if err != nil {
Exit(err.Error())
}
privVal := wire.ReadJSON(&PrivValidator{}, privValJSONBytes, &err).(*PrivValidator)
privVal := PrivValidator{}
err = json.Unmarshal(privValJSONBytes, &privVal)
if err != nil {
Exit(Fmt("Error reading PrivValidator from %v: %v\n", filePath, err))
}
privVal.filePath = filePath
privVal.Signer = NewDefaultSigner(privVal.PrivKey)
return privVal
return &privVal
}
func LoadOrGenPrivValidator(filePath string) *PrivValidator {
@@ -136,8 +137,12 @@ func (privVal *PrivValidator) save() {
if privVal.filePath == "" {
PanicSanity("Cannot save PrivValidator: filePath not set")
}
jsonBytes := wire.JSONBytesPretty(privVal)
err := WriteFileAtomic(privVal.filePath, jsonBytes, 0600)
jsonBytes, err := json.Marshal(privVal)
if err != nil {
// `@; BOOM!!!
PanicCrisis(err)
}
err = WriteFileAtomic(privVal.filePath, jsonBytes, 0600)
if err != nil {
// `@; BOOM!!!
PanicCrisis(err)