2020-05-22 12:43:46 +00:00
|
|
|
package payload
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/io"
|
|
|
|
)
|
|
|
|
|
2020-07-31 10:58:22 +00:00
|
|
|
// GetBlockByIndex payload
|
|
|
|
type GetBlockByIndex struct {
|
2020-05-22 12:43:46 +00:00
|
|
|
IndexStart uint32
|
|
|
|
Count uint16
|
|
|
|
}
|
|
|
|
|
2020-07-31 10:58:22 +00:00
|
|
|
// NewGetBlockByIndex returns GetBlockByIndex payload with specified start index and count
|
|
|
|
func NewGetBlockByIndex(indexStart uint32, count uint16) *GetBlockByIndex {
|
|
|
|
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()
|
|
|
|
d.Count = br.ReadU16LE()
|
2020-07-31 11:03:35 +00:00
|
|
|
if 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)
|
|
|
|
bw.WriteU16LE(d.Count)
|
|
|
|
}
|