2018-02-01 09:25:34 +00:00
|
|
|
package payload
|
|
|
|
|
|
|
|
import (
|
2020-05-22 14:30:56 +00:00
|
|
|
"errors"
|
|
|
|
|
2020-03-03 14:21:42 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/io"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
2018-02-01 09:25:34 +00:00
|
|
|
)
|
|
|
|
|
2019-12-25 16:40:18 +00:00
|
|
|
// Maximum inventory hashes number is limited to 500.
|
|
|
|
const (
|
|
|
|
MaxHashesCount = 500
|
|
|
|
)
|
|
|
|
|
2021-05-12 20:17:03 +00:00
|
|
|
// GetBlocks contains getblocks message payload fields.
|
2018-02-04 19:54:51 +00:00
|
|
|
type GetBlocks struct {
|
2021-05-12 20:17:03 +00:00
|
|
|
// Hash of the latest block that node requests.
|
2020-05-22 14:30:56 +00:00
|
|
|
HashStart util.Uint256
|
|
|
|
Count int16
|
2018-02-01 09:25:34 +00:00
|
|
|
}
|
|
|
|
|
2019-10-22 14:56:03 +00:00
|
|
|
// NewGetBlocks returns a pointer to a GetBlocks object.
|
2020-05-22 14:30:56 +00:00
|
|
|
func NewGetBlocks(start util.Uint256, count int16) *GetBlocks {
|
2018-02-07 14:16:50 +00:00
|
|
|
return &GetBlocks{
|
|
|
|
HashStart: start,
|
2020-05-22 14:30:56 +00:00
|
|
|
Count: count,
|
2018-02-07 14:16:50 +00:00
|
|
|
}
|
2018-02-04 19:54:51 +00:00
|
|
|
}
|
2018-02-01 09:25:34 +00:00
|
|
|
|
2019-09-16 16:31:49 +00:00
|
|
|
// DecodeBinary implements Serializable interface.
|
|
|
|
func (p *GetBlocks) DecodeBinary(br *io.BinReader) {
|
2020-05-22 14:30:56 +00:00
|
|
|
p.HashStart.DecodeBinary(br)
|
|
|
|
p.Count = int16(br.ReadU16LE())
|
|
|
|
if p.Count < -1 || p.Count == 0 {
|
|
|
|
br.Err = errors.New("invalid count")
|
|
|
|
}
|
2018-02-01 09:25:34 +00:00
|
|
|
}
|
|
|
|
|
2019-09-16 16:31:49 +00:00
|
|
|
// EncodeBinary implements Serializable interface.
|
|
|
|
func (p *GetBlocks) EncodeBinary(bw *io.BinWriter) {
|
2020-05-22 14:30:56 +00:00
|
|
|
p.HashStart.EncodeBinary(bw)
|
|
|
|
bw.WriteU16LE(uint16(p.Count))
|
2018-02-01 09:25:34 +00:00
|
|
|
}
|