github.com/btcsuite/btcd@v0.24.0/wire/msgfeefilter.go (about)

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