2020-05-22 12:43:46 +00:00
|
|
|
package payload
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/io"
|
|
|
|
)
|
|
|
|
|
2021-05-12 20:17:03 +00:00
|
|
|
// GetBlockByIndex payload.
|
2020-07-31 10:58:22 +00:00
|
|
|
type GetBlockByIndex struct {
|
2020-05-22 12:43:46 +00:00
|
|
|
IndexStart uint32
|
2020-07-31 11:17:14 +00:00
|
|
|
Count int16
|
2020-05-22 12:43:46 +00:00
|
|
|
}
|
|
|
|
|
2021-05-12 20:17:03 +00:00
|
|
|
// NewGetBlockByIndex returns GetBlockByIndex payload with specified start index and count.
|
2020-07-31 11:17:14 +00:00
|
|
|
func NewGetBlockByIndex(indexStart uint32, count int16) *GetBlockByIndex {
|
2020-07-31 10:58:22 +00:00
|
|
|
return &GetBlockByIndex{
|
2020-05-22 12:43:46 +00:00
|
|
|
IndexStart: indexStart,
|
|
|
|
Count: count,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// DecodeBinary implements Serializable interface.
|
2020-07-31 10:58:22 +00:00
|
|
|
func (d *GetBlockByIndex) DecodeBinary(br *io.BinReader) {
|
2020-05-22 12:43:46 +00:00
|
|
|
d.IndexStart = br.ReadU32LE()
|
2020-07-31 11:17:14 +00:00
|
|
|
d.Count = int16(br.ReadU16LE())
|
|
|
|
if d.Count < -1 || d.Count == 0 || d.Count > MaxHeadersAllowed {
|
2020-05-22 12:43:46 +00:00
|
|
|
br.Err = errors.New("invalid block count")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// EncodeBinary implements Serializable interface.
|
2020-07-31 10:58:22 +00:00
|
|
|
func (d *GetBlockByIndex) EncodeBinary(bw *io.BinWriter) {
|
2020-05-22 12:43:46 +00:00
|
|
|
bw.WriteU32LE(d.IndexStart)
|
2020-07-31 11:17:14 +00:00
|
|
|
bw.WriteU16LE(uint16(d.Count))
|
2020-05-22 12:43:46 +00:00
|
|
|
}
|