mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-02-14 11:15:51 +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:
parent
6e46d75c61
commit
7f5b6753f5
@ -1268,7 +1268,7 @@ public class ECKey implements EncryptableItem {
|
||||
|
||||
public void formatKeyWithAddress(boolean includePrivateKeys, @Nullable KeyParameter aesKey, StringBuilder builder,
|
||||
NetworkParameters params) {
|
||||
final LegacyAddress address = LegacyAddress.fromKey(params, this);
|
||||
final Address address = LegacyAddress.fromKey(params, this);
|
||||
builder.append(" addr:");
|
||||
builder.append(address.toString());
|
||||
builder.append(" hash160:");
|
||||
|
@ -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
|
||||
* 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>
|
||||
*/
|
||||
|
@ -617,7 +617,7 @@ public class DeterministicKey extends ECKey {
|
||||
@Override
|
||||
public void formatKeyWithAddress(boolean includePrivateKeys, @Nullable KeyParameter aesKey, StringBuilder builder,
|
||||
NetworkParameters params) {
|
||||
final LegacyAddress address = LegacyAddress.fromKey(params, this);
|
||||
final Address address = LegacyAddress.fromKey(params, this);
|
||||
builder.append(" addr:").append(address);
|
||||
builder.append(" hash160:").append(Utils.HEX.encode(getPubKeyHash()));
|
||||
builder.append(" (").append(getPathAsString()).append(")\n");
|
||||
|
@ -66,7 +66,7 @@ public class PaymentProtocol {
|
||||
* @return created payment request, in its builder form
|
||||
*/
|
||||
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) {
|
||||
return createPaymentRequest(params, ImmutableList.of(createPayToAddressOutput(amount, toAddress)), memo,
|
||||
paymentUrl, merchantData);
|
||||
@ -292,7 +292,7 @@ public class PaymentProtocol {
|
||||
* @return created payment message
|
||||
*/
|
||||
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) {
|
||||
if (refundAddress != null) {
|
||||
if (refundAmount == null)
|
||||
@ -397,7 +397,7 @@ public class PaymentProtocol {
|
||||
* @param address address to pay to
|
||||
* @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();
|
||||
if (amount != null) {
|
||||
final NetworkParameters params = address.getParameters();
|
||||
|
@ -316,7 +316,7 @@ public class PaymentSession {
|
||||
* @param memo is a message to include in the payment message sent to the merchant.
|
||||
*/
|
||||
@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 {
|
||||
Protos.Payment payment = getPayment(txns, refundAddr, memo);
|
||||
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.
|
||||
*/
|
||||
@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 {
|
||||
if (paymentDetails.hasPaymentUrl()) {
|
||||
for (Transaction tx : txns)
|
||||
|
@ -255,19 +255,18 @@ public class ScriptBuilder {
|
||||
public static Script createOutputScript(Address to) {
|
||||
ScriptBuilder builder = new ScriptBuilder();
|
||||
if (to instanceof LegacyAddress) {
|
||||
LegacyAddress toLegacy = (LegacyAddress) to;
|
||||
ScriptType scriptType = toLegacy.getOutputScriptType();
|
||||
ScriptType scriptType = to.getOutputScriptType();
|
||||
if (scriptType == ScriptType.P2PKH) {
|
||||
// OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG
|
||||
builder.op(OP_DUP);
|
||||
builder.op(OP_HASH160);
|
||||
builder.data(toLegacy.getHash());
|
||||
builder.data(to.getHash());
|
||||
builder.op(OP_EQUALVERIFY);
|
||||
builder.op(OP_CHECKSIG);
|
||||
} else if (scriptType == ScriptType.P2SH) {
|
||||
// OP_HASH160 <scriptHash> OP_EQUAL
|
||||
builder.op(OP_HASH160);
|
||||
builder.data(toLegacy.getHash());
|
||||
builder.data(to.getHash());
|
||||
builder.op(OP_EQUAL);
|
||||
} else {
|
||||
throw new IllegalStateException("Cannot handle " + scriptType);
|
||||
|
@ -1124,7 +1124,7 @@ public abstract class DatabaseFullPrunedBlockStore implements FullPrunedBlockSto
|
||||
* address, the return value is 0.
|
||||
* @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();
|
||||
PreparedStatement s = null;
|
||||
try {
|
||||
|
@ -28,10 +28,10 @@ import java.util.concurrent.TimeUnit;
|
||||
import java.io.*;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import org.bitcoinj.core.LegacyAddress;
|
||||
import org.bitcoinj.core.Address;
|
||||
import org.bitcoinj.core.AddressFormatException;
|
||||
import org.bitcoinj.core.ECKey;
|
||||
import org.bitcoinj.core.LegacyAddress;
|
||||
import org.bitcoinj.core.NetworkParameters;
|
||||
import org.bitcoinj.core.Sha256Hash;
|
||||
import org.bitcoinj.core.StoredBlock;
|
||||
@ -788,7 +788,7 @@ public class LevelDBFullPrunedBlockStore implements FullPrunedBlockStore {
|
||||
|
||||
// Could run this in parallel with above too.
|
||||
// Should update instrumentation to see if worth while.
|
||||
LegacyAddress a;
|
||||
Address a;
|
||||
if (out.getAddress() == null || out.getAddress().equals("")) {
|
||||
if (instrument)
|
||||
endMethod("addUnspentTransactionOutput");
|
||||
@ -882,13 +882,13 @@ public class LevelDBFullPrunedBlockStore implements FullPrunedBlockStore {
|
||||
// TODO storing as byte[] hash to save space. But think should just
|
||||
// store as String of address. Might be faster. Need to test.
|
||||
ByteBuffer bb = ByteBuffer.allocate(57);
|
||||
LegacyAddress a;
|
||||
Address a;
|
||||
byte[] hashBytes = null;
|
||||
try {
|
||||
String address = out.getAddress();
|
||||
if (address == null || address.equals("")) {
|
||||
Script sc = out.getScript();
|
||||
a = (LegacyAddress) sc.getToAddress(params);
|
||||
a = sc.getToAddress(params);
|
||||
hashBytes = a.getHash();
|
||||
} else {
|
||||
a = LegacyAddress.fromBase58(params, out.getAddress());
|
||||
|
@ -19,7 +19,13 @@ package org.bitcoinj.wallet;
|
||||
|
||||
import com.google.common.collect.*;
|
||||
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.script.*;
|
||||
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
|
||||
// P2SH addresses. They're mutually exclusive.
|
||||
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;
|
||||
private int lookaheadSize = -1;
|
||||
private int lookaheadThreshold = -1;
|
||||
@ -125,7 +131,7 @@ public class KeyChainGroup implements KeyBag {
|
||||
if (isMarried()) {
|
||||
for (Map.Entry<KeyChain.KeyPurpose, DeterministicKey> entry : this.currentKeys.entrySet()) {
|
||||
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)}
|
||||
*/
|
||||
public LegacyAddress currentAddress(KeyChain.KeyPurpose purpose) {
|
||||
public Address currentAddress(KeyChain.KeyPurpose purpose) {
|
||||
DeterministicKeyChain chain = getActiveKeyChain();
|
||||
if (chain.isMarried()) {
|
||||
LegacyAddress current = currentAddresses.get(purpose);
|
||||
Address current = currentAddresses.get(purpose);
|
||||
if (current == null) {
|
||||
current = freshAddress(purpose);
|
||||
currentAddresses.put(purpose, current);
|
||||
@ -241,12 +247,12 @@ public class KeyChainGroup implements KeyBag {
|
||||
/**
|
||||
* Returns address for a {@link #freshKey(KeyChain.KeyPurpose)}
|
||||
*/
|
||||
public LegacyAddress freshAddress(KeyChain.KeyPurpose purpose) {
|
||||
public Address freshAddress(KeyChain.KeyPurpose purpose) {
|
||||
DeterministicKeyChain chain = getActiveKeyChain();
|
||||
if (chain.isMarried()) {
|
||||
Script outputScript = chain.freshOutputScript(purpose);
|
||||
checkState(ScriptPattern.isPayToScriptHash(outputScript)); // Only handle P2SH for now
|
||||
LegacyAddress freshAddress = LegacyAddress.fromScriptHash(params,
|
||||
Address freshAddress = LegacyAddress.fromScriptHash(params,
|
||||
ScriptPattern.extractHashFromPayToScriptHash(outputScript));
|
||||
maybeLookaheadScripts();
|
||||
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. */
|
||||
private void maybeMarkCurrentAddressAsUsed(LegacyAddress address) {
|
||||
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)) {
|
||||
log.info("Marking P2SH address as used: {}", address);
|
||||
currentAddresses.put(entry.getKey(), freshAddress(entry.getKey()));
|
||||
|
@ -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
|
||||
* 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
|
||||
|
@ -27,7 +27,6 @@ import net.jcip.annotations.*;
|
||||
import org.bitcoinj.core.listeners.*;
|
||||
import org.bitcoinj.core.Address;
|
||||
import org.bitcoinj.core.AbstractBlockChain;
|
||||
import org.bitcoinj.core.LegacyAddress;
|
||||
import org.bitcoinj.core.BlockChain;
|
||||
import org.bitcoinj.core.BloomFilter;
|
||||
import org.bitcoinj.core.Coin;
|
||||
@ -35,6 +34,7 @@ import org.bitcoinj.core.Context;
|
||||
import org.bitcoinj.core.ECKey;
|
||||
import org.bitcoinj.core.FilteredBlock;
|
||||
import org.bitcoinj.core.InsufficientMoneyException;
|
||||
import org.bitcoinj.core.LegacyAddress;
|
||||
import org.bitcoinj.core.Message;
|
||||
import org.bitcoinj.core.NetworkParameters;
|
||||
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)}
|
||||
*/
|
||||
public LegacyAddress currentAddress(KeyChain.KeyPurpose purpose) {
|
||||
public Address currentAddress(KeyChain.KeyPurpose purpose) {
|
||||
keyChainGroupLock.lock();
|
||||
try {
|
||||
maybeUpgradeToHD();
|
||||
@ -483,7 +483,7 @@ public class Wallet extends BaseTaggableObject
|
||||
* An alias for calling {@link #currentAddress(org.bitcoinj.wallet.KeyChain.KeyPurpose)} with
|
||||
* {@link org.bitcoinj.wallet.KeyChain.KeyPurpose#RECEIVE_FUNDS} as the parameter.
|
||||
*/
|
||||
public LegacyAddress currentReceiveAddress() {
|
||||
public Address currentReceiveAddress() {
|
||||
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)}
|
||||
*/
|
||||
public LegacyAddress freshAddress(KeyChain.KeyPurpose purpose) {
|
||||
LegacyAddress key;
|
||||
public Address freshAddress(KeyChain.KeyPurpose purpose) {
|
||||
Address address;
|
||||
keyChainGroupLock.lock();
|
||||
try {
|
||||
key = keyChainGroup.freshAddress(purpose);
|
||||
address = keyChainGroup.freshAddress(purpose);
|
||||
} finally {
|
||||
keyChainGroupLock.unlock();
|
||||
}
|
||||
saveNow();
|
||||
return key;
|
||||
return address;
|
||||
}
|
||||
|
||||
/**
|
||||
* An alias for calling {@link #freshAddress(org.bitcoinj.wallet.KeyChain.KeyPurpose)} with
|
||||
* {@link org.bitcoinj.wallet.KeyChain.KeyPurpose#RECEIVE_FUNDS} as the parameter.
|
||||
*/
|
||||
public LegacyAddress freshReceiveAddress() {
|
||||
public Address freshReceiveAddress() {
|
||||
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()},
|
||||
* {@link #currentReceiveKey()} or {@link #currentReceiveAddress()}.
|
||||
*/
|
||||
public List<LegacyAddress> getIssuedReceiveAddresses() {
|
||||
public List<Address> getIssuedReceiveAddresses() {
|
||||
final List<ECKey> keys = getIssuedReceiveKeys();
|
||||
List<LegacyAddress> addresses = new ArrayList<>(keys.size());
|
||||
List<Address> addresses = new ArrayList<>(keys.size());
|
||||
for (ECKey key : keys)
|
||||
addresses.add(LegacyAddress.fromKey(getParams(), key));
|
||||
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. */
|
||||
public LegacyAddress currentChangeAddress() {
|
||||
public Address currentChangeAddress() {
|
||||
return currentAddress(KeyChain.KeyPurpose.CHANGE);
|
||||
}
|
||||
|
||||
@ -850,15 +850,15 @@ public class Wallet extends BaseTaggableObject
|
||||
/**
|
||||
* Return true if we are watching this address.
|
||||
*/
|
||||
public boolean isAddressWatched(LegacyAddress address) {
|
||||
public boolean isAddressWatched(Address address) {
|
||||
Script script = ScriptBuilder.createOutputScript(address);
|
||||
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;
|
||||
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
|
||||
* @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;
|
||||
}
|
||||
|
||||
@ -879,10 +879,10 @@ public class Wallet extends BaseTaggableObject
|
||||
*
|
||||
* @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();
|
||||
|
||||
for (LegacyAddress address : addresses) {
|
||||
for (Address address : addresses) {
|
||||
Script script = ScriptBuilder.createOutputScript(address);
|
||||
script.setCreationTimeSeconds(creationTime);
|
||||
scripts.add(script);
|
||||
@ -929,7 +929,7 @@ public class Wallet extends BaseTaggableObject
|
||||
*
|
||||
* @return true if successful
|
||||
*/
|
||||
public boolean removeWatchedAddress(final LegacyAddress address) {
|
||||
public boolean removeWatchedAddress(final Address address) {
|
||||
return removeWatchedAddresses(ImmutableList.of(address));
|
||||
}
|
||||
|
||||
@ -938,10 +938,10 @@ public class Wallet extends BaseTaggableObject
|
||||
*
|
||||
* @return true if successful
|
||||
*/
|
||||
public boolean removeWatchedAddresses(final List<LegacyAddress> addresses) {
|
||||
public boolean removeWatchedAddresses(final List<Address> addresses) {
|
||||
List<Script> scripts = Lists.newArrayList();
|
||||
|
||||
for (LegacyAddress address : addresses) {
|
||||
for (Address address : addresses) {
|
||||
Script script = ScriptBuilder.createOutputScript(address);
|
||||
scripts.add(script);
|
||||
}
|
||||
@ -975,13 +975,13 @@ public class Wallet extends BaseTaggableObject
|
||||
/**
|
||||
* Returns all addresses watched by this wallet.
|
||||
*/
|
||||
public List<LegacyAddress> getWatchedAddresses() {
|
||||
public List<Address> getWatchedAddresses() {
|
||||
keyChainGroupLock.lock();
|
||||
try {
|
||||
List<LegacyAddress> addresses = new LinkedList<>();
|
||||
List<Address> addresses = new LinkedList<>();
|
||||
for (Script script : watchedScripts)
|
||||
if (ScriptPattern.isPayToPubKeyHash(script))
|
||||
addresses.add(((LegacyAddress) script.getToAddress(params)));
|
||||
addresses.add(script.getToAddress(params));
|
||||
return addresses;
|
||||
} finally {
|
||||
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)}.
|
||||
* @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,
|
||||
// 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.
|
||||
LegacyAddress changeAddress = req.changeAddress;
|
||||
Address changeAddress = req.changeAddress;
|
||||
if (changeAddress == null)
|
||||
changeAddress = currentChangeAddress();
|
||||
TransactionOutput changeOutput = new TransactionOutput(params, tx, change, changeAddress);
|
||||
|
@ -261,7 +261,7 @@ public abstract class AbstractFullPrunedBlockChainTest {
|
||||
// Create bitcoin spend of 1 BTC.
|
||||
ECKey toKey = new ECKey();
|
||||
Coin amount = Coin.valueOf(100000000);
|
||||
LegacyAddress address = LegacyAddress.fromKey(PARAMS, toKey);
|
||||
Address address = LegacyAddress.fromKey(PARAMS, toKey);
|
||||
Coin totalAmount = Coin.ZERO;
|
||||
|
||||
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).
|
||||
ECKey toKey2 = new ECKey();
|
||||
Coin amount2 = amount.divide(2);
|
||||
LegacyAddress address2 = LegacyAddress.fromKey(PARAMS, toKey2);
|
||||
Address address2 = LegacyAddress.fromKey(PARAMS, toKey2);
|
||||
SendRequest req = SendRequest.to(address2, amount2);
|
||||
wallet.completeTx(req);
|
||||
wallet.commitTx(req.tx);
|
||||
|
@ -54,7 +54,7 @@ public class BlockChainTest {
|
||||
private Wallet wallet;
|
||||
private BlockChain chain;
|
||||
private BlockStore blockStore;
|
||||
private LegacyAddress coinbaseTo;
|
||||
private Address coinbaseTo;
|
||||
|
||||
private final StoredBlock[] block = new StoredBlock[1];
|
||||
private Transaction coinbaseTransaction;
|
||||
@ -293,10 +293,10 @@ public class BlockChainTest {
|
||||
public void intraBlockDependencies() throws Exception {
|
||||
// Covers issue 166 in which transactions that depend on each other inside a block were not always being
|
||||
// considered relevant.
|
||||
LegacyAddress somebodyElse = LegacyAddress.fromKey(UNITTEST, new ECKey());
|
||||
Address somebodyElse = LegacyAddress.fromKey(UNITTEST, new ECKey());
|
||||
Block b1 = UNITTEST.getGenesisBlock().createNextBlock(somebodyElse);
|
||||
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.
|
||||
Transaction t1 = FakeTxBuilder.createFakeTx(UNITTEST, COIN, addr);
|
||||
Transaction t2 = new Transaction(UNITTEST);
|
||||
@ -319,7 +319,7 @@ public class BlockChainTest {
|
||||
int height = 1;
|
||||
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).
|
||||
Block b1 = UNITTEST.getGenesisBlock().createNextBlockWithCoinbase(Block.BLOCK_VERSION_GENESIS, wallet.currentReceiveKey().getPubKey(), height++);
|
||||
|
@ -74,7 +74,7 @@ public class BloomFilterTest {
|
||||
|
||||
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"));
|
||||
|
||||
KeyChainGroup group = new KeyChainGroup(MAINNET);
|
||||
|
@ -51,9 +51,9 @@ public class ChainSplitTest {
|
||||
private static final NetworkParameters UNITTEST = UnitTestParams.get();
|
||||
private Wallet wallet;
|
||||
private BlockChain chain;
|
||||
private LegacyAddress coinsTo;
|
||||
private LegacyAddress coinsTo2;
|
||||
private LegacyAddress someOtherGuy;
|
||||
private Address coinsTo;
|
||||
private Address coinsTo2;
|
||||
private Address someOtherGuy;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
@ -186,7 +186,7 @@ public class ChainSplitTest {
|
||||
Block b1 = UNITTEST.getGenesisBlock().createNextBlock(coinsTo);
|
||||
chain.add(b1);
|
||||
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));
|
||||
wallet.commitTx(spend);
|
||||
// Waiting for confirmation ... make it eligible for selection.
|
||||
@ -220,7 +220,7 @@ public class ChainSplitTest {
|
||||
Block b1 = UNITTEST.getGenesisBlock().createNextBlock(coinsTo);
|
||||
chain.add(b1);
|
||||
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);
|
||||
// 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.
|
||||
@ -311,7 +311,7 @@ public class ChainSplitTest {
|
||||
chain.add(b1);
|
||||
|
||||
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));
|
||||
wallet.commitTx(t1);
|
||||
// Receive t1 as confirmed by the network.
|
||||
@ -354,7 +354,7 @@ public class ChainSplitTest {
|
||||
chain.add(b1);
|
||||
|
||||
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)));
|
||||
wallet.commitTx(t1);
|
||||
// t1 is still pending ...
|
||||
|
@ -233,9 +233,9 @@ public class ECKeyTest {
|
||||
// Test vector generated by Bitcoin-Qt.
|
||||
String message = "hello";
|
||||
String sigBase64 = "HxNZdo6ggZ41hd3mM3gfJRqOQPZYcO8z8qdX2BwmpbF11CaOQV+QiZGGQxaYOncKoNW61oRuSMMF8udfK54XqI8=";
|
||||
LegacyAddress expectedAddress = LegacyAddress.fromBase58(MAINNET, "14YPSNPi6NSXnUxtPAsyJSuw3pv7AU3Cag");
|
||||
Address expectedAddress = LegacyAddress.fromBase58(MAINNET, "14YPSNPi6NSXnUxtPAsyJSuw3pv7AU3Cag");
|
||||
ECKey key = ECKey.signedMessageToKey(message, sigBase64);
|
||||
LegacyAddress gotAddress = LegacyAddress.fromKey(MAINNET, key);
|
||||
Address gotAddress = LegacyAddress.fromKey(MAINNET, key);
|
||||
assertEquals(expectedAddress, gotAddress);
|
||||
}
|
||||
|
||||
|
@ -245,7 +245,7 @@ public class PeerGroupTest extends TestWithPeerGroup {
|
||||
|
||||
Wallet wallet2 = new Wallet(UNITTEST);
|
||||
ECKey key2 = wallet2.freshReceiveKey();
|
||||
LegacyAddress address2 = LegacyAddress.fromKey(UNITTEST, key2);
|
||||
Address address2 = LegacyAddress.fromKey(UNITTEST, key2);
|
||||
|
||||
peerGroup.addWallet(wallet2);
|
||||
blockChain.addWallet(wallet2);
|
||||
@ -804,7 +804,7 @@ public class PeerGroupTest extends TestWithPeerGroup {
|
||||
Coin expectedBalance = Coin.ZERO;
|
||||
Block prev = blockStore.getChainHead().getHeader();
|
||||
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));
|
||||
expectedBalance = expectedBalance.add(next.getTransactions().get(2).getOutput(0).getValue());
|
||||
blocks.add(next);
|
||||
|
@ -159,7 +159,7 @@ public class TransactionBroadcastTest extends TestWithPeerGroup {
|
||||
assertEquals(FIFTY_COINS, wallet.getBalance());
|
||||
|
||||
// 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);
|
||||
assertFalse(sendResult.broadcastComplete.isDone());
|
||||
Transaction t1;
|
||||
@ -208,7 +208,7 @@ public class TransactionBroadcastTest extends TestWithPeerGroup {
|
||||
});
|
||||
|
||||
// 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);
|
||||
assertNotNull(sendResult.tx);
|
||||
Threading.waitForUserCode();
|
||||
|
@ -38,7 +38,7 @@ public class TransactionInputTest {
|
||||
public void testStandardWalletDisconnect() throws Exception {
|
||||
Wallet w = new Wallet(new Context(UNITTEST));
|
||||
w.setCoinSelector(new AllowUnconfirmedCoinSelector());
|
||||
LegacyAddress a = w.currentReceiveAddress();
|
||||
Address a = w.currentReceiveAddress();
|
||||
Transaction tx1 = FakeTxBuilder.createFakeTxWithoutChangeAddress(UNITTEST, Coin.COIN, a);
|
||||
w.receivePending(tx1, null);
|
||||
Transaction tx2 = new Transaction(UNITTEST);
|
||||
@ -59,7 +59,7 @@ public class TransactionInputTest {
|
||||
@Test
|
||||
public void testUTXOWalletDisconnect() throws Exception {
|
||||
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,
|
||||
ScriptBuilder.createOutputScript(a));
|
||||
w.setUTXOProvider(new UTXOProvider() {
|
||||
|
@ -68,7 +68,7 @@ public class TransactionOutputTest extends TestWithWallet {
|
||||
@Test
|
||||
public void testP2SHOutputScript() throws Exception {
|
||||
String P2SHAddressString = "35b9vsyH1KoFT5a5KtrKusaCcPLkiSo1tU";
|
||||
LegacyAddress P2SHAddress = LegacyAddress.fromBase58(MAINNET, P2SHAddressString);
|
||||
Address P2SHAddress = LegacyAddress.fromBase58(MAINNET, P2SHAddressString);
|
||||
Script script = ScriptBuilder.createOutputScript(P2SHAddress);
|
||||
Transaction tx = new Transaction(MAINNET);
|
||||
tx.addOutput(Coin.COIN, script);
|
||||
|
@ -40,7 +40,7 @@ import static org.junit.Assert.*;
|
||||
*/
|
||||
public class TransactionTest {
|
||||
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;
|
||||
|
||||
@ -344,7 +344,7 @@ public class TransactionTest {
|
||||
@Test(expected = ScriptException.class)
|
||||
public void testAddSignedInputThrowsExceptionWhenScriptIsNotToRawPubKeyAndIsNotToAddress() {
|
||||
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 tx = new Transaction(UNITTEST);
|
||||
|
@ -38,8 +38,8 @@ public class TxConfidenceTableTest {
|
||||
Context context = new Context(UNITTEST);
|
||||
table = context.getConfidenceTable();
|
||||
|
||||
LegacyAddress to = LegacyAddress.fromKey(UNITTEST, new ECKey());
|
||||
LegacyAddress change = LegacyAddress.fromKey(UNITTEST, new ECKey());
|
||||
Address to = LegacyAddress.fromKey(UNITTEST, new ECKey());
|
||||
Address change = LegacyAddress.fromKey(UNITTEST, new ECKey());
|
||||
|
||||
tx1 = FakeTxBuilder.createFakeTxWithChangeAddress(UNITTEST, COIN, to, change);
|
||||
tx2 = FakeTxBuilder.createFakeTxWithChangeAddress(UNITTEST, COIN, to, change);
|
||||
|
@ -16,7 +16,12 @@
|
||||
|
||||
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.params.TestNet3Params;
|
||||
import org.bitcoinj.params.UnitTestParams;
|
||||
@ -46,7 +51,7 @@ public class PaymentProtocolTest {
|
||||
|
||||
// static test data
|
||||
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 PAYMENT_URL = "https://example.com";
|
||||
private static final byte[] MERCHANT_DATA = { 0, 1, 2 };
|
||||
@ -125,7 +130,7 @@ public class PaymentProtocolTest {
|
||||
List<Transaction> transactions = new LinkedList<>();
|
||||
transactions.add(FakeTxBuilder.createFakeTx(UNITTEST, AMOUNT, TO_ADDRESS));
|
||||
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,
|
||||
MERCHANT_DATA);
|
||||
byte[] paymentBytes = payment.toByteArray();
|
||||
|
@ -17,7 +17,15 @@
|
||||
|
||||
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.params.MainNetParams;
|
||||
import org.bitcoinj.params.TestNet3Params;
|
||||
@ -75,7 +83,7 @@ public class PaymentSessionTest {
|
||||
tx.addInput(new TransactionInput(TESTNET, tx, outputToMe.getScriptBytes()));
|
||||
ArrayList<Transaction> txns = new ArrayList<>();
|
||||
txns.add(tx);
|
||||
LegacyAddress refundAddr = LegacyAddress.fromKey(TESTNET, serverKey);
|
||||
Address refundAddr = LegacyAddress.fromKey(TESTNET, serverKey);
|
||||
paymentSession.sendPayment(txns, refundAddr, paymentMemo);
|
||||
assertEquals(1, paymentSession.getPaymentLog().size());
|
||||
assertEquals(simplePaymentUrl, paymentSession.getPaymentLog().get(0).getUrl().toString());
|
||||
@ -147,7 +155,7 @@ public class PaymentSessionTest {
|
||||
tx.addInput(new TransactionInput(TESTNET, tx, outputToMe.getScriptBytes()));
|
||||
ArrayList<Transaction> txns = new ArrayList<>();
|
||||
txns.add(tx);
|
||||
LegacyAddress refundAddr = LegacyAddress.fromKey(TESTNET, serverKey);
|
||||
Address refundAddr = LegacyAddress.fromKey(TESTNET, serverKey);
|
||||
paymentSession.sendPayment(txns, refundAddr, paymentMemo);
|
||||
assertEquals(1, paymentSession.getPaymentLog().size());
|
||||
}
|
||||
|
@ -80,7 +80,7 @@ public class ScriptTest {
|
||||
byte[] pubkeyBytes = HEX.decode(pubkeyProg);
|
||||
Script pubkey = new Script(pubkeyBytes);
|
||||
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());
|
||||
}
|
||||
|
||||
@ -112,7 +112,7 @@ public class ScriptTest {
|
||||
|
||||
@Test
|
||||
public void testP2SHOutputScript() throws Exception {
|
||||
LegacyAddress p2shAddress = LegacyAddress.fromBase58(MAINNET, "35b9vsyH1KoFT5a5KtrKusaCcPLkiSo1tU");
|
||||
Address p2shAddress = LegacyAddress.fromBase58(MAINNET, "35b9vsyH1KoFT5a5KtrKusaCcPLkiSo1tU");
|
||||
assertTrue(ScriptPattern.isPayToScriptHash(ScriptBuilder.createOutputScript(p2shAddress)));
|
||||
}
|
||||
|
||||
@ -134,7 +134,7 @@ public class ScriptTest {
|
||||
Transaction transaction = TESTNET.getDefaultSerializer().makeTransaction(bytes);
|
||||
TransactionOutput output = transaction.getOutput(1);
|
||||
Transaction spendTx = new Transaction(TESTNET);
|
||||
LegacyAddress address = LegacyAddress.fromBase58(TESTNET, "n3CFiCmBXVt5d3HXKQ15EFZyhPz4yj5F3H");
|
||||
Address address = LegacyAddress.fromBase58(TESTNET, "n3CFiCmBXVt5d3HXKQ15EFZyhPz4yj5F3H");
|
||||
Script outputScript = ScriptBuilder.createOutputScript(address);
|
||||
spendTx.addOutput(output.getValue(), outputScript);
|
||||
spendTx.addInput(output);
|
||||
@ -439,13 +439,13 @@ public class ScriptTest {
|
||||
public void getToAddress() throws Exception {
|
||||
// pay to pubkey
|
||||
ECKey toKey = new ECKey();
|
||||
LegacyAddress toAddress = LegacyAddress.fromKey(TESTNET, toKey);
|
||||
Address toAddress = LegacyAddress.fromKey(TESTNET, toKey);
|
||||
assertEquals(toAddress, ScriptBuilder.createOutputScript(toKey).getToAddress(TESTNET, true));
|
||||
// pay to pubkey hash
|
||||
assertEquals(toAddress, ScriptBuilder.createOutputScript(toAddress).getToAddress(TESTNET, true));
|
||||
// pay to script hash
|
||||
Script p2shScript = ScriptBuilder.createP2SHOutputScript(new byte[20]);
|
||||
LegacyAddress scriptAddress = LegacyAddress.fromScriptHash(TESTNET,
|
||||
Address scriptAddress = LegacyAddress.fromScriptHash(TESTNET,
|
||||
ScriptPattern.extractHashFromPayToScriptHash(p2shScript));
|
||||
assertEquals(scriptAddress, p2shScript.getToAddress(TESTNET, true));
|
||||
}
|
||||
|
@ -16,7 +16,11 @@
|
||||
|
||||
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.junit.*;
|
||||
|
||||
@ -42,7 +46,7 @@ public class LevelDBBlockStoreTest {
|
||||
assertEquals(0, genesis.getHeight());
|
||||
|
||||
// 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());
|
||||
store.put(b1);
|
||||
store.setChainHead(b1);
|
||||
|
@ -16,8 +16,9 @@
|
||||
|
||||
package org.bitcoinj.store;
|
||||
|
||||
import org.bitcoinj.core.LegacyAddress;
|
||||
import org.bitcoinj.core.Address;
|
||||
import org.bitcoinj.core.ECKey;
|
||||
import org.bitcoinj.core.LegacyAddress;
|
||||
import org.bitcoinj.core.NetworkParameters;
|
||||
import org.bitcoinj.core.StoredBlock;
|
||||
import org.bitcoinj.params.UnitTestParams;
|
||||
@ -37,7 +38,7 @@ public class SPVBlockStoreTest {
|
||||
f.deleteOnExit();
|
||||
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.
|
||||
StoredBlock genesis = store.getChainHead();
|
||||
assertEquals(UNITTEST.getGenesisBlock(), genesis.getHeader());
|
||||
|
@ -17,9 +17,23 @@
|
||||
|
||||
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.TransactionConfidence;
|
||||
import org.bitcoinj.core.TransactionConfidence.ConfidenceType;
|
||||
import org.bitcoinj.core.TransactionInput;
|
||||
import org.bitcoinj.core.Utils;
|
||||
import org.bitcoinj.crypto.DeterministicKey;
|
||||
import org.bitcoinj.params.MainNetParams;
|
||||
import org.bitcoinj.params.UnitTestParams;
|
||||
@ -65,7 +79,7 @@ public class WalletProtobufSerializerTest {
|
||||
|
||||
private ECKey myKey;
|
||||
private ECKey myWatchedKey;
|
||||
private LegacyAddress myAddress;
|
||||
private Address myAddress;
|
||||
private Wallet myWallet;
|
||||
|
||||
public static String WALLET_DESCRIPTION = "The quick brown fox lives in \u4f26\u6566"; // Beijing in Chinese
|
||||
|
@ -219,7 +219,7 @@ public class FakeTxBuilder {
|
||||
public static DoubleSpends createFakeDoubleSpendTxns(NetworkParameters params, Address to) {
|
||||
DoubleSpends doubleSpends = new DoubleSpends();
|
||||
Coin value = COIN;
|
||||
LegacyAddress someBadGuy = LegacyAddress.fromKey(params, new ECKey());
|
||||
Address someBadGuy = LegacyAddress.fromKey(params, new ECKey());
|
||||
|
||||
doubleSpends.prevTx = new Transaction(params);
|
||||
TransactionOutput prevOut = new TransactionOutput(params, doubleSpends.prevTx, value, someBadGuy);
|
||||
@ -261,7 +261,7 @@ public class FakeTxBuilder {
|
||||
Transaction... transactions) {
|
||||
try {
|
||||
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);
|
||||
// Coinbase tx was already added.
|
||||
for (Transaction tx : transactions) {
|
||||
@ -313,7 +313,7 @@ public class FakeTxBuilder {
|
||||
}
|
||||
|
||||
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);
|
||||
// Coinbase tx already exists.
|
||||
for (Transaction tx : transactions) {
|
||||
|
@ -54,7 +54,7 @@ public class TestWithNetworkConnections {
|
||||
protected BlockChain blockChain;
|
||||
protected Wallet wallet;
|
||||
protected ECKey key;
|
||||
protected LegacyAddress address;
|
||||
protected Address address;
|
||||
protected SocketAddress socketAddress;
|
||||
|
||||
private NioServer[] peerServers = new NioServer[PEER_SERVERS];
|
||||
|
@ -16,7 +16,17 @@
|
||||
|
||||
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.UnitTestParams;
|
||||
import org.bitcoinj.store.BlockStore;
|
||||
@ -42,7 +52,7 @@ public class TestWithWallet {
|
||||
protected static final NetworkParameters MAINNET = MainNetParams.get();
|
||||
|
||||
protected ECKey myKey;
|
||||
protected LegacyAddress myAddress;
|
||||
protected Address myAddress;
|
||||
protected Wallet wallet;
|
||||
protected BlockChain chain;
|
||||
protected BlockStore blockStore;
|
||||
@ -82,7 +92,7 @@ public class TestWithWallet {
|
||||
}
|
||||
|
||||
@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));
|
||||
}
|
||||
|
||||
@ -102,7 +112,7 @@ public class TestWithWallet {
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
package org.bitcoinj.uri;
|
||||
|
||||
import org.bitcoinj.core.Address;
|
||||
import org.bitcoinj.core.LegacyAddress;
|
||||
import org.bitcoinj.params.MainNetParams;
|
||||
import org.bitcoinj.params.TestNet3Params;
|
||||
@ -39,7 +40,7 @@ public class BitcoinURITest {
|
||||
|
||||
@Test
|
||||
public void testConvertToBitcoinURI() throws Exception {
|
||||
LegacyAddress goodAddress = LegacyAddress.fromBase58(MAINNET, MAINNET_GOOD_ADDRESS);
|
||||
Address goodAddress = LegacyAddress.fromBase58(MAINNET, MAINNET_GOOD_ADDRESS);
|
||||
|
||||
// simple example
|
||||
assertEquals("bitcoin:" + MAINNET_GOOD_ADDRESS + "?amount=12.34&label=Hello&message=AMessage", BitcoinURI.convertToBitcoinURI(goodAddress, parseCoin("12.34"), "Hello", "AMessage"));
|
||||
|
@ -17,7 +17,13 @@
|
||||
|
||||
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.params.MainNetParams;
|
||||
import org.bitcoinj.params.UnitTestParams;
|
||||
@ -72,7 +78,7 @@ public class DeterministicKeyChainTest {
|
||||
ECKey key2 = chain.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS);
|
||||
assertFalse(key2.isPubKeyOnly());
|
||||
|
||||
final LegacyAddress address = LegacyAddress.fromBase58(UNITTEST, "n1bQNoEx8uhmCzzA5JPG6sFdtsUQhwiQJV");
|
||||
final Address address = LegacyAddress.fromBase58(UNITTEST, "n1bQNoEx8uhmCzzA5JPG6sFdtsUQhwiQJV");
|
||||
assertEquals(address, LegacyAddress.fromKey(UNITTEST, key1));
|
||||
assertEquals("mnHUcqUVvrfi5kAaXJDQzBb9HsWs78b42R", LegacyAddress.fromKey(UNITTEST, key2).toString());
|
||||
assertEquals(key1, chain.findKeyFromPubHash(address.getHash()));
|
||||
@ -103,7 +109,7 @@ public class DeterministicKeyChainTest {
|
||||
ECKey key1 = 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("mnp2j9za5zMuz44vNxrJCXXhZsCdh89QXn", LegacyAddress.fromKey(UNITTEST, key2).toString());
|
||||
assertEquals(key1, chain1.findKeyFromPubHash(address.getHash()));
|
||||
@ -137,7 +143,7 @@ public class DeterministicKeyChainTest {
|
||||
DeterministicKeyChain chain1 = new AccountOneChain(ENTROPY, "", secs);
|
||||
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));
|
||||
|
||||
DeterministicKey watching = chain1.getWatchingKey();
|
||||
|
@ -16,7 +16,12 @@
|
||||
|
||||
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.params.MainNetParams;
|
||||
import org.bitcoinj.script.Script.ScriptType;
|
||||
@ -170,19 +175,19 @@ public class KeyChainGroupTest {
|
||||
@Test
|
||||
public void currentP2SHAddress() throws Exception {
|
||||
group = createMarriedKeyChainGroup();
|
||||
LegacyAddress a1 = group.currentAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
|
||||
Address a1 = group.currentAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
|
||||
assertEquals(ScriptType.P2SH, a1.getOutputScriptType());
|
||||
LegacyAddress a2 = group.currentAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
|
||||
Address a2 = group.currentAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
|
||||
assertEquals(a1, a2);
|
||||
LegacyAddress a3 = group.currentAddress(KeyChain.KeyPurpose.CHANGE);
|
||||
Address a3 = group.currentAddress(KeyChain.KeyPurpose.CHANGE);
|
||||
assertNotEquals(a2, a3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void freshAddress() throws Exception {
|
||||
group = createMarriedKeyChainGroup();
|
||||
LegacyAddress a1 = group.freshAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
|
||||
LegacyAddress a2 = group.freshAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
|
||||
Address a1 = group.freshAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
|
||||
Address a2 = group.freshAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
|
||||
assertEquals(ScriptType.P2SH, a1.getOutputScriptType());
|
||||
assertNotEquals(a1, a2);
|
||||
group.getBloomFilterElementCount();
|
||||
@ -190,7 +195,7 @@ public class KeyChainGroupTest {
|
||||
+ (2 - group.getLookaheadThreshold()) // keys issued
|
||||
+ 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);
|
||||
}
|
||||
|
||||
@ -202,7 +207,7 @@ public class KeyChainGroupTest {
|
||||
assertNull(group.findRedeemDataFromScriptHash(new ECKey().getPubKey()));
|
||||
|
||||
// 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());
|
||||
assertNotNull(redeemData);
|
||||
assertNotNull(redeemData.redeemScript);
|
||||
@ -332,7 +337,7 @@ public class KeyChainGroupTest {
|
||||
@Test
|
||||
public void findRedeemScriptFromPubHash() throws Exception {
|
||||
group = createMarriedKeyChainGroup();
|
||||
LegacyAddress address = group.freshAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
|
||||
Address address = group.freshAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
|
||||
assertTrue(group.findRedeemDataFromScriptHash(address.getHash()) != null);
|
||||
group.getBloomFilterElementCount();
|
||||
KeyChainGroup group2 = createMarriedKeyChainGroup();
|
||||
@ -352,17 +357,17 @@ public class KeyChainGroupTest {
|
||||
int bufferSize = group.getLookaheadSize() + group.getLookaheadThreshold();
|
||||
int expected = bufferSize * 2 /* chains */ * 2 /* elements */;
|
||||
assertEquals(expected, group.getBloomFilterElementCount());
|
||||
LegacyAddress address1 = group.freshAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
|
||||
Address address1 = group.freshAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
|
||||
assertEquals(expected, group.getBloomFilterElementCount());
|
||||
BloomFilter filter = group.getBloomFilter(expected + 2, 0.001, (long)(Math.random() * Long.MAX_VALUE));
|
||||
assertTrue(filter.contains(address1.getHash()));
|
||||
|
||||
LegacyAddress address2 = group.freshAddress(KeyChain.KeyPurpose.CHANGE);
|
||||
Address address2 = group.freshAddress(KeyChain.KeyPurpose.CHANGE);
|
||||
assertTrue(filter.contains(address2.getHash()));
|
||||
|
||||
// Check that the filter contains the lookahead buffer.
|
||||
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()));
|
||||
}
|
||||
// We ran ahead of the lookahead buffer.
|
||||
@ -463,7 +468,7 @@ public class KeyChainGroupTest {
|
||||
@Test
|
||||
public void serializeMarried() throws Exception {
|
||||
group = createMarriedKeyChainGroup();
|
||||
LegacyAddress address1 = group.currentAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
|
||||
Address address1 = group.currentAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
|
||||
assertTrue(group.isMarried());
|
||||
assertEquals(2, group.getActiveKeyChain().getSigsRequiredToSpend());
|
||||
|
||||
@ -471,7 +476,7 @@ public class KeyChainGroupTest {
|
||||
KeyChainGroup group2 = KeyChainGroup.fromProtobufUnencrypted(MAINNET, protoKeys);
|
||||
assertTrue(group2.isMarried());
|
||||
assertEquals(2, group.getActiveKeyChain().getSigsRequiredToSpend());
|
||||
LegacyAddress address2 = group2.currentAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
|
||||
Address address2 = group2.currentAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
|
||||
assertEquals(address1, address2);
|
||||
}
|
||||
|
||||
@ -579,11 +584,11 @@ public class KeyChainGroupTest {
|
||||
|
||||
@Test
|
||||
public void markAsUsed() throws Exception {
|
||||
LegacyAddress addr1 = group.currentAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
|
||||
LegacyAddress addr2 = group.currentAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
|
||||
Address addr1 = group.currentAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
|
||||
Address addr2 = group.currentAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
|
||||
assertEquals(addr1, addr2);
|
||||
group.markPubKeyHashAsUsed(addr1.getHash());
|
||||
LegacyAddress addr3 = group.currentAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
|
||||
Address addr3 = group.currentAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
|
||||
assertNotEquals(addr2, addr3);
|
||||
}
|
||||
|
||||
|
@ -20,12 +20,12 @@ package org.bitcoinj.wallet;
|
||||
import org.bitcoinj.core.listeners.TransactionConfidenceEventListener;
|
||||
import org.bitcoinj.core.AbstractBlockChain;
|
||||
import org.bitcoinj.core.Address;
|
||||
import org.bitcoinj.core.LegacyAddress;
|
||||
import org.bitcoinj.core.Block;
|
||||
import org.bitcoinj.core.BlockChain;
|
||||
import org.bitcoinj.core.Coin;
|
||||
import org.bitcoinj.core.ECKey;
|
||||
import org.bitcoinj.core.InsufficientMoneyException;
|
||||
import org.bitcoinj.core.LegacyAddress;
|
||||
import org.bitcoinj.core.PeerAddress;
|
||||
import org.bitcoinj.core.Sha256Hash;
|
||||
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 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
|
||||
@Override
|
||||
@ -153,7 +153,7 @@ public class WalletTest extends TestWithWallet {
|
||||
|
||||
@Test
|
||||
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);
|
||||
}
|
||||
|
||||
@ -161,7 +161,7 @@ public class WalletTest extends TestWithWallet {
|
||||
public void basicSpendingWithEncryptedWallet() throws Exception {
|
||||
Wallet encryptedWallet = new Wallet(UNITTEST);
|
||||
encryptedWallet.encrypt(PASSWORD1);
|
||||
LegacyAddress myEncryptedAddress = LegacyAddress.fromKey(UNITTEST, encryptedWallet.freshReceiveKey());
|
||||
Address myEncryptedAddress = LegacyAddress.fromKey(UNITTEST, encryptedWallet.freshReceiveKey());
|
||||
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);
|
||||
|
||||
Coin v2 = valueOf(0, 50);
|
||||
@ -297,7 +297,7 @@ public class WalletTest extends TestWithWallet {
|
||||
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
|
||||
// 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.
|
||||
@ -378,11 +378,11 @@ public class WalletTest extends TestWithWallet {
|
||||
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);
|
||||
}
|
||||
|
||||
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> estimatedFuture = wallet.getBalanceFuture(amount, Wallet.BalanceType.ESTIMATED);
|
||||
assertFalse(availFuture.isDone());
|
||||
@ -411,7 +411,7 @@ public class WalletTest extends TestWithWallet {
|
||||
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 outputs",2, t.getOutputs().size());
|
||||
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.
|
||||
Transaction send1 = wallet.createSend(OTHER_ADDRESS, valueOf(2, 90));
|
||||
// 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);
|
||||
send2 = UNITTEST.getDefaultSerializer().makeTransaction(send2.bitcoinSerialize());
|
||||
// Broadcast send1, it's now pending.
|
||||
@ -874,7 +874,7 @@ public class WalletTest extends TestWithWallet {
|
||||
// Create a send to a merchant.
|
||||
Transaction send1 = wallet.createSend(OTHER_ADDRESS, valueOf(0, 50));
|
||||
// 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));
|
||||
send2 = UNITTEST.getDefaultSerializer().makeTransaction(send2.bitcoinSerialize());
|
||||
// Broadcast send1.
|
||||
@ -1409,7 +1409,7 @@ public class WalletTest extends TestWithWallet {
|
||||
Coin nanos = COIN;
|
||||
|
||||
// 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);
|
||||
TransactionOutput doubleSpentOut = new TransactionOutput(UNITTEST, doubleSpentTx, nanos, badGuy);
|
||||
doubleSpentTx.addOutput(doubleSpentOut);
|
||||
@ -1645,7 +1645,7 @@ public class WalletTest extends TestWithWallet {
|
||||
@Test
|
||||
public void watchingScripts() throws Exception {
|
||||
// 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);
|
||||
Coin value = valueOf(5, 0);
|
||||
Transaction t1 = createFakeTx(UNITTEST, value, watchedAddress);
|
||||
@ -1655,7 +1655,7 @@ public class WalletTest extends TestWithWallet {
|
||||
|
||||
@Test(expected = InsufficientMoneyException.class)
|
||||
public void watchingScriptsConfirmed() throws Exception {
|
||||
LegacyAddress watchedAddress = LegacyAddress.fromKey(UNITTEST, new ECKey());
|
||||
Address watchedAddress = LegacyAddress.fromKey(UNITTEST, new ECKey());
|
||||
wallet.addWatchedAddress(watchedAddress);
|
||||
sendMoneyToWallet(BlockChain.NewBlockType.BEST_CHAIN, CENT, watchedAddress);
|
||||
assertEquals(CENT, wallet.getBalance());
|
||||
@ -1668,7 +1668,7 @@ public class WalletTest extends TestWithWallet {
|
||||
public void watchingScriptsSentFrom() throws Exception {
|
||||
int baseElements = wallet.getBloomFilterElementCount();
|
||||
|
||||
LegacyAddress watchedAddress = LegacyAddress.fromKey(UNITTEST, new ECKey());
|
||||
Address watchedAddress = LegacyAddress.fromKey(UNITTEST, new ECKey());
|
||||
wallet.addWatchedAddress(watchedAddress);
|
||||
assertEquals(baseElements + 1, wallet.getBloomFilterElementCount());
|
||||
|
||||
@ -1690,7 +1690,7 @@ public class WalletTest extends TestWithWallet {
|
||||
public void watchingScriptsBloomFilter() throws Exception {
|
||||
assertFalse(wallet.isRequiringUpdateAllBloomFilter());
|
||||
|
||||
LegacyAddress watchedAddress = LegacyAddress.fromKey(UNITTEST, new ECKey());
|
||||
Address watchedAddress = LegacyAddress.fromKey(UNITTEST, new ECKey());
|
||||
Transaction t1 = createFakeTx(UNITTEST, CENT, watchedAddress);
|
||||
TransactionOutPoint outPoint = new TransactionOutPoint(UNITTEST, 0, t1);
|
||||
wallet.addWatchedAddress(watchedAddress);
|
||||
@ -1705,24 +1705,24 @@ public class WalletTest extends TestWithWallet {
|
||||
|
||||
@Test
|
||||
public void getWatchedAddresses() throws Exception {
|
||||
LegacyAddress watchedAddress = LegacyAddress.fromKey(UNITTEST, new ECKey());
|
||||
Address watchedAddress = LegacyAddress.fromKey(UNITTEST, new ECKey());
|
||||
wallet.addWatchedAddress(watchedAddress);
|
||||
List<LegacyAddress> watchedAddresses = wallet.getWatchedAddresses();
|
||||
List<Address> watchedAddresses = wallet.getWatchedAddresses();
|
||||
assertEquals(1, watchedAddresses.size());
|
||||
assertEquals(watchedAddress, watchedAddresses.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removeWatchedAddresses() {
|
||||
List<LegacyAddress> addressesForRemoval = new ArrayList<>();
|
||||
List<Address> addressesForRemoval = new ArrayList<>();
|
||||
for (int i = 0; i < 10; i++) {
|
||||
LegacyAddress watchedAddress = LegacyAddress.fromKey(UNITTEST, new ECKey());
|
||||
Address watchedAddress = LegacyAddress.fromKey(UNITTEST, new ECKey());
|
||||
addressesForRemoval.add(watchedAddress);
|
||||
wallet.addWatchedAddress(watchedAddress);
|
||||
}
|
||||
|
||||
wallet.removeWatchedAddresses(addressesForRemoval);
|
||||
for (LegacyAddress addr : addressesForRemoval)
|
||||
for (Address addr : addressesForRemoval)
|
||||
assertFalse(wallet.isAddressWatched(addr));
|
||||
|
||||
assertFalse(wallet.isRequiringUpdateAllBloomFilter());
|
||||
@ -1730,7 +1730,7 @@ public class WalletTest extends TestWithWallet {
|
||||
|
||||
@Test
|
||||
public void removeWatchedAddress() {
|
||||
LegacyAddress watchedAddress = LegacyAddress.fromKey(UNITTEST, new ECKey());
|
||||
Address watchedAddress = LegacyAddress.fromKey(UNITTEST, new ECKey());
|
||||
wallet.addWatchedAddress(watchedAddress);
|
||||
wallet.removeWatchedAddress(watchedAddress);
|
||||
assertFalse(wallet.isAddressWatched(watchedAddress));
|
||||
@ -1739,16 +1739,16 @@ public class WalletTest extends TestWithWallet {
|
||||
|
||||
@Test
|
||||
public void removeScriptsBloomFilter() throws Exception {
|
||||
List<LegacyAddress> addressesForRemoval = new ArrayList<>();
|
||||
List<Address> addressesForRemoval = new ArrayList<>();
|
||||
for (int i = 0; i < 10; i++) {
|
||||
LegacyAddress watchedAddress = LegacyAddress.fromKey(UNITTEST, new ECKey());
|
||||
Address watchedAddress = LegacyAddress.fromKey(UNITTEST, new ECKey());
|
||||
addressesForRemoval.add(watchedAddress);
|
||||
wallet.addWatchedAddress(watchedAddress);
|
||||
}
|
||||
|
||||
wallet.removeWatchedAddresses(addressesForRemoval);
|
||||
|
||||
for (LegacyAddress addr : addressesForRemoval) {
|
||||
for (Address addr : addressesForRemoval) {
|
||||
Transaction t1 = createFakeTx(UNITTEST, CENT, addr);
|
||||
TransactionOutPoint outPoint = new TransactionOutPoint(UNITTEST, 0, t1);
|
||||
|
||||
@ -1763,7 +1763,7 @@ public class WalletTest extends TestWithWallet {
|
||||
@Test
|
||||
public void marriedKeychainBloomFilter() throws Exception {
|
||||
createMarriedWallet(2, 2);
|
||||
LegacyAddress address = wallet.currentReceiveAddress();
|
||||
Address address = wallet.currentReceiveAddress();
|
||||
|
||||
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.subtract(tx.getFee()), tx.getValueSentToMe(wallet));
|
||||
// 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());
|
||||
assertNotNull(rotatingToKey);
|
||||
assertFalse(wallet.isKeyRotating(rotatingToKey));
|
||||
@ -3063,7 +3063,7 @@ public class WalletTest extends TestWithWallet {
|
||||
public void fragmentedReKeying() throws Exception {
|
||||
// Send lots of small coins and check the fee is correct.
|
||||
ECKey key = wallet.freshReceiveKey();
|
||||
LegacyAddress address = LegacyAddress.fromKey(UNITTEST, key);
|
||||
Address address = LegacyAddress.fromKey(UNITTEST, key);
|
||||
Utils.setMockClock();
|
||||
Utils.rollMockClock(86400);
|
||||
for (int i = 0; i < 800; i++) {
|
||||
@ -3356,7 +3356,7 @@ public class WalletTest extends TestWithWallet {
|
||||
.build();
|
||||
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);
|
||||
|
||||
SendRequest req = SendRequest.emptyWallet(OTHER_ADDRESS);
|
||||
|
@ -17,7 +17,13 @@
|
||||
|
||||
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.kits.WalletAppKit;
|
||||
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.
|
||||
*/
|
||||
public class ForwardingService {
|
||||
private static LegacyAddress forwardingAddress;
|
||||
private static Address forwardingAddress;
|
||||
private static WalletAppKit kit;
|
||||
|
||||
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("Waiting for coins to arrive. Press Ctrl-C to quit.");
|
||||
|
||||
|
@ -17,7 +17,15 @@
|
||||
|
||||
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.store.MemoryBlockStore;
|
||||
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());
|
||||
// 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.
|
||||
Wallet wallet = new Wallet(params);
|
||||
|
@ -17,7 +17,6 @@
|
||||
|
||||
package org.bitcoinj.tools;
|
||||
|
||||
import org.bitcoinj.core.*;
|
||||
import org.bitcoinj.crypto.*;
|
||||
import org.bitcoinj.params.MainNetParams;
|
||||
import org.bitcoinj.params.RegTestParams;
|
||||
@ -47,6 +46,32 @@ import joptsimple.OptionSet;
|
||||
import joptsimple.OptionSpec;
|
||||
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.DownloadProgressTracker;
|
||||
import org.bitcoinj.wallet.MarriedKeyChain;
|
||||
@ -583,7 +608,7 @@ public class WalletTool {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
LegacyAddress address = LegacyAddress.fromBase58(params, addr);
|
||||
Address address = LegacyAddress.fromBase58(params, addr);
|
||||
// If no creation time is specified, assume genesis (zero).
|
||||
wallet.addWatchedAddress(address, getCreationTimeSeconds());
|
||||
} catch (AddressFormatException e) {
|
||||
@ -1464,7 +1489,7 @@ public class WalletTool {
|
||||
key = wallet.findKeyFromPubKey(Hex.decode(pubkey));
|
||||
} else {
|
||||
try {
|
||||
LegacyAddress address = LegacyAddress.fromBase58(wallet.getParams(), addr);
|
||||
Address address = LegacyAddress.fromBase58(wallet.getParams(), addr);
|
||||
key = wallet.findKeyFromPubHash(address.getHash());
|
||||
} catch (AddressFormatException e) {
|
||||
System.err.println(addr + " does not parse as a Bitcoin address of the right network parameters.");
|
||||
|
@ -16,7 +16,7 @@
|
||||
|
||||
package wallettemplate.controls;
|
||||
|
||||
import org.bitcoinj.core.LegacyAddress;
|
||||
import org.bitcoinj.core.Address;
|
||||
import org.bitcoinj.uri.BitcoinURI;
|
||||
import de.jensd.fx.fontawesome.AwesomeDude;
|
||||
import de.jensd.fx.fontawesome.AwesomeIcon;
|
||||
@ -61,7 +61,7 @@ public class ClickableBitcoinAddress extends AnchorPane {
|
||||
@FXML protected Label copyWidget;
|
||||
@FXML protected Label qrCode;
|
||||
|
||||
protected SimpleObjectProperty<LegacyAddress> address = new SimpleObjectProperty<>();
|
||||
protected SimpleObjectProperty<Address> address = new SimpleObjectProperty<>();
|
||||
private final StringExpression addressStr;
|
||||
|
||||
public ClickableBitcoinAddress() {
|
||||
@ -90,15 +90,15 @@ public class ClickableBitcoinAddress extends AnchorPane {
|
||||
return BitcoinURI.convertToBitcoinURI(address.get(), null, Main.APP_NAME, null);
|
||||
}
|
||||
|
||||
public LegacyAddress getAddress() {
|
||||
public Address getAddress() {
|
||||
return address.get();
|
||||
}
|
||||
|
||||
public void setAddress(LegacyAddress address) {
|
||||
public void setAddress(Address address) {
|
||||
this.address.set(address);
|
||||
}
|
||||
|
||||
public ObjectProperty<LegacyAddress> addressProperty() {
|
||||
public ObjectProperty<Address> addressProperty() {
|
||||
return address;
|
||||
}
|
||||
|
||||
|
@ -16,10 +16,11 @@
|
||||
|
||||
package wallettemplate.utils;
|
||||
|
||||
import org.bitcoinj.core.Address;
|
||||
import org.bitcoinj.core.Coin;
|
||||
import org.bitcoinj.core.listeners.DownloadProgressTracker;
|
||||
import org.bitcoinj.wallet.Wallet;
|
||||
import org.bitcoinj.wallet.listeners.WalletChangeEventListener;
|
||||
import org.bitcoinj.core.*;
|
||||
import javafx.application.Platform;
|
||||
import javafx.beans.property.ReadOnlyDoubleProperty;
|
||||
import javafx.beans.property.ReadOnlyObjectProperty;
|
||||
@ -32,7 +33,7 @@ import java.util.Date;
|
||||
* A class that exposes relevant bitcoin stuff as JavaFX bindable properties.
|
||||
*/
|
||||
public class BitcoinUIModel {
|
||||
private SimpleObjectProperty<LegacyAddress> address = new SimpleObjectProperty<>();
|
||||
private SimpleObjectProperty<Address> address = new SimpleObjectProperty<>();
|
||||
private SimpleObjectProperty<Coin> balance = new SimpleObjectProperty<>(Coin.ZERO);
|
||||
private SimpleDoubleProperty syncProgress = new SimpleDoubleProperty(-1);
|
||||
private ProgressBarUpdater syncProgressUpdater = new ProgressBarUpdater();
|
||||
@ -77,7 +78,7 @@ public class BitcoinUIModel {
|
||||
|
||||
public ReadOnlyDoubleProperty syncProgressProperty() { return syncProgress; }
|
||||
|
||||
public ReadOnlyObjectProperty<LegacyAddress> addressProperty() {
|
||||
public ReadOnlyObjectProperty<Address> addressProperty() {
|
||||
return address;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user