diff options
author | Jimmy Hu <jimmy.hu@dexon.org> | 2018-11-13 15:34:22 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@dexon.org> | 2019-04-09 21:32:53 +0800 |
commit | ef24d59fe79fd57a88ff886afdc3a01be1d49e55 (patch) | |
tree | 3ad7843e3c5115e966b23203fbc3d4404c371664 /vendor/github.com/dexon-foundation/dexon-consensus/core/types/vote.go | |
parent | 5f2bcc7fba1d247763892c35d694f61e12676969 (diff) | |
download | dexon-ef24d59fe79fd57a88ff886afdc3a01be1d49e55.tar dexon-ef24d59fe79fd57a88ff886afdc3a01be1d49e55.tar.gz dexon-ef24d59fe79fd57a88ff886afdc3a01be1d49e55.tar.bz2 dexon-ef24d59fe79fd57a88ff886afdc3a01be1d49e55.tar.lz dexon-ef24d59fe79fd57a88ff886afdc3a01be1d49e55.tar.xz dexon-ef24d59fe79fd57a88ff886afdc3a01be1d49e55.tar.zst dexon-ef24d59fe79fd57a88ff886afdc3a01be1d49e55.zip |
vendor: sync to latest core (#16)
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.go | 39 |
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(), } } |