mirror of
https://github.com/tendermint/tendermint.git
synced 2026-06-07 23:02:36 +00:00
Lots of updates to use new go-crypto / json style
This commit is contained in:
committed by
Ethan Buchman
parent
516e78ea54
commit
e325ffc681
@@ -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
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user