msgfeefilter.go raw

   1  package wire
   2  
   3  import (
   4  	"fmt"
   5  	"io"
   6  )
   7  
   8  // MsgFeeFilter implements the Message interface and represents a bitcoin feefilter message. It is used to request the
   9  // receiving peer does not announce any transactions below the specified minimum fee rate. This message was not added
  10  // until protocol versions starting with FeeFilterVersion.
  11  type MsgFeeFilter struct {
  12  	MinFee int64
  13  }
  14  
  15  // BtcDecode decodes r using the bitcoin protocol encoding into the receiver. This is part of the Message interface
  16  // implementation.
  17  func (msg *MsgFeeFilter) BtcDecode(r io.Reader, pver uint32, enc MessageEncoding) (e error) {
  18  	if pver < FeeFilterVersion {
  19  		str := fmt.Sprintf("feefilter message invalid for protocol "+
  20  			"version %d", pver,
  21  		)
  22  		return messageError("MsgFeeFilter.BtcDecode", str)
  23  	}
  24  	return readElement(r, &msg.MinFee)
  25  }
  26  
  27  // BtcEncode encodes the receiver to w using the bitcoin protocol encoding. This is part of the Message interface
  28  // implementation.
  29  func (msg *MsgFeeFilter) BtcEncode(w io.Writer, pver uint32, enc MessageEncoding) (e error) {
  30  	if pver < FeeFilterVersion {
  31  		str := fmt.Sprintf("feefilter message invalid for protocol "+
  32  			"version %d", pver,
  33  		)
  34  		return messageError("MsgFeeFilter.BtcEncode", str)
  35  	}
  36  	return writeElement(w, msg.MinFee)
  37  }
  38  
  39  // Command returns the protocol command string for the message. This is part of the Message interface implementation.
  40  func (msg *MsgFeeFilter) Command() string {
  41  	return CmdFeeFilter
  42  }
  43  
  44  // MaxPayloadLength returns the maximum length the payload can be for the receiver. This is part of the Message
  45  // interface implementation.
  46  func (msg *MsgFeeFilter) MaxPayloadLength(pver uint32) uint32 {
  47  	return 8
  48  }
  49  
  50  // NewMsgFeeFilter returns a new bitcoin feefilter message that conforms to the Message interface. See MsgFeeFilter for
  51  // details.
  52  func NewMsgFeeFilter(minfee int64) *MsgFeeFilter {
  53  	return &MsgFeeFilter{
  54  		MinFee: minfee,
  55  	}
  56  }
  57