github.com/lbryio/lbcd@v0.22.119/wire/msggetcfcheckpt.go (about)

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