Unverified Commit bbd03e03 authored by TDevD's avatar TDevD Committed by GitHub
Browse files

Merge pull request #6 from Samourai-Wallet/develop

build 004
parents 33852ab5 2058bafb
[![](https://jitpack.io/v/Samourai-Wallet/bitcoinj.svg)](https://jitpack.io/#Samourai-Wallet/bitcoinj)
[![Build Status](https://travis-ci.org/bitcoinj/bitcoinj.png?branch=master)](https://travis-ci.org/bitcoinj/bitcoinj) [![Coverage Status](https://coveralls.io/repos/bitcoinj/bitcoinj/badge.png?branch=master)](https://coveralls.io/r/bitcoinj/bitcoinj?branch=master) [![Build Status](https://travis-ci.org/bitcoinj/bitcoinj.png?branch=master)](https://travis-ci.org/bitcoinj/bitcoinj) [![Coverage Status](https://coveralls.io/repos/bitcoinj/bitcoinj/badge.png?branch=master)](https://coveralls.io/r/bitcoinj/bitcoinj?branch=master)
[![Visit our IRC channel](https://kiwiirc.com/buttons/irc.freenode.net/bitcoinj.png)](https://kiwiirc.com/client/irc.freenode.net/bitcoinj) [![Visit our IRC channel](https://kiwiirc.com/buttons/irc.freenode.net/bitcoinj.png)](https://kiwiirc.com/client/irc.freenode.net/bitcoinj)
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
<parent> <parent>
<groupId>org.bitcoinj</groupId> <groupId>org.bitcoinj</groupId>
<artifactId>bitcoinj-parent</artifactId> <artifactId>bitcoinj-parent</artifactId>
<version>0.15-Segwit-Samourai-001</version> <version>0.15-Segwit-Samourai-004</version>
</parent> </parent>
<artifactId>bitcoinj-core</artifactId> <artifactId>bitcoinj-core</artifactId>
...@@ -183,15 +183,17 @@ ...@@ -183,15 +183,17 @@
<!-- classifier is "null" if not present --> <!-- classifier is "null" if not present -->
<urns> <urns>
<urn>cglib:cglib-nodep:2.2:jar:null:test:59afed7ab65e7ec6585d5bc60556c3cbd203532b</urn> <urn>cglib:cglib-nodep:2.2:jar:null:test:59afed7ab65e7ec6585d5bc60556c3cbd203532b</urn>
<!--
<urn>com.fasterxml.jackson.core:jackson-annotations:2.5.0:jar:null:test:a2a55a3375bc1cef830ca426d68d2ea22961190e</urn> <urn>com.fasterxml.jackson.core:jackson-annotations:2.5.0:jar:null:test:a2a55a3375bc1cef830ca426d68d2ea22961190e</urn>
<urn>com.fasterxml.jackson.core:jackson-core:2.5.1:jar:null:test:e2a00ad1d7e540ec395e9296a34da484c8888d4d</urn> <urn>com.fasterxml.jackson.core:jackson-core:2.5.1:jar:null:test:e2a00ad1d7e540ec395e9296a34da484c8888d4d</urn>
<urn>com.fasterxml.jackson.core:jackson-databind:2.5.2:jar:null:test:2b4dd13fbe6f8c6b146d4c3b7fd70862f136802d</urn> <urn>com.fasterxml.jackson.core:jackson-databind:2.5.2:jar:null:test:2b4dd13fbe6f8c6b146d4c3b7fd70862f136802d</urn>
-->
<urn>com.google.code.findbugs:jsr305:2.0.1:jar:null:compile:516c03b21d50a644d538de0f0369c620989cd8f0</urn> <urn>com.google.code.findbugs:jsr305:2.0.1:jar:null:compile:516c03b21d50a644d538de0f0369c620989cd8f0</urn>
<urn>com.google.guava:guava:18.0:jar:null:compile:cce0823396aa693798f8882e64213b1772032b09</urn> <urn>com.google.guava:guava:18.0:jar:null:compile:cce0823396aa693798f8882e64213b1772032b09</urn>
<urn>com.google.protobuf:protobuf-java:2.6.1:jar:null:compile:d9521f2aecb909835746b7a5facf612af5e890e8</urn> <urn>com.google.protobuf:protobuf-java:2.6.1:jar:null:compile:d9521f2aecb909835746b7a5facf612af5e890e8</urn>
<urn>com.h2database:h2:1.3.167:jar:null:compile:d3867d586f087e53eb12fc65e5693d8ee9a5da17</urn> <urn>com.h2database:h2:1.3.167:jar:null:compile:d3867d586f087e53eb12fc65e5693d8ee9a5da17</urn>
<urn>com.lambdaworks:scrypt:1.4.0:jar:null:compile:906506b74f30c8c20bccd9ed4a11112d8941fe87</urn> <urn>com.lambdaworks:scrypt:1.4.0:jar:null:compile:906506b74f30c8c20bccd9ed4a11112d8941fe87</urn>
<urn>org.bouncycastle:bcprov-jdk15on:1.55:jar:null:compile:6fc928491ada0974140257e85e2b016a2eee0e1d</urn> <urn>org.bouncycastle:bcprov-jdk15on:1.55:jar:null:compile:935f2e57a00ec2c489cbd2ad830d4a399708f979</urn>
<urn>junit:junit:4.12:jar:null:test:2973d150c0dc1fefe998f834810d68f278ea58ec</urn> <urn>junit:junit:4.12:jar:null:test:2973d150c0dc1fefe998f834810d68f278ea58ec</urn>
<urn>mysql:mysql-connector-java:5.1.33:jar:null:compile:8af455a9a3267e6664cafc87ace71a4e4ef02837</urn> <urn>mysql:mysql-connector-java:5.1.33:jar:null:compile:8af455a9a3267e6664cafc87ace71a4e4ef02837</urn>
<urn>net.jcip:jcip-annotations:1.0:jar:null:compile:afba4942caaeaf46aab0b976afd57cc7c181467e</urn> <urn>net.jcip:jcip-annotations:1.0:jar:null:compile:afba4942caaeaf46aab0b976afd57cc7c181467e</urn>
...@@ -365,7 +367,7 @@ ...@@ -365,7 +367,7 @@
<dependency> <dependency>
<groupId>com.fasterxml.jackson.core</groupId> <groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId> <artifactId>jackson-databind</artifactId>
<version>2.5.2</version> <version>2.8.11.1</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
...@@ -432,5 +434,4 @@ ...@@ -432,5 +434,4 @@
<version>2.7.5</version> <version>2.7.5</version>
</dependency> </dependency>
</dependencies> </dependencies>
</project> </project>
...@@ -21,6 +21,7 @@ import com.google.common.base.*; ...@@ -21,6 +21,7 @@ import com.google.common.base.*;
import com.google.common.collect.*; import com.google.common.collect.*;
import com.google.common.util.concurrent.*; import com.google.common.util.concurrent.*;
import org.bitcoinj.core.listeners.*; import org.bitcoinj.core.listeners.*;
import org.bitcoinj.script.ScriptException;
import org.bitcoinj.store.*; import org.bitcoinj.store.*;
import org.bitcoinj.utils.*; import org.bitcoinj.utils.*;
import org.bitcoinj.wallet.Wallet; import org.bitcoinj.wallet.Wallet;
......
...@@ -90,6 +90,10 @@ public abstract class NetworkParameters { ...@@ -90,6 +90,10 @@ public abstract class NetworkParameters {
protected byte[] alertSigningKey; protected byte[] alertSigningKey;
protected int bip32HeaderPub; protected int bip32HeaderPub;
protected int bip32HeaderPriv; protected int bip32HeaderPriv;
protected int bip49HeaderPub;
protected int bip49HeaderPriv;
protected int bip84HeaderPub;
protected int bip84HeaderPriv;
/** Used to check majorities for block version upgrade */ /** Used to check majorities for block version upgrade */
protected int majorityEnforceBlockUpgrade; protected int majorityEnforceBlockUpgrade;
...@@ -406,6 +410,26 @@ public abstract class NetworkParameters { ...@@ -406,6 +410,26 @@ public abstract class NetworkParameters {
return bip32HeaderPriv; return bip32HeaderPriv;
} }
/** Returns the 4 byte header for BIP49 (HD) wallet - public key part. */
public int getBip49HeaderPub() {
return bip49HeaderPub;
}
/** Returns the 4 byte header for BIP49 (HD) wallet - private key part. */
public int getBip49HeaderPriv() {
return bip49HeaderPriv;
}
/** Returns the 4 byte header for BIP84 (HD) wallet - public key part. */
public int getBip84HeaderPub() {
return bip84HeaderPub;
}
/** Returns the 4 byte header for BIP84 (HD) wallet - private key part. */
public int getBip84HeaderPriv() {
return bip84HeaderPriv;
}
/** /**
* Returns the number of coins that will be produced in total, on this * 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 * network. Where not applicable, a very large number of coins is returned
......
...@@ -564,6 +564,15 @@ public class Peer extends PeerSocketHandler { ...@@ -564,6 +564,15 @@ public class Peer extends PeerSocketHandler {
close(); close();
return; return;
} }
if (((vPeerVersionMessage.localServices
& VersionMessage.NODE_BITCOIN_CASH) == VersionMessage.NODE_BITCOIN_CASH) ||
((vPeerVersionMessage.localServices
& VersionMessage.NODE_SEGWIT2X) == VersionMessage.NODE_SEGWIT2X)) {
log.info("{}: Peer follows an incompatible block chain.", this);
// Shut down the channel gracefully.
close();
return;
}
if (vPeerVersionMessage.bestHeight < 0) if (vPeerVersionMessage.bestHeight < 0)
// In this case, it's a protocol violation. // In this case, it's a protocol violation.
throw new ProtocolException("Peer reports invalid best height: " + vPeerVersionMessage.bestHeight); throw new ProtocolException("Peer reports invalid best height: " + vPeerVersionMessage.bestHeight);
......
...@@ -21,6 +21,7 @@ import org.bitcoinj.core.TransactionConfidence.ConfidenceType; ...@@ -21,6 +21,7 @@ import org.bitcoinj.core.TransactionConfidence.ConfidenceType;
import org.bitcoinj.crypto.TransactionSignature; import org.bitcoinj.crypto.TransactionSignature;
import org.bitcoinj.script.Script; import org.bitcoinj.script.Script;
import org.bitcoinj.script.ScriptBuilder; import org.bitcoinj.script.ScriptBuilder;
import org.bitcoinj.script.ScriptException;
import org.bitcoinj.script.ScriptOpCodes; import org.bitcoinj.script.ScriptOpCodes;
import org.bitcoinj.signers.TransactionSigner; import org.bitcoinj.signers.TransactionSigner;
import org.bitcoinj.utils.ExchangeRate; import org.bitcoinj.utils.ExchangeRate;
...@@ -188,6 +189,11 @@ public class Transaction extends ChildMessage { ...@@ -188,6 +189,11 @@ public class Transaction extends ChildMessage {
@Nullable @Nullable
private String memo; private String memo;
/**
* Segwit makes sigop limit four times higher and scales regular sigops by four.
*/
public static final int WITNESS_SCALE_FACTOR = 4;
public Transaction(NetworkParameters params) { public Transaction(NetworkParameters params) {
super(params); super(params);
version = 1; version = 1;
...@@ -1687,4 +1693,40 @@ public class Transaction extends ChildMessage { ...@@ -1687,4 +1693,40 @@ public class Transaction extends ChildMessage {
public void setMemo(String memo) { public void setMemo(String memo) {
this.memo = memo; this.memo = memo;
} }
/**
* Transaction weight is a segwit-related computation 3b+t where b is the size of a transaction serialized in the
* traditional manner without witness data, and t is the size of a transaction serialized in the segwit format
* with witness data.
*/
public int getWeight() {
final int baseLength;
{
final ByteArrayOutputStream base = new UnsafeByteArrayOutputStream(length < 32 ? 32 : length + 32);
try {
bitcoinSerializeToStream(base, TransactionOptions.NONE);
} catch (IOException e) {
; // Cannot happen, we are serializing to a memory stream
}
baseLength = base.size();
}
final int totalLength;
{
final ByteArrayOutputStream total = new UnsafeByteArrayOutputStream(length < 32 ? 32 : length + 32);
try {
bitcoinSerializeToStream(total, TransactionOptions.WITNESS);
} catch (IOException e) {
; // Cannot happen, we are serializing to a memory stream
}
totalLength = total.size();
}
return baseLength * (WITNESS_SCALE_FACTOR - 1) + totalLength;
}
public int getVirtualTransactionSize() {
return (getWeight() + WITNESS_SCALE_FACTOR - 1) / WITNESS_SCALE_FACTOR;
}
} }
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
package org.bitcoinj.core; package org.bitcoinj.core;
import org.bitcoinj.script.Script; import org.bitcoinj.script.Script;
import org.bitcoinj.script.ScriptException;
import org.bitcoinj.wallet.DefaultRiskAnalysis; import org.bitcoinj.wallet.DefaultRiskAnalysis;
import org.bitcoinj.wallet.KeyBag; import org.bitcoinj.wallet.KeyBag;
import org.bitcoinj.wallet.RedeemData; import org.bitcoinj.wallet.RedeemData;
...@@ -238,7 +239,7 @@ public class TransactionInput extends ChildMessage { ...@@ -238,7 +239,7 @@ public class TransactionInput extends ChildMessage {
/** /**
* @param scriptBytes the scriptBytes to set * @param scriptBytes the scriptBytes to set
*/ */
void setScriptBytes(byte[] scriptBytes) { public void setScriptBytes(byte[] scriptBytes) {
unCache(); unCache();
this.scriptSig = null; this.scriptSig = null;
int oldLength = length; int oldLength = length;
......
...@@ -49,6 +49,10 @@ public class VersionMessage extends Message { ...@@ -49,6 +49,10 @@ public class VersionMessage extends Message {
public static final int NODE_NETWORK = 1 << 0; public static final int NODE_NETWORK = 1 << 0;
/** A flag that denotes whether the peer supports the getutxos message or not. */ /** A flag that denotes whether the peer supports the getutxos message or not. */
public static final int NODE_GETUTXOS = 1 << 1; public static final int NODE_GETUTXOS = 1 << 1;
/** A service bit used by Bitcoin-ABC to announce Bitcoin Cash nodes. */
public static final int NODE_BITCOIN_CASH = 1 << 5;
/** A service bit used by BTC1 to announce Segwit2x nodes. */
public static final int NODE_SEGWIT2X = 1 << 7;
/** Indicates that a node can be asked for blocks and transactions including witness data. */ /** Indicates that a node can be asked for blocks and transactions including witness data. */
public static final int NODE_WITNESS = 1 << 3; public static final int NODE_WITNESS = 1 << 3;
......
...@@ -461,17 +461,29 @@ public class DeterministicKey extends ECKey { ...@@ -461,17 +461,29 @@ public class DeterministicKey extends ECKey {
return key; return key;
} }
public byte[] serializePublic(NetworkParameters params) { public byte[] serializePublic(NetworkParameters params, int purpose) {
return serialize(params, true); return serialize(params, true, purpose);
} }
public byte[] serializePrivate(NetworkParameters params) { public byte[] serializePrivate(NetworkParameters params, int purpose) {
return serialize(params, false); return serialize(params, false, purpose);
} }
private byte[] serialize(NetworkParameters params, boolean pub) { private byte[] serialize(NetworkParameters params, boolean pub, int purpose) {
ByteBuffer ser = ByteBuffer.allocate(78); ByteBuffer ser = ByteBuffer.allocate(78);
switch(purpose) {
case 49:
ser.putInt(pub ? params.getBip49HeaderPub() : params.getBip49HeaderPriv());
break;
case 84:
ser.putInt(pub ? params.getBip84HeaderPub() : params.getBip84HeaderPriv());
break;
// assume purpose == 44
default:
ser.putInt(pub ? params.getBip32HeaderPub() : params.getBip32HeaderPriv()); ser.putInt(pub ? params.getBip32HeaderPub() : params.getBip32HeaderPriv());
break;
}
ser.put((byte) getDepth()); ser.put((byte) getDepth());
ser.putInt(getParentFingerprint()); ser.putInt(getParentFingerprint());
ser.putInt(getChildNumber().i()); ser.putInt(getChildNumber().i());
...@@ -482,11 +494,19 @@ public class DeterministicKey extends ECKey { ...@@ -482,11 +494,19 @@ public class DeterministicKey extends ECKey {
} }
public String serializePubB58(NetworkParameters params) { public String serializePubB58(NetworkParameters params) {
return toBase58(serialize(params, true)); return toBase58(serialize(params, true, 44));
} }
public String serializePrivB58(NetworkParameters params) { public String serializePrivB58(NetworkParameters params) {
return toBase58(serialize(params, false)); return toBase58(serialize(params, false, 44));
}
public String serializePubB58(NetworkParameters params, int purpose) {
return toBase58(serialize(params, true, purpose));
}
public String serializePrivB58(NetworkParameters params, int purpose) {
return toBase58(serialize(params, false, purpose));
} }
static String toBase58(byte[] ser) { static String toBase58(byte[] ser) {
...@@ -521,9 +541,9 @@ public class DeterministicKey extends ECKey { ...@@ -521,9 +541,9 @@ public class DeterministicKey extends ECKey {
public static DeterministicKey deserialize(NetworkParameters params, byte[] serializedKey, @Nullable DeterministicKey parent) { public static DeterministicKey deserialize(NetworkParameters params, byte[] serializedKey, @Nullable DeterministicKey parent) {
ByteBuffer buffer = ByteBuffer.wrap(serializedKey); ByteBuffer buffer = ByteBuffer.wrap(serializedKey);
int header = buffer.getInt(); int header = buffer.getInt();
if (header != params.getBip32HeaderPriv() && header != params.getBip32HeaderPub()) if (header != params.getBip32HeaderPriv() && header != params.getBip32HeaderPub() && header != params.getBip49HeaderPriv() && header != params.getBip49HeaderPub())
throw new IllegalArgumentException("Unknown header bytes: " + toBase58(serializedKey).substring(0, 4)); throw new IllegalArgumentException("Unknown header bytes: " + toBase58(serializedKey).substring(0, 4));
boolean pub = header == params.getBip32HeaderPub(); boolean pub = (header == params.getBip32HeaderPub() || header == params.getBip49HeaderPub());
int depth = buffer.get() & 0xFF; // convert signed byte to positive int since depth cannot be negative int depth = buffer.get() & 0xFF; // convert signed byte to positive int since depth cannot be negative
final int parentFingerprint = buffer.getInt(); final int parentFingerprint = buffer.getInt();
final int i = buffer.getInt(); final int i = buffer.getInt();
......
...@@ -47,6 +47,10 @@ public class MainNetParams extends AbstractBitcoinNetParams { ...@@ -47,6 +47,10 @@ public class MainNetParams extends AbstractBitcoinNetParams {
packetMagic = 0xf9beb4d9L; packetMagic = 0xf9beb4d9L;
bip32HeaderPub = 0x0488B21E; //The 4 byte header that serializes in base58 to "xpub". bip32HeaderPub = 0x0488B21E; //The 4 byte header that serializes in base58 to "xpub".
bip32HeaderPriv = 0x0488ADE4; //The 4 byte header that serializes in base58 to "xprv" bip32HeaderPriv = 0x0488ADE4; //The 4 byte header that serializes in base58 to "xprv"
bip49HeaderPub = 0x049D7CB2; //The 4 byte header that serializes in base58 to "ypub".
bip49HeaderPriv = 0x049D7878; //The 4 byte header that serializes in base58 to "yprv"
bip84HeaderPub = 0x04B24746; //The 4 byte header that serializes in base58 to "zpub".
bip84HeaderPriv = 0x04B2430C; //The 4 byte header that serializes in base58 to "zprv"
majorityEnforceBlockUpgrade = MAINNET_MAJORITY_ENFORCE_BLOCK_UPGRADE; majorityEnforceBlockUpgrade = MAINNET_MAJORITY_ENFORCE_BLOCK_UPGRADE;
majorityRejectBlockOutdated = MAINNET_MAJORITY_REJECT_BLOCK_OUTDATED; majorityRejectBlockOutdated = MAINNET_MAJORITY_REJECT_BLOCK_OUTDATED;
......
...@@ -68,6 +68,10 @@ public class TestNet3Params extends AbstractBitcoinNetParams { ...@@ -68,6 +68,10 @@ public class TestNet3Params extends AbstractBitcoinNetParams {
addrSeeds = null; addrSeeds = null;
bip32HeaderPub = 0x043587CF; bip32HeaderPub = 0x043587CF;
bip32HeaderPriv = 0x04358394; bip32HeaderPriv = 0x04358394;
bip49HeaderPub = 0x044A5262;
bip49HeaderPriv = 0x044A4E28;
bip84HeaderPub = 0x045F1CF6;
bip84HeaderPriv = 0x045F18BC;
majorityEnforceBlockUpgrade = TestNet2Params.TESTNET_MAJORITY_ENFORCE_BLOCK_UPGRADE; majorityEnforceBlockUpgrade = TestNet2Params.TESTNET_MAJORITY_ENFORCE_BLOCK_UPGRADE;
majorityRejectBlockOutdated = TestNet2Params.TESTNET_MAJORITY_REJECT_BLOCK_OUTDATED; majorityRejectBlockOutdated = TestNet2Params.TESTNET_MAJORITY_REJECT_BLOCK_OUTDATED;
......
...@@ -23,6 +23,7 @@ import org.bitcoinj.crypto.TransactionSignature; ...@@ -23,6 +23,7 @@ import org.bitcoinj.crypto.TransactionSignature;
import org.bitcoinj.protocols.channels.IPaymentChannelClient.ClientChannelProperties; import org.bitcoinj.protocols.channels.IPaymentChannelClient.ClientChannelProperties;
import org.bitcoinj.script.Script; import org.bitcoinj.script.Script;
import org.bitcoinj.script.ScriptBuilder; import org.bitcoinj.script.ScriptBuilder;
import org.bitcoinj.script.ScriptException;
import org.bitcoinj.wallet.AllowUnconfirmedCoinSelector; import org.bitcoinj.wallet.AllowUnconfirmedCoinSelector;
import org.bitcoinj.wallet.SendRequest; import org.bitcoinj.wallet.SendRequest;
import org.bitcoinj.wallet.Wallet; import org.bitcoinj.wallet.Wallet;
......
...@@ -14,7 +14,9 @@ ...@@ -14,7 +14,9 @@
* limitations under the License. * limitations under the License.
*/ */
package org.bitcoinj.core; package org.bitcoinj.script;
import org.bitcoinj.core.VerificationException;
@SuppressWarnings("serial") @SuppressWarnings("serial")
public class ScriptException extends VerificationException { public class ScriptException extends VerificationException {
......
...@@ -20,6 +20,7 @@ import org.bitcoinj.core.*; ...@@ -20,6 +20,7 @@ import org.bitcoinj.core.*;
import org.bitcoinj.crypto.ChildNumber; import org.bitcoinj.crypto.ChildNumber;
import org.bitcoinj.crypto.TransactionSignature; import org.bitcoinj.crypto.TransactionSignature;
import org.bitcoinj.script.Script; import org.bitcoinj.script.Script;
import org.bitcoinj.script.ScriptException;
import org.bitcoinj.wallet.KeyBag; import org.bitcoinj.wallet.KeyBag;
import org.bitcoinj.wallet.RedeemData; import org.bitcoinj.wallet.RedeemData;
import org.slf4j.Logger; import org.slf4j.Logger;
...@@ -104,5 +105,3 @@ public abstract class CustomTransactionSigner extends StatelessTransactionSigner ...@@ -104,5 +105,3 @@ public abstract class CustomTransactionSigner extends StatelessTransactionSigner
} }
} }
...@@ -18,12 +18,12 @@ package org.bitcoinj.signers; ...@@ -18,12 +18,12 @@ package org.bitcoinj.signers;
import java.util.EnumSet; import java.util.EnumSet;
import org.bitcoinj.core.ECKey; import org.bitcoinj.core.ECKey;
import org.bitcoinj.core.ScriptException;
import org.bitcoinj.core.Transaction; import org.bitcoinj.core.Transaction;
import org.bitcoinj.core.TransactionInput; import org.bitcoinj.core.TransactionInput;
import org.bitcoinj.crypto.DeterministicKey; import org.bitcoinj.crypto.DeterministicKey;
import org.bitcoinj.crypto.TransactionSignature; import org.bitcoinj.crypto.TransactionSignature;
import org.bitcoinj.script.Script; import org.bitcoinj.script.Script;
import org.bitcoinj.script.ScriptException;
import org.bitcoinj.script.Script.VerifyFlag; import org.bitcoinj.script.Script.VerifyFlag;
import org.bitcoinj.wallet.KeyBag; import org.bitcoinj.wallet.KeyBag;
import org.bitcoinj.wallet.RedeemData; import org.bitcoinj.wallet.RedeemData;
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
package org.bitcoinj.store; package org.bitcoinj.store;
import org.bitcoinj.core.*; import org.bitcoinj.core.*;
import org.bitcoinj.script.ScriptException;
import org.fusesource.leveldbjni.*; import org.fusesource.leveldbjni.*;
import org.iq80.leveldb.*; import org.iq80.leveldb.*;
......
...@@ -31,7 +31,6 @@ import java.nio.ByteBuffer; ...@@ -31,7 +31,6 @@ import java.nio.ByteBuffer;
import org.bitcoinj.core.Address; import org.bitcoinj.core.Address;
import org.bitcoinj.core.AddressFormatException; import org.bitcoinj.core.AddressFormatException;
import org.bitcoinj.core.NetworkParameters; import org.bitcoinj.core.NetworkParameters;
import org.bitcoinj.core.ScriptException;
import org.bitcoinj.core.Sha256Hash; import org.bitcoinj.core.Sha256Hash;
import org.bitcoinj.core.StoredBlock; import org.bitcoinj.core.StoredBlock;
import org.bitcoinj.core.StoredUndoableBlock; import org.bitcoinj.core.StoredUndoableBlock;
...@@ -41,6 +40,7 @@ import org.bitcoinj.core.UTXO; ...@@ -41,6 +40,7 @@ import org.bitcoinj.core.UTXO;
import org.bitcoinj.core.UTXOProviderException; import org.bitcoinj.core.UTXOProviderException;
import org.bitcoinj.core.VerificationException; import org.bitcoinj.core.VerificationException;
import org.bitcoinj.script.Script; import org.bitcoinj.script.Script;
import org.bitcoinj.script.ScriptException;
import org.iq80.leveldb.*; import org.iq80.leveldb.*;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
......
...@@ -278,10 +278,6 @@ public class SPVBlockStore implements BlockStore { ...@@ -278,10 +278,6 @@ public class SPVBlockStore implements BlockStore {
public void close() throws BlockStoreException { public void close() throws BlockStoreException {
try { try {
buffer.force(); buffer.force();
if (System.getProperty("os.name").toLowerCase().contains("win")) {
log.info("Windows mmap hack: Forcing buffer cleaning");
WindowsMMapHack.forceRelease(buffer);
}
buffer = null; // Allow it to be GCd and the underlying file mapping to go away. buffer = null; // Allow it to be GCd and the underlying file mapping to go away.
randomAccessFile.close(); randomAccessFile.close();
} catch (IOException e) { } catch (IOException e) {
......
/*
* Copyright by the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.bitcoinj.store;
import sun.misc.*;
import sun.nio.ch.*;
import java.nio.*;
/**
* <p>This class knows how to force an mmap'd ByteBuffer to reliquish its file handles before it becomes garbage collected,
* by exploiting implementation details of the HotSpot JVM implementation.</p>
*
* <p>This is required on Windows because otherwise an attempt to delete a file that is still mmapped will fail. This can
* happen when a user requests a "restore from seed" function, which involves deleting and recreating the chain file.
* At some point we should stop using mmap in SPVBlockStore and we can then delete this class.</p>
*
* <p>It is a separate class to avoid hitting unknown imports when running on other JVMs.</p>
*/
public class WindowsMMapHack {
public static void forceRelease(MappedByteBuffer buffer) {
Cleaner cleaner = ((DirectBuffer) buffer).cleaner();
if (cleaner != null) cleaner.clean();
}
}
...@@ -1328,7 +1328,9 @@ public class DeterministicKeyChain implements EncryptableKeyChain { ...@@ -1328,7 +1328,9 @@ public class DeterministicKeyChain implements EncryptableKeyChain {
builder.append("Key birthday: ").append(watchingKey.getCreationTimeSeconds()).append(" [") builder.append("Key birthday: ").append(watchingKey.getCreationTimeSeconds()).append(" [")
.append(Utils.dateTimeFormat(watchingKey.getCreationTimeSeconds() * 1000)).append("]\n"); .append(Utils.dateTimeFormat(watchingKey.getCreationTimeSeconds() * 1000)).append("]\n");
} }
builder.append("Key to watch: ").append(watchingKey.serializePubB58(params)).append('\n'); builder.append("Key to watch: ").append(watchingKey.serializePubB58(params, 44)).append('\n');
builder.append("Key to watch: ").append(watchingKey.serializePubB58(params, 49)).append('\n');
builder.append("Key to watch: ").append(watchingKey.serializePubB58(params, 84)).append('\n');