types: update for new go-wire. WriteSignBytes -> SignBytes

This commit is contained in:
Ethan Buchman
2018-01-14 19:05:22 -05:00
parent 9cdba04fe9
commit 200787ede2
12 changed files with 67 additions and 81 deletions

View File

@ -4,7 +4,6 @@ import (
"bytes"
"errors"
"fmt"
"io"
"strings"
"time"
@ -96,7 +95,11 @@ func (b *Block) Hash() cmn.HexBytes {
// MakePartSet returns a PartSet containing parts of a serialized block.
// This is the form in which the block is gossipped to peers.
func (b *Block) MakePartSet(partSize int) *PartSet {
return NewPartSetFromData(wire.BinaryBytes(b), partSize)
bz, err := wire.MarshalBinary(b)
if err != nil {
panic(err)
}
return NewPartSetFromData(bz, partSize)
}
// HashesTo is a convenience function that checks if a block hashes to the given argument.
@ -493,17 +496,11 @@ func (blockID BlockID) Equals(other BlockID) bool {
// Key returns a machine-readable string representation of the BlockID
func (blockID BlockID) Key() string {
return string(blockID.Hash) + string(wire.BinaryBytes(blockID.PartsHeader))
}
// WriteSignBytes writes the canonical bytes of the BlockID to the given writer for digital signing
func (blockID BlockID) WriteSignBytes(w io.Writer, n *int, err *error) {
if blockID.IsZero() {
wire.WriteTo([]byte("null"), w, n, err)
} else {
wire.WriteJSON(CanonicalBlockID(blockID), w, n, err)
bz, err := wire.MarshalBinary(blockID.PartsHeader)
if err != nil {
panic(err)
}
return string(blockID.Hash) + string(bz)
}
// String returns a human readable string representation of the BlockID
@ -527,6 +524,11 @@ func (h hasher) Hash() []byte {
}
func tmHash(item interface{}) []byte {
h := hasher{item}
return h.Hash()
}
func wireHasher(item interface{}) merkle.Hasher {
return hasher{item}
}