Class Services


  • public class Services
    extends java.lang.Object
    Wrapper for services bitfield used in various messages of the Bitcoin protocol. Each bit represents a node service, e.g. NODE_NETWORK if the node serves the full blockchain.

    Instances of this class are immutable and should be treated as Java value-based.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int BYTES
      Number of bytes of this bitfield.
      static int NODE_BITCOIN_CASH
      A service bit used by Bitcoin-ABC to announce Bitcoin Cash nodes.
      static int NODE_BLOOM
      A service bit that denotes whether the peer supports BIP37 bloom filters or not.
      static int NODE_NETWORK
      A service bit that denotes whether the peer has a full copy of the block chain or not.
      static int NODE_NETWORK_LIMITED
      A service bit that denotes whether the peer has at least the last two days worth of blockchain (BIP159).
      static int NODE_WITNESS
      Indicates that a node can be asked for blocks and transactions including witness data.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean anyOf​(long bitmask)
      Checks if at least one of the given node services is signaled by this bitfield.
      long bits()
      Gets the 64 bits of this bitfield, each representing a node service.
      boolean equals​(java.lang.Object o)  
      boolean has​(long bitmask)
      Checks if given specific node services are signaled by this bitfield.
      boolean hasAny()
      Checks if this bitfield signals any node services at all.
      int hashCode()  
      static Services none()
      Constructs a services bitfield representing "no node services".
      static Services of​(long bits)
      Wrap 64 bits, each representing a node service.
      static Services read​(java.nio.ByteBuffer buf)
      Construct a services bitfield by reading from the given buffer.
      byte[] serialize()
      Allocates a byte array and writes the node service bits into it.
      java.lang.String toString()  
      java.nio.ByteBuffer write​(java.nio.ByteBuffer buf)
      Write the node service bits into the given buffer.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • NODE_NETWORK

        public static final int NODE_NETWORK
        A service bit that denotes whether the peer has a full copy of the block chain or not.
        See Also:
        Constant Field Values
      • NODE_BLOOM

        public static final int NODE_BLOOM
        A service bit that denotes whether the peer supports BIP37 bloom filters or not. The service bit is defined in BIP111.
        See Also:
        Constant Field Values
      • NODE_WITNESS

        public static final int NODE_WITNESS
        Indicates that a node can be asked for blocks and transactions including witness data.
        See Also:
        Constant Field Values
      • NODE_NETWORK_LIMITED

        public static final int NODE_NETWORK_LIMITED
        A service bit that denotes whether the peer has at least the last two days worth of blockchain (BIP159).
        See Also:
        Constant Field Values
      • NODE_BITCOIN_CASH

        public static final int NODE_BITCOIN_CASH
        A service bit used by Bitcoin-ABC to announce Bitcoin Cash nodes.
        See Also:
        Constant Field Values
    • Method Detail

      • of

        public static Services of​(long bits)
        Wrap 64 bits, each representing a node service.
        Parameters:
        bits - bits to wrap
        Returns:
        wrapped service bits
      • none

        public static Services none()
        Constructs a services bitfield representing "no node services".
        Returns:
        wrapped service bits
      • read

        public static Services read​(java.nio.ByteBuffer buf)
                             throws java.nio.BufferUnderflowException
        Construct a services bitfield by reading from the given buffer.
        Parameters:
        buf - buffer to read from
        Returns:
        wrapped service bits
        Throws:
        java.nio.BufferUnderflowException - if the read services bitfield extends beyond the remaining bytes of the buffer
      • bits

        public long bits()
        Gets the 64 bits of this bitfield, each representing a node service.
        Returns:
        the service bits
      • hasAny

        public boolean hasAny()
        Checks if this bitfield signals any node services at all.
        Returns:
        true if at least one service is signaled, false otherwise
      • has

        public boolean has​(long bitmask)
        Checks if given specific node services are signaled by this bitfield.
        Parameters:
        bitmask - bitmask representing the services to be checked for
        Returns:
        true if the given services are all signaled, false otherwise
      • anyOf

        public boolean anyOf​(long bitmask)
        Checks if at least one of the given node services is signaled by this bitfield.
        Parameters:
        bitmask - bitmask representing the services to be checked for
        Returns:
        true if at least one of the given services is signaled, false otherwise
      • write

        public java.nio.ByteBuffer write​(java.nio.ByteBuffer buf)
                                  throws java.nio.BufferOverflowException
        Write the node service bits into the given buffer.
        Parameters:
        buf - buffer to write into
        Returns:
        the buffer
        Throws:
        java.nio.BufferOverflowException - if the service bits don't fit the remaining buffer
      • serialize

        public byte[] serialize()
        Allocates a byte array and writes the node service bits into it.
        Returns:
        byte array containing the service bits
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object