/
tmValKey.go
34 lines (29 loc) · 1.02 KB
/
tmValKey.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package config
import (
cmn "github.com/tendermint/tendermint/libs/common"
"github.com/tendermint/tendermint/privval"
)
const (
stepNone int8 = 0 // Used to distinguish the initial state
)
// LoadOrGenFilePV loads a FilePV from the given filePaths
// or else generates a new one and saves it to the filePaths.
func LoadOrGenFilePV(keyFilePath, stateFilePath string) *privval.FilePV {
var pv *privval.FilePV
if cmn.FileExists(keyFilePath) {
pv = LoadFilePV(keyFilePath, stateFilePath)
} else {
pv = GenFilePV(keyFilePath, stateFilePath)
pv.Save()
}
return pv
}
// GenFilePV generates a new validator with randomly generated private key
// and sets the filePaths, but does not call Save().
func GenFilePV(keyFilePath, stateFilePath string) *privval.FilePV {
return privval.GenFilePV(keyFilePath, stateFilePath)
}
// LoadFilePV loads the private validator file and generates the FilePV object
func LoadFilePV(privValKeyFile, privValStateFile string) *privval.FilePV {
return privval.LoadFilePV(privValKeyFile, privValStateFile)
}