2018-03-17 11:53:21 +00:00
|
|
|
package core
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2019-09-16 09:18:13 +00:00
|
|
|
|
|
|
|
"github.com/CityOfZion/neo-go/pkg/io"
|
2018-03-17 11:53:21 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Header holds the head info of a block.
|
|
|
|
type Header struct {
|
|
|
|
// Base of the block.
|
|
|
|
BlockBase
|
|
|
|
// Padding that is fixed to 0
|
|
|
|
_ uint8
|
|
|
|
}
|
|
|
|
|
2019-02-13 18:01:10 +00:00
|
|
|
// DecodeBinary implements the Payload interface.
|
2019-09-16 09:18:13 +00:00
|
|
|
func (h *Header) DecodeBinary(r *io.BinReader) error {
|
2018-03-17 11:53:21 +00:00
|
|
|
if err := h.BlockBase.DecodeBinary(r); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
var padding uint8
|
2019-09-16 09:18:13 +00:00
|
|
|
r.ReadLE(&padding)
|
|
|
|
if r.Err != nil {
|
|
|
|
return r.Err
|
2019-01-25 11:20:35 +00:00
|
|
|
}
|
|
|
|
|
2018-03-17 11:53:21 +00:00
|
|
|
if padding != 0 {
|
|
|
|
return fmt.Errorf("format error: padding must equal 0 got %d", padding)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-02-13 18:01:10 +00:00
|
|
|
// EncodeBinary implements the Payload interface.
|
2019-09-16 09:18:13 +00:00
|
|
|
func (h *Header) EncodeBinary(w *io.BinWriter) error {
|
|
|
|
h.BlockBase.EncodeBinary(w)
|
|
|
|
w.WriteLE(uint8(0))
|
|
|
|
return w.Err
|
2018-03-17 11:53:21 +00:00
|
|
|
}
|