msggetcfilters.go raw

   1  package wire
   2  
   3  import (
   4  	"io"
   5  	
   6  	"github.com/p9c/p9/pkg/chainhash"
   7  )
   8  
   9  // MaxGetCFiltersReqRange the maximum number of filters that may be requested in a getcfheaders message.
  10  const MaxGetCFiltersReqRange = 1000
  11  
  12  // MsgGetCFilters implements the Message interface and represents a bitcoin getcfilters message. It is used to request
  13  // committed filters for a range of blocks.
  14  type MsgGetCFilters struct {
  15  	FilterType  FilterType
  16  	StartHeight uint32
  17  	StopHash    chainhash.Hash
  18  }
  19  
  20  // BtcDecode decodes r using the bitcoin protocol encoding into the receiver. This is part of the Message interface
  21  // implementation.
  22  func (msg *MsgGetCFilters) BtcDecode(r io.Reader, pver uint32, _ MessageEncoding) (e error) {
  23  	if e = readElement(r, &msg.FilterType); E.Chk(e) {
  24  		return
  25  	}
  26  	if e = readElement(r, &msg.StartHeight); E.Chk(e) {
  27  		return
  28  	}
  29  	return readElement(r, &msg.StopHash)
  30  }
  31  
  32  // BtcEncode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface
  33  // implementation.
  34  func (msg *MsgGetCFilters) BtcEncode(w io.Writer, pver uint32, _ MessageEncoding) (e error) {
  35  	if e = writeElement(w, msg.FilterType); E.Chk(e) {
  36  		return
  37  	}
  38  	if e = writeElement(w, &msg.StartHeight); E.Chk(e) {
  39  		return
  40  	}
  41  	return writeElement(w, &msg.StopHash)
  42  }
  43  
  44  // Command returns the protocol command string for the message.  This is part of the Message interface implementation.
  45  func (msg *MsgGetCFilters) Command() string {
  46  	return CmdGetCFilters
  47  }
  48  
  49  // MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message
  50  // interface implementation.
  51  func (msg *MsgGetCFilters) MaxPayloadLength(pver uint32) uint32 {
  52  	// Filter type + uint32 + block hash
  53  	return 1 + 4 + chainhash.HashSize
  54  }
  55  
  56  // NewMsgGetCFilters returns a new bitcoin getcfilters message that conforms to the Message interface using the passed
  57  // parameters and defaults for the remaining fields.
  58  func NewMsgGetCFilters(
  59  	filterType FilterType, startHeight uint32,
  60  	stopHash *chainhash.Hash,
  61  ) *MsgGetCFilters {
  62  	return &MsgGetCFilters{
  63  		FilterType:  filterType,
  64  		StartHeight: startHeight,
  65  		StopHash:    *stopHash,
  66  	}
  67  }
  68