mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-28 04:01:40 +00:00
Add timestamp to vote canonical encoding
This commit is contained in:
@ -1,11 +1,16 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/tendermint/go-wire/data"
|
||||
)
|
||||
|
||||
// canonical json is go-wire's json for structs with fields in alphabetical order
|
||||
|
||||
// timeFormat is RFC3339Millis, used for generating the sigs
|
||||
const timeFormat = "2006-01-02T15:04:05.999Z07:00"
|
||||
|
||||
type CanonicalJSONBlockID struct {
|
||||
Hash data.Bytes `json:"hash,omitempty"`
|
||||
PartsHeader CanonicalJSONPartSetHeader `json:"parts,omitempty"`
|
||||
@ -26,10 +31,11 @@ type CanonicalJSONProposal struct {
|
||||
}
|
||||
|
||||
type CanonicalJSONVote struct {
|
||||
BlockID CanonicalJSONBlockID `json:"block_id"`
|
||||
Height int64 `json:"height"`
|
||||
Round int `json:"round"`
|
||||
Type byte `json:"type"`
|
||||
BlockID CanonicalJSONBlockID `json:"block_id"`
|
||||
Height int64 `json:"height"`
|
||||
Round int `json:"round"`
|
||||
Timestamp string `json:"timestamp"`
|
||||
Type byte `json:"type"`
|
||||
}
|
||||
|
||||
type CanonicalJSONHeartbeat struct {
|
||||
@ -79,7 +85,7 @@ func CanonicalProposal(proposal *Proposal) CanonicalJSONProposal {
|
||||
return CanonicalJSONProposal{
|
||||
BlockPartsHeader: CanonicalPartSetHeader(proposal.BlockPartsHeader),
|
||||
Height: proposal.Height,
|
||||
Timestamp: proposal.TimeString(),
|
||||
Timestamp: CanonicalTime(proposal.Timestamp),
|
||||
POLBlockID: CanonicalBlockID(proposal.POLBlockID),
|
||||
POLRound: proposal.POLRound,
|
||||
Round: proposal.Round,
|
||||
@ -88,10 +94,11 @@ func CanonicalProposal(proposal *Proposal) CanonicalJSONProposal {
|
||||
|
||||
func CanonicalVote(vote *Vote) CanonicalJSONVote {
|
||||
return CanonicalJSONVote{
|
||||
CanonicalBlockID(vote.BlockID),
|
||||
vote.Height,
|
||||
vote.Round,
|
||||
vote.Type,
|
||||
BlockID: CanonicalBlockID(vote.BlockID),
|
||||
Height: vote.Height,
|
||||
Round: vote.Round,
|
||||
Timestamp: CanonicalTime(vote.Timestamp),
|
||||
Type: vote.Type,
|
||||
}
|
||||
}
|
||||
|
||||
@ -104,3 +111,7 @@ func CanonicalHeartbeat(heartbeat *Heartbeat) CanonicalJSONHeartbeat {
|
||||
heartbeat.ValidatorIndex,
|
||||
}
|
||||
}
|
||||
|
||||
func CanonicalTime(t time.Time) string {
|
||||
return t.Format(timeFormat)
|
||||
}
|
||||
|
Reference in New Issue
Block a user