neoneo-go/pkg/network/payload/getblocks.go

50 lines
1.3 KiB
Go
Raw Normal View History

2018-02-01 09:25:34 +00:00
package payload
import (
"encoding/binary"
"io"
"github.com/CityOfZion/neo-go/pkg/util"
2018-02-01 09:25:34 +00:00
)
// GetBlocks contains fields and methods to be shared with the
type GetBlocks struct {
2018-02-01 09:25:34 +00:00
// hash of latest block that node requests
HashStart []util.Uint256
2018-02-01 09:25:34 +00:00
// hash of last block that node requests
HashStop util.Uint256
2018-02-01 09:25:34 +00:00
}
// NewGetBlocks return a pointer to a GetBlocks object.
func NewGetBlocks(start []util.Uint256, stop util.Uint256) *GetBlocks {
return &GetBlocks{
HashStart: start,
HashStop: stop,
}
}
2018-02-01 09:25:34 +00:00
// DecodeBinary implements the payload interface.
func (p *GetBlocks) DecodeBinary(r io.Reader) error {
lenStart := util.ReadVarUint(r)
p.HashStart = make([]util.Uint256, lenStart)
2018-02-01 09:25:34 +00:00
if err := binary.Read(r, binary.LittleEndian, &p.HashStart); err != nil {
return err
}
return binary.Read(r, binary.LittleEndian, &p.HashStop)
2018-02-01 09:25:34 +00:00
}
// EncodeBinary implements the payload interface.
func (p *GetBlocks) EncodeBinary(w io.Writer) error {
if err := util.WriteVarUint(w, uint64(len(p.HashStart))); err != nil {
return err
}
if err := binary.Write(w, binary.LittleEndian, p.HashStart); err != nil {
return err
}
return binary.Write(w, binary.LittleEndian, p.HashStop)
2018-02-01 09:25:34 +00:00
}
// Size implements the payload interface.
func (p *GetBlocks) Size() uint32 { return 0 }