mirror of
https://github.com/fluencelabs/tendermint
synced 2025-04-25 14:52:17 +00:00
tmtime: Canonical, some comments (#2312)
This commit is contained in:
parent
166fd82b70
commit
eabb1ece8e
@ -4,6 +4,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
cmn "github.com/tendermint/tendermint/libs/common"
|
cmn "github.com/tendermint/tendermint/libs/common"
|
||||||
|
tmtime "github.com/tendermint/tendermint/types/time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Canonical json is amino's json for structs with fields in alphabetical order
|
// Canonical json is amino's json for structs with fields in alphabetical order
|
||||||
@ -110,5 +111,5 @@ func CanonicalTime(t time.Time) string {
|
|||||||
// Note that sending time over amino resets it to
|
// Note that sending time over amino resets it to
|
||||||
// local time, we need to force UTC here, so the
|
// local time, we need to force UTC here, so the
|
||||||
// signatures match
|
// signatures match
|
||||||
return t.Round(0).UTC().Format(TimeFormat)
|
return tmtime.Canonical(t).Format(TimeFormat)
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ import (
|
|||||||
|
|
||||||
"github.com/tendermint/tendermint/crypto"
|
"github.com/tendermint/tendermint/crypto"
|
||||||
cmn "github.com/tendermint/tendermint/libs/common"
|
cmn "github.com/tendermint/tendermint/libs/common"
|
||||||
|
tmtime "github.com/tendermint/tendermint/types/time"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -79,7 +80,7 @@ func (genDoc *GenesisDoc) ValidateAndComplete() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if genDoc.GenesisTime.IsZero() {
|
if genDoc.GenesisTime.IsZero() {
|
||||||
genDoc.GenesisTime = time.Now()
|
genDoc.GenesisTime = tmtime.Now()
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -9,6 +9,7 @@ import (
|
|||||||
"github.com/tendermint/tendermint/crypto"
|
"github.com/tendermint/tendermint/crypto"
|
||||||
"github.com/tendermint/tendermint/crypto/ed25519"
|
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||||
"github.com/tendermint/tendermint/crypto/secp256k1"
|
"github.com/tendermint/tendermint/crypto/secp256k1"
|
||||||
|
tmtime "github.com/tendermint/tendermint/types/time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestABCIPubKey(t *testing.T) {
|
func TestABCIPubKey(t *testing.T) {
|
||||||
@ -77,7 +78,7 @@ func TestABCIConsensusParams(t *testing.T) {
|
|||||||
func TestABCIHeader(t *testing.T) {
|
func TestABCIHeader(t *testing.T) {
|
||||||
header := &Header{
|
header := &Header{
|
||||||
Height: int64(3),
|
Height: int64(3),
|
||||||
Time: time.Now(),
|
Time: tmtime.Now(),
|
||||||
NumTxs: int64(10),
|
NumTxs: int64(10),
|
||||||
ProposerAddress: []byte("cloak"),
|
ProposerAddress: []byte("cloak"),
|
||||||
}
|
}
|
||||||
|
@ -5,16 +5,23 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Now returns UTC time rounded since the zero time.
|
// Now returns the current time in UTC with no monotonic component.
|
||||||
func Now() time.Time {
|
func Now() time.Time {
|
||||||
return time.Now().Round(0).UTC()
|
return Canonical(time.Now())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Canonical returns UTC time with no monotonic component.
|
||||||
|
func Canonical(t time.Time) time.Time {
|
||||||
|
return t.Round(0).UTC()
|
||||||
|
}
|
||||||
|
|
||||||
|
// WeightedTime for computing a median.
|
||||||
type WeightedTime struct {
|
type WeightedTime struct {
|
||||||
Time time.Time
|
Time time.Time
|
||||||
Weight int64
|
Weight int64
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewWeightedTime with time and weight.
|
||||||
func NewWeightedTime(time time.Time, weight int64) *WeightedTime {
|
func NewWeightedTime(time time.Time, weight int64) *WeightedTime {
|
||||||
return &WeightedTime{
|
return &WeightedTime{
|
||||||
Time: time,
|
Time: time,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user