neo-go/pkg/network/payload/headers.go
Anthony De Meulemeester aa4bc1b6e8
Node improvements (#47)
* block partial persist

* replaced refactored files with old one.

* removed gokit/log from deps

* Tweaks to not overburden remote nodes with getheaders/getblocks

* Changed Transporter interface to not take the server as argument due to a cause of race warning from the compiler

* started server test suite

* more test + return errors from message handlers

* removed --race from build

* Little improvements.
2018-03-14 10:36:59 +01:00

43 lines
841 B
Go

package payload
import (
"io"
"github.com/CityOfZion/neo-go/pkg/core"
"github.com/CityOfZion/neo-go/pkg/util"
)
// Headers payload
type Headers struct {
Hdrs []*core.Header
}
// DecodeBinary implements the Payload interface.
func (p *Headers) DecodeBinary(r io.Reader) error {
lenHeaders := util.ReadVarUint(r)
p.Hdrs = make([]*core.Header, lenHeaders)
for i := 0; i < int(lenHeaders); i++ {
header := &core.Header{}
if err := header.DecodeBinary(r); err != nil {
return err
}
p.Hdrs[i] = header
}
return nil
}
// EncodeBinary implements the Payload interface.
func (p *Headers) EncodeBinary(w io.Writer) error {
if err := util.WriteVarUint(w, uint64(len(p.Hdrs))); err != nil {
return err
}
for _, header := range p.Hdrs {
if err := header.EncodeBinary(w); err != nil {
return err
}
}
return nil
}