Remove reliance on default Signer

This change allows the default privValidator to use a custom Signer
implementation with no reliance on the default Signer implementation.
This commit is contained in:
Duncan Jones
2017-09-21 15:50:43 -04:00
committed by Ethan Buchman
parent bf5e956087
commit 7e4a704bd1
2 changed files with 15 additions and 3 deletions
+6 -2
View File
@@ -35,8 +35,12 @@ func main() {
rootCmd.AddCommand(tc.TestnetFilesCmd)
rootCmd.AddCommand(tc.VersionCmd)
privValidator := types.LoadOrGenPrivValidator(config.PrivValidatorFile(), logger)
privValidator.SetSigner(types.NewDefaultSigner(privValidator.PrivKey))
// Override with HSM implementation, otherwise nil will trigger default
// software signer:
var signer types.Signer = nil
privValidator := types.LoadPrivValidatorWithSigner(config.PrivValidatorFile(),
signer)
rootCmd.AddCommand(tc.NewRunNodeCmd(privValidator))
cmd := cli.PrepareBaseCmd(rootCmd, "TM", os.ExpandEnv("$HOME/.tendermint"))
+9 -1
View File
@@ -112,6 +112,10 @@ func GenPrivValidator() *PrivValidator {
}
func LoadPrivValidator(filePath string) *PrivValidator {
return LoadPrivValidatorWithSigner(filePath, nil)
}
func LoadPrivValidatorWithSigner(filePath string, signer Signer) *PrivValidator {
privValJSONBytes, err := ioutil.ReadFile(filePath)
if err != nil {
Exit(err.Error())
@@ -123,7 +127,11 @@ func LoadPrivValidator(filePath string) *PrivValidator {
}
privVal.filePath = filePath
privVal.Signer = NewDefaultSigner(privVal.PrivKey)
if signer == nil {
privVal.Signer = NewDefaultSigner(privVal.PrivKey)
} else {
privVal.Signer = signer
}
privVal.setPubKeyAndAddress()
return &privVal
}