fixed time key marshal (#2516)

Do not use Amino Binary for key sorting.
This commit is contained in:
Sunny Aggarwal
2018-10-16 23:09:19 -07:00
committed by Jae Kwon
parent 070bda3a25
commit e419396bd1
2 changed files with 27 additions and 3 deletions
+13
View File
@@ -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.
//