aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/types/validator.go7
1 files changed, 7 insertions, 0 deletions
diff --git a/core/types/validator.go b/core/types/validator.go
index 86c3acc..27a9acd 100644
--- a/core/types/validator.go
+++ b/core/types/validator.go
@@ -21,6 +21,7 @@ import (
"bytes"
"github.com/dexon-foundation/dexon-consensus-core/common"
+ "github.com/dexon-foundation/dexon-consensus-core/crypto"
)
// ValidatorID is the ID type for validators.
@@ -28,6 +29,12 @@ type ValidatorID struct {
common.Hash
}
+// NewValidatorID returns a ValidatorID with Hash set to the hash value of
+// public key.
+func NewValidatorID(pubKey crypto.PublicKey) ValidatorID {
+ return ValidatorID{Hash: crypto.Keccak256Hash(pubKey.Bytes())}
+}
+
// ValidatorIDs implements sort.Interface for ValidatorID.
type ValidatorIDs []ValidatorID