Skip to content

Commit

Permalink
Updating to bitcoinj 0.12; few fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
HashEngineering committed Feb 7, 2014
2 parents 191078d + 417c81f commit e56dc42
Show file tree
Hide file tree
Showing 77 changed files with 9,177 additions and 502 deletions.
2 changes: 2 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ Eric William Dickerson <[email protected]>
Ken Sedgwick <[email protected]>
Mike Rosseel <[email protected]>
Mike Belshe <[email protected]>
Kevin Greene <[email protected]>
Alex Taylor <[email protected]>
56 changes: 40 additions & 16 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,34 @@
<parent>
<groupId>com.google</groupId>
<artifactId>digitalcoinj-parent</artifactId>
<version>0.11</version>
<version>0.12-SNAPSHOT</version>
</parent>

<artifactId>digitalcoinj</artifactId>

<name>digitalcoinj</name>
<description>A Java digitalcoin library</description>

<packaging>jar</packaging>

<url>https://code.google.com/p/bitcoinj</url>

<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
</license>
</licenses>

<!-- Dummy block to make Maven Central happy: authors list is in AUTHORS -->
<developers>
<developer>
<name>The bitcoinj team</name>
<email>[email protected]</email>
</developer>
</developers>

<profiles>
<profile>
<id>update-protobuf</id>
Expand Down Expand Up @@ -132,12 +152,11 @@
<urns>
<urn>com.google.code.findbugs:jsr305:1.3.9:jar:null:compile:40719ea6961c0cb6afaeb6a921eaa1f6afd4cfdf</urn>
<urn>com.google.guava:guava:13.0.1:jar:null:compile:0d6f22b1e60a2f1ef99e22c9f5fde270b2088365</urn>
<urn>com.google.protobuf:protobuf-java:2.4.1:jar:null:compile:0c589509ec6fd86d5d2fda37e07c08538235d3b9</urn>
<urn>com.google.protobuf:protobuf-java:2.5.0:jar:null:compile:a10732c76bfacdbd633a7eb0f7968b1059a65dfa</urn>
<urn>com.h2database:h2:1.3.167:jar:null:compile:d3867d586f087e53eb12fc65e5693d8ee9a5da17</urn>
<urn>com.lambdaworks:scrypt:1.3.3:jar:null:compile:06d6813de41e177189e1722717979b4fb5454b1d</urn>
<urn>com.madgag:sc-light-jdk15on:1.47.0.2:jar:null:compile:d5c98671cc97fa0d928be1c7eb5edd3fb95d3234</urn>
<urn>net.jcip:jcip-annotations:1.0:jar:null:compile:afba4942caaeaf46aab0b976afd57cc7c181467e</urn>
<urn>net.sf.jopt-simple:jopt-simple:4.3:jar:null:compile:88ffca34311a6564a98f14820431e17b4382a069</urn>
<urn>org.slf4j:slf4j-api:1.7.5:jar:null:compile:6b262da268f8ad9eff941b25503a9198f0a0ac93</urn>
<urn>org.slf4j:slf4j-jdk14:1.7.5:jar:null:runtime:33cf4abac351aa45dd130d31a1e7e33fbbba4762</urn>
<!-- A check for the rules themselves -->
Expand Down Expand Up @@ -166,64 +185,69 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>3.0</version>
<scope>test</scope>
</dependency>
<!-- digitalcoinj consumers are expected to provide their own SLF4J adapters
such as logback, slf4j-log4j12, slf4j-jcl and so on
see http://www.slf4j.org/faq.html -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
<version>1.7.5</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.3.167</version>
<optional>true</optional>
</dependency>

<dependency>
<groupId>com.madgag</groupId>
<artifactId>sc-light-jdk15on</artifactId>
<version>1.47.0.2</version>
</dependency>

<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>2.5.0</version>
</dependency>

<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>13.0.1</version>
</dependency>

<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<version>1.3.9</version>
</dependency>

<dependency>
<groupId>net.jcip</groupId>
<artifactId>jcip-annotations</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>com.lambdaworks</groupId>
<artifactId>scrypt</artifactId>
<version>1.3.3</version>
</dependency>

<!-- Add in to test/use Postgres blockstore -->
<!--
<dependency>
<groupId>com.lambdaworks</groupId>
<artifactId>scrypt</artifactId>
<version>1.3.3</version>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.1-901.jdbc4</version>
</dependency>
-->
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,18 @@ public abstract class AbstractBlockChain {
private final CopyOnWriteArrayList<ListenerRegistration<BlockChainListener>> listeners;

// Holds a block header and, optionally, a list of tx hashes or block's transactions
static class OrphanBlock {
class OrphanBlock {
final Block block;
final List<Sha256Hash> filteredTxHashes;
final Map<Sha256Hash, Transaction> filteredTxn;
OrphanBlock(Block block, @Nullable List<Sha256Hash> filteredTxHashes, @Nullable Map<Sha256Hash, Transaction> filteredTxn) {
final boolean filtered = filteredTxHashes != null && filteredTxn != null;
Preconditions.checkArgument((block.transactions == null && filtered)
|| (block.transactions != null && !filtered));
this.block = block;
if (!shouldVerifyTransactions())
this.block = block.cloneAsHeader();
else
this.block = block;
this.filteredTxHashes = filteredTxHashes;
this.filteredTxn = filteredTxn;
}
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/com/google/bitcoin/core/Address.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public Address(NetworkParameters params, int version, byte[] hash160) throws Wro
}

/** Returns an Address that represents the given P2SH script hash. */
public static Address fromP2SHScript(NetworkParameters params, byte[] hash160) {
public static Address fromP2SHHash(NetworkParameters params, byte[] hash160) {
try {
return new Address(params, params.getP2SHHeader(), hash160);
} catch (WrongNetworkException e) {
Expand All @@ -67,7 +67,7 @@ public static Address fromP2SHScript(NetworkParameters params, byte[] hash160) {
/** Returns an Address that represents the script hash extracted from the given scriptPubKey */
public static Address fromP2SHScript(NetworkParameters params, Script scriptPubKey) {
checkArgument(scriptPubKey.isPayToScriptHash(), "Not a P2SH script");
return fromP2SHScript(params, scriptPubKey.getPubKeyHash());
return fromP2SHHash(params, scriptPubKey.getPubKeyHash());
}

/**
Expand Down
10 changes: 5 additions & 5 deletions core/src/main/java/com/google/bitcoin/core/Block.java
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ private boolean checkProofOfWork(boolean throwException) throws VerificationExce
private void checkTimestamp() throws VerificationException {
maybeParseHeader();
// Allow injection of a fake clock to allow unit testing.
long currentTime = Utils.now().getTime()/1000;
long currentTime = Utils.currentTimeMillis()/1000;
if (time > currentTime + ALLOWED_TIME_DRIFT)
throw new VerificationException("Block too far in future");
}
Expand Down Expand Up @@ -1057,12 +1057,12 @@ Block createNextBlock(@Nullable Address to, @Nullable TransactionOutPoint prevOu

@VisibleForTesting
public Block createNextBlock(@Nullable Address to, TransactionOutPoint prevOut) {
return createNextBlock(to, prevOut, Utils.now().getTime() / 1000, EMPTY_BYTES, Utils.toNanoCoins(50, 0));
return createNextBlock(to, prevOut, Utils.currentTimeMillis() / 1000, EMPTY_BYTES, Utils.toNanoCoins(50, 0));
}

@VisibleForTesting
public Block createNextBlock(@Nullable Address to, BigInteger value) {
return createNextBlock(to, null, Utils.now().getTime() / 1000, EMPTY_BYTES, value);
return createNextBlock(to, null, Utils.currentTimeMillis() / 1000, EMPTY_BYTES, value);
}

@VisibleForTesting
Expand All @@ -1072,7 +1072,7 @@ public Block createNextBlock(@Nullable Address to) {

@VisibleForTesting
public Block createNextBlockWithCoinbase(byte[] pubKey, BigInteger coinbaseValue) {
return createNextBlock(null, null, Utils.now().getTime() / 1000, pubKey, coinbaseValue);
return createNextBlock(null, null, Utils.currentTimeMillis() / 1000, pubKey, coinbaseValue);
}

/**
Expand All @@ -1081,7 +1081,7 @@ public Block createNextBlockWithCoinbase(byte[] pubKey, BigInteger coinbaseValue
*/
@VisibleForTesting
Block createNextBlockWithCoinbase(byte[] pubKey) {
return createNextBlock(null, null, Utils.now().getTime() / 1000, pubKey, Utils.toNanoCoins(50, 0));
return createNextBlock(null, null, Utils.currentTimeMillis() / 1000, pubKey, Utils.toNanoCoins(50, 0));
}

@VisibleForTesting
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/com/google/bitcoin/core/ECKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public ECKey() {
ECPoint compressed = compressPoint(uncompressed);
pub = compressed.getEncoded();

creationTimeSeconds = Utils.now().getTime() / 1000;
creationTimeSeconds = Utils.currentTimeMillis() / 1000;
}

private static ECPoint compressPoint(ECPoint uncompressed) {
Expand Down
19 changes: 19 additions & 0 deletions core/src/main/java/com/google/bitcoin/core/NetworkParameters.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ public abstract class NetworkParameters implements Serializable {
/** Unit test network. */
public static final String ID_UNITTESTNET = CoinDefinition.ID_UNITTESTNET; //"com.google.bitcoin.unittest";

/** The string used by the payment protocol to represent the main net. */
public static final String PAYMENT_PROTOCOL_ID_MAINNET = "main";
/** The string used by the payment protocol to represent the test net. */
public static final String PAYMENT_PROTOCOL_ID_TESTNET = "test";

// TODO: Seed nodes should be here as well.

protected Block genesisBlock;
Expand Down Expand Up @@ -197,6 +202,8 @@ public String getId() {
return id;
}

public abstract String getPaymentProtocolId();

@Override
public boolean equals(Object other) {
if (!(other instanceof NetworkParameters)) return false;
Expand All @@ -223,6 +230,18 @@ public static NetworkParameters fromID(String id) {
}
}

/** Returns the network parameters for the given string paymentProtocolID or NULL if not recognized. */
@Nullable
public static NetworkParameters fromPmtProtocolID(String pmtProtocolId) {
if (pmtProtocolId.equals(PAYMENT_PROTOCOL_ID_MAINNET)) {
return MainNetParams.get();
} else if (pmtProtocolId.equals(PAYMENT_PROTOCOL_ID_TESTNET)) {
return TestNet3Params.get();
} else {
return null;
}
}

public int getSpendableCoinbaseDepth() {
return spendableCoinbaseDepth;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
* as an inventory message and lists the hashes of the missing items.
*/
public class NotFoundMessage extends InventoryMessage {
public static int MIN_PROTOCOL_VERSION = 70001;

public NotFoundMessage(NetworkParameters params) {
super(params);
}
Expand All @@ -32,8 +34,8 @@ public NotFoundMessage(NetworkParameters params, byte[] payloadBytes) throws Pro
super(params, payloadBytes);
}

public NotFoundMessage(NetworkParameters unitTestParams, List<InventoryItem> items) {
super(unitTestParams);
public NotFoundMessage(NetworkParameters params, List<InventoryItem> items) {
super(params);
this.items = new ArrayList<InventoryItem>(items);
}
}
7 changes: 3 additions & 4 deletions core/src/main/java/com/google/bitcoin/core/Peer.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import org.slf4j.LoggerFactory;

import javax.annotation.Nullable;
import java.net.InetSocketAddress;
import java.util.*;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CopyOnWriteArraySet;
Expand Down Expand Up @@ -1268,12 +1267,12 @@ private class PendingPing {
public PendingPing(long nonce) {
future = SettableFuture.create();
this.nonce = nonce;
startTimeMsec = Utils.now().getTime();
startTimeMsec = Utils.currentTimeMillis();
}

public void complete() {
checkNotNull(future, "Already completed");
Long elapsed = Utils.now().getTime() - startTimeMsec;
Long elapsed = Utils.currentTimeMillis() - startTimeMsec;
Peer.this.addPingTimeData(elapsed);
log.debug("{}: ping time is {} msec", Peer.this.toString(), elapsed);
future.set(elapsed);
Expand Down Expand Up @@ -1382,7 +1381,7 @@ public int getPeerBlockHeightDifference() {
}

private boolean isNotFoundMessageSupported() {
return vPeerVersionMessage.clientVersion >= 70001;
return vPeerVersionMessage.clientVersion >= NotFoundMessage.MIN_PROTOCOL_VERSION;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ protected void bitcoinSerializeToStream(OutputStream stream) throws IOException
//TODO this appears to be dynamic because the client only ever sends out it's own address
//so assumes itself to be up. For a fuller implementation this needs to be dynamic only if
//the address refers to this client.
int secs = (int) (Utils.now().getTime() / 1000);
int secs = (int) (Utils.currentTimeMillis() / 1000);
uint32ToByteStreamLE(secs, stream);
}
uint64ToByteStreamLE(services, stream); // nServices.
Expand Down
Loading

0 comments on commit e56dc42

Please sign in to comment.