3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-02-16 04:05:50 +00:00

Use Address whereever possible in the API, rather than LegacyAddress.

This is a preparation for the remaining segwit changes. LegacyAddress
variables in unit tests are also changed.
This commit is contained in:
Andreas Schildbach 2018-03-04 19:58:49 +01:00
parent 6e46d75c61
commit 7f5b6753f5
40 changed files with 269 additions and 170 deletions

View File

@ -1268,7 +1268,7 @@ public class ECKey implements EncryptableItem {
public void formatKeyWithAddress(boolean includePrivateKeys, @Nullable KeyParameter aesKey, StringBuilder builder, public void formatKeyWithAddress(boolean includePrivateKeys, @Nullable KeyParameter aesKey, StringBuilder builder,
NetworkParameters params) { NetworkParameters params) {
final LegacyAddress address = LegacyAddress.fromKey(params, this); final Address address = LegacyAddress.fromKey(params, this);
builder.append(" addr:"); builder.append(" addr:");
builder.append(address.toString()); builder.append(address.toString());
builder.append(" hash160:"); builder.append(" hash160:");

View File

@ -18,7 +18,7 @@ package org.bitcoinj.core;
/** /**
* <p>Represents the "getaddr" P2P protocol message, which requests network {@link AddressMessage}s from a peer. Not to * <p>Represents the "getaddr" P2P protocol message, which requests network {@link AddressMessage}s from a peer. Not to
* be confused with {@link LegacyAddress} which is sort of like an account number.</p> * be confused with {@link Address} which is sort of like an account number.</p>
* *
* <p>Instances of this class are not safe for use by multiple threads.</p> * <p>Instances of this class are not safe for use by multiple threads.</p>
*/ */

View File

@ -617,7 +617,7 @@ public class DeterministicKey extends ECKey {
@Override @Override
public void formatKeyWithAddress(boolean includePrivateKeys, @Nullable KeyParameter aesKey, StringBuilder builder, public void formatKeyWithAddress(boolean includePrivateKeys, @Nullable KeyParameter aesKey, StringBuilder builder,
NetworkParameters params) { NetworkParameters params) {
final LegacyAddress address = LegacyAddress.fromKey(params, this); final Address address = LegacyAddress.fromKey(params, this);
builder.append(" addr:").append(address); builder.append(" addr:").append(address);
builder.append(" hash160:").append(Utils.HEX.encode(getPubKeyHash())); builder.append(" hash160:").append(Utils.HEX.encode(getPubKeyHash()));
builder.append(" (").append(getPathAsString()).append(")\n"); builder.append(" (").append(getPathAsString()).append(")\n");

View File

@ -66,7 +66,7 @@ public class PaymentProtocol {
* @return created payment request, in its builder form * @return created payment request, in its builder form
*/ */
public static Protos.PaymentRequest.Builder createPaymentRequest(NetworkParameters params, public static Protos.PaymentRequest.Builder createPaymentRequest(NetworkParameters params,
@Nullable Coin amount, LegacyAddress toAddress, @Nullable String memo, @Nullable String paymentUrl, @Nullable Coin amount, Address toAddress, @Nullable String memo, @Nullable String paymentUrl,
@Nullable byte[] merchantData) { @Nullable byte[] merchantData) {
return createPaymentRequest(params, ImmutableList.of(createPayToAddressOutput(amount, toAddress)), memo, return createPaymentRequest(params, ImmutableList.of(createPayToAddressOutput(amount, toAddress)), memo,
paymentUrl, merchantData); paymentUrl, merchantData);
@ -292,7 +292,7 @@ public class PaymentProtocol {
* @return created payment message * @return created payment message
*/ */
public static Protos.Payment createPaymentMessage(List<Transaction> transactions, public static Protos.Payment createPaymentMessage(List<Transaction> transactions,
@Nullable Coin refundAmount, @Nullable LegacyAddress refundAddress, @Nullable String memo, @Nullable Coin refundAmount, @Nullable Address refundAddress, @Nullable String memo,
@Nullable byte[] merchantData) { @Nullable byte[] merchantData) {
if (refundAddress != null) { if (refundAddress != null) {
if (refundAmount == null) if (refundAmount == null)
@ -397,7 +397,7 @@ public class PaymentProtocol {
* @param address address to pay to * @param address address to pay to
* @return output * @return output
*/ */
public static Protos.Output createPayToAddressOutput(@Nullable Coin amount, LegacyAddress address) { public static Protos.Output createPayToAddressOutput(@Nullable Coin amount, Address address) {
Protos.Output.Builder output = Protos.Output.newBuilder(); Protos.Output.Builder output = Protos.Output.newBuilder();
if (amount != null) { if (amount != null) {
final NetworkParameters params = address.getParameters(); final NetworkParameters params = address.getParameters();

View File

@ -316,7 +316,7 @@ public class PaymentSession {
* @param memo is a message to include in the payment message sent to the merchant. * @param memo is a message to include in the payment message sent to the merchant.
*/ */
@Nullable @Nullable
public ListenableFuture<PaymentProtocol.Ack> sendPayment(List<Transaction> txns, @Nullable LegacyAddress refundAddr, @Nullable String memo) public ListenableFuture<PaymentProtocol.Ack> sendPayment(List<Transaction> txns, @Nullable Address refundAddr, @Nullable String memo)
throws PaymentProtocolException, VerificationException, IOException { throws PaymentProtocolException, VerificationException, IOException {
Protos.Payment payment = getPayment(txns, refundAddr, memo); Protos.Payment payment = getPayment(txns, refundAddr, memo);
if (payment == null) if (payment == null)
@ -341,7 +341,7 @@ public class PaymentSession {
* @param memo is a message to include in the payment message sent to the merchant. * @param memo is a message to include in the payment message sent to the merchant.
*/ */
@Nullable @Nullable
public Protos.Payment getPayment(List<Transaction> txns, @Nullable LegacyAddress refundAddr, @Nullable String memo) public Protos.Payment getPayment(List<Transaction> txns, @Nullable Address refundAddr, @Nullable String memo)
throws IOException, PaymentProtocolException.InvalidNetwork { throws IOException, PaymentProtocolException.InvalidNetwork {
if (paymentDetails.hasPaymentUrl()) { if (paymentDetails.hasPaymentUrl()) {
for (Transaction tx : txns) for (Transaction tx : txns)

View File

@ -255,19 +255,18 @@ public class ScriptBuilder {
public static Script createOutputScript(Address to) { public static Script createOutputScript(Address to) {
ScriptBuilder builder = new ScriptBuilder(); ScriptBuilder builder = new ScriptBuilder();
if (to instanceof LegacyAddress) { if (to instanceof LegacyAddress) {
LegacyAddress toLegacy = (LegacyAddress) to; ScriptType scriptType = to.getOutputScriptType();
ScriptType scriptType = toLegacy.getOutputScriptType();
if (scriptType == ScriptType.P2PKH) { if (scriptType == ScriptType.P2PKH) {
// OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG // OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG
builder.op(OP_DUP); builder.op(OP_DUP);
builder.op(OP_HASH160); builder.op(OP_HASH160);
builder.data(toLegacy.getHash()); builder.data(to.getHash());
builder.op(OP_EQUALVERIFY); builder.op(OP_EQUALVERIFY);
builder.op(OP_CHECKSIG); builder.op(OP_CHECKSIG);
} else if (scriptType == ScriptType.P2SH) { } else if (scriptType == ScriptType.P2SH) {
// OP_HASH160 <scriptHash> OP_EQUAL // OP_HASH160 <scriptHash> OP_EQUAL
builder.op(OP_HASH160); builder.op(OP_HASH160);
builder.data(toLegacy.getHash()); builder.data(to.getHash());
builder.op(OP_EQUAL); builder.op(OP_EQUAL);
} else { } else {
throw new IllegalStateException("Cannot handle " + scriptType); throw new IllegalStateException("Cannot handle " + scriptType);

View File

@ -1124,7 +1124,7 @@ public abstract class DatabaseFullPrunedBlockStore implements FullPrunedBlockSto
* address, the return value is 0. * address, the return value is 0.
* @throws BlockStoreException If there is an error getting the balance. * @throws BlockStoreException If there is an error getting the balance.
*/ */
public BigInteger calculateBalanceForAddress(LegacyAddress address) throws BlockStoreException { public BigInteger calculateBalanceForAddress(Address address) throws BlockStoreException {
maybeConnect(); maybeConnect();
PreparedStatement s = null; PreparedStatement s = null;
try { try {

View File

@ -28,10 +28,10 @@ import java.util.concurrent.TimeUnit;
import java.io.*; import java.io.*;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import org.bitcoinj.core.LegacyAddress;
import org.bitcoinj.core.Address; import org.bitcoinj.core.Address;
import org.bitcoinj.core.AddressFormatException; import org.bitcoinj.core.AddressFormatException;
import org.bitcoinj.core.ECKey; import org.bitcoinj.core.ECKey;
import org.bitcoinj.core.LegacyAddress;
import org.bitcoinj.core.NetworkParameters; import org.bitcoinj.core.NetworkParameters;
import org.bitcoinj.core.Sha256Hash; import org.bitcoinj.core.Sha256Hash;
import org.bitcoinj.core.StoredBlock; import org.bitcoinj.core.StoredBlock;
@ -788,7 +788,7 @@ public class LevelDBFullPrunedBlockStore implements FullPrunedBlockStore {
// Could run this in parallel with above too. // Could run this in parallel with above too.
// Should update instrumentation to see if worth while. // Should update instrumentation to see if worth while.
LegacyAddress a; Address a;
if (out.getAddress() == null || out.getAddress().equals("")) { if (out.getAddress() == null || out.getAddress().equals("")) {
if (instrument) if (instrument)
endMethod("addUnspentTransactionOutput"); endMethod("addUnspentTransactionOutput");
@ -882,13 +882,13 @@ public class LevelDBFullPrunedBlockStore implements FullPrunedBlockStore {
// TODO storing as byte[] hash to save space. But think should just // TODO storing as byte[] hash to save space. But think should just
// store as String of address. Might be faster. Need to test. // store as String of address. Might be faster. Need to test.
ByteBuffer bb = ByteBuffer.allocate(57); ByteBuffer bb = ByteBuffer.allocate(57);
LegacyAddress a; Address a;
byte[] hashBytes = null; byte[] hashBytes = null;
try { try {
String address = out.getAddress(); String address = out.getAddress();
if (address == null || address.equals("")) { if (address == null || address.equals("")) {
Script sc = out.getScript(); Script sc = out.getScript();
a = (LegacyAddress) sc.getToAddress(params); a = sc.getToAddress(params);
hashBytes = a.getHash(); hashBytes = a.getHash();
} else { } else {
a = LegacyAddress.fromBase58(params, out.getAddress()); a = LegacyAddress.fromBase58(params, out.getAddress());

View File

@ -19,7 +19,13 @@ package org.bitcoinj.wallet;
import com.google.common.collect.*; import com.google.common.collect.*;
import com.google.protobuf.*; import com.google.protobuf.*;
import org.bitcoinj.core.*;
import org.bitcoinj.core.Address;
import org.bitcoinj.core.BloomFilter;
import org.bitcoinj.core.ECKey;
import org.bitcoinj.core.LegacyAddress;
import org.bitcoinj.core.NetworkParameters;
import org.bitcoinj.core.Utils;
import org.bitcoinj.crypto.*; import org.bitcoinj.crypto.*;
import org.bitcoinj.script.*; import org.bitcoinj.script.*;
import org.bitcoinj.script.Script.ScriptType; import org.bitcoinj.script.Script.ScriptType;
@ -70,7 +76,7 @@ public class KeyChainGroup implements KeyBag {
// currentKeys is used for normal, non-multisig/married wallets. currentAddresses is used when we're handing out // currentKeys is used for normal, non-multisig/married wallets. currentAddresses is used when we're handing out
// P2SH addresses. They're mutually exclusive. // P2SH addresses. They're mutually exclusive.
private final EnumMap<KeyChain.KeyPurpose, DeterministicKey> currentKeys; private final EnumMap<KeyChain.KeyPurpose, DeterministicKey> currentKeys;
private final EnumMap<KeyChain.KeyPurpose, LegacyAddress> currentAddresses; private final EnumMap<KeyChain.KeyPurpose, Address> currentAddresses;
@Nullable private KeyCrypter keyCrypter; @Nullable private KeyCrypter keyCrypter;
private int lookaheadSize = -1; private int lookaheadSize = -1;
private int lookaheadThreshold = -1; private int lookaheadThreshold = -1;
@ -125,7 +131,7 @@ public class KeyChainGroup implements KeyBag {
if (isMarried()) { if (isMarried()) {
for (Map.Entry<KeyChain.KeyPurpose, DeterministicKey> entry : this.currentKeys.entrySet()) { for (Map.Entry<KeyChain.KeyPurpose, DeterministicKey> entry : this.currentKeys.entrySet()) {
Address address = makeP2SHOutputScript(entry.getValue(), getActiveKeyChain()).getToAddress(params); Address address = makeP2SHOutputScript(entry.getValue(), getActiveKeyChain()).getToAddress(params);
currentAddresses.put(entry.getKey(), (LegacyAddress) address); currentAddresses.put(entry.getKey(), address);
} }
} }
} }
@ -187,10 +193,10 @@ public class KeyChainGroup implements KeyBag {
/** /**
* Returns address for a {@link #currentKey(KeyChain.KeyPurpose)} * Returns address for a {@link #currentKey(KeyChain.KeyPurpose)}
*/ */
public LegacyAddress currentAddress(KeyChain.KeyPurpose purpose) { public Address currentAddress(KeyChain.KeyPurpose purpose) {
DeterministicKeyChain chain = getActiveKeyChain(); DeterministicKeyChain chain = getActiveKeyChain();
if (chain.isMarried()) { if (chain.isMarried()) {
LegacyAddress current = currentAddresses.get(purpose); Address current = currentAddresses.get(purpose);
if (current == null) { if (current == null) {
current = freshAddress(purpose); current = freshAddress(purpose);
currentAddresses.put(purpose, current); currentAddresses.put(purpose, current);
@ -241,12 +247,12 @@ public class KeyChainGroup implements KeyBag {
/** /**
* Returns address for a {@link #freshKey(KeyChain.KeyPurpose)} * Returns address for a {@link #freshKey(KeyChain.KeyPurpose)}
*/ */
public LegacyAddress freshAddress(KeyChain.KeyPurpose purpose) { public Address freshAddress(KeyChain.KeyPurpose purpose) {
DeterministicKeyChain chain = getActiveKeyChain(); DeterministicKeyChain chain = getActiveKeyChain();
if (chain.isMarried()) { if (chain.isMarried()) {
Script outputScript = chain.freshOutputScript(purpose); Script outputScript = chain.freshOutputScript(purpose);
checkState(ScriptPattern.isPayToScriptHash(outputScript)); // Only handle P2SH for now checkState(ScriptPattern.isPayToScriptHash(outputScript)); // Only handle P2SH for now
LegacyAddress freshAddress = LegacyAddress.fromScriptHash(params, Address freshAddress = LegacyAddress.fromScriptHash(params,
ScriptPattern.extractHashFromPayToScriptHash(outputScript)); ScriptPattern.extractHashFromPayToScriptHash(outputScript));
maybeLookaheadScripts(); maybeLookaheadScripts();
currentAddresses.put(purpose, freshAddress); currentAddresses.put(purpose, freshAddress);
@ -411,7 +417,7 @@ public class KeyChainGroup implements KeyBag {
/** If the given P2SH address is "current", advance it to a new one. */ /** If the given P2SH address is "current", advance it to a new one. */
private void maybeMarkCurrentAddressAsUsed(LegacyAddress address) { private void maybeMarkCurrentAddressAsUsed(LegacyAddress address) {
checkArgument(address.getOutputScriptType() == ScriptType.P2SH); checkArgument(address.getOutputScriptType() == ScriptType.P2SH);
for (Map.Entry<KeyChain.KeyPurpose, LegacyAddress> entry : currentAddresses.entrySet()) { for (Map.Entry<KeyChain.KeyPurpose, Address> entry : currentAddresses.entrySet()) {
if (entry.getValue() != null && entry.getValue().equals(address)) { if (entry.getValue() != null && entry.getValue().equals(address)) {
log.info("Marking P2SH address as used: {}", address); log.info("Marking P2SH address as used: {}", address);
currentAddresses.put(entry.getKey(), freshAddress(entry.getKey())); currentAddresses.put(entry.getKey(), freshAddress(entry.getKey()));

View File

@ -76,7 +76,7 @@ public class SendRequest {
* don't really control as it depends on who sent you money), and the value being sent somewhere else. The * don't really control as it depends on who sent you money), and the value being sent somewhere else. The
* change address should be selected from this wallet, normally. <b>If null this will be chosen for you.</b> * change address should be selected from this wallet, normally. <b>If null this will be chosen for you.</b>
*/ */
public LegacyAddress changeAddress = null; public Address changeAddress = null;
/** /**
* <p>A transaction can have a fee attached, which is defined as the difference between the input values * <p>A transaction can have a fee attached, which is defined as the difference between the input values

View File

@ -27,7 +27,6 @@ import net.jcip.annotations.*;
import org.bitcoinj.core.listeners.*; import org.bitcoinj.core.listeners.*;
import org.bitcoinj.core.Address; import org.bitcoinj.core.Address;
import org.bitcoinj.core.AbstractBlockChain; import org.bitcoinj.core.AbstractBlockChain;
import org.bitcoinj.core.LegacyAddress;
import org.bitcoinj.core.BlockChain; import org.bitcoinj.core.BlockChain;
import org.bitcoinj.core.BloomFilter; import org.bitcoinj.core.BloomFilter;
import org.bitcoinj.core.Coin; import org.bitcoinj.core.Coin;
@ -35,6 +34,7 @@ import org.bitcoinj.core.Context;
import org.bitcoinj.core.ECKey; import org.bitcoinj.core.ECKey;
import org.bitcoinj.core.FilteredBlock; import org.bitcoinj.core.FilteredBlock;
import org.bitcoinj.core.InsufficientMoneyException; import org.bitcoinj.core.InsufficientMoneyException;
import org.bitcoinj.core.LegacyAddress;
import org.bitcoinj.core.Message; import org.bitcoinj.core.Message;
import org.bitcoinj.core.NetworkParameters; import org.bitcoinj.core.NetworkParameters;
import org.bitcoinj.core.Peer; import org.bitcoinj.core.Peer;
@ -469,7 +469,7 @@ public class Wallet extends BaseTaggableObject
/** /**
* Returns address for a {@link #currentKey(org.bitcoinj.wallet.KeyChain.KeyPurpose)} * Returns address for a {@link #currentKey(org.bitcoinj.wallet.KeyChain.KeyPurpose)}
*/ */
public LegacyAddress currentAddress(KeyChain.KeyPurpose purpose) { public Address currentAddress(KeyChain.KeyPurpose purpose) {
keyChainGroupLock.lock(); keyChainGroupLock.lock();
try { try {
maybeUpgradeToHD(); maybeUpgradeToHD();
@ -483,7 +483,7 @@ public class Wallet extends BaseTaggableObject
* An alias for calling {@link #currentAddress(org.bitcoinj.wallet.KeyChain.KeyPurpose)} with * An alias for calling {@link #currentAddress(org.bitcoinj.wallet.KeyChain.KeyPurpose)} with
* {@link org.bitcoinj.wallet.KeyChain.KeyPurpose#RECEIVE_FUNDS} as the parameter. * {@link org.bitcoinj.wallet.KeyChain.KeyPurpose#RECEIVE_FUNDS} as the parameter.
*/ */
public LegacyAddress currentReceiveAddress() { public Address currentReceiveAddress() {
return currentAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS); return currentAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
} }
@ -533,23 +533,23 @@ public class Wallet extends BaseTaggableObject
/** /**
* Returns address for a {@link #freshKey(org.bitcoinj.wallet.KeyChain.KeyPurpose)} * Returns address for a {@link #freshKey(org.bitcoinj.wallet.KeyChain.KeyPurpose)}
*/ */
public LegacyAddress freshAddress(KeyChain.KeyPurpose purpose) { public Address freshAddress(KeyChain.KeyPurpose purpose) {
LegacyAddress key; Address address;
keyChainGroupLock.lock(); keyChainGroupLock.lock();
try { try {
key = keyChainGroup.freshAddress(purpose); address = keyChainGroup.freshAddress(purpose);
} finally { } finally {
keyChainGroupLock.unlock(); keyChainGroupLock.unlock();
} }
saveNow(); saveNow();
return key; return address;
} }
/** /**
* An alias for calling {@link #freshAddress(org.bitcoinj.wallet.KeyChain.KeyPurpose)} with * An alias for calling {@link #freshAddress(org.bitcoinj.wallet.KeyChain.KeyPurpose)} with
* {@link org.bitcoinj.wallet.KeyChain.KeyPurpose#RECEIVE_FUNDS} as the parameter. * {@link org.bitcoinj.wallet.KeyChain.KeyPurpose#RECEIVE_FUNDS} as the parameter.
*/ */
public LegacyAddress freshReceiveAddress() { public Address freshReceiveAddress() {
return freshAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS); return freshAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
} }
@ -570,9 +570,9 @@ public class Wallet extends BaseTaggableObject
* Returns only the addresses that have been issued by {@link #freshReceiveKey()}, {@link #freshReceiveAddress()}, * Returns only the addresses that have been issued by {@link #freshReceiveKey()}, {@link #freshReceiveAddress()},
* {@link #currentReceiveKey()} or {@link #currentReceiveAddress()}. * {@link #currentReceiveKey()} or {@link #currentReceiveAddress()}.
*/ */
public List<LegacyAddress> getIssuedReceiveAddresses() { public List<Address> getIssuedReceiveAddresses() {
final List<ECKey> keys = getIssuedReceiveKeys(); final List<ECKey> keys = getIssuedReceiveKeys();
List<LegacyAddress> addresses = new ArrayList<>(keys.size()); List<Address> addresses = new ArrayList<>(keys.size());
for (ECKey key : keys) for (ECKey key : keys)
addresses.add(LegacyAddress.fromKey(getParams(), key)); addresses.add(LegacyAddress.fromKey(getParams(), key));
return addresses; return addresses;
@ -688,7 +688,7 @@ public class Wallet extends BaseTaggableObject
} }
/** Returns the address used for change outputs. Note: this will probably go away in future. */ /** Returns the address used for change outputs. Note: this will probably go away in future. */
public LegacyAddress currentChangeAddress() { public Address currentChangeAddress() {
return currentAddress(KeyChain.KeyPurpose.CHANGE); return currentAddress(KeyChain.KeyPurpose.CHANGE);
} }
@ -850,15 +850,15 @@ public class Wallet extends BaseTaggableObject
/** /**
* Return true if we are watching this address. * Return true if we are watching this address.
*/ */
public boolean isAddressWatched(LegacyAddress address) { public boolean isAddressWatched(Address address) {
Script script = ScriptBuilder.createOutputScript(address); Script script = ScriptBuilder.createOutputScript(address);
return isWatchedScript(script); return isWatchedScript(script);
} }
/** /**
* Same as {@link #addWatchedAddress(LegacyAddress, long)} with the current time as the creation time. * Same as {@link #addWatchedAddress(Address, long)} with the current time as the creation time.
*/ */
public boolean addWatchedAddress(final LegacyAddress address) { public boolean addWatchedAddress(final Address address) {
long now = Utils.currentTimeMillis() / 1000; long now = Utils.currentTimeMillis() / 1000;
return addWatchedAddresses(Lists.newArrayList(address), now) == 1; return addWatchedAddresses(Lists.newArrayList(address), now) == 1;
} }
@ -869,7 +869,7 @@ public class Wallet extends BaseTaggableObject
* @param creationTime creation time in seconds since the epoch, for scanning the blockchain * @param creationTime creation time in seconds since the epoch, for scanning the blockchain
* @return whether the address was added successfully (not already present) * @return whether the address was added successfully (not already present)
*/ */
public boolean addWatchedAddress(final LegacyAddress address, long creationTime) { public boolean addWatchedAddress(final Address address, long creationTime) {
return addWatchedAddresses(Lists.newArrayList(address), creationTime) == 1; return addWatchedAddresses(Lists.newArrayList(address), creationTime) == 1;
} }
@ -879,10 +879,10 @@ public class Wallet extends BaseTaggableObject
* *
* @return how many addresses were added successfully * @return how many addresses were added successfully
*/ */
public int addWatchedAddresses(final List<LegacyAddress> addresses, long creationTime) { public int addWatchedAddresses(final List<Address> addresses, long creationTime) {
List<Script> scripts = Lists.newArrayList(); List<Script> scripts = Lists.newArrayList();
for (LegacyAddress address : addresses) { for (Address address : addresses) {
Script script = ScriptBuilder.createOutputScript(address); Script script = ScriptBuilder.createOutputScript(address);
script.setCreationTimeSeconds(creationTime); script.setCreationTimeSeconds(creationTime);
scripts.add(script); scripts.add(script);
@ -929,7 +929,7 @@ public class Wallet extends BaseTaggableObject
* *
* @return true if successful * @return true if successful
*/ */
public boolean removeWatchedAddress(final LegacyAddress address) { public boolean removeWatchedAddress(final Address address) {
return removeWatchedAddresses(ImmutableList.of(address)); return removeWatchedAddresses(ImmutableList.of(address));
} }
@ -938,10 +938,10 @@ public class Wallet extends BaseTaggableObject
* *
* @return true if successful * @return true if successful
*/ */
public boolean removeWatchedAddresses(final List<LegacyAddress> addresses) { public boolean removeWatchedAddresses(final List<Address> addresses) {
List<Script> scripts = Lists.newArrayList(); List<Script> scripts = Lists.newArrayList();
for (LegacyAddress address : addresses) { for (Address address : addresses) {
Script script = ScriptBuilder.createOutputScript(address); Script script = ScriptBuilder.createOutputScript(address);
scripts.add(script); scripts.add(script);
} }
@ -975,13 +975,13 @@ public class Wallet extends BaseTaggableObject
/** /**
* Returns all addresses watched by this wallet. * Returns all addresses watched by this wallet.
*/ */
public List<LegacyAddress> getWatchedAddresses() { public List<Address> getWatchedAddresses() {
keyChainGroupLock.lock(); keyChainGroupLock.lock();
try { try {
List<LegacyAddress> addresses = new LinkedList<>(); List<Address> addresses = new LinkedList<>();
for (Script script : watchedScripts) for (Script script : watchedScripts)
if (ScriptPattern.isPayToPubKeyHash(script)) if (ScriptPattern.isPayToPubKeyHash(script))
addresses.add(((LegacyAddress) script.getToAddress(params))); addresses.add(script.getToAddress(params));
return addresses; return addresses;
} finally { } finally {
keyChainGroupLock.unlock(); keyChainGroupLock.unlock();
@ -3010,7 +3010,7 @@ public class Wallet extends BaseTaggableObject
} }
/** /**
* Returns all the outputs that match addresses or scripts added via {@link #addWatchedAddress(LegacyAddress)} or * Returns all the outputs that match addresses or scripts added via {@link #addWatchedAddress(Address)} or
* {@link #addWatchedScripts(java.util.List)}. * {@link #addWatchedScripts(java.util.List)}.
* @param excludeImmatureCoinbases Whether to ignore outputs that are unspendable due to being immature. * @param excludeImmatureCoinbases Whether to ignore outputs that are unspendable due to being immature.
*/ */
@ -4854,7 +4854,7 @@ public class Wallet extends BaseTaggableObject
// The value of the inputs is greater than what we want to send. Just like in real life then, // The value of the inputs is greater than what we want to send. Just like in real life then,
// we need to take back some coins ... this is called "change". Add another output that sends the change // we need to take back some coins ... this is called "change". Add another output that sends the change
// back to us. The address comes either from the request or currentChangeAddress() as a default. // back to us. The address comes either from the request or currentChangeAddress() as a default.
LegacyAddress changeAddress = req.changeAddress; Address changeAddress = req.changeAddress;
if (changeAddress == null) if (changeAddress == null)
changeAddress = currentChangeAddress(); changeAddress = currentChangeAddress();
TransactionOutput changeOutput = new TransactionOutput(params, tx, change, changeAddress); TransactionOutput changeOutput = new TransactionOutput(params, tx, change, changeAddress);

View File

@ -261,7 +261,7 @@ public abstract class AbstractFullPrunedBlockChainTest {
// Create bitcoin spend of 1 BTC. // Create bitcoin spend of 1 BTC.
ECKey toKey = new ECKey(); ECKey toKey = new ECKey();
Coin amount = Coin.valueOf(100000000); Coin amount = Coin.valueOf(100000000);
LegacyAddress address = LegacyAddress.fromKey(PARAMS, toKey); Address address = LegacyAddress.fromKey(PARAMS, toKey);
Coin totalAmount = Coin.ZERO; Coin totalAmount = Coin.ZERO;
Transaction t = new Transaction(PARAMS); Transaction t = new Transaction(PARAMS);
@ -328,7 +328,7 @@ public abstract class AbstractFullPrunedBlockChainTest {
// Create another spend of 1/2 the value of BTC we have available using the wallet (store coin selector). // Create another spend of 1/2 the value of BTC we have available using the wallet (store coin selector).
ECKey toKey2 = new ECKey(); ECKey toKey2 = new ECKey();
Coin amount2 = amount.divide(2); Coin amount2 = amount.divide(2);
LegacyAddress address2 = LegacyAddress.fromKey(PARAMS, toKey2); Address address2 = LegacyAddress.fromKey(PARAMS, toKey2);
SendRequest req = SendRequest.to(address2, amount2); SendRequest req = SendRequest.to(address2, amount2);
wallet.completeTx(req); wallet.completeTx(req);
wallet.commitTx(req.tx); wallet.commitTx(req.tx);

View File

@ -54,7 +54,7 @@ public class BlockChainTest {
private Wallet wallet; private Wallet wallet;
private BlockChain chain; private BlockChain chain;
private BlockStore blockStore; private BlockStore blockStore;
private LegacyAddress coinbaseTo; private Address coinbaseTo;
private final StoredBlock[] block = new StoredBlock[1]; private final StoredBlock[] block = new StoredBlock[1];
private Transaction coinbaseTransaction; private Transaction coinbaseTransaction;
@ -293,10 +293,10 @@ public class BlockChainTest {
public void intraBlockDependencies() throws Exception { public void intraBlockDependencies() throws Exception {
// Covers issue 166 in which transactions that depend on each other inside a block were not always being // Covers issue 166 in which transactions that depend on each other inside a block were not always being
// considered relevant. // considered relevant.
LegacyAddress somebodyElse = LegacyAddress.fromKey(UNITTEST, new ECKey()); Address somebodyElse = LegacyAddress.fromKey(UNITTEST, new ECKey());
Block b1 = UNITTEST.getGenesisBlock().createNextBlock(somebodyElse); Block b1 = UNITTEST.getGenesisBlock().createNextBlock(somebodyElse);
ECKey key = wallet.freshReceiveKey(); ECKey key = wallet.freshReceiveKey();
LegacyAddress addr = LegacyAddress.fromKey(UNITTEST, key); Address addr = LegacyAddress.fromKey(UNITTEST, key);
// Create a tx that gives us some coins, and another that spends it to someone else in the same block. // Create a tx that gives us some coins, and another that spends it to someone else in the same block.
Transaction t1 = FakeTxBuilder.createFakeTx(UNITTEST, COIN, addr); Transaction t1 = FakeTxBuilder.createFakeTx(UNITTEST, COIN, addr);
Transaction t2 = new Transaction(UNITTEST); Transaction t2 = new Transaction(UNITTEST);
@ -319,7 +319,7 @@ public class BlockChainTest {
int height = 1; int height = 1;
chain.addWallet(wallet2); chain.addWallet(wallet2);
LegacyAddress addressToSendTo = LegacyAddress.fromKey(UNITTEST, receiveKey); Address addressToSendTo = LegacyAddress.fromKey(UNITTEST, receiveKey);
// Create a block, sending the coinbase to the coinbaseTo address (which is in the wallet). // Create a block, sending the coinbase to the coinbaseTo address (which is in the wallet).
Block b1 = UNITTEST.getGenesisBlock().createNextBlockWithCoinbase(Block.BLOCK_VERSION_GENESIS, wallet.currentReceiveKey().getPubKey(), height++); Block b1 = UNITTEST.getGenesisBlock().createNextBlockWithCoinbase(Block.BLOCK_VERSION_GENESIS, wallet.currentReceiveKey().getPubKey(), height++);

View File

@ -74,7 +74,7 @@ public class BloomFilterTest {
DumpedPrivateKey privKey = DumpedPrivateKey.fromBase58(MAINNET, "5Kg1gnAjaLfKiwhhPpGS3QfRg2m6awQvaj98JCZBZQ5SuS2F15C"); DumpedPrivateKey privKey = DumpedPrivateKey.fromBase58(MAINNET, "5Kg1gnAjaLfKiwhhPpGS3QfRg2m6awQvaj98JCZBZQ5SuS2F15C");
LegacyAddress addr = LegacyAddress.fromKey(MAINNET, privKey.getKey()); Address addr = LegacyAddress.fromKey(MAINNET, privKey.getKey());
assertTrue(addr.toString().equals("17Wx1GQfyPTNWpQMHrTwRSMTCAonSiZx9e")); assertTrue(addr.toString().equals("17Wx1GQfyPTNWpQMHrTwRSMTCAonSiZx9e"));
KeyChainGroup group = new KeyChainGroup(MAINNET); KeyChainGroup group = new KeyChainGroup(MAINNET);

View File

@ -51,9 +51,9 @@ public class ChainSplitTest {
private static final NetworkParameters UNITTEST = UnitTestParams.get(); private static final NetworkParameters UNITTEST = UnitTestParams.get();
private Wallet wallet; private Wallet wallet;
private BlockChain chain; private BlockChain chain;
private LegacyAddress coinsTo; private Address coinsTo;
private LegacyAddress coinsTo2; private Address coinsTo2;
private LegacyAddress someOtherGuy; private Address someOtherGuy;
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
@ -186,7 +186,7 @@ public class ChainSplitTest {
Block b1 = UNITTEST.getGenesisBlock().createNextBlock(coinsTo); Block b1 = UNITTEST.getGenesisBlock().createNextBlock(coinsTo);
chain.add(b1); chain.add(b1);
assertEquals(FIFTY_COINS, wallet.getBalance()); assertEquals(FIFTY_COINS, wallet.getBalance());
LegacyAddress dest = LegacyAddress.fromKey(UNITTEST, new ECKey()); Address dest = LegacyAddress.fromKey(UNITTEST, new ECKey());
Transaction spend = wallet.createSend(dest, valueOf(10, 0)); Transaction spend = wallet.createSend(dest, valueOf(10, 0));
wallet.commitTx(spend); wallet.commitTx(spend);
// Waiting for confirmation ... make it eligible for selection. // Waiting for confirmation ... make it eligible for selection.
@ -220,7 +220,7 @@ public class ChainSplitTest {
Block b1 = UNITTEST.getGenesisBlock().createNextBlock(coinsTo); Block b1 = UNITTEST.getGenesisBlock().createNextBlock(coinsTo);
chain.add(b1); chain.add(b1);
assertEquals(FIFTY_COINS, wallet.getBalance()); assertEquals(FIFTY_COINS, wallet.getBalance());
LegacyAddress dest = LegacyAddress.fromKey(UNITTEST, new ECKey()); Address dest = LegacyAddress.fromKey(UNITTEST, new ECKey());
Transaction spend = wallet.createSend(dest, FIFTY_COINS); Transaction spend = wallet.createSend(dest, FIFTY_COINS);
// We do NOT confirm the spend here. That means it's not considered to be pending because createSend is // We do NOT confirm the spend here. That means it's not considered to be pending because createSend is
// stateless. For our purposes it is as if some other program with our keys created the tx. // stateless. For our purposes it is as if some other program with our keys created the tx.
@ -311,7 +311,7 @@ public class ChainSplitTest {
chain.add(b1); chain.add(b1);
Transaction t1 = wallet.createSend(someOtherGuy, valueOf(10, 0)); Transaction t1 = wallet.createSend(someOtherGuy, valueOf(10, 0));
LegacyAddress yetAnotherGuy = LegacyAddress.fromKey(UNITTEST, new ECKey()); Address yetAnotherGuy = LegacyAddress.fromKey(UNITTEST, new ECKey());
Transaction t2 = wallet.createSend(yetAnotherGuy, valueOf(20, 0)); Transaction t2 = wallet.createSend(yetAnotherGuy, valueOf(20, 0));
wallet.commitTx(t1); wallet.commitTx(t1);
// Receive t1 as confirmed by the network. // Receive t1 as confirmed by the network.
@ -354,7 +354,7 @@ public class ChainSplitTest {
chain.add(b1); chain.add(b1);
Transaction t1 = checkNotNull(wallet.createSend(someOtherGuy, valueOf(10, 0))); Transaction t1 = checkNotNull(wallet.createSend(someOtherGuy, valueOf(10, 0)));
LegacyAddress yetAnotherGuy = LegacyAddress.fromKey(UNITTEST, new ECKey()); Address yetAnotherGuy = LegacyAddress.fromKey(UNITTEST, new ECKey());
Transaction t2 = checkNotNull(wallet.createSend(yetAnotherGuy, valueOf(20, 0))); Transaction t2 = checkNotNull(wallet.createSend(yetAnotherGuy, valueOf(20, 0)));
wallet.commitTx(t1); wallet.commitTx(t1);
// t1 is still pending ... // t1 is still pending ...

View File

@ -233,9 +233,9 @@ public class ECKeyTest {
// Test vector generated by Bitcoin-Qt. // Test vector generated by Bitcoin-Qt.
String message = "hello"; String message = "hello";
String sigBase64 = "HxNZdo6ggZ41hd3mM3gfJRqOQPZYcO8z8qdX2BwmpbF11CaOQV+QiZGGQxaYOncKoNW61oRuSMMF8udfK54XqI8="; String sigBase64 = "HxNZdo6ggZ41hd3mM3gfJRqOQPZYcO8z8qdX2BwmpbF11CaOQV+QiZGGQxaYOncKoNW61oRuSMMF8udfK54XqI8=";
LegacyAddress expectedAddress = LegacyAddress.fromBase58(MAINNET, "14YPSNPi6NSXnUxtPAsyJSuw3pv7AU3Cag"); Address expectedAddress = LegacyAddress.fromBase58(MAINNET, "14YPSNPi6NSXnUxtPAsyJSuw3pv7AU3Cag");
ECKey key = ECKey.signedMessageToKey(message, sigBase64); ECKey key = ECKey.signedMessageToKey(message, sigBase64);
LegacyAddress gotAddress = LegacyAddress.fromKey(MAINNET, key); Address gotAddress = LegacyAddress.fromKey(MAINNET, key);
assertEquals(expectedAddress, gotAddress); assertEquals(expectedAddress, gotAddress);
} }

View File

@ -245,7 +245,7 @@ public class PeerGroupTest extends TestWithPeerGroup {
Wallet wallet2 = new Wallet(UNITTEST); Wallet wallet2 = new Wallet(UNITTEST);
ECKey key2 = wallet2.freshReceiveKey(); ECKey key2 = wallet2.freshReceiveKey();
LegacyAddress address2 = LegacyAddress.fromKey(UNITTEST, key2); Address address2 = LegacyAddress.fromKey(UNITTEST, key2);
peerGroup.addWallet(wallet2); peerGroup.addWallet(wallet2);
blockChain.addWallet(wallet2); blockChain.addWallet(wallet2);
@ -804,7 +804,7 @@ public class PeerGroupTest extends TestWithPeerGroup {
Coin expectedBalance = Coin.ZERO; Coin expectedBalance = Coin.ZERO;
Block prev = blockStore.getChainHead().getHeader(); Block prev = blockStore.getChainHead().getHeader();
for (ECKey key1 : keys) { for (ECKey key1 : keys) {
LegacyAddress addr = LegacyAddress.fromKey(UNITTEST, key1); Address addr = LegacyAddress.fromKey(UNITTEST, key1);
Block next = FakeTxBuilder.makeSolvedTestBlock(prev, FakeTxBuilder.createFakeTx(UNITTEST, Coin.FIFTY_COINS, addr)); Block next = FakeTxBuilder.makeSolvedTestBlock(prev, FakeTxBuilder.createFakeTx(UNITTEST, Coin.FIFTY_COINS, addr));
expectedBalance = expectedBalance.add(next.getTransactions().get(2).getOutput(0).getValue()); expectedBalance = expectedBalance.add(next.getTransactions().get(2).getOutput(0).getValue());
blocks.add(next); blocks.add(next);

View File

@ -159,7 +159,7 @@ public class TransactionBroadcastTest extends TestWithPeerGroup {
assertEquals(FIFTY_COINS, wallet.getBalance()); assertEquals(FIFTY_COINS, wallet.getBalance());
// Now create a spend, and expect the announcement on p1. // Now create a spend, and expect the announcement on p1.
LegacyAddress dest = LegacyAddress.fromKey(UNITTEST, new ECKey()); Address dest = LegacyAddress.fromKey(UNITTEST, new ECKey());
Wallet.SendResult sendResult = wallet.sendCoins(peerGroup, dest, COIN); Wallet.SendResult sendResult = wallet.sendCoins(peerGroup, dest, COIN);
assertFalse(sendResult.broadcastComplete.isDone()); assertFalse(sendResult.broadcastComplete.isDone());
Transaction t1; Transaction t1;
@ -208,7 +208,7 @@ public class TransactionBroadcastTest extends TestWithPeerGroup {
}); });
// Now create a spend, and expect the announcement on p1. // Now create a spend, and expect the announcement on p1.
LegacyAddress dest = LegacyAddress.fromKey(UNITTEST, new ECKey()); Address dest = LegacyAddress.fromKey(UNITTEST, new ECKey());
Wallet.SendResult sendResult = wallet.sendCoins(peerGroup, dest, COIN); Wallet.SendResult sendResult = wallet.sendCoins(peerGroup, dest, COIN);
assertNotNull(sendResult.tx); assertNotNull(sendResult.tx);
Threading.waitForUserCode(); Threading.waitForUserCode();

View File

@ -38,7 +38,7 @@ public class TransactionInputTest {
public void testStandardWalletDisconnect() throws Exception { public void testStandardWalletDisconnect() throws Exception {
Wallet w = new Wallet(new Context(UNITTEST)); Wallet w = new Wallet(new Context(UNITTEST));
w.setCoinSelector(new AllowUnconfirmedCoinSelector()); w.setCoinSelector(new AllowUnconfirmedCoinSelector());
LegacyAddress a = w.currentReceiveAddress(); Address a = w.currentReceiveAddress();
Transaction tx1 = FakeTxBuilder.createFakeTxWithoutChangeAddress(UNITTEST, Coin.COIN, a); Transaction tx1 = FakeTxBuilder.createFakeTxWithoutChangeAddress(UNITTEST, Coin.COIN, a);
w.receivePending(tx1, null); w.receivePending(tx1, null);
Transaction tx2 = new Transaction(UNITTEST); Transaction tx2 = new Transaction(UNITTEST);
@ -59,7 +59,7 @@ public class TransactionInputTest {
@Test @Test
public void testUTXOWalletDisconnect() throws Exception { public void testUTXOWalletDisconnect() throws Exception {
Wallet w = new Wallet(new Context(UNITTEST)); Wallet w = new Wallet(new Context(UNITTEST));
LegacyAddress a = w.currentReceiveAddress(); Address a = w.currentReceiveAddress();
final UTXO utxo = new UTXO(Sha256Hash.of(new byte[] { 1, 2, 3 }), 1, Coin.COIN, 0, false, final UTXO utxo = new UTXO(Sha256Hash.of(new byte[] { 1, 2, 3 }), 1, Coin.COIN, 0, false,
ScriptBuilder.createOutputScript(a)); ScriptBuilder.createOutputScript(a));
w.setUTXOProvider(new UTXOProvider() { w.setUTXOProvider(new UTXOProvider() {

View File

@ -68,7 +68,7 @@ public class TransactionOutputTest extends TestWithWallet {
@Test @Test
public void testP2SHOutputScript() throws Exception { public void testP2SHOutputScript() throws Exception {
String P2SHAddressString = "35b9vsyH1KoFT5a5KtrKusaCcPLkiSo1tU"; String P2SHAddressString = "35b9vsyH1KoFT5a5KtrKusaCcPLkiSo1tU";
LegacyAddress P2SHAddress = LegacyAddress.fromBase58(MAINNET, P2SHAddressString); Address P2SHAddress = LegacyAddress.fromBase58(MAINNET, P2SHAddressString);
Script script = ScriptBuilder.createOutputScript(P2SHAddress); Script script = ScriptBuilder.createOutputScript(P2SHAddress);
Transaction tx = new Transaction(MAINNET); Transaction tx = new Transaction(MAINNET);
tx.addOutput(Coin.COIN, script); tx.addOutput(Coin.COIN, script);

View File

@ -40,7 +40,7 @@ import static org.junit.Assert.*;
*/ */
public class TransactionTest { public class TransactionTest {
private static final NetworkParameters UNITTEST = UnitTestParams.get(); private static final NetworkParameters UNITTEST = UnitTestParams.get();
private static final LegacyAddress ADDRESS = LegacyAddress.fromKey(UNITTEST, new ECKey()); private static final Address ADDRESS = LegacyAddress.fromKey(UNITTEST, new ECKey());
private Transaction tx; private Transaction tx;
@ -344,7 +344,7 @@ public class TransactionTest {
@Test(expected = ScriptException.class) @Test(expected = ScriptException.class)
public void testAddSignedInputThrowsExceptionWhenScriptIsNotToRawPubKeyAndIsNotToAddress() { public void testAddSignedInputThrowsExceptionWhenScriptIsNotToRawPubKeyAndIsNotToAddress() {
ECKey key = new ECKey(); ECKey key = new ECKey();
LegacyAddress addr = LegacyAddress.fromKey(UNITTEST, key); Address addr = LegacyAddress.fromKey(UNITTEST, key);
Transaction fakeTx = FakeTxBuilder.createFakeTx(UNITTEST, Coin.COIN, addr); Transaction fakeTx = FakeTxBuilder.createFakeTx(UNITTEST, Coin.COIN, addr);
Transaction tx = new Transaction(UNITTEST); Transaction tx = new Transaction(UNITTEST);

View File

@ -38,8 +38,8 @@ public class TxConfidenceTableTest {
Context context = new Context(UNITTEST); Context context = new Context(UNITTEST);
table = context.getConfidenceTable(); table = context.getConfidenceTable();
LegacyAddress to = LegacyAddress.fromKey(UNITTEST, new ECKey()); Address to = LegacyAddress.fromKey(UNITTEST, new ECKey());
LegacyAddress change = LegacyAddress.fromKey(UNITTEST, new ECKey()); Address change = LegacyAddress.fromKey(UNITTEST, new ECKey());
tx1 = FakeTxBuilder.createFakeTxWithChangeAddress(UNITTEST, COIN, to, change); tx1 = FakeTxBuilder.createFakeTxWithChangeAddress(UNITTEST, COIN, to, change);
tx2 = FakeTxBuilder.createFakeTxWithChangeAddress(UNITTEST, COIN, to, change); tx2 = FakeTxBuilder.createFakeTxWithChangeAddress(UNITTEST, COIN, to, change);

View File

@ -16,7 +16,12 @@
package org.bitcoinj.protocols.payments; package org.bitcoinj.protocols.payments;
import org.bitcoinj.core.*; import org.bitcoinj.core.Address;
import org.bitcoinj.core.Coin;
import org.bitcoinj.core.ECKey;
import org.bitcoinj.core.LegacyAddress;
import org.bitcoinj.core.NetworkParameters;
import org.bitcoinj.core.Transaction;
import org.bitcoinj.crypto.X509Utils; import org.bitcoinj.crypto.X509Utils;
import org.bitcoinj.params.TestNet3Params; import org.bitcoinj.params.TestNet3Params;
import org.bitcoinj.params.UnitTestParams; import org.bitcoinj.params.UnitTestParams;
@ -46,7 +51,7 @@ public class PaymentProtocolTest {
// static test data // static test data
private static final Coin AMOUNT = Coin.SATOSHI; private static final Coin AMOUNT = Coin.SATOSHI;
private static final LegacyAddress TO_ADDRESS = LegacyAddress.fromKey(UNITTEST, new ECKey()); private static final Address TO_ADDRESS = LegacyAddress.fromKey(UNITTEST, new ECKey());
private static final String MEMO = "memo"; private static final String MEMO = "memo";
private static final String PAYMENT_URL = "https://example.com"; private static final String PAYMENT_URL = "https://example.com";
private static final byte[] MERCHANT_DATA = { 0, 1, 2 }; private static final byte[] MERCHANT_DATA = { 0, 1, 2 };
@ -125,7 +130,7 @@ public class PaymentProtocolTest {
List<Transaction> transactions = new LinkedList<>(); List<Transaction> transactions = new LinkedList<>();
transactions.add(FakeTxBuilder.createFakeTx(UNITTEST, AMOUNT, TO_ADDRESS)); transactions.add(FakeTxBuilder.createFakeTx(UNITTEST, AMOUNT, TO_ADDRESS));
Coin refundAmount = Coin.SATOSHI; Coin refundAmount = Coin.SATOSHI;
LegacyAddress refundAddress = LegacyAddress.fromKey(UNITTEST, new ECKey()); Address refundAddress = LegacyAddress.fromKey(UNITTEST, new ECKey());
Payment payment = PaymentProtocol.createPaymentMessage(transactions, refundAmount, refundAddress, MEMO, Payment payment = PaymentProtocol.createPaymentMessage(transactions, refundAmount, refundAddress, MEMO,
MERCHANT_DATA); MERCHANT_DATA);
byte[] paymentBytes = payment.toByteArray(); byte[] paymentBytes = payment.toByteArray();

View File

@ -17,7 +17,15 @@
package org.bitcoinj.protocols.payments; package org.bitcoinj.protocols.payments;
import org.bitcoinj.core.*; import org.bitcoinj.core.Address;
import org.bitcoinj.core.Coin;
import org.bitcoinj.core.Context;
import org.bitcoinj.core.ECKey;
import org.bitcoinj.core.LegacyAddress;
import org.bitcoinj.core.NetworkParameters;
import org.bitcoinj.core.Transaction;
import org.bitcoinj.core.TransactionInput;
import org.bitcoinj.core.TransactionOutput;
import org.bitcoinj.crypto.TrustStoreLoader; import org.bitcoinj.crypto.TrustStoreLoader;
import org.bitcoinj.params.MainNetParams; import org.bitcoinj.params.MainNetParams;
import org.bitcoinj.params.TestNet3Params; import org.bitcoinj.params.TestNet3Params;
@ -75,7 +83,7 @@ public class PaymentSessionTest {
tx.addInput(new TransactionInput(TESTNET, tx, outputToMe.getScriptBytes())); tx.addInput(new TransactionInput(TESTNET, tx, outputToMe.getScriptBytes()));
ArrayList<Transaction> txns = new ArrayList<>(); ArrayList<Transaction> txns = new ArrayList<>();
txns.add(tx); txns.add(tx);
LegacyAddress refundAddr = LegacyAddress.fromKey(TESTNET, serverKey); Address refundAddr = LegacyAddress.fromKey(TESTNET, serverKey);
paymentSession.sendPayment(txns, refundAddr, paymentMemo); paymentSession.sendPayment(txns, refundAddr, paymentMemo);
assertEquals(1, paymentSession.getPaymentLog().size()); assertEquals(1, paymentSession.getPaymentLog().size());
assertEquals(simplePaymentUrl, paymentSession.getPaymentLog().get(0).getUrl().toString()); assertEquals(simplePaymentUrl, paymentSession.getPaymentLog().get(0).getUrl().toString());
@ -147,7 +155,7 @@ public class PaymentSessionTest {
tx.addInput(new TransactionInput(TESTNET, tx, outputToMe.getScriptBytes())); tx.addInput(new TransactionInput(TESTNET, tx, outputToMe.getScriptBytes()));
ArrayList<Transaction> txns = new ArrayList<>(); ArrayList<Transaction> txns = new ArrayList<>();
txns.add(tx); txns.add(tx);
LegacyAddress refundAddr = LegacyAddress.fromKey(TESTNET, serverKey); Address refundAddr = LegacyAddress.fromKey(TESTNET, serverKey);
paymentSession.sendPayment(txns, refundAddr, paymentMemo); paymentSession.sendPayment(txns, refundAddr, paymentMemo);
assertEquals(1, paymentSession.getPaymentLog().size()); assertEquals(1, paymentSession.getPaymentLog().size());
} }

View File

@ -80,7 +80,7 @@ public class ScriptTest {
byte[] pubkeyBytes = HEX.decode(pubkeyProg); byte[] pubkeyBytes = HEX.decode(pubkeyProg);
Script pubkey = new Script(pubkeyBytes); Script pubkey = new Script(pubkeyBytes);
assertEquals("DUP HASH160 PUSHDATA(20)[33e81a941e64cda12c6a299ed322ddbdd03f8d0e] EQUALVERIFY CHECKSIG", pubkey.toString()); assertEquals("DUP HASH160 PUSHDATA(20)[33e81a941e64cda12c6a299ed322ddbdd03f8d0e] EQUALVERIFY CHECKSIG", pubkey.toString());
LegacyAddress toAddr = LegacyAddress.fromPubKeyHash(TESTNET, ScriptPattern.extractHashFromPayToPubKeyHash(pubkey)); Address toAddr = LegacyAddress.fromPubKeyHash(TESTNET, ScriptPattern.extractHashFromPayToPubKeyHash(pubkey));
assertEquals("mkFQohBpy2HDXrCwyMrYL5RtfrmeiuuPY2", toAddr.toString()); assertEquals("mkFQohBpy2HDXrCwyMrYL5RtfrmeiuuPY2", toAddr.toString());
} }
@ -112,7 +112,7 @@ public class ScriptTest {
@Test @Test
public void testP2SHOutputScript() throws Exception { public void testP2SHOutputScript() throws Exception {
LegacyAddress p2shAddress = LegacyAddress.fromBase58(MAINNET, "35b9vsyH1KoFT5a5KtrKusaCcPLkiSo1tU"); Address p2shAddress = LegacyAddress.fromBase58(MAINNET, "35b9vsyH1KoFT5a5KtrKusaCcPLkiSo1tU");
assertTrue(ScriptPattern.isPayToScriptHash(ScriptBuilder.createOutputScript(p2shAddress))); assertTrue(ScriptPattern.isPayToScriptHash(ScriptBuilder.createOutputScript(p2shAddress)));
} }
@ -134,7 +134,7 @@ public class ScriptTest {
Transaction transaction = TESTNET.getDefaultSerializer().makeTransaction(bytes); Transaction transaction = TESTNET.getDefaultSerializer().makeTransaction(bytes);
TransactionOutput output = transaction.getOutput(1); TransactionOutput output = transaction.getOutput(1);
Transaction spendTx = new Transaction(TESTNET); Transaction spendTx = new Transaction(TESTNET);
LegacyAddress address = LegacyAddress.fromBase58(TESTNET, "n3CFiCmBXVt5d3HXKQ15EFZyhPz4yj5F3H"); Address address = LegacyAddress.fromBase58(TESTNET, "n3CFiCmBXVt5d3HXKQ15EFZyhPz4yj5F3H");
Script outputScript = ScriptBuilder.createOutputScript(address); Script outputScript = ScriptBuilder.createOutputScript(address);
spendTx.addOutput(output.getValue(), outputScript); spendTx.addOutput(output.getValue(), outputScript);
spendTx.addInput(output); spendTx.addInput(output);
@ -439,13 +439,13 @@ public class ScriptTest {
public void getToAddress() throws Exception { public void getToAddress() throws Exception {
// pay to pubkey // pay to pubkey
ECKey toKey = new ECKey(); ECKey toKey = new ECKey();
LegacyAddress toAddress = LegacyAddress.fromKey(TESTNET, toKey); Address toAddress = LegacyAddress.fromKey(TESTNET, toKey);
assertEquals(toAddress, ScriptBuilder.createOutputScript(toKey).getToAddress(TESTNET, true)); assertEquals(toAddress, ScriptBuilder.createOutputScript(toKey).getToAddress(TESTNET, true));
// pay to pubkey hash // pay to pubkey hash
assertEquals(toAddress, ScriptBuilder.createOutputScript(toAddress).getToAddress(TESTNET, true)); assertEquals(toAddress, ScriptBuilder.createOutputScript(toAddress).getToAddress(TESTNET, true));
// pay to script hash // pay to script hash
Script p2shScript = ScriptBuilder.createP2SHOutputScript(new byte[20]); Script p2shScript = ScriptBuilder.createP2SHOutputScript(new byte[20]);
LegacyAddress scriptAddress = LegacyAddress.fromScriptHash(TESTNET, Address scriptAddress = LegacyAddress.fromScriptHash(TESTNET,
ScriptPattern.extractHashFromPayToScriptHash(p2shScript)); ScriptPattern.extractHashFromPayToScriptHash(p2shScript));
assertEquals(scriptAddress, p2shScript.getToAddress(TESTNET, true)); assertEquals(scriptAddress, p2shScript.getToAddress(TESTNET, true));
} }

View File

@ -16,7 +16,11 @@
package org.bitcoinj.store; package org.bitcoinj.store;
import org.bitcoinj.core.*; import org.bitcoinj.core.Address;
import org.bitcoinj.core.Context;
import org.bitcoinj.core.LegacyAddress;
import org.bitcoinj.core.NetworkParameters;
import org.bitcoinj.core.StoredBlock;
import org.bitcoinj.params.*; import org.bitcoinj.params.*;
import org.junit.*; import org.junit.*;
@ -42,7 +46,7 @@ public class LevelDBBlockStoreTest {
assertEquals(0, genesis.getHeight()); assertEquals(0, genesis.getHeight());
// Build a new block. // Build a new block.
LegacyAddress to = LegacyAddress.fromBase58(UNITTEST, "mrj2K6txjo2QBcSmuAzHj4nD1oXSEJE1Qo"); Address to = LegacyAddress.fromBase58(UNITTEST, "mrj2K6txjo2QBcSmuAzHj4nD1oXSEJE1Qo");
StoredBlock b1 = genesis.build(genesis.getHeader().createNextBlock(to).cloneAsHeader()); StoredBlock b1 = genesis.build(genesis.getHeader().createNextBlock(to).cloneAsHeader());
store.put(b1); store.put(b1);
store.setChainHead(b1); store.setChainHead(b1);

View File

@ -16,8 +16,9 @@
package org.bitcoinj.store; package org.bitcoinj.store;
import org.bitcoinj.core.LegacyAddress; import org.bitcoinj.core.Address;
import org.bitcoinj.core.ECKey; import org.bitcoinj.core.ECKey;
import org.bitcoinj.core.LegacyAddress;
import org.bitcoinj.core.NetworkParameters; import org.bitcoinj.core.NetworkParameters;
import org.bitcoinj.core.StoredBlock; import org.bitcoinj.core.StoredBlock;
import org.bitcoinj.params.UnitTestParams; import org.bitcoinj.params.UnitTestParams;
@ -37,7 +38,7 @@ public class SPVBlockStoreTest {
f.deleteOnExit(); f.deleteOnExit();
SPVBlockStore store = new SPVBlockStore(UNITTEST, f); SPVBlockStore store = new SPVBlockStore(UNITTEST, f);
LegacyAddress to = LegacyAddress.fromKey(UNITTEST, new ECKey()); Address to = LegacyAddress.fromKey(UNITTEST, new ECKey());
// Check the first block in a new store is the genesis block. // Check the first block in a new store is the genesis block.
StoredBlock genesis = store.getChainHead(); StoredBlock genesis = store.getChainHead();
assertEquals(UNITTEST.getGenesisBlock(), genesis.getHeader()); assertEquals(UNITTEST.getGenesisBlock(), genesis.getHeader());

View File

@ -17,9 +17,23 @@
package org.bitcoinj.store; package org.bitcoinj.store;
import org.bitcoinj.core.*; import org.bitcoinj.core.Address;
import org.bitcoinj.core.Block;
import org.bitcoinj.core.BlockChain;
import org.bitcoinj.core.BlockTest;
import org.bitcoinj.core.Coin;
import org.bitcoinj.core.Context;
import org.bitcoinj.core.ECKey;
import org.bitcoinj.core.LegacyAddress;
import org.bitcoinj.core.NetworkParameters;
import org.bitcoinj.core.PeerAddress;
import org.bitcoinj.core.Sha256Hash;
import org.bitcoinj.core.Transaction;
import org.bitcoinj.core.Transaction.Purpose; import org.bitcoinj.core.Transaction.Purpose;
import org.bitcoinj.core.TransactionConfidence;
import org.bitcoinj.core.TransactionConfidence.ConfidenceType; import org.bitcoinj.core.TransactionConfidence.ConfidenceType;
import org.bitcoinj.core.TransactionInput;
import org.bitcoinj.core.Utils;
import org.bitcoinj.crypto.DeterministicKey; import org.bitcoinj.crypto.DeterministicKey;
import org.bitcoinj.params.MainNetParams; import org.bitcoinj.params.MainNetParams;
import org.bitcoinj.params.UnitTestParams; import org.bitcoinj.params.UnitTestParams;
@ -65,7 +79,7 @@ public class WalletProtobufSerializerTest {
private ECKey myKey; private ECKey myKey;
private ECKey myWatchedKey; private ECKey myWatchedKey;
private LegacyAddress myAddress; private Address myAddress;
private Wallet myWallet; private Wallet myWallet;
public static String WALLET_DESCRIPTION = "The quick brown fox lives in \u4f26\u6566"; // Beijing in Chinese public static String WALLET_DESCRIPTION = "The quick brown fox lives in \u4f26\u6566"; // Beijing in Chinese

View File

@ -219,7 +219,7 @@ public class FakeTxBuilder {
public static DoubleSpends createFakeDoubleSpendTxns(NetworkParameters params, Address to) { public static DoubleSpends createFakeDoubleSpendTxns(NetworkParameters params, Address to) {
DoubleSpends doubleSpends = new DoubleSpends(); DoubleSpends doubleSpends = new DoubleSpends();
Coin value = COIN; Coin value = COIN;
LegacyAddress someBadGuy = LegacyAddress.fromKey(params, new ECKey()); Address someBadGuy = LegacyAddress.fromKey(params, new ECKey());
doubleSpends.prevTx = new Transaction(params); doubleSpends.prevTx = new Transaction(params);
TransactionOutput prevOut = new TransactionOutput(params, doubleSpends.prevTx, value, someBadGuy); TransactionOutput prevOut = new TransactionOutput(params, doubleSpends.prevTx, value, someBadGuy);
@ -261,7 +261,7 @@ public class FakeTxBuilder {
Transaction... transactions) { Transaction... transactions) {
try { try {
Block previousBlock = previousStoredBlock.getHeader(); Block previousBlock = previousStoredBlock.getHeader();
LegacyAddress to = LegacyAddress.fromKey(previousBlock.getParams(), new ECKey()); Address to = LegacyAddress.fromKey(previousBlock.getParams(), new ECKey());
Block b = previousBlock.createNextBlock(to, version, timeSeconds, height); Block b = previousBlock.createNextBlock(to, version, timeSeconds, height);
// Coinbase tx was already added. // Coinbase tx was already added.
for (Transaction tx : transactions) { for (Transaction tx : transactions) {
@ -313,7 +313,7 @@ public class FakeTxBuilder {
} }
public static Block makeSolvedTestBlock(Block prev, Transaction... transactions) throws BlockStoreException { public static Block makeSolvedTestBlock(Block prev, Transaction... transactions) throws BlockStoreException {
LegacyAddress to = LegacyAddress.fromKey(prev.getParams(), new ECKey()); Address to = LegacyAddress.fromKey(prev.getParams(), new ECKey());
Block b = prev.createNextBlock(to); Block b = prev.createNextBlock(to);
// Coinbase tx already exists. // Coinbase tx already exists.
for (Transaction tx : transactions) { for (Transaction tx : transactions) {

View File

@ -54,7 +54,7 @@ public class TestWithNetworkConnections {
protected BlockChain blockChain; protected BlockChain blockChain;
protected Wallet wallet; protected Wallet wallet;
protected ECKey key; protected ECKey key;
protected LegacyAddress address; protected Address address;
protected SocketAddress socketAddress; protected SocketAddress socketAddress;
private NioServer[] peerServers = new NioServer[PEER_SERVERS]; private NioServer[] peerServers = new NioServer[PEER_SERVERS];

View File

@ -16,7 +16,17 @@
package org.bitcoinj.testing; package org.bitcoinj.testing;
import org.bitcoinj.core.*; import org.bitcoinj.core.AbstractBlockChain;
import org.bitcoinj.core.Address;
import org.bitcoinj.core.Block;
import org.bitcoinj.core.BlockChain;
import org.bitcoinj.core.Coin;
import org.bitcoinj.core.Context;
import org.bitcoinj.core.ECKey;
import org.bitcoinj.core.LegacyAddress;
import org.bitcoinj.core.NetworkParameters;
import org.bitcoinj.core.Transaction;
import org.bitcoinj.core.VerificationException;
import org.bitcoinj.params.MainNetParams; import org.bitcoinj.params.MainNetParams;
import org.bitcoinj.params.UnitTestParams; import org.bitcoinj.params.UnitTestParams;
import org.bitcoinj.store.BlockStore; import org.bitcoinj.store.BlockStore;
@ -42,7 +52,7 @@ public class TestWithWallet {
protected static final NetworkParameters MAINNET = MainNetParams.get(); protected static final NetworkParameters MAINNET = MainNetParams.get();
protected ECKey myKey; protected ECKey myKey;
protected LegacyAddress myAddress; protected Address myAddress;
protected Wallet wallet; protected Wallet wallet;
protected BlockChain chain; protected BlockChain chain;
protected BlockStore blockStore; protected BlockStore blockStore;
@ -82,7 +92,7 @@ public class TestWithWallet {
} }
@Nullable @Nullable
protected Transaction sendMoneyToWallet(Wallet wallet, AbstractBlockChain.NewBlockType type, Coin value, LegacyAddress toAddress) throws VerificationException { protected Transaction sendMoneyToWallet(Wallet wallet, AbstractBlockChain.NewBlockType type, Coin value, Address toAddress) throws VerificationException {
return sendMoneyToWallet(wallet, type, createFakeTx(UNITTEST, value, toAddress)); return sendMoneyToWallet(wallet, type, createFakeTx(UNITTEST, value, toAddress));
} }
@ -102,7 +112,7 @@ public class TestWithWallet {
} }
@Nullable @Nullable
protected Transaction sendMoneyToWallet(AbstractBlockChain.NewBlockType type, Coin value, LegacyAddress toAddress) throws VerificationException { protected Transaction sendMoneyToWallet(AbstractBlockChain.NewBlockType type, Coin value, Address toAddress) throws VerificationException {
return sendMoneyToWallet(this.wallet, type, value, toAddress); return sendMoneyToWallet(this.wallet, type, value, toAddress);
} }

View File

@ -16,6 +16,7 @@
package org.bitcoinj.uri; package org.bitcoinj.uri;
import org.bitcoinj.core.Address;
import org.bitcoinj.core.LegacyAddress; import org.bitcoinj.core.LegacyAddress;
import org.bitcoinj.params.MainNetParams; import org.bitcoinj.params.MainNetParams;
import org.bitcoinj.params.TestNet3Params; import org.bitcoinj.params.TestNet3Params;
@ -39,7 +40,7 @@ public class BitcoinURITest {
@Test @Test
public void testConvertToBitcoinURI() throws Exception { public void testConvertToBitcoinURI() throws Exception {
LegacyAddress goodAddress = LegacyAddress.fromBase58(MAINNET, MAINNET_GOOD_ADDRESS); Address goodAddress = LegacyAddress.fromBase58(MAINNET, MAINNET_GOOD_ADDRESS);
// simple example // simple example
assertEquals("bitcoin:" + MAINNET_GOOD_ADDRESS + "?amount=12.34&label=Hello&message=AMessage", BitcoinURI.convertToBitcoinURI(goodAddress, parseCoin("12.34"), "Hello", "AMessage")); assertEquals("bitcoin:" + MAINNET_GOOD_ADDRESS + "?amount=12.34&label=Hello&message=AMessage", BitcoinURI.convertToBitcoinURI(goodAddress, parseCoin("12.34"), "Hello", "AMessage"));

View File

@ -17,7 +17,13 @@
package org.bitcoinj.wallet; package org.bitcoinj.wallet;
import org.bitcoinj.core.*; import org.bitcoinj.core.Address;
import org.bitcoinj.core.BloomFilter;
import org.bitcoinj.core.ECKey;
import org.bitcoinj.core.LegacyAddress;
import org.bitcoinj.core.NetworkParameters;
import org.bitcoinj.core.Sha256Hash;
import org.bitcoinj.core.Utils;
import org.bitcoinj.crypto.*; import org.bitcoinj.crypto.*;
import org.bitcoinj.params.MainNetParams; import org.bitcoinj.params.MainNetParams;
import org.bitcoinj.params.UnitTestParams; import org.bitcoinj.params.UnitTestParams;
@ -72,7 +78,7 @@ public class DeterministicKeyChainTest {
ECKey key2 = chain.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS); ECKey key2 = chain.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS);
assertFalse(key2.isPubKeyOnly()); assertFalse(key2.isPubKeyOnly());
final LegacyAddress address = LegacyAddress.fromBase58(UNITTEST, "n1bQNoEx8uhmCzzA5JPG6sFdtsUQhwiQJV"); final Address address = LegacyAddress.fromBase58(UNITTEST, "n1bQNoEx8uhmCzzA5JPG6sFdtsUQhwiQJV");
assertEquals(address, LegacyAddress.fromKey(UNITTEST, key1)); assertEquals(address, LegacyAddress.fromKey(UNITTEST, key1));
assertEquals("mnHUcqUVvrfi5kAaXJDQzBb9HsWs78b42R", LegacyAddress.fromKey(UNITTEST, key2).toString()); assertEquals("mnHUcqUVvrfi5kAaXJDQzBb9HsWs78b42R", LegacyAddress.fromKey(UNITTEST, key2).toString());
assertEquals(key1, chain.findKeyFromPubHash(address.getHash())); assertEquals(key1, chain.findKeyFromPubHash(address.getHash()));
@ -103,7 +109,7 @@ public class DeterministicKeyChainTest {
ECKey key1 = chain1.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS); ECKey key1 = chain1.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS);
ECKey key2 = chain1.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS); ECKey key2 = chain1.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS);
final LegacyAddress address = LegacyAddress.fromBase58(UNITTEST, "n2nHHRHs7TiZScTuVhZUkzZfTfVgGYwy6X"); final Address address = LegacyAddress.fromBase58(UNITTEST, "n2nHHRHs7TiZScTuVhZUkzZfTfVgGYwy6X");
assertEquals(address, LegacyAddress.fromKey(UNITTEST, key1)); assertEquals(address, LegacyAddress.fromKey(UNITTEST, key1));
assertEquals("mnp2j9za5zMuz44vNxrJCXXhZsCdh89QXn", LegacyAddress.fromKey(UNITTEST, key2).toString()); assertEquals("mnp2j9za5zMuz44vNxrJCXXhZsCdh89QXn", LegacyAddress.fromKey(UNITTEST, key2).toString());
assertEquals(key1, chain1.findKeyFromPubHash(address.getHash())); assertEquals(key1, chain1.findKeyFromPubHash(address.getHash()));
@ -137,7 +143,7 @@ public class DeterministicKeyChainTest {
DeterministicKeyChain chain1 = new AccountOneChain(ENTROPY, "", secs); DeterministicKeyChain chain1 = new AccountOneChain(ENTROPY, "", secs);
ECKey key1 = chain1.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS); ECKey key1 = chain1.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS);
final LegacyAddress address = LegacyAddress.fromBase58(UNITTEST, "n2nHHRHs7TiZScTuVhZUkzZfTfVgGYwy6X"); final Address address = LegacyAddress.fromBase58(UNITTEST, "n2nHHRHs7TiZScTuVhZUkzZfTfVgGYwy6X");
assertEquals(address, LegacyAddress.fromKey(UNITTEST, key1)); assertEquals(address, LegacyAddress.fromKey(UNITTEST, key1));
DeterministicKey watching = chain1.getWatchingKey(); DeterministicKey watching = chain1.getWatchingKey();

View File

@ -16,7 +16,12 @@
package org.bitcoinj.wallet; package org.bitcoinj.wallet;
import org.bitcoinj.core.*; import org.bitcoinj.core.Address;
import org.bitcoinj.core.BloomFilter;
import org.bitcoinj.core.ECKey;
import org.bitcoinj.core.NetworkParameters;
import org.bitcoinj.core.Sha256Hash;
import org.bitcoinj.core.Utils;
import org.bitcoinj.crypto.*; import org.bitcoinj.crypto.*;
import org.bitcoinj.params.MainNetParams; import org.bitcoinj.params.MainNetParams;
import org.bitcoinj.script.Script.ScriptType; import org.bitcoinj.script.Script.ScriptType;
@ -170,19 +175,19 @@ public class KeyChainGroupTest {
@Test @Test
public void currentP2SHAddress() throws Exception { public void currentP2SHAddress() throws Exception {
group = createMarriedKeyChainGroup(); group = createMarriedKeyChainGroup();
LegacyAddress a1 = group.currentAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS); Address a1 = group.currentAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
assertEquals(ScriptType.P2SH, a1.getOutputScriptType()); assertEquals(ScriptType.P2SH, a1.getOutputScriptType());
LegacyAddress a2 = group.currentAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS); Address a2 = group.currentAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
assertEquals(a1, a2); assertEquals(a1, a2);
LegacyAddress a3 = group.currentAddress(KeyChain.KeyPurpose.CHANGE); Address a3 = group.currentAddress(KeyChain.KeyPurpose.CHANGE);
assertNotEquals(a2, a3); assertNotEquals(a2, a3);
} }
@Test @Test
public void freshAddress() throws Exception { public void freshAddress() throws Exception {
group = createMarriedKeyChainGroup(); group = createMarriedKeyChainGroup();
LegacyAddress a1 = group.freshAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS); Address a1 = group.freshAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
LegacyAddress a2 = group.freshAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS); Address a2 = group.freshAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
assertEquals(ScriptType.P2SH, a1.getOutputScriptType()); assertEquals(ScriptType.P2SH, a1.getOutputScriptType());
assertNotEquals(a1, a2); assertNotEquals(a1, a2);
group.getBloomFilterElementCount(); group.getBloomFilterElementCount();
@ -190,7 +195,7 @@ public class KeyChainGroupTest {
+ (2 - group.getLookaheadThreshold()) // keys issued + (2 - group.getLookaheadThreshold()) // keys issued
+ group.getActiveKeyChain().getAccountPath().size() + 3 /* master, account, int, ext */, group.numKeys()); + group.getActiveKeyChain().getAccountPath().size() + 3 /* master, account, int, ext */, group.numKeys());
LegacyAddress a3 = group.currentAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS); Address a3 = group.currentAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
assertEquals(a2, a3); assertEquals(a2, a3);
} }
@ -202,7 +207,7 @@ public class KeyChainGroupTest {
assertNull(group.findRedeemDataFromScriptHash(new ECKey().getPubKey())); assertNull(group.findRedeemDataFromScriptHash(new ECKey().getPubKey()));
// test our script hash // test our script hash
LegacyAddress address = group.currentAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS); Address address = group.currentAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
RedeemData redeemData = group.findRedeemDataFromScriptHash(address.getHash()); RedeemData redeemData = group.findRedeemDataFromScriptHash(address.getHash());
assertNotNull(redeemData); assertNotNull(redeemData);
assertNotNull(redeemData.redeemScript); assertNotNull(redeemData.redeemScript);
@ -332,7 +337,7 @@ public class KeyChainGroupTest {
@Test @Test
public void findRedeemScriptFromPubHash() throws Exception { public void findRedeemScriptFromPubHash() throws Exception {
group = createMarriedKeyChainGroup(); group = createMarriedKeyChainGroup();
LegacyAddress address = group.freshAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS); Address address = group.freshAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
assertTrue(group.findRedeemDataFromScriptHash(address.getHash()) != null); assertTrue(group.findRedeemDataFromScriptHash(address.getHash()) != null);
group.getBloomFilterElementCount(); group.getBloomFilterElementCount();
KeyChainGroup group2 = createMarriedKeyChainGroup(); KeyChainGroup group2 = createMarriedKeyChainGroup();
@ -352,17 +357,17 @@ public class KeyChainGroupTest {
int bufferSize = group.getLookaheadSize() + group.getLookaheadThreshold(); int bufferSize = group.getLookaheadSize() + group.getLookaheadThreshold();
int expected = bufferSize * 2 /* chains */ * 2 /* elements */; int expected = bufferSize * 2 /* chains */ * 2 /* elements */;
assertEquals(expected, group.getBloomFilterElementCount()); assertEquals(expected, group.getBloomFilterElementCount());
LegacyAddress address1 = group.freshAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS); Address address1 = group.freshAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
assertEquals(expected, group.getBloomFilterElementCount()); assertEquals(expected, group.getBloomFilterElementCount());
BloomFilter filter = group.getBloomFilter(expected + 2, 0.001, (long)(Math.random() * Long.MAX_VALUE)); BloomFilter filter = group.getBloomFilter(expected + 2, 0.001, (long)(Math.random() * Long.MAX_VALUE));
assertTrue(filter.contains(address1.getHash())); assertTrue(filter.contains(address1.getHash()));
LegacyAddress address2 = group.freshAddress(KeyChain.KeyPurpose.CHANGE); Address address2 = group.freshAddress(KeyChain.KeyPurpose.CHANGE);
assertTrue(filter.contains(address2.getHash())); assertTrue(filter.contains(address2.getHash()));
// Check that the filter contains the lookahead buffer. // Check that the filter contains the lookahead buffer.
for (int i = 0; i < bufferSize - 1 /* issued address */; i++) { for (int i = 0; i < bufferSize - 1 /* issued address */; i++) {
LegacyAddress address = group.freshAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS); Address address = group.freshAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
assertTrue("key " + i, filter.contains(address.getHash())); assertTrue("key " + i, filter.contains(address.getHash()));
} }
// We ran ahead of the lookahead buffer. // We ran ahead of the lookahead buffer.
@ -463,7 +468,7 @@ public class KeyChainGroupTest {
@Test @Test
public void serializeMarried() throws Exception { public void serializeMarried() throws Exception {
group = createMarriedKeyChainGroup(); group = createMarriedKeyChainGroup();
LegacyAddress address1 = group.currentAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS); Address address1 = group.currentAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
assertTrue(group.isMarried()); assertTrue(group.isMarried());
assertEquals(2, group.getActiveKeyChain().getSigsRequiredToSpend()); assertEquals(2, group.getActiveKeyChain().getSigsRequiredToSpend());
@ -471,7 +476,7 @@ public class KeyChainGroupTest {
KeyChainGroup group2 = KeyChainGroup.fromProtobufUnencrypted(MAINNET, protoKeys); KeyChainGroup group2 = KeyChainGroup.fromProtobufUnencrypted(MAINNET, protoKeys);
assertTrue(group2.isMarried()); assertTrue(group2.isMarried());
assertEquals(2, group.getActiveKeyChain().getSigsRequiredToSpend()); assertEquals(2, group.getActiveKeyChain().getSigsRequiredToSpend());
LegacyAddress address2 = group2.currentAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS); Address address2 = group2.currentAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
assertEquals(address1, address2); assertEquals(address1, address2);
} }
@ -579,11 +584,11 @@ public class KeyChainGroupTest {
@Test @Test
public void markAsUsed() throws Exception { public void markAsUsed() throws Exception {
LegacyAddress addr1 = group.currentAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS); Address addr1 = group.currentAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
LegacyAddress addr2 = group.currentAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS); Address addr2 = group.currentAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
assertEquals(addr1, addr2); assertEquals(addr1, addr2);
group.markPubKeyHashAsUsed(addr1.getHash()); group.markPubKeyHashAsUsed(addr1.getHash());
LegacyAddress addr3 = group.currentAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS); Address addr3 = group.currentAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
assertNotEquals(addr2, addr3); assertNotEquals(addr2, addr3);
} }

View File

@ -20,12 +20,12 @@ package org.bitcoinj.wallet;
import org.bitcoinj.core.listeners.TransactionConfidenceEventListener; import org.bitcoinj.core.listeners.TransactionConfidenceEventListener;
import org.bitcoinj.core.AbstractBlockChain; import org.bitcoinj.core.AbstractBlockChain;
import org.bitcoinj.core.Address; import org.bitcoinj.core.Address;
import org.bitcoinj.core.LegacyAddress;
import org.bitcoinj.core.Block; import org.bitcoinj.core.Block;
import org.bitcoinj.core.BlockChain; import org.bitcoinj.core.BlockChain;
import org.bitcoinj.core.Coin; import org.bitcoinj.core.Coin;
import org.bitcoinj.core.ECKey; import org.bitcoinj.core.ECKey;
import org.bitcoinj.core.InsufficientMoneyException; import org.bitcoinj.core.InsufficientMoneyException;
import org.bitcoinj.core.LegacyAddress;
import org.bitcoinj.core.PeerAddress; import org.bitcoinj.core.PeerAddress;
import org.bitcoinj.core.Sha256Hash; import org.bitcoinj.core.Sha256Hash;
import org.bitcoinj.core.StoredBlock; import org.bitcoinj.core.StoredBlock;
@ -96,7 +96,7 @@ public class WalletTest extends TestWithWallet {
private static final CharSequence PASSWORD1 = "my helicopter contains eels"; private static final CharSequence PASSWORD1 = "my helicopter contains eels";
private static final CharSequence WRONG_PASSWORD = "nothing noone nobody nowhere"; private static final CharSequence WRONG_PASSWORD = "nothing noone nobody nowhere";
private final LegacyAddress OTHER_ADDRESS = LegacyAddress.fromKey(UNITTEST, new ECKey()); private final Address OTHER_ADDRESS = LegacyAddress.fromKey(UNITTEST, new ECKey());
@Before @Before
@Override @Override
@ -153,7 +153,7 @@ public class WalletTest extends TestWithWallet {
@Test @Test
public void basicSpendingToP2SH() throws Exception { public void basicSpendingToP2SH() throws Exception {
LegacyAddress destination = LegacyAddress.fromScriptHash(UNITTEST, HEX.decode("4a22c3c4cbb31e4d03b15550636762bda0baf85a")); Address destination = LegacyAddress.fromScriptHash(UNITTEST, HEX.decode("4a22c3c4cbb31e4d03b15550636762bda0baf85a"));
basicSpendingCommon(wallet, myAddress, destination, null); basicSpendingCommon(wallet, myAddress, destination, null);
} }
@ -161,7 +161,7 @@ public class WalletTest extends TestWithWallet {
public void basicSpendingWithEncryptedWallet() throws Exception { public void basicSpendingWithEncryptedWallet() throws Exception {
Wallet encryptedWallet = new Wallet(UNITTEST); Wallet encryptedWallet = new Wallet(UNITTEST);
encryptedWallet.encrypt(PASSWORD1); encryptedWallet.encrypt(PASSWORD1);
LegacyAddress myEncryptedAddress = LegacyAddress.fromKey(UNITTEST, encryptedWallet.freshReceiveKey()); Address myEncryptedAddress = LegacyAddress.fromKey(UNITTEST, encryptedWallet.freshReceiveKey());
basicSpendingCommon(encryptedWallet, myEncryptedAddress, OTHER_ADDRESS, encryptedWallet); basicSpendingCommon(encryptedWallet, myEncryptedAddress, OTHER_ADDRESS, encryptedWallet);
} }
@ -224,7 +224,7 @@ public class WalletTest extends TestWithWallet {
} }
} }
private Transaction cleanupCommon(LegacyAddress destination) throws Exception { private Transaction cleanupCommon(Address destination) throws Exception {
receiveATransaction(wallet, myAddress); receiveATransaction(wallet, myAddress);
Coin v2 = valueOf(0, 50); Coin v2 = valueOf(0, 50);
@ -297,7 +297,7 @@ public class WalletTest extends TestWithWallet {
assertEquals(ZERO, wallet.getBalance(Wallet.BalanceType.ESTIMATED)); assertEquals(ZERO, wallet.getBalance(Wallet.BalanceType.ESTIMATED));
} }
private void basicSpendingCommon(Wallet wallet, LegacyAddress toAddress, LegacyAddress destination, Wallet encryptedWallet) throws Exception { private void basicSpendingCommon(Wallet wallet, Address toAddress, Address destination, Wallet encryptedWallet) throws Exception {
// We'll set up a wallet that receives a coin, then sends a coin of lesser value and keeps the change. We // We'll set up a wallet that receives a coin, then sends a coin of lesser value and keeps the change. We
// will attach a small fee. Because the Bitcoin protocol makes it difficult to determine the fee of an // will attach a small fee. Because the Bitcoin protocol makes it difficult to determine the fee of an
// arbitrary transaction in isolation, we'll check that the fee was set by examining the size of the change. // arbitrary transaction in isolation, we'll check that the fee was set by examining the size of the change.
@ -378,11 +378,11 @@ public class WalletTest extends TestWithWallet {
assertNotEquals(unspents2, wallet.getUnspents()); assertNotEquals(unspents2, wallet.getUnspents());
} }
private void receiveATransaction(Wallet wallet, LegacyAddress toAddress) throws Exception { private void receiveATransaction(Wallet wallet, Address toAddress) throws Exception {
receiveATransactionAmount(wallet, toAddress, COIN); receiveATransactionAmount(wallet, toAddress, COIN);
} }
private void receiveATransactionAmount(Wallet wallet, LegacyAddress toAddress, Coin amount) { private void receiveATransactionAmount(Wallet wallet, Address toAddress, Coin amount) {
final ListenableFuture<Coin> availFuture = wallet.getBalanceFuture(amount, Wallet.BalanceType.AVAILABLE); final ListenableFuture<Coin> availFuture = wallet.getBalanceFuture(amount, Wallet.BalanceType.AVAILABLE);
final ListenableFuture<Coin> estimatedFuture = wallet.getBalanceFuture(amount, Wallet.BalanceType.ESTIMATED); final ListenableFuture<Coin> estimatedFuture = wallet.getBalanceFuture(amount, Wallet.BalanceType.ESTIMATED);
assertFalse(availFuture.isDone()); assertFalse(availFuture.isDone());
@ -411,7 +411,7 @@ public class WalletTest extends TestWithWallet {
assertTrue(depthFuture.isDone()); assertTrue(depthFuture.isDone());
} }
private void basicSanityChecks(Wallet wallet, Transaction t, LegacyAddress destination) throws VerificationException { private void basicSanityChecks(Wallet wallet, Transaction t, Address destination) throws VerificationException {
assertEquals("Wrong number of tx inputs", 1, t.getInputs().size()); assertEquals("Wrong number of tx inputs", 1, t.getInputs().size());
assertEquals("Wrong number of tx outputs",2, t.getOutputs().size()); assertEquals("Wrong number of tx outputs",2, t.getOutputs().size());
assertEquals(destination, t.getOutput(0).getScriptPubKey().getToAddress(UNITTEST)); assertEquals(destination, t.getOutput(0).getScriptPubKey().getToAddress(UNITTEST));
@ -780,7 +780,7 @@ public class WalletTest extends TestWithWallet {
// Create a send to a merchant of all our coins. // Create a send to a merchant of all our coins.
Transaction send1 = wallet.createSend(OTHER_ADDRESS, valueOf(2, 90)); Transaction send1 = wallet.createSend(OTHER_ADDRESS, valueOf(2, 90));
// Create a double spend of just the first one. // Create a double spend of just the first one.
LegacyAddress BAD_GUY = LegacyAddress.fromKey(UNITTEST, new ECKey()); Address BAD_GUY = LegacyAddress.fromKey(UNITTEST, new ECKey());
Transaction send2 = wallet.createSend(BAD_GUY, COIN); Transaction send2 = wallet.createSend(BAD_GUY, COIN);
send2 = UNITTEST.getDefaultSerializer().makeTransaction(send2.bitcoinSerialize()); send2 = UNITTEST.getDefaultSerializer().makeTransaction(send2.bitcoinSerialize());
// Broadcast send1, it's now pending. // Broadcast send1, it's now pending.
@ -874,7 +874,7 @@ public class WalletTest extends TestWithWallet {
// Create a send to a merchant. // Create a send to a merchant.
Transaction send1 = wallet.createSend(OTHER_ADDRESS, valueOf(0, 50)); Transaction send1 = wallet.createSend(OTHER_ADDRESS, valueOf(0, 50));
// Create a double spend. // Create a double spend.
LegacyAddress BAD_GUY = LegacyAddress.fromKey(UNITTEST, new ECKey()); Address BAD_GUY = LegacyAddress.fromKey(UNITTEST, new ECKey());
Transaction send2 = wallet.createSend(BAD_GUY, valueOf(0, 50)); Transaction send2 = wallet.createSend(BAD_GUY, valueOf(0, 50));
send2 = UNITTEST.getDefaultSerializer().makeTransaction(send2.bitcoinSerialize()); send2 = UNITTEST.getDefaultSerializer().makeTransaction(send2.bitcoinSerialize());
// Broadcast send1. // Broadcast send1.
@ -1409,7 +1409,7 @@ public class WalletTest extends TestWithWallet {
Coin nanos = COIN; Coin nanos = COIN;
// Create two transactions that share the same input tx. // Create two transactions that share the same input tx.
LegacyAddress badGuy = LegacyAddress.fromKey(UNITTEST, new ECKey()); Address badGuy = LegacyAddress.fromKey(UNITTEST, new ECKey());
Transaction doubleSpentTx = new Transaction(UNITTEST); Transaction doubleSpentTx = new Transaction(UNITTEST);
TransactionOutput doubleSpentOut = new TransactionOutput(UNITTEST, doubleSpentTx, nanos, badGuy); TransactionOutput doubleSpentOut = new TransactionOutput(UNITTEST, doubleSpentTx, nanos, badGuy);
doubleSpentTx.addOutput(doubleSpentOut); doubleSpentTx.addOutput(doubleSpentOut);
@ -1645,7 +1645,7 @@ public class WalletTest extends TestWithWallet {
@Test @Test
public void watchingScripts() throws Exception { public void watchingScripts() throws Exception {
// Verify that pending transactions to watched addresses are relevant // Verify that pending transactions to watched addresses are relevant
LegacyAddress watchedAddress = LegacyAddress.fromKey(UNITTEST, new ECKey()); Address watchedAddress = LegacyAddress.fromKey(UNITTEST, new ECKey());
wallet.addWatchedAddress(watchedAddress); wallet.addWatchedAddress(watchedAddress);
Coin value = valueOf(5, 0); Coin value = valueOf(5, 0);
Transaction t1 = createFakeTx(UNITTEST, value, watchedAddress); Transaction t1 = createFakeTx(UNITTEST, value, watchedAddress);
@ -1655,7 +1655,7 @@ public class WalletTest extends TestWithWallet {
@Test(expected = InsufficientMoneyException.class) @Test(expected = InsufficientMoneyException.class)
public void watchingScriptsConfirmed() throws Exception { public void watchingScriptsConfirmed() throws Exception {
LegacyAddress watchedAddress = LegacyAddress.fromKey(UNITTEST, new ECKey()); Address watchedAddress = LegacyAddress.fromKey(UNITTEST, new ECKey());
wallet.addWatchedAddress(watchedAddress); wallet.addWatchedAddress(watchedAddress);
sendMoneyToWallet(BlockChain.NewBlockType.BEST_CHAIN, CENT, watchedAddress); sendMoneyToWallet(BlockChain.NewBlockType.BEST_CHAIN, CENT, watchedAddress);
assertEquals(CENT, wallet.getBalance()); assertEquals(CENT, wallet.getBalance());
@ -1668,7 +1668,7 @@ public class WalletTest extends TestWithWallet {
public void watchingScriptsSentFrom() throws Exception { public void watchingScriptsSentFrom() throws Exception {
int baseElements = wallet.getBloomFilterElementCount(); int baseElements = wallet.getBloomFilterElementCount();
LegacyAddress watchedAddress = LegacyAddress.fromKey(UNITTEST, new ECKey()); Address watchedAddress = LegacyAddress.fromKey(UNITTEST, new ECKey());
wallet.addWatchedAddress(watchedAddress); wallet.addWatchedAddress(watchedAddress);
assertEquals(baseElements + 1, wallet.getBloomFilterElementCount()); assertEquals(baseElements + 1, wallet.getBloomFilterElementCount());
@ -1690,7 +1690,7 @@ public class WalletTest extends TestWithWallet {
public void watchingScriptsBloomFilter() throws Exception { public void watchingScriptsBloomFilter() throws Exception {
assertFalse(wallet.isRequiringUpdateAllBloomFilter()); assertFalse(wallet.isRequiringUpdateAllBloomFilter());
LegacyAddress watchedAddress = LegacyAddress.fromKey(UNITTEST, new ECKey()); Address watchedAddress = LegacyAddress.fromKey(UNITTEST, new ECKey());
Transaction t1 = createFakeTx(UNITTEST, CENT, watchedAddress); Transaction t1 = createFakeTx(UNITTEST, CENT, watchedAddress);
TransactionOutPoint outPoint = new TransactionOutPoint(UNITTEST, 0, t1); TransactionOutPoint outPoint = new TransactionOutPoint(UNITTEST, 0, t1);
wallet.addWatchedAddress(watchedAddress); wallet.addWatchedAddress(watchedAddress);
@ -1705,24 +1705,24 @@ public class WalletTest extends TestWithWallet {
@Test @Test
public void getWatchedAddresses() throws Exception { public void getWatchedAddresses() throws Exception {
LegacyAddress watchedAddress = LegacyAddress.fromKey(UNITTEST, new ECKey()); Address watchedAddress = LegacyAddress.fromKey(UNITTEST, new ECKey());
wallet.addWatchedAddress(watchedAddress); wallet.addWatchedAddress(watchedAddress);
List<LegacyAddress> watchedAddresses = wallet.getWatchedAddresses(); List<Address> watchedAddresses = wallet.getWatchedAddresses();
assertEquals(1, watchedAddresses.size()); assertEquals(1, watchedAddresses.size());
assertEquals(watchedAddress, watchedAddresses.get(0)); assertEquals(watchedAddress, watchedAddresses.get(0));
} }
@Test @Test
public void removeWatchedAddresses() { public void removeWatchedAddresses() {
List<LegacyAddress> addressesForRemoval = new ArrayList<>(); List<Address> addressesForRemoval = new ArrayList<>();
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
LegacyAddress watchedAddress = LegacyAddress.fromKey(UNITTEST, new ECKey()); Address watchedAddress = LegacyAddress.fromKey(UNITTEST, new ECKey());
addressesForRemoval.add(watchedAddress); addressesForRemoval.add(watchedAddress);
wallet.addWatchedAddress(watchedAddress); wallet.addWatchedAddress(watchedAddress);
} }
wallet.removeWatchedAddresses(addressesForRemoval); wallet.removeWatchedAddresses(addressesForRemoval);
for (LegacyAddress addr : addressesForRemoval) for (Address addr : addressesForRemoval)
assertFalse(wallet.isAddressWatched(addr)); assertFalse(wallet.isAddressWatched(addr));
assertFalse(wallet.isRequiringUpdateAllBloomFilter()); assertFalse(wallet.isRequiringUpdateAllBloomFilter());
@ -1730,7 +1730,7 @@ public class WalletTest extends TestWithWallet {
@Test @Test
public void removeWatchedAddress() { public void removeWatchedAddress() {
LegacyAddress watchedAddress = LegacyAddress.fromKey(UNITTEST, new ECKey()); Address watchedAddress = LegacyAddress.fromKey(UNITTEST, new ECKey());
wallet.addWatchedAddress(watchedAddress); wallet.addWatchedAddress(watchedAddress);
wallet.removeWatchedAddress(watchedAddress); wallet.removeWatchedAddress(watchedAddress);
assertFalse(wallet.isAddressWatched(watchedAddress)); assertFalse(wallet.isAddressWatched(watchedAddress));
@ -1739,16 +1739,16 @@ public class WalletTest extends TestWithWallet {
@Test @Test
public void removeScriptsBloomFilter() throws Exception { public void removeScriptsBloomFilter() throws Exception {
List<LegacyAddress> addressesForRemoval = new ArrayList<>(); List<Address> addressesForRemoval = new ArrayList<>();
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
LegacyAddress watchedAddress = LegacyAddress.fromKey(UNITTEST, new ECKey()); Address watchedAddress = LegacyAddress.fromKey(UNITTEST, new ECKey());
addressesForRemoval.add(watchedAddress); addressesForRemoval.add(watchedAddress);
wallet.addWatchedAddress(watchedAddress); wallet.addWatchedAddress(watchedAddress);
} }
wallet.removeWatchedAddresses(addressesForRemoval); wallet.removeWatchedAddresses(addressesForRemoval);
for (LegacyAddress addr : addressesForRemoval) { for (Address addr : addressesForRemoval) {
Transaction t1 = createFakeTx(UNITTEST, CENT, addr); Transaction t1 = createFakeTx(UNITTEST, CENT, addr);
TransactionOutPoint outPoint = new TransactionOutPoint(UNITTEST, 0, t1); TransactionOutPoint outPoint = new TransactionOutPoint(UNITTEST, 0, t1);
@ -1763,7 +1763,7 @@ public class WalletTest extends TestWithWallet {
@Test @Test
public void marriedKeychainBloomFilter() throws Exception { public void marriedKeychainBloomFilter() throws Exception {
createMarriedWallet(2, 2); createMarriedWallet(2, 2);
LegacyAddress address = wallet.currentReceiveAddress(); Address address = wallet.currentReceiveAddress();
assertTrue(wallet.getBloomFilter(0.001).contains(address.getHash())); assertTrue(wallet.getBloomFilter(0.001).contains(address.getHash()));
@ -2929,7 +2929,7 @@ public class WalletTest extends TestWithWallet {
assertEquals(THREE_CENTS, tx.getValueSentFromMe(wallet)); assertEquals(THREE_CENTS, tx.getValueSentFromMe(wallet));
assertEquals(THREE_CENTS.subtract(tx.getFee()), tx.getValueSentToMe(wallet)); assertEquals(THREE_CENTS.subtract(tx.getFee()), tx.getValueSentToMe(wallet));
// TX sends to one of our addresses (for now we ignore married wallets). // TX sends to one of our addresses (for now we ignore married wallets).
final LegacyAddress toAddress = (LegacyAddress) tx.getOutput(0).getScriptPubKey().getToAddress(UNITTEST); final Address toAddress = tx.getOutput(0).getScriptPubKey().getToAddress(UNITTEST);
final ECKey rotatingToKey = wallet.findKeyFromPubHash(toAddress.getHash()); final ECKey rotatingToKey = wallet.findKeyFromPubHash(toAddress.getHash());
assertNotNull(rotatingToKey); assertNotNull(rotatingToKey);
assertFalse(wallet.isKeyRotating(rotatingToKey)); assertFalse(wallet.isKeyRotating(rotatingToKey));
@ -3063,7 +3063,7 @@ public class WalletTest extends TestWithWallet {
public void fragmentedReKeying() throws Exception { public void fragmentedReKeying() throws Exception {
// Send lots of small coins and check the fee is correct. // Send lots of small coins and check the fee is correct.
ECKey key = wallet.freshReceiveKey(); ECKey key = wallet.freshReceiveKey();
LegacyAddress address = LegacyAddress.fromKey(UNITTEST, key); Address address = LegacyAddress.fromKey(UNITTEST, key);
Utils.setMockClock(); Utils.setMockClock();
Utils.rollMockClock(86400); Utils.rollMockClock(86400);
for (int i = 0; i < 800; i++) { for (int i = 0; i < 800; i++) {
@ -3356,7 +3356,7 @@ public class WalletTest extends TestWithWallet {
.build(); .build();
wallet.addAndActivateHDChain(chain); wallet.addAndActivateHDChain(chain);
LegacyAddress myAddress = wallet.currentAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS); Address myAddress = wallet.currentAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
sendMoneyToWallet(wallet, AbstractBlockChain.NewBlockType.BEST_CHAIN, COIN, myAddress); sendMoneyToWallet(wallet, AbstractBlockChain.NewBlockType.BEST_CHAIN, COIN, myAddress);
SendRequest req = SendRequest.emptyWallet(OTHER_ADDRESS); SendRequest req = SendRequest.emptyWallet(OTHER_ADDRESS);

View File

@ -17,7 +17,13 @@
package org.bitcoinj.examples; package org.bitcoinj.examples;
import org.bitcoinj.core.*; import org.bitcoinj.core.Address;
import org.bitcoinj.core.Coin;
import org.bitcoinj.core.InsufficientMoneyException;
import org.bitcoinj.core.LegacyAddress;
import org.bitcoinj.core.NetworkParameters;
import org.bitcoinj.core.Transaction;
import org.bitcoinj.core.TransactionConfidence;
import org.bitcoinj.crypto.KeyCrypterException; import org.bitcoinj.crypto.KeyCrypterException;
import org.bitcoinj.kits.WalletAppKit; import org.bitcoinj.kits.WalletAppKit;
import org.bitcoinj.params.MainNetParams; import org.bitcoinj.params.MainNetParams;
@ -40,7 +46,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
* sends them onwards to an address given on the command line. * sends them onwards to an address given on the command line.
*/ */
public class ForwardingService { public class ForwardingService {
private static LegacyAddress forwardingAddress; private static Address forwardingAddress;
private static WalletAppKit kit; private static WalletAppKit kit;
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
@ -111,7 +117,7 @@ public class ForwardingService {
} }
}); });
LegacyAddress sendToAddress = LegacyAddress.fromKey(params, kit.wallet().currentReceiveKey()); Address sendToAddress = LegacyAddress.fromKey(params, kit.wallet().currentReceiveKey());
System.out.println("Send coins to: " + sendToAddress); System.out.println("Send coins to: " + sendToAddress);
System.out.println("Waiting for coins to arrive. Press Ctrl-C to quit."); System.out.println("Waiting for coins to arrive. Press Ctrl-C to quit.");

View File

@ -17,7 +17,15 @@
package org.bitcoinj.examples; package org.bitcoinj.examples;
import org.bitcoinj.core.*; import org.bitcoinj.core.Address;
import org.bitcoinj.core.Base58;
import org.bitcoinj.core.BlockChain;
import org.bitcoinj.core.DumpedPrivateKey;
import org.bitcoinj.core.ECKey;
import org.bitcoinj.core.LegacyAddress;
import org.bitcoinj.core.NetworkParameters;
import org.bitcoinj.core.PeerAddress;
import org.bitcoinj.core.PeerGroup;
import org.bitcoinj.params.MainNetParams; import org.bitcoinj.params.MainNetParams;
import org.bitcoinj.store.MemoryBlockStore; import org.bitcoinj.store.MemoryBlockStore;
import org.bitcoinj.wallet.Wallet; import org.bitcoinj.wallet.Wallet;
@ -52,7 +60,7 @@ public class PrivateKeys {
} }
System.out.println("Address from private key is: " + LegacyAddress.fromKey(params, key).toString()); System.out.println("Address from private key is: " + LegacyAddress.fromKey(params, key).toString());
// And the address ... // And the address ...
LegacyAddress destination = LegacyAddress.fromBase58(params, args[1]); Address destination = LegacyAddress.fromBase58(params, args[1]);
// Import the private key to a fresh wallet. // Import the private key to a fresh wallet.
Wallet wallet = new Wallet(params); Wallet wallet = new Wallet(params);

View File

@ -17,7 +17,6 @@
package org.bitcoinj.tools; package org.bitcoinj.tools;
import org.bitcoinj.core.*;
import org.bitcoinj.crypto.*; import org.bitcoinj.crypto.*;
import org.bitcoinj.params.MainNetParams; import org.bitcoinj.params.MainNetParams;
import org.bitcoinj.params.RegTestParams; import org.bitcoinj.params.RegTestParams;
@ -47,6 +46,32 @@ import joptsimple.OptionSet;
import joptsimple.OptionSpec; import joptsimple.OptionSpec;
import joptsimple.util.DateConverter; import joptsimple.util.DateConverter;
import org.bitcoinj.core.AbstractBlockChain;
import org.bitcoinj.core.Address;
import org.bitcoinj.core.AddressFormatException;
import org.bitcoinj.core.Base58;
import org.bitcoinj.core.Block;
import org.bitcoinj.core.BlockChain;
import org.bitcoinj.core.CheckpointManager;
import org.bitcoinj.core.Coin;
import org.bitcoinj.core.Context;
import org.bitcoinj.core.DumpedPrivateKey;
import org.bitcoinj.core.ECKey;
import org.bitcoinj.core.FilteredBlock;
import org.bitcoinj.core.FullPrunedBlockChain;
import org.bitcoinj.core.InsufficientMoneyException;
import org.bitcoinj.core.LegacyAddress;
import org.bitcoinj.core.NetworkParameters;
import org.bitcoinj.core.Peer;
import org.bitcoinj.core.PeerAddress;
import org.bitcoinj.core.PeerGroup;
import org.bitcoinj.core.Sha256Hash;
import org.bitcoinj.core.StoredBlock;
import org.bitcoinj.core.Transaction;
import org.bitcoinj.core.TransactionInput;
import org.bitcoinj.core.TransactionOutput;
import org.bitcoinj.core.Utils;
import org.bitcoinj.core.VerificationException;
import org.bitcoinj.core.listeners.BlocksDownloadedEventListener; import org.bitcoinj.core.listeners.BlocksDownloadedEventListener;
import org.bitcoinj.core.listeners.DownloadProgressTracker; import org.bitcoinj.core.listeners.DownloadProgressTracker;
import org.bitcoinj.wallet.MarriedKeyChain; import org.bitcoinj.wallet.MarriedKeyChain;
@ -583,7 +608,7 @@ public class WalletTool {
return; return;
} }
try { try {
LegacyAddress address = LegacyAddress.fromBase58(params, addr); Address address = LegacyAddress.fromBase58(params, addr);
// If no creation time is specified, assume genesis (zero). // If no creation time is specified, assume genesis (zero).
wallet.addWatchedAddress(address, getCreationTimeSeconds()); wallet.addWatchedAddress(address, getCreationTimeSeconds());
} catch (AddressFormatException e) { } catch (AddressFormatException e) {
@ -1464,7 +1489,7 @@ public class WalletTool {
key = wallet.findKeyFromPubKey(Hex.decode(pubkey)); key = wallet.findKeyFromPubKey(Hex.decode(pubkey));
} else { } else {
try { try {
LegacyAddress address = LegacyAddress.fromBase58(wallet.getParams(), addr); Address address = LegacyAddress.fromBase58(wallet.getParams(), addr);
key = wallet.findKeyFromPubHash(address.getHash()); key = wallet.findKeyFromPubHash(address.getHash());
} catch (AddressFormatException e) { } catch (AddressFormatException e) {
System.err.println(addr + " does not parse as a Bitcoin address of the right network parameters."); System.err.println(addr + " does not parse as a Bitcoin address of the right network parameters.");

View File

@ -16,7 +16,7 @@
package wallettemplate.controls; package wallettemplate.controls;
import org.bitcoinj.core.LegacyAddress; import org.bitcoinj.core.Address;
import org.bitcoinj.uri.BitcoinURI; import org.bitcoinj.uri.BitcoinURI;
import de.jensd.fx.fontawesome.AwesomeDude; import de.jensd.fx.fontawesome.AwesomeDude;
import de.jensd.fx.fontawesome.AwesomeIcon; import de.jensd.fx.fontawesome.AwesomeIcon;
@ -61,7 +61,7 @@ public class ClickableBitcoinAddress extends AnchorPane {
@FXML protected Label copyWidget; @FXML protected Label copyWidget;
@FXML protected Label qrCode; @FXML protected Label qrCode;
protected SimpleObjectProperty<LegacyAddress> address = new SimpleObjectProperty<>(); protected SimpleObjectProperty<Address> address = new SimpleObjectProperty<>();
private final StringExpression addressStr; private final StringExpression addressStr;
public ClickableBitcoinAddress() { public ClickableBitcoinAddress() {
@ -90,15 +90,15 @@ public class ClickableBitcoinAddress extends AnchorPane {
return BitcoinURI.convertToBitcoinURI(address.get(), null, Main.APP_NAME, null); return BitcoinURI.convertToBitcoinURI(address.get(), null, Main.APP_NAME, null);
} }
public LegacyAddress getAddress() { public Address getAddress() {
return address.get(); return address.get();
} }
public void setAddress(LegacyAddress address) { public void setAddress(Address address) {
this.address.set(address); this.address.set(address);
} }
public ObjectProperty<LegacyAddress> addressProperty() { public ObjectProperty<Address> addressProperty() {
return address; return address;
} }

View File

@ -16,10 +16,11 @@
package wallettemplate.utils; package wallettemplate.utils;
import org.bitcoinj.core.Address;
import org.bitcoinj.core.Coin;
import org.bitcoinj.core.listeners.DownloadProgressTracker; import org.bitcoinj.core.listeners.DownloadProgressTracker;
import org.bitcoinj.wallet.Wallet; import org.bitcoinj.wallet.Wallet;
import org.bitcoinj.wallet.listeners.WalletChangeEventListener; import org.bitcoinj.wallet.listeners.WalletChangeEventListener;
import org.bitcoinj.core.*;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.beans.property.ReadOnlyDoubleProperty; import javafx.beans.property.ReadOnlyDoubleProperty;
import javafx.beans.property.ReadOnlyObjectProperty; import javafx.beans.property.ReadOnlyObjectProperty;
@ -32,7 +33,7 @@ import java.util.Date;
* A class that exposes relevant bitcoin stuff as JavaFX bindable properties. * A class that exposes relevant bitcoin stuff as JavaFX bindable properties.
*/ */
public class BitcoinUIModel { public class BitcoinUIModel {
private SimpleObjectProperty<LegacyAddress> address = new SimpleObjectProperty<>(); private SimpleObjectProperty<Address> address = new SimpleObjectProperty<>();
private SimpleObjectProperty<Coin> balance = new SimpleObjectProperty<>(Coin.ZERO); private SimpleObjectProperty<Coin> balance = new SimpleObjectProperty<>(Coin.ZERO);
private SimpleDoubleProperty syncProgress = new SimpleDoubleProperty(-1); private SimpleDoubleProperty syncProgress = new SimpleDoubleProperty(-1);
private ProgressBarUpdater syncProgressUpdater = new ProgressBarUpdater(); private ProgressBarUpdater syncProgressUpdater = new ProgressBarUpdater();
@ -77,7 +78,7 @@ public class BitcoinUIModel {
public ReadOnlyDoubleProperty syncProgressProperty() { return syncProgress; } public ReadOnlyDoubleProperty syncProgressProperty() { return syncProgress; }
public ReadOnlyObjectProperty<LegacyAddress> addressProperty() { public ReadOnlyObjectProperty<Address> addressProperty() {
return address; return address;
} }