mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-25 10:41:41 +00:00
[types] overwrite pubkey/addr in LoadPrivValidator. closes #500
This commit is contained in:
@ -58,6 +58,7 @@ type PrivValidator struct {
|
|||||||
// eg. to avoid double signing.
|
// eg. to avoid double signing.
|
||||||
// Currently, the only callers are SignVote and SignProposal
|
// Currently, the only callers are SignVote and SignProposal
|
||||||
type Signer interface {
|
type Signer interface {
|
||||||
|
PubKey() crypto.PubKey
|
||||||
Sign(msg []byte) crypto.Signature
|
Sign(msg []byte) crypto.Signature
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,8 +76,20 @@ func (ds *DefaultSigner) Sign(msg []byte) crypto.Signature {
|
|||||||
return ds.priv.Sign(msg)
|
return ds.priv.Sign(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Implements Signer
|
||||||
|
func (ds *DefaultSigner) PubKey() crypto.PubKey {
|
||||||
|
return ds.priv.PubKey()
|
||||||
|
}
|
||||||
|
|
||||||
func (privVal *PrivValidator) SetSigner(s Signer) {
|
func (privVal *PrivValidator) SetSigner(s Signer) {
|
||||||
privVal.Signer = s
|
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.
|
// Generates a new validator with private key.
|
||||||
@ -103,8 +116,10 @@ func LoadPrivValidator(filePath string) *PrivValidator {
|
|||||||
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)
|
||||||
|
privVal.setPubKeyAndAddress()
|
||||||
return &privVal
|
return &privVal
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user