core: add EncodeBinary() support for the block

This commit is contained in:
Roman Khimov 2019-08-30 10:42:07 +03:00
parent 0ff38e9645
commit c093f070d3

View file

@ -152,5 +152,20 @@ func (b *Block) DecodeBinary(r io.Reader) error {
// EncodeBinary encodes the block to the given writer. // EncodeBinary encodes the block to the given writer.
func (b *Block) EncodeBinary(w io.Writer) error { func (b *Block) EncodeBinary(w io.Writer) error {
err := b.BlockBase.EncodeBinary(w)
if err != nil {
return err
}
bw := util.BinWriter{W: w}
bw.WriteVarUint(uint64(len(b.Transactions)))
if bw.Err != nil {
return err
}
for _, tx := range b.Transactions {
err := tx.EncodeBinary(w)
if err != nil {
return err
}
}
return nil return nil
} }