diff options
author | Jimmy Hu <jimmy.hu@dexon.org> | 2018-11-13 15:34:22 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@byzantine-lab.io> | 2019-06-12 17:27:18 +0800 |
commit | 08ec9c78c4acfc09f24ddd0f864504fc58cb07e2 (patch) | |
tree | 6f197a58383c922bc541d27e3dff36083d145036 /vendor/github.com/dexon-foundation/dexon-consensus/core/types/vote.go | |
parent | aec90eae15b9ad106e3443fc5c5ab6f285e131a0 (diff) | |
download | go-tangerine-08ec9c78c4acfc09f24ddd0f864504fc58cb07e2.tar.gz go-tangerine-08ec9c78c4acfc09f24ddd0f864504fc58cb07e2.tar.zst go-tangerine-08ec9c78c4acfc09f24ddd0f864504fc58cb07e2.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(), } } |