msggetcfcheckpt.go raw

   1  package wire
   2  
   3  import (
   4  	"io"
   5  	
   6  	"github.com/p9c/p9/pkg/chainhash"
   7  )
   8  
   9  // MsgGetCFCheckpt is a request for filter headers at evenly spaced intervals throughout the blockchain history. It
  10  // allows to set the FilterType field to get headers in the chain of basic (0x00) or extended (0x01) headers.
  11  type MsgGetCFCheckpt struct {
  12  	FilterType FilterType
  13  	StopHash   chainhash.Hash
  14  }
  15  
  16  // BtcDecode decodes r using the bitcoin protocol encoding into the receiver. This is part of the Message interface
  17  // implementation.
  18  func (msg *MsgGetCFCheckpt) BtcDecode(r io.Reader, pver uint32, _ MessageEncoding) (e error) {
  19  	if e = readElement(r, &msg.FilterType); E.Chk(e) {
  20  		return
  21  	}
  22  	return readElement(r, &msg.StopHash)
  23  }
  24  
  25  // BtcEncode encodes the receiver to w using the bitcoin protocol encoding. This
  26  // is part of the Message interface implementation.
  27  func (msg *MsgGetCFCheckpt) BtcEncode(w io.Writer, pver uint32, _ MessageEncoding) (e error) {
  28  	if e = writeElement(w, msg.FilterType); E.Chk(e) {
  29  		return
  30  	}
  31  	return writeElement(w, &msg.StopHash)
  32  }
  33  
  34  // Command returns the protocol command string for the message. This is part of
  35  // the Message interface implementation.
  36  func (msg *MsgGetCFCheckpt) Command() string {
  37  	return CmdGetCFCheckpt
  38  }
  39  
  40  // MaxPayloadLength returns the maximum length the payload can be for the
  41  // receiver. This is part of the Message interface implementation.
  42  func (msg *MsgGetCFCheckpt) MaxPayloadLength(pver uint32) uint32 {
  43  	// Filter type + uint32 + block hash
  44  	return 1 + chainhash.HashSize
  45  }
  46  
  47  // NewMsgGetCFCheckpt returns a new bitcoin getcfcheckpt message that conforms
  48  // to the Message interface using the passed parameters and defaults for the
  49  // remaining fields.
  50  func NewMsgGetCFCheckpt(filterType FilterType, stopHash *chainhash.Hash) *MsgGetCFCheckpt {
  51  	return &MsgGetCFCheckpt{
  52  		FilterType: filterType,
  53  		StopHash:   *stopHash,
  54  	}
  55  }
  56