2018-02-01 09:25:34 +00:00
|
|
|
package payload
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/binary"
|
2018-02-04 19:54:51 +00:00
|
|
|
"fmt"
|
2018-02-01 09:25:34 +00:00
|
|
|
"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 {
|
|
|
|
p := &GetBlocks{}
|
|
|
|
p.HashStart = start
|
|
|
|
p.HashStop = stop
|
|
|
|
return p
|
|
|
|
}
|
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 {
|
|
|
|
lenStart := util.ReadVarUint(r)
|
|
|
|
fmt.Println(lenStart)
|
|
|
|
p.HashStart = make([]util.Uint256, lenStart)
|
|
|
|
err := binary.Read(r, binary.LittleEndian, &p.HashStart)
|
2018-02-01 09:25:34 +00:00
|
|
|
err = binary.Read(r, binary.LittleEndian, &p.HashStop)
|
|
|
|
|
2018-02-04 19:54:51 +00:00
|
|
|
fmt.Println(p)
|
|
|
|
if err == io.EOF {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-02-01 09:25:34 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// EncodeBinary implements the payload interface.
|
2018-02-04 19:54:51 +00:00
|
|
|
func (p *GetBlocks) EncodeBinary(w io.Writer) error {
|
|
|
|
err := util.WriteVarUint(w, uint64(len(p.HashStart)))
|
2018-02-01 09:25:34 +00:00
|
|
|
err = binary.Write(w, binary.LittleEndian, p.HashStart)
|
2018-02-04 19:54:51 +00:00
|
|
|
//err = binary.Write(w, binary.LittleEndian, p.HashStop)
|
2018-02-01 09:25:34 +00:00
|
|
|
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Size implements the payload interface.
|
2018-02-04 19:54:51 +00:00
|
|
|
func (p *GetBlocks) Size() uint32 { return 0 }
|