2018-02-01 09:25:34 +00:00
|
|
|
package payload
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
|
2018-02-04 19:54:51 +00:00
|
|
|
"github.com/CityOfZion/neo-go/pkg/util"
|
2018-02-01 09:25:34 +00:00
|
|
|
)
|
|
|
|
|
2018-02-04 19:54:51 +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
|
2018-02-04 19:54:51 +00:00
|
|
|
HashStart []util.Uint256
|
2018-02-01 09:25:34 +00:00
|
|
|
// hash of last block that node requests
|
2018-02-04 19:54:51 +00:00
|
|
|
HashStop util.Uint256
|
2018-02-01 09:25:34 +00:00
|
|
|
}
|
|
|
|
|
2018-02-04 19:54:51 +00:00
|
|
|
// NewGetBlocks return a pointer to a GetBlocks object.
|
|
|
|
func NewGetBlocks(start []util.Uint256, stop util.Uint256) *GetBlocks {
|
2018-02-07 14:16:50 +00:00
|
|
|
return &GetBlocks{
|
|
|
|
HashStart: start,
|
|
|
|
HashStop: stop,
|
|
|
|
}
|
2018-02-04 19:54:51 +00:00
|
|
|
}
|
2018-02-01 09:25:34 +00:00
|
|
|
|
2018-02-04 19:54:51 +00:00
|
|
|
// DecodeBinary implements the payload interface.
|
|
|
|
func (p *GetBlocks) DecodeBinary(r io.Reader) error {
|
2019-08-28 12:43:56 +00:00
|
|
|
br := util.BinReader{R: r}
|
|
|
|
lenStart := br.ReadVarUint()
|
2018-02-04 19:54:51 +00:00
|
|
|
p.HashStart = make([]util.Uint256, lenStart)
|
2018-02-01 09:25:34 +00:00
|
|
|
|
2019-08-28 12:43:56 +00:00
|
|
|
br.ReadLE(&p.HashStart)
|
|
|
|
br.ReadLE(&p.HashStop)
|
|
|
|
return br.Err
|
2018-02-01 09:25:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// EncodeBinary implements the payload interface.
|
2018-02-04 19:54:51 +00:00
|
|
|
func (p *GetBlocks) EncodeBinary(w io.Writer) error {
|
2019-08-28 12:43:56 +00:00
|
|
|
bw := util.BinWriter{W: w}
|
|
|
|
bw.WriteVarUint(uint64(len(p.HashStart)))
|
|
|
|
bw.WriteLE(p.HashStart)
|
|
|
|
bw.WriteLE(p.HashStop)
|
|
|
|
return bw.Err
|
2018-02-01 09:25:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Size implements the payload interface.
|
2018-02-04 19:54:51 +00:00
|
|
|
func (p *GetBlocks) Size() uint32 { return 0 }
|