2017-03-09 01:14:39 +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"
|
|
|
|
|
|
|
|
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
|
|
|
)
|
|
|
|
|
|
|
|
// MsgGetCFHeaders is a message similar to MsgGetHeaders, but for committed
|
2017-09-13 14:42:24 +02:00
|
|
|
// filter headers. It allows to set the FilterType field to get headers in the
|
|
|
|
// chain of basic (0x00) or extended (0x01) headers.
|
2017-03-09 01:14:39 +01:00
|
|
|
type MsgGetCFHeaders struct {
|
2018-01-19 21:34:28 +01:00
|
|
|
FilterType FilterType
|
|
|
|
StartHeight uint32
|
|
|
|
StopHash chainhash.Hash
|
2017-03-09 01:14:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// BtcDecode decodes r using the bitcoin protocol encoding into the receiver.
|
|
|
|
// This is part of the Message interface implementation.
|
2017-08-25 01:29:57 +02:00
|
|
|
func (msg *MsgGetCFHeaders) BtcDecode(r io.Reader, pver uint32, _ MessageEncoding) error {
|
2018-01-19 21:34:28 +01:00
|
|
|
err := readElement(r, &msg.FilterType)
|
2017-03-09 01:14:39 +01:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-01-19 21:34:28 +01:00
|
|
|
err = readElement(r, &msg.StartHeight)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2017-03-09 01:14:39 +01:00
|
|
|
}
|
|
|
|
|
2018-05-19 03:55:52 +02:00
|
|
|
return readElement(r, &msg.StopHash)
|
2017-03-09 01:14:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// BtcEncode encodes the receiver to w using the bitcoin protocol encoding.
|
|
|
|
// This is part of the Message interface implementation.
|
2017-08-25 01:29:57 +02:00
|
|
|
func (msg *MsgGetCFHeaders) BtcEncode(w io.Writer, pver uint32, _ MessageEncoding) error {
|
2018-01-19 21:34:28 +01:00
|
|
|
err := writeElement(w, msg.FilterType)
|
2017-03-09 01:14:39 +01:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-01-19 21:34:28 +01:00
|
|
|
err = writeElement(w, &msg.StartHeight)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2017-03-09 01:14:39 +01:00
|
|
|
}
|
|
|
|
|
2018-05-19 03:55:52 +02:00
|
|
|
return writeElement(w, &msg.StopHash)
|
2017-03-09 01:14:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Command returns the protocol command string for the message. This is part
|
|
|
|
// of the Message interface implementation.
|
|
|
|
func (msg *MsgGetCFHeaders) Command() string {
|
|
|
|
return CmdGetCFHeaders
|
|
|
|
}
|
|
|
|
|
|
|
|
// MaxPayloadLength returns the maximum length the payload can be for the
|
|
|
|
// receiver. This is part of the Message interface implementation.
|
|
|
|
func (msg *MsgGetCFHeaders) MaxPayloadLength(pver uint32) uint32 {
|
2018-01-19 21:34:28 +01:00
|
|
|
// Filter type + uint32 + block hash
|
|
|
|
return 1 + 4 + chainhash.HashSize
|
2017-03-09 01:14:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewMsgGetCFHeaders returns a new bitcoin getcfheader message that conforms to
|
|
|
|
// the Message interface using the passed parameters and defaults for the
|
|
|
|
// remaining fields.
|
2018-01-19 21:34:28 +01:00
|
|
|
func NewMsgGetCFHeaders(filterType FilterType, startHeight uint32,
|
|
|
|
stopHash *chainhash.Hash) *MsgGetCFHeaders {
|
2017-03-09 01:14:39 +01:00
|
|
|
return &MsgGetCFHeaders{
|
2018-01-19 21:34:28 +01:00
|
|
|
FilterType: filterType,
|
|
|
|
StartHeight: startHeight,
|
|
|
|
StopHash: *stopHash,
|
2017-03-09 01:14:39 +01:00
|
|
|
}
|
|
|
|
}
|