Class NetworkParameters
- java.lang.Object
-
- org.bitcoinj.core.NetworkParameters
-
- Direct Known Subclasses:
BitcoinNetworkParams
,MockAltNetworkParams
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 java.lang.String
id
See getId()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
Deprecated.static Coin
MAX_MONEY
Deprecated.protected java.math.BigInteger
maxTarget
protected Network
network
protected int
p2shHeader
protected long
packetMagic
static java.lang.String
PAYMENT_PROTOCOL_ID_MAINNET
Deprecated.static java.lang.String
PAYMENT_PROTOCOL_ID_REGTEST
Deprecated.static java.lang.String
PAYMENT_PROTOCOL_ID_SIGNET
Deprecated.static java.lang.String
PAYMENT_PROTOCOL_ID_TESTNET
Deprecated.static java.lang.String
PAYMENT_PROTOCOL_ID_UNIT_TESTS
Deprecated.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(Network network)
-
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
fromAddress(Address address)
Deprecated.You should be usingAddress.network()
insteadstatic NetworkParameters
fromID(java.lang.String id)
Deprecated.static NetworkParameters
fromPmtProtocolID(java.lang.String pmtProtocolId)
Deprecated.UsePaymentProtocol.paramsFromPmtProtocolID(String)
(String)}int
getAddressHeader()
Deprecated.int[]
getAddrSeeds()
Return IP addresses of active peersint
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()
Return DNS names that when resolved, give IP addresses of active peersint
getDumpedPrivateKeyHeader()
First byte of a base58 encoded dumped private key.abstract Block
getGenesisBlock()
Genesis block for this chain.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()
Deprecated.java.math.BigInteger
getMaxTarget()
Maximum target represents the easiest allowable proof of work.abstract MonetaryFormat
getMonetaryFormat()
Deprecated.Get one another way or construct your ownMonetaryFormat
as needed.int
getP2SHHeader()
Deprecated.long
getPacketMagic()
The header bytes that identify the start of a packet on this network.abstract java.lang.String
getPaymentProtocolId()
Deprecated.int
getPort()
Default TCP port on which to connect to nodesabstract int
getProtocolVersionNum(NetworkParameters.ProtocolVersion version)
java.lang.String
getSegwitAddressHrp()
Deprecated.abstract BitcoinSerializer
getSerializer()
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()
Deprecated.int
hashCode()
abstract boolean
hasMaxMoney()
Deprecated.boolean
isCheckpoint(int height)
Is height a checkpointNetwork
network()
static NetworkParameters
of(Network network)
Return network parameters for aNetwork
.boolean
passesCheckpoint(int height, Sha256Hash hash)
Validate the hash for a given block height against checkpoints
-
-
-
Field Detail
-
PAYMENT_PROTOCOL_ID_MAINNET
@Deprecated public static final java.lang.String PAYMENT_PROTOCOL_ID_MAINNET
Deprecated.The string used by the payment protocol to represent the main net.- See Also:
- Constant Field Values
-
PAYMENT_PROTOCOL_ID_TESTNET
@Deprecated public static final java.lang.String PAYMENT_PROTOCOL_ID_TESTNET
Deprecated.The string used by the payment protocol to represent the test net.- See Also:
- Constant Field Values
-
PAYMENT_PROTOCOL_ID_SIGNET
@Deprecated public static final java.lang.String PAYMENT_PROTOCOL_ID_SIGNET
Deprecated.The string used by the payment protocol to represent signet (note that this is non-standard).- See Also:
- Constant Field Values
-
PAYMENT_PROTOCOL_ID_UNIT_TESTS
@Deprecated public static final java.lang.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:
- Constant Field Values
-
PAYMENT_PROTOCOL_ID_REGTEST
@Deprecated public static final java.lang.String PAYMENT_PROTOCOL_ID_REGTEST
Deprecated.- 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 final java.lang.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 java.lang.String[] dnsSeeds
-
addrSeeds
protected int[] addrSeeds
-
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
@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 Detail
-
NetworkParameters
protected NetworkParameters(Network network)
-
-
Method Detail
-
getId
public java.lang.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 java.lang.String getPaymentProtocolId()
Deprecated.- Returns:
- the payment protocol network id string
-
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
@Deprecated @Nullable public static NetworkParameters fromID(java.lang.String id)
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
public static NetworkParameters of(Network network)
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:
java.lang.IllegalArgumentException
- if unknown network
-
fromPmtProtocolID
@Nullable @Deprecated public static NetworkParameters fromPmtProtocolID(java.lang.String pmtProtocolId)
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 public static NetworkParameters fromAddress(Address address)
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
public boolean passesCheckpoint(int height, Sha256Hash hash)
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
public java.lang.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 long 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. SeeLegacyAddress
.- 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. SeeDumpedPrivateKey
.- Returns:
- the header value
-
getSegwitAddressHrp
@Deprecated public java.lang.String 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
public java.math.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 ownMonetaryFormat
as needed.The monetary object for this currency.- Returns:
- formatting utility object
-
getUriScheme
@Deprecated public abstract java.lang.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 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 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.tally
- caching tally counter- Returns:
- the flags
-
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.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
public abstract int getProtocolVersionNum(NetworkParameters.ProtocolVersion version)
-
-