fixed time key marshal (#2516)
Do not use Amino Binary for key sorting.
This commit is contained in:
@@ -2,6 +2,8 @@ package types
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"time"
|
||||
|
||||
tcmd "github.com/tendermint/tendermint/cmd/tendermint/commands"
|
||||
tmtypes "github.com/tendermint/tendermint/types"
|
||||
)
|
||||
@@ -34,6 +36,17 @@ func MustSortJSON(toSortJSON []byte) []byte {
|
||||
return js
|
||||
}
|
||||
|
||||
// Formats a time.Time into a []byte that can be sorted
|
||||
func FormatTimeBytes(t time.Time) []byte {
|
||||
return []byte(t.UTC().Round(0).Format("2006-01-02T15:04:05.000000000"))
|
||||
}
|
||||
|
||||
// Parses a []byte encoded using FormatTimeKey back into a time.Time
|
||||
func ParseTimeBytes(bz []byte) (time.Time, error) {
|
||||
str := string(bz)
|
||||
return time.Parse("2006-01-02T15:04:05.000000000", str)
|
||||
}
|
||||
|
||||
// DefaultChainID returns the chain ID from the genesis file if present. An
|
||||
// error is returned if the file cannot be read or parsed.
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user