Enum BitcoinNetwork

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Comparable<BitcoinNetwork>, Network

    public enum BitcoinNetwork
    extends java.lang.Enum<BitcoinNetwork>
    implements Network
    A convenient enum representation of a Bitcoin network.

    Note that the name of each enum constant is defined in uppercase as is the convention in Java. However, the canonical representation in bitcoinj for user-facing display and input of Bitcoin network names is lowercase (e.g. as a command-line parameter.) Implementations should use the toString() method for output and the fromString(String) method for input of network values.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String BITCOIN_SCHEME
      Scheme part for Bitcoin URIs.
      static java.lang.String ID_MAINNET
      The ID string for the main, production network where people trade things.
      static java.lang.String ID_REGTEST
      The ID string for regtest mode.
      static java.lang.String ID_SIGNET
      The ID string for the signet.
      static java.lang.String ID_TESTNET
      The ID string for the testnet.
      static java.lang.String ID_UNITTESTNET
      The ID string for the Unit test network -- there is no corresponding enum.
      static Coin MAX_MONEY
      The maximum money to be generated
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean exceedsMaxMoney​(Monetary amount)
      Check if an amount exceeds the maximum allowed for a network (if the network has one)
      static java.util.Optional<BitcoinNetwork> fromIdString​(java.lang.String idString)
      Find the BitcoinNetwork from an ID String
      static java.util.Optional<BitcoinNetwork> fromString​(java.lang.String nameString)
      Find the BitcoinNetwork from a name string, e.g.
      boolean hasMaxMoney()
      Does this network have a fixed maximum number of coins
      java.lang.String id()
      Return the network ID string (previously specified in NetworkParameters)
      int legacyAddressHeader()
      Header byte of base58 encoded legacy P2PKH addresses for this network.
      int legacyP2SHHeader()
      Header byte of base58 encoded legacy P2SH addresses for this network.
      Coin maxMoney()
      Maximum number of coins for this network as a Monetary value.
      java.lang.String segwitAddressHrp()
      Return the standard Bech32 SegwitAddress.SegwitHrp (as a String) for this network.
      java.lang.String toString()
      Return the canonical, lowercase, user-facing String for an enum
      java.lang.String uriScheme()
      The URI scheme for Bitcoin.
      static BitcoinNetwork valueOf​(java.lang.String name)
      Returns the enum constant of this type with the specified name.
      static BitcoinNetwork[] values()
      Returns an array containing the constants of this enum type, in the order they are declared.
      • Methods inherited from class java.lang.Enum

        clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, valueOf
      • Methods inherited from class java.lang.Object

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

      • BITCOIN_SCHEME

        public static final java.lang.String BITCOIN_SCHEME
        Scheme part for Bitcoin URIs.
        See Also:
        Constant Field Values
      • MAX_MONEY

        public static final Coin MAX_MONEY
        The maximum money to be generated
      • ID_MAINNET

        public static final java.lang.String ID_MAINNET
        The ID string for the main, production network where people trade things.
      • ID_TESTNET

        public static final java.lang.String ID_TESTNET
        The ID string for the testnet.
      • ID_SIGNET

        public static final java.lang.String ID_SIGNET
        The ID string for the signet.
      • ID_REGTEST

        public static final java.lang.String ID_REGTEST
        The ID string for regtest mode.
      • ID_UNITTESTNET

        public static final java.lang.String ID_UNITTESTNET
        The ID string for the Unit test network -- there is no corresponding enum.
        See Also:
        Constant Field Values
    • Method Detail

      • values

        public static BitcoinNetwork[] values()
        Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
        for (BitcoinNetwork c : BitcoinNetwork.values())
            System.out.println(c);
        
        Returns:
        an array containing the constants of this enum type, in the order they are declared
      • valueOf

        public static BitcoinNetwork valueOf​(java.lang.String name)
        Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
        Parameters:
        name - the name of the enum constant to be returned.
        Returns:
        the enum constant with the specified name
        Throws:
        java.lang.IllegalArgumentException - if this enum type has no constant with the specified name
        java.lang.NullPointerException - if the argument is null
      • toString

        public java.lang.String toString()
        Return the canonical, lowercase, user-facing String for an enum
        Overrides:
        toString in class java.lang.Enum<BitcoinNetwork>
        Returns:
        canonical lowercase value
      • id

        public java.lang.String id()
        Return the network ID string (previously specified in NetworkParameters)
        Specified by:
        id in interface Network
        Returns:
        The network ID string
      • legacyP2SHHeader

        public int legacyP2SHHeader()
        Header byte of base58 encoded legacy P2SH addresses for this network.
        Specified by:
        legacyP2SHHeader in interface Network
        Returns:
        header byte as an int.
        See Also:
        LegacyAddress.P2SHHeader
      • segwitAddressHrp

        public java.lang.String segwitAddressHrp()
        Return the standard Bech32 SegwitAddress.SegwitHrp (as a String) for this network.
        Specified by:
        segwitAddressHrp in interface Network
        Returns:
        The HRP as a (lowercase) string.
      • uriScheme

        public java.lang.String uriScheme()
        The URI scheme for Bitcoin.
        Specified by:
        uriScheme in interface Network
        Returns:
        string containing the URI scheme
        See Also:
        BIP 0021
      • hasMaxMoney

        public boolean hasMaxMoney()
        Description copied from interface: Network
        Does this network have a fixed maximum number of coins
        Specified by:
        hasMaxMoney in interface Network
        Returns:
        true if this network has a fixed maximum number of coins
      • maxMoney

        public Coin maxMoney()
        Description copied from interface: Network
        Maximum number of coins for this network as a Monetary value. Where not applicable, a very large number of coins is returned instead (e.g. the main coin issue for Dogecoin).
        Specified by:
        maxMoney in interface Network
        Returns:
        Maximum number of coins for this network
      • exceedsMaxMoney

        public boolean exceedsMaxMoney​(Monetary amount)
        Description copied from interface: Network
        Check if an amount exceeds the maximum allowed for a network (if the network has one)
        Specified by:
        exceedsMaxMoney in interface Network
        Parameters:
        amount - A monetary amount
        Returns:
        true if too big, false if an allowed amount
      • fromString

        public static java.util.Optional<BitcoinNetwork> fromString​(java.lang.String nameString)
        Find the BitcoinNetwork from a name string, e.g. "mainnet", "testnet" or "signet". A number of common alternate names are allowed too, e.g. "main" or "prod".
        Parameters:
        nameString - A name string
        Returns:
        An Optional containing the matching enum or empty
      • fromIdString

        public static java.util.Optional<BitcoinNetwork> fromIdString​(java.lang.String idString)
        Find the BitcoinNetwork from an ID String

        Note: ID_UNITTESTNET is not supported as an enum

        Parameters:
        idString - specifies the network
        Returns:
        An Optional containing the matching enum or empty