Class NetworkParameters

java.lang.Object
org.bitcoinj.core.NetworkParameters
Direct Known Subclasses:
BitcoinNetworkParams, MockAltNetworkParams

public abstract class NetworkParameters extends Object

NetworkParameters contains the data needed for working with an instantiation of a Bitcoin chain.

This is an abstract class, concrete instantiations can be found in the params package. There are four: one for the main network (MainNetParams), one for the public test network, and two others that are intended for unit testing and local app development purposes. Although this class contains some aliases for them, you are encouraged to call the static get() methods on each specific params class directly.

  • Field Details

    • PAYMENT_PROTOCOL_ID_MAINNET

      @Deprecated public static final String PAYMENT_PROTOCOL_ID_MAINNET
      Deprecated.
      The string used by the payment protocol to represent the main net.
      See Also:
    • PAYMENT_PROTOCOL_ID_TESTNET

      @Deprecated public static final String PAYMENT_PROTOCOL_ID_TESTNET
      Deprecated.
      The string used by the payment protocol to represent the test net.
      See Also:
    • PAYMENT_PROTOCOL_ID_SIGNET

      @Deprecated public static final String PAYMENT_PROTOCOL_ID_SIGNET
      Deprecated.
      The string used by the payment protocol to represent signet (note that this is non-standard).
      See Also:
    • PAYMENT_PROTOCOL_ID_UNIT_TESTS

      @Deprecated public static final String PAYMENT_PROTOCOL_ID_UNIT_TESTS
      Deprecated.
      The string used by the payment protocol to represent unit testing (note that this is non-standard).
      See Also:
    • PAYMENT_PROTOCOL_ID_REGTEST

      @Deprecated public static final String PAYMENT_PROTOCOL_ID_REGTEST
      Deprecated.
      See Also:
    • maxTarget

      protected BigInteger maxTarget
    • port

      protected int port
    • packetMagic

      protected int packetMagic
    • addressHeader

      protected int addressHeader
    • p2shHeader

      protected int p2shHeader
    • dumpedPrivateKeyHeader

      protected int dumpedPrivateKeyHeader
    • segwitAddressHrp

      protected String segwitAddressHrp
    • interval

      protected int interval
    • targetTimespan

      protected int targetTimespan
    • bip32HeaderP2PKHpub

      protected int bip32HeaderP2PKHpub
    • bip32HeaderP2PKHpriv

      protected int bip32HeaderP2PKHpriv
    • bip32HeaderP2WPKHpub

      protected int bip32HeaderP2WPKHpub
    • bip32HeaderP2WPKHpriv

      protected int bip32HeaderP2WPKHpriv
    • majorityEnforceBlockUpgrade

      protected int majorityEnforceBlockUpgrade
      Used to check majorities for block version upgrade
    • majorityRejectBlockOutdated

      protected int majorityRejectBlockOutdated
    • majorityWindow

      protected int majorityWindow
    • id

      protected final String id
      See getId()
    • network

      protected final Network network
    • spendableCoinbaseDepth

      protected int spendableCoinbaseDepth
      The depth of blocks required for a coinbase transaction to be spendable.
    • subsidyDecreaseBlockCount

      protected int subsidyDecreaseBlockCount
    • dnsSeeds

      protected String[] dnsSeeds
    • addrSeeds

      protected int[] addrSeeds
    • checkpoints

      protected Map<Integer,Sha256Hash> checkpoints
    • defaultSerializer

      protected transient volatile MessageSerializer defaultSerializer
    • TARGET_TIMESPAN

      public static final int TARGET_TIMESPAN
      See Also:
    • TARGET_SPACING

      public static final int TARGET_SPACING
      See Also:
    • INTERVAL

      public static final int INTERVAL
      See Also:
    • BIP16_ENFORCE_TIME

      public static final int BIP16_ENFORCE_TIME
      Blocks with a timestamp after this should enforce BIP 16, aka "Pay to script hash". This BIP changed the network rules in a soft-forking manner, that is, blocks that don't follow the rules are accepted but not mined upon and thus will be quickly re-orged out as long as the majority are enforcing the rule.
      See Also:
    • MAX_COINS

      @Deprecated public static final long MAX_COINS
      Deprecated.
      The maximum number of coins to be generated
    • MAX_MONEY

      @Deprecated public static final Coin MAX_MONEY
      Deprecated.
      The maximum money to be generated
  • Constructor Details

    • NetworkParameters

      protected NetworkParameters(Network network)
  • Method Details

    • getId

      public String getId()
      A Java package style string acting as unique ID for these parameters
      Returns:
      network id string
    • network

      public Network network()
      Returns:
      Network enum for this network
    • getPaymentProtocolId

      @Deprecated public abstract String getPaymentProtocolId()
      Returns:
      the payment protocol network id string
    • equals

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

      public int hashCode()
      Overrides:
      hashCode in class Object
    • fromID

      @Deprecated @Nullable public static NetworkParameters fromID(String id)
      Return network parameters for a network id
      Parameters:
      id - the network id
      Returns:
      the network parameters for the given string ID or NULL if not recognized
    • of

      public static NetworkParameters of(Network network)
      Return network parameters for a Network.

      Alternative networks will be found if they have been registered with Networks registry.

      Parameters:
      network - the network
      Returns:
      the network parameters for the given string ID
      Throws:
      IllegalArgumentException - if unknown network
    • fromPmtProtocolID

      @Nullable @Deprecated public static NetworkParameters fromPmtProtocolID(String pmtProtocolId)
      Return network parameters for a paymentProtocol ID string
      Parameters:
      pmtProtocolId - paymentProtocol ID string
      Returns:
      network parameters for the given string paymentProtocolID or NULL if not recognized
    • fromAddress

      @Deprecated public static NetworkParameters fromAddress(Address address)
      Deprecated.
      You should be using Address.network() instead
      Get a NetworkParameters from an Address. Addresses should not be used for storing NetworkParameters. In the future Address will be an interface that only makes a Network available.
      Parameters:
      address - An address
      Returns:
      network parameters
    • getSpendableCoinbaseDepth

      public int getSpendableCoinbaseDepth()
    • checkDifficultyTransitions

      public abstract void checkDifficultyTransitions(StoredBlock storedPrev, Block next, BlockStore blockStore) throws VerificationException, BlockStoreException
      Throws an exception if the block's difficulty is not correct.
      Parameters:
      storedPrev - previous stored block
      next - proposed block
      blockStore - active BlockStore
      Throws:
      VerificationException - if the block's difficulty is not correct.
      BlockStoreException - if an error occurred accessing the BlockStore
    • passesCheckpoint

      public boolean passesCheckpoint(int height, Sha256Hash hash)
      Validate the hash for a given block height against checkpoints
      Parameters:
      height - block height
      hash - hash for height
      Returns:
      true if the block height is either not a checkpoint, or is a checkpoint and the hash matches
    • isCheckpoint

      public boolean isCheckpoint(int height)
      Is height a checkpoint
      Parameters:
      height - block height
      Returns:
      true if the given height has a recorded checkpoint
    • getSubsidyDecreaseBlockCount

      public int getSubsidyDecreaseBlockCount()
    • getDnsSeeds

      public String[] getDnsSeeds()
      Return DNS names that when resolved, give IP addresses of active peers
      Returns:
      an array of DNS names
    • getAddrSeeds

      public int[] getAddrSeeds()
      Return IP addresses of active peers
      Returns:
      array of IP addresses
    • getGenesisBlock

      public abstract Block getGenesisBlock()

      Genesis block for this chain.

      The first block in every chain is a well known constant shared between all Bitcoin implementations. For a block to be valid, it must be eventually possible to work backwards to the genesis block by following the prevBlockHash pointers in the block headers.

      The genesis blocks for both test and main networks contain the timestamp of when they were created, and a message in the coinbase transaction. It says, "The Times 03/Jan/2009 Chancellor on brink of second bailout for banks".

      Returns:
      genesis block
    • getPort

      public int getPort()
      Default TCP port on which to connect to nodes
      Returns:
      default port for this network
    • getPacketMagic

      public int getPacketMagic()
      The header bytes that identify the start of a packet on this network.
      Returns:
      header bytes as a long
    • getAddressHeader

      @Deprecated public int getAddressHeader()
      Deprecated.
      First byte of a base58 encoded address. See LegacyAddress.
      Returns:
      the header value
    • getP2SHHeader

      @Deprecated public int getP2SHHeader()
      Deprecated.
      First byte of a base58 encoded P2SH address. P2SH addresses are defined as part of BIP0013.
      Returns:
      the header value
    • getDumpedPrivateKeyHeader

      public int getDumpedPrivateKeyHeader()
      First byte of a base58 encoded dumped private key. See DumpedPrivateKey.
      Returns:
      the header value
    • getSegwitAddressHrp

      @Deprecated public String getSegwitAddressHrp()
      Human-readable part of bech32 encoded segwit address.
      Returns:
      the human-readable part value
    • getTargetTimespan

      public int getTargetTimespan()
      How much time in seconds is supposed to pass between "interval" blocks. If the actual elapsed time is significantly different from this value, the network difficulty formula will produce a different value. Both test and main Bitcoin networks use 2 weeks (1209600 seconds).
      Returns:
      target timespan in seconds
    • allowEmptyPeerChain

      public boolean allowEmptyPeerChain()
      If we are running in testnet-in-a-box mode, we allow connections to nodes with 0 non-genesis blocks.
      Returns:
      true if allowed
    • getInterval

      public int getInterval()
      How many blocks pass between difficulty adjustment periods. Bitcoin standardises this to be 2016.
      Returns:
      number of blocks
    • getMaxTarget

      public BigInteger getMaxTarget()
      Maximum target represents the easiest allowable proof of work.
      Returns:
      maximum target integer
    • getBip32HeaderP2PKHpub

      public int getBip32HeaderP2PKHpub()
      Returns the 4 byte header for BIP32 wallet P2PKH - public key part.
      Returns:
      the header value
    • getBip32HeaderP2PKHpriv

      public int getBip32HeaderP2PKHpriv()
      Returns the 4 byte header for BIP32 wallet P2PKH - private key part.
      Returns:
      the header value
    • getBip32HeaderP2WPKHpub

      public int getBip32HeaderP2WPKHpub()
      Returns the 4 byte header for BIP32 wallet P2WPKH - public key part.
      Returns:
      the header value
    • getBip32HeaderP2WPKHpriv

      public int getBip32HeaderP2WPKHpriv()
      Returns the 4 byte header for BIP32 wallet P2WPKH - private key part.
      Returns:
      the header value
    • getMaxMoney

      @Deprecated public abstract Coin getMaxMoney()
      Deprecated.
      Returns the number of coins that will be produced in total, on this network. Where not applicable, a very large number of coins is returned instead (e.g. the main coin issue for Dogecoin).
      Returns:
      maximum number of coins for this network
    • getMonetaryFormat

      @Deprecated public abstract MonetaryFormat getMonetaryFormat()
      Deprecated.
      Get one another way or construct your own MonetaryFormat as needed.
      The monetary object for this currency.
      Returns:
      formatting utility object
    • getUriScheme

      @Deprecated public abstract String getUriScheme()
      Deprecated.
      Scheme part for URIs, for example "bitcoin".
      Returns:
      a string with the "scheme" part
    • hasMaxMoney

      @Deprecated public abstract boolean hasMaxMoney()
      Deprecated.
      Returns whether this network has a maximum number of coins (finite supply) or not. Always returns true for Bitcoin, but exists to be overridden for other networks.
      Returns:
      true if network has a fixed maximum number of coins
    • getDefaultSerializer

      public final MessageSerializer getDefaultSerializer()
      Return the default serializer for this network. This is a shared serializer.
      Returns:
      the default serializer for this network.
    • getSerializer

      public abstract BitcoinSerializer getSerializer()
      Construct and return a custom serializer.
      Returns:
      the serializer
    • getMajorityEnforceBlockUpgrade

      public int getMajorityEnforceBlockUpgrade()
      The number of blocks in the last getMajorityWindow() blocks at which to trigger a notice to the user to upgrade their client, where the client does not understand those blocks.
      Returns:
      number of blocks
    • getMajorityRejectBlockOutdated

      public int getMajorityRejectBlockOutdated()
      The number of blocks in the last getMajorityWindow() blocks at which to enforce the requirement that all new blocks are of the newer type (i.e. outdated blocks are rejected).
      Returns:
      number of blocks
    • getMajorityWindow

      public int getMajorityWindow()
      The sampling window from which the version numbers of blocks are taken in order to determine if a new block version is now the majority.
      Returns:
      number of blocks
    • getBlockVerificationFlags

      public EnumSet<Block.VerifyFlag> getBlockVerificationFlags(Block block, VersionTally tally, Integer height)
      The flags indicating which block validation tests should be applied to the given block. Enables support for alternative blockchains which enable tests based on different criteria.
      Parameters:
      block - block to determine flags for.
      height - height of the block, if known, null otherwise. Returned tests should be a safe subset if block height is unknown.
      tally - caching tally counter
      Returns:
      the flags
    • getTransactionVerificationFlags

      public EnumSet<Script.VerifyFlag> getTransactionVerificationFlags(Block block, Transaction transaction, VersionTally tally, Integer height)
      The flags indicating which script validation tests should be applied to the given transaction. Enables support for alternative blockchains which enable tests based on different criteria.
      Parameters:
      block - block the transaction belongs to.
      transaction - to determine flags for.
      tally - caching tally counter
      height - height of the block, if known, null otherwise. Returned tests should be a safe subset if block height is unknown.
      Returns:
      the flags
    • getProtocolVersionNum

      @Deprecated public int getProtocolVersionNum(ProtocolVersion version)