mirror of
https://github.com/fluencelabs/tendermint
synced 2025-04-25 14:52:17 +00:00
use WriteTime/ReadTime, and also log how the block header gets hashed
This commit is contained in:
parent
892a51014e
commit
b7b88cd763
@ -232,9 +232,9 @@ func readReflect(rv reflect.Value, rt reflect.Type, r io.Reader, n *int64, err *
|
||||
case reflect.Struct:
|
||||
if rt == timeType {
|
||||
// Special case: time.Time
|
||||
num := ReadInt64(r, n, err)
|
||||
log.Debug(Fmt("Read time: %v", num))
|
||||
rv.Set(reflect.ValueOf(time.Unix(num, 0)))
|
||||
t := ReadTime(r, n, err)
|
||||
log.Debug(Fmt("Read time: %v", t))
|
||||
rv.Set(reflect.ValueOf(t))
|
||||
} else {
|
||||
numFields := rt.NumField()
|
||||
for i := 0; i < numFields; i++ {
|
||||
@ -358,7 +358,7 @@ func writeReflect(rv reflect.Value, rt reflect.Type, w io.Writer, n *int64, err
|
||||
case reflect.Struct:
|
||||
if rt == timeType {
|
||||
// Special case: time.Time
|
||||
WriteInt64(rv.Interface().(time.Time).Unix(), w, n, err)
|
||||
WriteTime(rv.Interface().(time.Time), w, n, err)
|
||||
} else {
|
||||
numFields := rt.NumField()
|
||||
for i := 0; i < numFields; i++ {
|
||||
|
@ -124,12 +124,16 @@ type Header struct {
|
||||
|
||||
func (h *Header) Hash() []byte {
|
||||
if h.hash == nil {
|
||||
buf := new(bytes.Buffer)
|
||||
hasher, n, err := sha256.New(), new(int64), new(error)
|
||||
binary.WriteBinary(h, hasher, n, err)
|
||||
binary.WriteBinary(h, buf, n, err)
|
||||
if *err != nil {
|
||||
panic(err)
|
||||
}
|
||||
log.Debug("Hashing", "bytes", buf.Bytes())
|
||||
hasher.Write(buf.Bytes())
|
||||
h.hash = hasher.Sum(nil)
|
||||
log.Debug("Hashing got", "hash", h.hash)
|
||||
}
|
||||
return h.hash
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user