Class InventoryMessage

  • Direct Known Subclasses:
    NotFoundMessage

    public class InventoryMessage
    extends ListMessage

    Represents the "inv" P2P network message. An inv contains a list of hashes of either blocks or transactions. It's a bandwidth optimization - on receiving some data, a (fully validating) peer sends every connected peer an inv containing the hash of what it saw. It'll only transmit the full thing if a peer asks for it with a GetDataMessage.

    Instances of this class are not safe for use by multiple threads.

    • Field Detail

      • MAX_INV_SIZE

        public static final int MAX_INV_SIZE
        A hard coded constant in the protocol.
        See Also:
        Constant Field Values
    • Constructor Detail

      • InventoryMessage

        public InventoryMessage​(NetworkParameters params,
                                byte[] payload,
                                MessageSerializer serializer,
                                int length)
                         throws ProtocolException
        Deserializes an 'inv' message.
        Parameters:
        params - NetworkParameters object.
        payload - Bitcoin protocol formatted byte array containing message content.
        serializer - the serializer to use for this message.
        length - The length of message if known. Usually this is provided when deserializing of the wire as the length will be provided as part of the header. If unknown then set to Message.UNKNOWN_LENGTH
        Throws:
        ProtocolException
    • Method Detail

      • addBlock

        public void addBlock​(Block block)
      • addTransaction

        public void addTransaction​(Transaction tx)