diff --git a/core/src/main/java/com/google/bitcoin/core/AbstractBlockChain.java b/core/src/main/java/com/google/bitcoin/core/AbstractBlockChain.java index 7bd9ce0f..02ff3761 100644 --- a/core/src/main/java/com/google/bitcoin/core/AbstractBlockChain.java +++ b/core/src/main/java/com/google/bitcoin/core/AbstractBlockChain.java @@ -753,14 +753,15 @@ public abstract class AbstractBlockChain { Block blockIntervalAgo = cursor.getHeader(); int timespan = (int) (prev.getTimeSeconds() - blockIntervalAgo.getTimeSeconds()); // Limit the adjustment step. - if (timespan < params.targetTimespan / 4) - timespan = params.targetTimespan / 4; - if (timespan > params.targetTimespan * 4) - timespan = params.targetTimespan * 4; + final int targetTimespan = params.getTargetTimespan(); + if (timespan < targetTimespan / 4) + timespan = targetTimespan / 4; + if (timespan > targetTimespan * 4) + timespan = targetTimespan * 4; BigInteger newDifficulty = Utils.decodeCompactBits(prev.getDifficultyTarget()); newDifficulty = newDifficulty.multiply(BigInteger.valueOf(timespan)); - newDifficulty = newDifficulty.divide(BigInteger.valueOf(params.targetTimespan)); + newDifficulty = newDifficulty.divide(BigInteger.valueOf(targetTimespan)); if (newDifficulty.compareTo(params.proofOfWorkLimit) > 0) { log.info("Difficulty hit proof of work limit: {}", newDifficulty.toString(16)); diff --git a/core/src/main/java/com/google/bitcoin/core/Address.java b/core/src/main/java/com/google/bitcoin/core/Address.java index 8b90bdea..932ffd31 100644 --- a/core/src/main/java/com/google/bitcoin/core/Address.java +++ b/core/src/main/java/com/google/bitcoin/core/Address.java @@ -39,7 +39,7 @@ public class Address extends VersionedChecksummedBytes { *
new Address(NetworkParameters.prodNet(), Hex.decode("4a22c3c4cbb31e4d03b15550636762bda0baf85a"));*/ public Address(NetworkParameters params, byte[] hash160) { - super(params.addressHeader, hash160); + super(params.getAddressHeader(), hash160); if (hash160.length != 20) // 160 = 8 * 20 throw new RuntimeException("Addresses are 160-bit hashes, so you must provide 20 bytes"); } @@ -58,14 +58,14 @@ public class Address extends VersionedChecksummedBytes { super(address); if (params != null) { boolean found = false; - for (int v : params.acceptableAddressCodes) { + for (int v : params.getAcceptableAddressCodes()) { if (version == v) { found = true; break; } } if (!found) { - throw new WrongNetworkException(version, params.acceptableAddressCodes); + throw new WrongNetworkException(version, params.getAcceptableAddressCodes()); } } } @@ -89,7 +89,7 @@ public class Address extends VersionedChecksummedBytes { new NetworkParameters[] { NetworkParameters.testNet(), NetworkParameters.prodNet() }; for (NetworkParameters params : networks) { - for (int code : params.acceptableAddressCodes) { + for (int code : params.getAcceptableAddressCodes()) { if (code == version) { return params; } diff --git a/core/src/main/java/com/google/bitcoin/core/DumpedPrivateKey.java b/core/src/main/java/com/google/bitcoin/core/DumpedPrivateKey.java index e3bf1bfa..e76e64ca 100644 --- a/core/src/main/java/com/google/bitcoin/core/DumpedPrivateKey.java +++ b/core/src/main/java/com/google/bitcoin/core/DumpedPrivateKey.java @@ -32,7 +32,7 @@ public class DumpedPrivateKey extends VersionedChecksummedBytes { // Used by ECKey.getPrivateKeyEncoded() DumpedPrivateKey(NetworkParameters params, byte[] keyBytes, boolean compressed) { - super(params.dumpedPrivateKeyHeader, encode(keyBytes, compressed)); + super(params.getDumpedPrivateKeyHeader(), encode(keyBytes, compressed)); this.compressed = compressed; } @@ -58,9 +58,9 @@ public class DumpedPrivateKey extends VersionedChecksummedBytes { */ public DumpedPrivateKey(NetworkParameters params, String encoded) throws AddressFormatException { super(encoded); - if (params != null && version != params.dumpedPrivateKeyHeader) + if (params != null && version != params.getDumpedPrivateKeyHeader()) throw new AddressFormatException("Mismatched version number, trying to cross networks? " + version + - " vs " + params.dumpedPrivateKeyHeader); + " vs " + params.getDumpedPrivateKeyHeader()); if (bytes.length == 33) { compressed = true; bytes = Arrays.copyOf(bytes, 32); // Chop off the additional marker byte. diff --git a/core/src/main/java/com/google/bitcoin/core/NetworkParameters.java b/core/src/main/java/com/google/bitcoin/core/NetworkParameters.java index e1020db1..456f02e3 100644 --- a/core/src/main/java/com/google/bitcoin/core/NetworkParameters.java +++ b/core/src/main/java/com/google/bitcoin/core/NetworkParameters.java @@ -63,22 +63,11 @@ public class NetworkParameters implements Serializable { public /*final*/ BigInteger proofOfWorkLimit; private final int port; private final long packetMagic; - /** - * First byte of a base58 encoded address. See {@link 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. - */ - public final int addressHeader; - /** First byte of a base58 encoded dumped private key. See {@link DumpedPrivateKey}. */ - public final int dumpedPrivateKeyHeader; + private final int addressHeader; + private final int dumpedPrivateKeyHeader; /** How many blocks pass between difficulty adjustment periods. Bitcoin standardises this to be 2015. */ public /*final*/ int interval; - /** - * 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). - */ - public final int targetTimespan; + private final int targetTimespan; /** * The key used to sign {@link AlertMessage}s. You can use {@link ECKey#verify(byte[], byte[], byte[])} to verify * signatures using it. @@ -95,36 +84,15 @@ public class NetworkParameters implements Serializable { * The depth of blocks required for a coinbase transaction to be spendable. */ private final int spendableCoinbaseDepth; - - /** - * Returns the number of blocks between subsidy decreases - */ private /*final*/ int subsidyDecreaseBlockCount; /** * If we are running in testnet-in-a-box mode, we allow connections to nodes with 0 non-genesis blocks */ boolean allowEmptyPeerChains; - - /** - * 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. - */ - public final int[] acceptableAddressCodes; - - /** - * DNS names that when resolved, give active peers on the network. Used to bootstrap the P2P connectivity. - */ + private final int[] acceptableAddressCodes; private final String[] dnsSeeds; - - - /** - * Block checkpoints are a safety mechanism that hard-codes the hashes of blocks at particular heights. Re-orgs - * beyond this point will never be accepted. This field should be accessed using - * {@link NetworkParameters#passesCheckpoint(int, Sha256Hash)} and {@link NetworkParameters#isCheckpoint(int)}. - */ - public Map