com.google.bitcoin.core
Class NetworkParameters

java.lang.Object
  extended by com.google.bitcoin.core.NetworkParameters
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
MainNetParams, TestNet2Params, TestNet3Params, UnitTestParams

public abstract class NetworkParameters
extends Object
implements Serializable

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.

See Also:
Serialized Form

Field Summary
protected  int[] acceptableAddressCodes
           
protected  int addressHeader
           
protected  byte[] alertSigningKey
           
static int BIP16_ENFORCE_TIME
          Blocks with a timestamp after this should enforce BIP 16, aka "Pay to script hash".
protected  Map<Integer,Sha256Hash> checkpoints
           
protected  String[] dnsSeeds
           
protected  int dumpedPrivateKeyHeader
           
protected  Block genesisBlock
           
protected  String id
          See getId().
static String ID_MAINNET
          The string returned by getId() for the main, production network where people trade things.
static String ID_TESTNET
          The string returned by getId() for the testnet.
static String ID_UNITTESTNET
          Unit test network.
protected  int interval
           
static int INTERVAL
           
static BigInteger MAX_MONEY
          The maximum money to be generated
protected  int p2shHeader
           
protected  long packetMagic
           
static String PAYMENT_PROTOCOL_ID_MAINNET
          The string used by the payment protocol to represent the main net.
static String PAYMENT_PROTOCOL_ID_TESTNET
          The string used by the payment protocol to represent the test net.
protected  int port
           
protected  BigInteger proofOfWorkLimit
           
static int PROTOCOL_VERSION
          The protocol version this library implements.
static byte[] SATOSHI_KEY
          The alert signing key originally owned by Satoshi, and now passed on to Gavin along with a few others.
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
protected NetworkParameters()
           
 
Method Summary
 boolean allowEmptyPeerChain()
          If we are running in testnet-in-a-box mode, we allow connections to nodes with 0 non-genesis blocks.
 boolean equals(Object other)
           
static NetworkParameters fromID(String id)
          Returns the network parameters for the given string ID or NULL if not recognized.
static NetworkParameters fromPmtProtocolID(String pmtProtocolId)
          Returns the network parameters for the given string paymentProtocolID or NULL if not recognized.
 int[] getAcceptableAddressCodes()
          The version codes that prefix addresses which are acceptable on this network.
 int getAddressHeader()
          First byte of a base58 encoded address.
 byte[] getAlertSigningKey()
          The key used to sign AlertMessages.
 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.
 Block getGenesisBlock()
          Genesis block for this chain.
 String getId()
          A Java package style string acting as unique ID for these parameters
 int getInterval()
          How many blocks pass between difficulty adjustment periods.
 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  String getPaymentProtocolId()
           
 int getPort()
          Default TCP port on which to connect to nodes.
 BigInteger getProofOfWorkLimit()
          What the easiest allowable proof of work should be.
 int getSpendableCoinbaseDepth()
           
 int getSubsidyDecreaseBlockCount()
           
 int getTargetTimespan()
          How much time in seconds is supposed to pass between "interval" blocks.
 int hashCode()
           
 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.
static NetworkParameters prodNet()
          Deprecated. 
static NetworkParameters regTests()
          Deprecated. 
static NetworkParameters testNet()
          Deprecated. 
static NetworkParameters testNet2()
          Deprecated. 
static NetworkParameters testNet3()
          Deprecated. 
static NetworkParameters unitTests()
          Deprecated. 
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROTOCOL_VERSION

public static final int PROTOCOL_VERSION
The protocol version this library implements.

See Also:
Constant Field Values

SATOSHI_KEY

public static final byte[] SATOSHI_KEY
The alert signing key originally owned by Satoshi, and now passed on to Gavin along with a few others.


ID_MAINNET

public static final 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 String ID_TESTNET
The string returned by getId() for the testnet.

See Also:
Constant Field Values

ID_UNITTESTNET

public static final String ID_UNITTESTNET
Unit test network.

See Also:
Constant Field Values

PAYMENT_PROTOCOL_ID_MAINNET

public static final 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 String PAYMENT_PROTOCOL_ID_TESTNET
The string used by the payment protocol to represent the test net.

See Also:
Constant Field Values

genesisBlock

protected Block genesisBlock

proofOfWorkLimit

protected BigInteger proofOfWorkLimit

port

protected int port

packetMagic

protected long packetMagic

addressHeader

protected int addressHeader

p2shHeader

protected int p2shHeader

dumpedPrivateKeyHeader

protected int dumpedPrivateKeyHeader

interval

protected int interval

targetTimespan

protected int targetTimespan

alertSigningKey

protected byte[] alertSigningKey

id

protected 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

acceptableAddressCodes

protected int[] acceptableAddressCodes

dnsSeeds

protected String[] dnsSeeds

checkpoints

protected Map<Integer,Sha256Hash> checkpoints

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_MONEY

public static final BigInteger MAX_MONEY
The maximum money to be generated

Constructor Detail

NetworkParameters

protected NetworkParameters()
Method Detail

testNet

@Deprecated
public static NetworkParameters testNet()
Deprecated. 

Alias for TestNet3Params.get(), use that instead.


testNet2

@Deprecated
public static NetworkParameters testNet2()
Deprecated. 

Alias for TestNet2Params.get(), use that instead.


testNet3

@Deprecated
public static NetworkParameters testNet3()
Deprecated. 

Alias for TestNet3Params.get(), use that instead.


prodNet

@Deprecated
public static NetworkParameters prodNet()
Deprecated. 

Alias for MainNetParams.get(), use that instead


unitTests

@Deprecated
public static NetworkParameters unitTests()
Deprecated. 

Returns a testnet params modified to allow any difficulty target.


regTests

@Deprecated
public static NetworkParameters regTests()
Deprecated. 

Returns a standard regression test params (similar to unitTests)


getId

public String getId()
A Java package style string acting as unique ID for these parameters


getPaymentProtocolId

public abstract String getPaymentProtocolId()

equals

public boolean equals(Object other)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

fromID

@Nullable
public static NetworkParameters fromID(String id)
Returns the network parameters for the given string ID or NULL if not recognized.


fromPmtProtocolID

@Nullable
public static NetworkParameters fromPmtProtocolID(String pmtProtocolId)
Returns the network parameters for the given string paymentProtocolID or NULL if not recognized.


getSpendableCoinbaseDepth

public int getSpendableCoinbaseDepth()

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 String[] getDnsSeeds()
Returns DNS names that when resolved, give IP addresses of active peers.


getGenesisBlock

public Block getGenesisBlock()

Genesis block for this chain.

The first block in every chain is a well known constant shared between all Bitcoin implemenetations. 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 prod 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. See Address. 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. See DumpedPrivateKey.


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 production Bitcoin networks use 2 weeks (1209600 seconds).


getAcceptableAddressCodes

public int[] getAcceptableAddressCodes()
The version codes that prefix addresses which are acceptable on this network. Although Satoshi intended these to be used for "versioning", in fact they are today used to discriminate what kind of data is contained in the address and to prevent accidentally sending coins across chains which would destroy them.


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 2015.


getProofOfWorkLimit

public BigInteger getProofOfWorkLimit()
What the easiest allowable proof of work should be.


getAlertSigningKey

public byte[] getAlertSigningKey()
The key used to sign AlertMessages. You can use ECKey.verify(byte[], byte[], byte[]) to verify signatures using it.



Copyright © 2014. All rights reserved.