From 42626d9e16ff7eab2c0647d76b7825ed29de3abe Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Thu, 25 May 2017 13:39:36 -0400 Subject: [PATCH] [types] overwrite pubkey/addr in LoadPrivValidator. closes #500 --- types/priv_validator.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/types/priv_validator.go b/types/priv_validator.go index c3d59c9eb..8c9a011ca 100644 --- a/types/priv_validator.go +++ b/types/priv_validator.go @@ -58,6 +58,7 @@ type PrivValidator struct { // eg. to avoid double signing. // Currently, the only callers are SignVote and SignProposal type Signer interface { + PubKey() crypto.PubKey Sign(msg []byte) crypto.Signature } @@ -75,8 +76,20 @@ func (ds *DefaultSigner) Sign(msg []byte) crypto.Signature { return ds.priv.Sign(msg) } +// Implements Signer +func (ds *DefaultSigner) PubKey() crypto.PubKey { + return ds.priv.PubKey() +} + func (privVal *PrivValidator) SetSigner(s Signer) { privVal.Signer = s + privVal.setPubKeyAndAddress() +} + +// Overwrite address and pubkey for convenience +func (privVal *PrivValidator) setPubKeyAndAddress() { + privVal.PubKey = privVal.Signer.PubKey() + privVal.Address = privVal.PubKey.Address() } // Generates a new validator with private key. @@ -103,8 +116,10 @@ func LoadPrivValidator(filePath string) *PrivValidator { if err != nil { Exit(Fmt("Error reading PrivValidator from %v: %v\n", filePath, err)) } + privVal.filePath = filePath privVal.Signer = NewDefaultSigner(privVal.PrivKey) + privVal.setPubKeyAndAddress() return &privVal }