Class NetworkParameters
- java.lang.Object
-
- org.bitcoinj.core.NetworkParameters
-
- Direct Known Subclasses:
AbstractBitcoinNetParams
public abstract class NetworkParameters extends java.lang.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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
NetworkParameters.ProtocolVersion
-
Field Summary
Fields Modifier and Type Field Description protected int
addressHeader
protected int[]
addrSeeds
static int
BIP16_ENFORCE_TIME
Blocks with a timestamp after this should enforce BIP 16, aka "Pay to script hash".protected int
bip32HeaderP2PKHpriv
protected int
bip32HeaderP2PKHpub
protected int
bip32HeaderP2WPKHpriv
protected int
bip32HeaderP2WPKHpub
protected java.util.Map<java.lang.Integer,Sha256Hash>
checkpoints
protected MessageSerializer
defaultSerializer
protected java.lang.String[]
dnsSeeds
protected int
dumpedPrivateKeyHeader
protected HttpDiscovery.Details[]
httpSeeds
protected java.lang.String
id
See getId().static java.lang.String
ID_MAINNET
The string returned by getId() for the main, production network where people trade things.static java.lang.String
ID_REGTEST
The string returned by getId() for regtest mode.static java.lang.String
ID_TESTNET
The string returned by getId() for the testnet.static java.lang.String
ID_UNITTESTNET
Unit test network.protected int
interval
static int
INTERVAL
protected int
majorityEnforceBlockUpgrade
Used to check majorities for block version upgradeprotected int
majorityRejectBlockOutdated
protected int
majorityWindow
static long
MAX_COINS
The maximum number of coins to be generatedstatic Coin
MAX_MONEY
The maximum money to be generatedprotected java.math.BigInteger
maxTarget
protected int
p2shHeader
protected long
packetMagic
static java.lang.String
PAYMENT_PROTOCOL_ID_MAINNET
The string used by the payment protocol to represent the main net.static java.lang.String
PAYMENT_PROTOCOL_ID_REGTEST
static java.lang.String
PAYMENT_PROTOCOL_ID_TESTNET
The string used by the payment protocol to represent the test net.static java.lang.String
PAYMENT_PROTOCOL_ID_UNIT_TESTS
The string used by the payment protocol to represent unit testing (note that this is non-standard).protected int
port
protected java.lang.String
segwitAddressHrp
protected int
spendableCoinbaseDepth
The depth of blocks required for a coinbase transaction to be spendable.protected int
subsidyDecreaseBlockCount
static int
TARGET_SPACING
static int
TARGET_TIMESPAN
protected int
targetTimespan
-
Constructor Summary
Constructors Modifier Constructor Description protected
NetworkParameters()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description boolean
allowEmptyPeerChain()
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
equals(java.lang.Object o)
static NetworkParameters
fromID(java.lang.String id)
Returns the network parameters for the given string ID or NULL if not recognized.static NetworkParameters
fromPmtProtocolID(java.lang.String pmtProtocolId)
Returns the network parameters for the given string paymentProtocolID or NULL if not recognized.int
getAddressHeader()
First byte of a base58 encoded address.int[]
getAddrSeeds()
Returns IP address of active peers.int
getBip32HeaderP2PKHpriv()
Returns the 4 byte header for BIP32 wallet P2PKH - private key part.int
getBip32HeaderP2PKHpub()
Returns the 4 byte header for BIP32 wallet P2PKH - public key part.int
getBip32HeaderP2WPKHpriv()
Returns the 4 byte header for BIP32 wallet P2WPKH - private key part.int
getBip32HeaderP2WPKHpub()
Returns the 4 byte header for BIP32 wallet P2WPKH - public key part.java.util.EnumSet<Block.VerifyFlag>
getBlockVerificationFlags(Block block, VersionTally tally, java.lang.Integer height)
The flags indicating which block validation tests should be applied to the given block.MessageSerializer
getDefaultSerializer()
Return the default serializer for this network.java.lang.String[]
getDnsSeeds()
Returns DNS names that when resolved, give IP addresses of active peers.int
getDumpedPrivateKeyHeader()
First byte of a base58 encoded dumped private key.abstract Block
getGenesisBlock()
Genesis block for this chain.HttpDiscovery.Details[]
getHttpSeeds()
Returns discovery objects for seeds implementing the Cartographer protocol.java.lang.String
getId()
A Java package style string acting as unique ID for these parametersint
getInterval()
How many blocks pass between difficulty adjustment periods.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.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.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.abstract Coin
getMaxMoney()
Returns the number of coins that will be produced in total, on this network.java.math.BigInteger
getMaxTarget()
Maximum target represents the easiest allowable proof of work.abstract Coin
getMinNonDustOutput()
Deprecated.abstract MonetaryFormat
getMonetaryFormat()
The monetary object for this currency.int
getP2SHHeader()
First byte of a base58 encoded P2SH address.long
getPacketMagic()
The header bytes that identify the start of a packet on this network.abstract java.lang.String
getPaymentProtocolId()
int
getPort()
Default TCP port on which to connect to nodes.abstract int
getProtocolVersionNum(NetworkParameters.ProtocolVersion version)
java.lang.String
getSegwitAddressHrp()
Human readable part of bech32 encoded segwit address.abstract BitcoinSerializer
getSerializer(boolean parseRetain)
Construct and return a custom serializer.int
getSpendableCoinbaseDepth()
int
getSubsidyDecreaseBlockCount()
int
getTargetTimespan()
How much time in seconds is supposed to pass between "interval" blocks.java.util.EnumSet<Script.VerifyFlag>
getTransactionVerificationFlags(Block block, Transaction transaction, VersionTally tally, java.lang.Integer height)
The flags indicating which script validation tests should be applied to the given transaction.abstract java.lang.String
getUriScheme()
Scheme part for URIs, for example "bitcoin".int
hashCode()
abstract boolean
hasMaxMoney()
Returns whether this network has a maximum number of coins (finite supply) or not.boolean
isCheckpoint(int height)
Returns true if the given height has a recorded checkpoint.boolean
passesCheckpoint(int height, Sha256Hash hash)
Returns true if the block height is either not a checkpoint, or is a checkpoint and the hash matches.
-
-
-
Field Detail
-
ID_MAINNET
public static final java.lang.String ID_MAINNET
The string returned by getId() for the main, production network where people trade things.- See Also:
- Constant Field Values
-
ID_TESTNET
public static final java.lang.String ID_TESTNET
The string returned by getId() for the testnet.- See Also:
- Constant Field Values
-
ID_REGTEST
public static final java.lang.String ID_REGTEST
The string returned by getId() for regtest mode.- See Also:
- Constant Field Values
-
ID_UNITTESTNET
public static final java.lang.String ID_UNITTESTNET
Unit test network.- See Also:
- Constant Field Values
-
PAYMENT_PROTOCOL_ID_MAINNET
public static final java.lang.String PAYMENT_PROTOCOL_ID_MAINNET
The string used by the payment protocol to represent the main net.- See Also:
- Constant Field Values
-
PAYMENT_PROTOCOL_ID_TESTNET
public static final java.lang.String PAYMENT_PROTOCOL_ID_TESTNET
The string used by the payment protocol to represent the test net.- See Also:
- Constant Field Values
-
PAYMENT_PROTOCOL_ID_UNIT_TESTS
public static final java.lang.String PAYMENT_PROTOCOL_ID_UNIT_TESTS
The string used by the payment protocol to represent unit testing (note that this is non-standard).- See Also:
- Constant Field Values
-
PAYMENT_PROTOCOL_ID_REGTEST
public static final java.lang.String PAYMENT_PROTOCOL_ID_REGTEST
- See Also:
- Constant Field Values
-
maxTarget
protected java.math.BigInteger maxTarget
-
port
protected int port
-
packetMagic
protected long packetMagic
-
addressHeader
protected int addressHeader
-
p2shHeader
protected int p2shHeader
-
dumpedPrivateKeyHeader
protected int dumpedPrivateKeyHeader
-
segwitAddressHrp
protected java.lang.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 java.lang.String id
See getId(). This may be null for old deserialized wallets. In that case we derive it heuristically by looking at the port number.
-
spendableCoinbaseDepth
protected int spendableCoinbaseDepth
The depth of blocks required for a coinbase transaction to be spendable.
-
subsidyDecreaseBlockCount
protected int subsidyDecreaseBlockCount
-
dnsSeeds
protected java.lang.String[] dnsSeeds
-
addrSeeds
protected int[] addrSeeds
-
httpSeeds
protected HttpDiscovery.Details[] httpSeeds
-
checkpoints
protected java.util.Map<java.lang.Integer,Sha256Hash> checkpoints
-
defaultSerializer
protected transient volatile MessageSerializer defaultSerializer
-
TARGET_TIMESPAN
public static final int TARGET_TIMESPAN
- See Also:
- Constant Field Values
-
TARGET_SPACING
public static final int TARGET_SPACING
- See Also:
- Constant Field Values
-
INTERVAL
public static final int INTERVAL
- See Also:
- Constant Field Values
-
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:
- Constant Field Values
-
MAX_COINS
public static final long MAX_COINS
The maximum number of coins to be generated- See Also:
- Constant Field Values
-
MAX_MONEY
public static final Coin MAX_MONEY
The maximum money to be generated
-
-
Method Detail
-
getId
public java.lang.String getId()
A Java package style string acting as unique ID for these parameters
-
getPaymentProtocolId
public abstract java.lang.String getPaymentProtocolId()
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
fromID
@Nullable public static NetworkParameters fromID(java.lang.String id)
Returns the network parameters for the given string ID or NULL if not recognized.
-
fromPmtProtocolID
@Nullable public static NetworkParameters fromPmtProtocolID(java.lang.String pmtProtocolId)
Returns the network parameters for the given string paymentProtocolID or NULL if not recognized.
-
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.- Throws:
VerificationException
- if the block's difficulty is not correct.BlockStoreException
-
passesCheckpoint
public boolean passesCheckpoint(int height, Sha256Hash hash)
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)
Returns true if the given height has a recorded checkpoint.
-
getSubsidyDecreaseBlockCount
public int getSubsidyDecreaseBlockCount()
-
getDnsSeeds
public java.lang.String[] getDnsSeeds()
Returns DNS names that when resolved, give IP addresses of active peers.
-
getAddrSeeds
public int[] getAddrSeeds()
Returns IP address of active peers.
-
getHttpSeeds
public HttpDiscovery.Details[] getHttpSeeds()
Returns discovery objects for seeds implementing the Cartographer protocol. SeeHttpDiscovery
for more info.
-
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".
-
getPort
public int getPort()
Default TCP port on which to connect to nodes.
-
getPacketMagic
public long getPacketMagic()
The header bytes that identify the start of a packet on this network.
-
getAddressHeader
public int getAddressHeader()
First byte of a base58 encoded address. SeeLegacyAddress
. This is the same as acceptableAddressCodes[0] and is the one used for "normal" addresses. Other types of address may be encountered with version codes found in the acceptableAddressCodes array.
-
getP2SHHeader
public int getP2SHHeader()
First byte of a base58 encoded P2SH address. P2SH addresses are defined as part of BIP0013.
-
getDumpedPrivateKeyHeader
public int getDumpedPrivateKeyHeader()
First byte of a base58 encoded dumped private key. SeeDumpedPrivateKey
.
-
getSegwitAddressHrp
public java.lang.String getSegwitAddressHrp()
Human readable part of bech32 encoded segwit address.
-
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).
-
allowEmptyPeerChain
public boolean allowEmptyPeerChain()
If we are running in testnet-in-a-box mode, we allow connections to nodes with 0 non-genesis blocks.
-
getInterval
public int getInterval()
How many blocks pass between difficulty adjustment periods. Bitcoin standardises this to be 2016.
-
getMaxTarget
public java.math.BigInteger getMaxTarget()
Maximum target represents the easiest allowable proof of work.
-
getBip32HeaderP2PKHpub
public int getBip32HeaderP2PKHpub()
Returns the 4 byte header for BIP32 wallet P2PKH - public key part.
-
getBip32HeaderP2PKHpriv
public int getBip32HeaderP2PKHpriv()
Returns the 4 byte header for BIP32 wallet P2PKH - private key part.
-
getBip32HeaderP2WPKHpub
public int getBip32HeaderP2WPKHpub()
Returns the 4 byte header for BIP32 wallet P2WPKH - public key part.
-
getBip32HeaderP2WPKHpriv
public int getBip32HeaderP2WPKHpriv()
Returns the 4 byte header for BIP32 wallet P2WPKH - private key part.
-
getMaxMoney
public abstract Coin getMaxMoney()
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 (i.e. the main coin issue for Dogecoin).
-
getMinNonDustOutput
@Deprecated public abstract Coin getMinNonDustOutput()
Deprecated.
-
getMonetaryFormat
public abstract MonetaryFormat getMonetaryFormat()
The monetary object for this currency.
-
getUriScheme
public abstract java.lang.String getUriScheme()
Scheme part for URIs, for example "bitcoin".
-
hasMaxMoney
public abstract boolean hasMaxMoney()
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.
-
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(boolean parseRetain)
Construct and return a custom 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.
-
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).
-
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.
-
getBlockVerificationFlags
public java.util.EnumSet<Block.VerifyFlag> getBlockVerificationFlags(Block block, VersionTally tally, java.lang.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.
-
getTransactionVerificationFlags
public java.util.EnumSet<Script.VerifyFlag> getTransactionVerificationFlags(Block block, Transaction transaction, VersionTally tally, java.lang.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.height
- height of the block, if known, null otherwise. Returned tests should be a safe subset if block height is unknown.
-
getProtocolVersionNum
public abstract int getProtocolVersionNum(NetworkParameters.ProtocolVersion version)
-
-