2018-01-19 04:10:42 +01:00
|
|
|
// Copyright (c) 2017 The btcsuite developers
|
|
|
|
// Use of this source code is governed by an ISC
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package wire
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
|
2021-10-15 07:45:32 +02:00
|
|
|
"github.com/lbryio/lbcd/chaincfg/chainhash"
|
2018-01-19 04:10:42 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// MaxGetCFiltersReqRange the maximum number of filters that may be requested in
|
|
|
|
// a getcfheaders message.
|
2018-04-01 01:38:14 +02:00
|
|
|
const MaxGetCFiltersReqRange = 1000
|
2018-01-19 04:10:42 +01:00
|
|
|
|
|
|
|
// MsgGetCFilters implements the Message interface and represents a bitcoin
|
|
|
|
// getcfilters message. It is used to request committed filters for a range of
|
|
|
|
// blocks.
|
|
|
|
type MsgGetCFilters struct {
|
|
|
|
FilterType FilterType
|
|
|
|
StartHeight uint32
|
|
|
|
StopHash chainhash.Hash
|
|
|
|
}
|
|
|
|
|
|
|
|
// BtcDecode decodes r using the bitcoin protocol encoding into the receiver.
|
|
|
|
// This is part of the Message interface implementation.
|
|
|
|
func (msg *MsgGetCFilters) BtcDecode(r io.Reader, pver uint32, _ MessageEncoding) error {
|
|
|
|
err := readElement(r, &msg.FilterType)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = readElement(r, &msg.StartHeight)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-05-19 03:55:52 +02:00
|
|
|
return readElement(r, &msg.StopHash)
|
2018-01-19 04:10:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// BtcEncode encodes the receiver to w using the bitcoin protocol encoding.
|
|
|
|
// This is part of the Message interface implementation.
|
|
|
|
func (msg *MsgGetCFilters) BtcEncode(w io.Writer, pver uint32, _ MessageEncoding) error {
|
|
|
|
err := writeElement(w, msg.FilterType)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = writeElement(w, &msg.StartHeight)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-05-19 03:55:52 +02:00
|
|
|
return writeElement(w, &msg.StopHash)
|
2018-01-19 04:10:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Command returns the protocol command string for the message. This is part
|
|
|
|
// of the Message interface implementation.
|
|
|
|
func (msg *MsgGetCFilters) Command() string {
|
|
|
|
return CmdGetCFilters
|
|
|
|
}
|
|
|
|
|
|
|
|
// MaxPayloadLength returns the maximum length the payload can be for the
|
|
|
|
// receiver. This is part of the Message interface implementation.
|
|
|
|
func (msg *MsgGetCFilters) MaxPayloadLength(pver uint32) uint32 {
|
|
|
|
// Filter type + uint32 + block hash
|
|
|
|
return 1 + 4 + chainhash.HashSize
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewMsgGetCFilters returns a new bitcoin getcfilters message that conforms to
|
|
|
|
// the Message interface using the passed parameters and defaults for the
|
|
|
|
// remaining fields.
|
|
|
|
func NewMsgGetCFilters(filterType FilterType, startHeight uint32,
|
|
|
|
stopHash *chainhash.Hash) *MsgGetCFilters {
|
|
|
|
return &MsgGetCFilters{
|
|
|
|
FilterType: filterType,
|
|
|
|
StartHeight: startHeight,
|
|
|
|
StopHash: *stopHash,
|
|
|
|
}
|
|
|
|
}
|