mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-26 19:42:23 +00:00
8142caaf8b
closes #891
39 lines
894 B
Go
39 lines
894 B
Go
package payload
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/io"
|
|
)
|
|
|
|
// maximum number of blocks to query about
|
|
const maxBlockCount = 500
|
|
|
|
// GetBlockData payload
|
|
type GetBlockData struct {
|
|
IndexStart uint32
|
|
Count uint16
|
|
}
|
|
|
|
// NewGetBlockData returns GetBlockData payload with specified start index and count
|
|
func NewGetBlockData(indexStart uint32, count uint16) *GetBlockData {
|
|
return &GetBlockData{
|
|
IndexStart: indexStart,
|
|
Count: count,
|
|
}
|
|
}
|
|
|
|
// DecodeBinary implements Serializable interface.
|
|
func (d *GetBlockData) DecodeBinary(br *io.BinReader) {
|
|
d.IndexStart = br.ReadU32LE()
|
|
d.Count = br.ReadU16LE()
|
|
if d.Count == 0 || d.Count > maxBlockCount {
|
|
br.Err = errors.New("invalid block count")
|
|
}
|
|
}
|
|
|
|
// EncodeBinary implements Serializable interface.
|
|
func (d *GetBlockData) EncodeBinary(bw *io.BinWriter) {
|
|
bw.WriteU32LE(d.IndexStart)
|
|
bw.WriteU16LE(d.Count)
|
|
}
|