aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/dexon-foundation/dexon-consensus/core/types/vote.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/dexon-foundation/dexon-consensus/core/types/vote.go')
-rw-r--r--vendor/github.com/dexon-foundation/dexon-consensus/core/types/vote.go39
1 files changed, 28 insertions, 11 deletions
diff --git a/vendor/github.com/dexon-foundation/dexon-consensus/core/types/vote.go b/vendor/github.com/dexon-foundation/dexon-consensus/core/types/vote.go
index 5b99f2253..12c3af892 100644
--- a/vendor/github.com/dexon-foundation/dexon-consensus/core/types/vote.go
+++ b/vendor/github.com/dexon-foundation/dexon-consensus/core/types/vote.go
@@ -36,13 +36,18 @@ const (
MaxVoteType
)
+// VoteHeader is the header for vote, which can be used as map keys.
+type VoteHeader struct {
+ ProposerID NodeID `json:"proposer_id"`
+ Type VoteType `json:"type"`
+ BlockHash common.Hash `json:"block_hash"`
+ Period uint64 `json:"period"`
+ Position Position `json:"position"`
+}
+
// Vote is the vote structure defined in Crypto Shuffle Algorithm.
type Vote struct {
- ProposerID NodeID `json:"proposer_id"`
- Type VoteType `json:"type"`
- BlockHash common.Hash `json:"block_hash"`
- Period uint64 `json:"period"`
- Position Position `json:"position"`
+ VoteHeader `json:"header"`
Signature crypto.Signature `json:"signature"`
}
@@ -51,14 +56,26 @@ func (v *Vote) String() string {
&v.Position, v.Period, v.Type, v.BlockHash.String()[:6])
}
+// NewVote constructs a Vote instance with header fields.
+func NewVote(t VoteType, hash common.Hash, period uint64) *Vote {
+ return &Vote{
+ VoteHeader: VoteHeader{
+ Type: t,
+ BlockHash: hash,
+ Period: period,
+ }}
+}
+
// Clone returns a deep copy of a vote.
func (v *Vote) Clone() *Vote {
return &Vote{
- ProposerID: v.ProposerID,
- Type: v.Type,
- BlockHash: v.BlockHash,
- Period: v.Period,
- Position: v.Position,
- Signature: v.Signature.Clone(),
+ VoteHeader: VoteHeader{
+ ProposerID: v.ProposerID,
+ Type: v.Type,
+ BlockHash: v.BlockHash,
+ Period: v.Period,
+ Position: v.Position,
+ },
+ Signature: v.Signature.Clone(),
}
}