mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-23 23:30:36 +00:00
4023661cf1
* added headersOp for safely processing headers * Better handling of protocol messages. * housekeeping + cleanup tests * Added more blockchain logic + unit tests * fixed unreachable error. * added structured logging for all (node) components. * added relay flag + bumped version
41 lines
801 B
Go
41 lines
801 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 {
|
|
util.WriteVarUint(w, uint64(len(p.Hdrs)))
|
|
for _, header := range p.Hdrs {
|
|
if err := header.EncodeBinary(w); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
}
|