Browse Source

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.
pull/637/head
Duncan Jones 7 years ago
committed by Ethan Buchman
parent
commit
7e4a704bd1
2 changed files with 15 additions and 3 deletions
  1. +6
    -2
      cmd/hsm/main.go
  2. +9
    -1
      types/priv_validator.go

+ 6
- 2
cmd/hsm/main.go 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
types/priv_validator.go 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
}


Loading…
Cancel
Save