Class Services

java.lang.Object
org.bitcoinj.core.Services

public class Services extends 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 final int
    Number of bytes of this bitfield.
    static final int
    A service bit used by Bitcoin-ABC to announce Bitcoin Cash nodes.
    static final int
    A service bit that denotes whether the peer supports BIP37 bloom filters or not.
    static final int
    Indicates the node will service basic block filter requests (BIP157, BIP158).
    static final int
    A service bit that denotes whether the peer has a full copy of the block chain or not.
    static final int
    A service bit that denotes whether the peer has at least the last two days worth of blockchain (BIP159).
    static final int
    Indicates the node supports BIP324 transport.
    static final int
    Indicates that a node can be asked for blocks and transactions including witness data.
  • Method Summary

    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
    Gets the 64 bits of this bitfield, each representing a node service.
    boolean
     
    boolean
    has(long bitmask)
    Checks if given specific node services are signaled by this bitfield.
    boolean
    Checks if this bitfield signals any node services at all.
    int
     
    static Services
    Constructs a services bitfield representing "no node services".
    static Services
    of(long bits)
    Wrap 64 bits, each representing a node service.
    static Services
    Construct a services bitfield by reading from the given buffer.
    byte[]
    Allocates a byte array and writes the node service bits into it.
     
    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 Details

    • 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:
    • 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:
    • NODE_WITNESS

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

      public static final int NODE_COMPACT_FILTERS
      Indicates the node will service basic block filter requests (BIP157, BIP158).
      See Also:
    • 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:
    • NODE_P2P_V2

      public static final int NODE_P2P_V2
      Indicates the node supports BIP324 transport.
      See Also:
    • NODE_BITCOIN_CASH

      public static final int NODE_BITCOIN_CASH
      A service bit used by Bitcoin-ABC to announce Bitcoin Cash nodes.
      See Also:
    • BYTES

      public static final int BYTES
      Number of bytes of this bitfield.
      See Also:
  • Method Details

    • 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(ByteBuffer buf) throws BufferUnderflowException
      Construct a services bitfield by reading from the given buffer.
      Parameters:
      buf - buffer to read from
      Returns:
      wrapped service bits
      Throws:
      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 ByteBuffer write(ByteBuffer buf) throws BufferOverflowException
      Write the node service bits into the given buffer.
      Parameters:
      buf - buffer to write into
      Returns:
      the buffer
      Throws:
      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 String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object