Class NetworkParameters
- Direct Known Subclasses:
BitcoinNetworkParams
,MockAltNetworkParams
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 Summary
Modifier and TypeFieldDescriptionprotected int
protected int[]
static final Instant
Blocks with a timestamp after this should enforce BIP 16, aka "Pay to script hash".protected int
protected int
protected int
protected int
protected Map<Integer,
Sha256Hash> protected MessageSerializer
protected String[]
protected int
protected final String
See getId()protected int
static final int
protected int
Used to check majorities for block version upgradeprotected int
protected int
static final long
Deprecated.static final Coin
Deprecated.protected BigInteger
protected final Network
protected int
protected int
static final String
Deprecated.static final String
Deprecated.static final String
Deprecated.static final String
Deprecated.static final String
Deprecated.protected int
protected String
protected int
The depth of blocks required for a coinbase transaction to be spendable.protected int
static final int
static final int
protected int
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
If we are running in testnet-in-a-box mode, we allow connections to nodes with 0 non-genesis blocks.abstract void
checkDifficultyTransitions
(StoredBlock storedPrev, Block next, BlockStore blockStore) Throws an exception if the block's difficulty is not correct.boolean
static NetworkParameters
fromAddress
(Address address) Deprecated.You should be usingAddress.network()
insteadstatic NetworkParameters
Deprecated.static NetworkParameters
fromPmtProtocolID
(String pmtProtocolId) Deprecated.UsePaymentProtocol.paramsFromPmtProtocolID(String)
(String)}int
Deprecated.int[]
Return IP addresses of active peersint
Returns the 4 byte header for BIP32 wallet P2PKH - private key part.int
Returns the 4 byte header for BIP32 wallet P2PKH - public key part.int
Returns the 4 byte header for BIP32 wallet P2WPKH - private key part.int
Returns the 4 byte header for BIP32 wallet P2WPKH - public key part.getBlockVerificationFlags
(Block block, VersionTally tally, Integer height) The flags indicating which block validation tests should be applied to the given block.final MessageSerializer
Return the default serializer for this network.String[]
Return DNS names that when resolved, give IP addresses of active peersint
First byte of a base58 encoded dumped private key.abstract Block
Genesis block for this chain.getId()
A Java package style string acting as unique ID for these parametersint
How many blocks pass between difficulty adjustment periods.int
The number of blocks in the lastgetMajorityWindow()
blocks at which to trigger a notice to the user to upgrade their client, where the client does not understand those blocks.int
The number of blocks in the lastgetMajorityWindow()
blocks at which to enforce the requirement that all new blocks are of the newer type (i.e.int
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.abstract Coin
Deprecated.Maximum target represents the easiest allowable proof of work.abstract MonetaryFormat
Deprecated.Get one another way or construct your ownMonetaryFormat
as needed.int
Deprecated.int
The header bytes that identify the start of a packet on this network.abstract String
Deprecated.int
getPort()
Default TCP port on which to connect to nodesint
getProtocolVersionNum
(ProtocolVersion version) Deprecated.Deprecated.abstract BitcoinSerializer
Construct and return a custom serializer.int
int
int
How much time in seconds is supposed to pass between "interval" blocks.getTransactionVerificationFlags
(Block block, Transaction transaction, VersionTally tally, Integer height) The flags indicating which script validation tests should be applied to the given transaction.abstract String
Deprecated.int
hashCode()
abstract boolean
Deprecated.boolean
isCheckpoint
(int height) Is height a checkpointnetwork()
static NetworkParameters
Return network parameters for aNetwork
.boolean
passesCheckpoint
(int height, Sha256Hash hash) Validate the hash for a given block height against checkpoints
-
Field Details
-
PAYMENT_PROTOCOL_ID_MAINNET
Deprecated.The string used by the payment protocol to represent the main net.- See Also:
-
PAYMENT_PROTOCOL_ID_TESTNET
Deprecated.The string used by the payment protocol to represent the test net.- See Also:
-
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.The string used by the payment protocol to represent unit testing (note that this is non-standard).- See Also:
-
PAYMENT_PROTOCOL_ID_REGTEST
Deprecated.- See Also:
-
maxTarget
-
port
protected int port -
packetMagic
protected int packetMagic -
addressHeader
protected int addressHeader -
p2shHeader
protected int p2shHeader -
dumpedPrivateKeyHeader
protected int dumpedPrivateKeyHeader -
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 majorityEnforceBlockUpgradeUsed to check majorities for block version upgrade -
majorityRejectBlockOutdated
protected int majorityRejectBlockOutdated -
majorityWindow
protected int majorityWindow -
id
See getId() -
network
-
spendableCoinbaseDepth
protected int spendableCoinbaseDepthThe depth of blocks required for a coinbase transaction to be spendable. -
subsidyDecreaseBlockCount
protected int subsidyDecreaseBlockCount -
dnsSeeds
-
addrSeeds
protected int[] addrSeeds -
checkpoints
-
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
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. -
MAX_COINS
Deprecated.The maximum number of coins to be generated -
MAX_MONEY
Deprecated.The maximum money to be generated
-
-
Constructor Details
-
NetworkParameters
-
-
Method Details
-
getId
A Java package style string acting as unique ID for these parameters- Returns:
- network id string
-
network
- Returns:
- Network enum for this network
-
getPaymentProtocolId
Deprecated.- Returns:
- the payment protocol network id string
-
equals
-
hashCode
public int hashCode() -
fromID
Deprecated.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
Return network parameters for aNetwork
.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
Deprecated.UsePaymentProtocol.paramsFromPmtProtocolID(String)
(String)}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.You should be usingAddress.network()
insteadGet a NetworkParameters from an Address. Addresses should not be used for storing NetworkParameters. In the future Address will be aninterface
that only makes aNetwork
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 blocknext
- proposed blockblockStore
- active BlockStore- Throws:
VerificationException
- if the block's difficulty is not correct.BlockStoreException
- if an error occurred accessing the BlockStore
-
passesCheckpoint
Validate the hash for a given block height against checkpoints- Parameters:
height
- block heighthash
- hash forheight
- 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
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
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.First byte of a base58 encoded address. SeeLegacyAddress
.- Returns:
- the header value
-
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. SeeDumpedPrivateKey
.- Returns:
- the header value
-
getSegwitAddressHrp
Deprecated.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
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.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.Get one another way or construct your ownMonetaryFormat
as needed.The monetary object for this currency.- Returns:
- formatting utility object
-
getUriScheme
Deprecated.Scheme part for URIs, for example "bitcoin".- Returns:
- a string with the "scheme" part
-
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
Return the default serializer for this network. This is a shared serializer.- Returns:
- the default serializer for this network.
-
getSerializer
Construct and return a custom serializer.- Returns:
- the serializer
-
getMajorityEnforceBlockUpgrade
public int getMajorityEnforceBlockUpgrade()The number of blocks in the lastgetMajorityWindow()
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 lastgetMajorityWindow()
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 counterheight
- 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.
-
BitcoinNetwork.MAX_MONEY