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