mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2025-02-22 14:22:45 +01:00
Address, LegacyAddress, SegwitAddress: migrate all usages of deprecated fromKey() to ECKey.toAddress()
This commit is contained in:
parent
1daa7d5569
commit
55d1919227
33 changed files with 164 additions and 146 deletions
|
@ -42,8 +42,8 @@ import static com.google.common.base.Preconditions.checkArgument;
|
|||
* <a href="https://github.com/bitcoin/bips/blob/master/bip-0173.mediawiki">BIP173</a> for details.</p>
|
||||
*
|
||||
* <p>However, you don't need to care about the internals. Use {@link #fromBech32(NetworkParameters, String)},
|
||||
* {@link #fromHash(NetworkParameters, byte[])} or {@link #fromKey(NetworkParameters, ECKey)} to construct a native
|
||||
* segwit address.</p>
|
||||
* {@link #fromHash(NetworkParameters, byte[])} or {@link ECKey#toAddress(ScriptType, org.bitcoinj.base.Network)}
|
||||
* to construct a native segwit address.</p>
|
||||
*/
|
||||
public class SegwitAddress extends Address {
|
||||
public static final int WITNESS_PROGRAM_LENGTH_PKH = 20;
|
||||
|
@ -54,7 +54,7 @@ public class SegwitAddress extends Address {
|
|||
|
||||
/**
|
||||
* Private constructor. Use {@link #fromBech32(NetworkParameters, String)},
|
||||
* {@link #fromHash(NetworkParameters, byte[])} or {@link #fromKey(NetworkParameters, ECKey)}.
|
||||
* {@link #fromHash(NetworkParameters, byte[])} or {@link ECKey#toAddress(ScriptType, org.bitcoinj.base.Network)}.
|
||||
*
|
||||
* @param params
|
||||
* network this address is valid for
|
||||
|
@ -81,7 +81,7 @@ public class SegwitAddress extends Address {
|
|||
|
||||
/**
|
||||
* Private constructor. Use {@link #fromBech32(NetworkParameters, String)},
|
||||
* {@link #fromHash(NetworkParameters, byte[])} or {@link #fromKey(NetworkParameters, ECKey)}.
|
||||
* {@link #fromHash(NetworkParameters, byte[])} or {@link ECKey#toAddress(ScriptType, org.bitcoinj.base.Network)}.
|
||||
*
|
||||
* @param params
|
||||
* network this address is valid for
|
||||
|
|
|
@ -17,11 +17,11 @@
|
|||
package org.bitcoinj.crypto;
|
||||
|
||||
import com.google.common.primitives.Bytes;
|
||||
import org.bitcoinj.base.ScriptType;
|
||||
import org.bitcoinj.base.utils.ByteUtils;
|
||||
import org.bitcoinj.base.exceptions.AddressFormatException;
|
||||
import org.bitcoinj.base.Base58;
|
||||
import org.bitcoinj.core.ECKey;
|
||||
import org.bitcoinj.core.LegacyAddress;
|
||||
import org.bitcoinj.core.NetworkParameters;
|
||||
import org.bitcoinj.core.PrefixedChecksummedBytes;
|
||||
import org.bitcoinj.base.Sha256Hash;
|
||||
|
@ -123,7 +123,7 @@ public class BIP38PrivateKey extends PrefixedChecksummedBytes {
|
|||
public ECKey decrypt(String passphrase) throws BadPassphraseException {
|
||||
String normalizedPassphrase = Normalizer.normalize(passphrase, Normalizer.Form.NFC);
|
||||
ECKey key = ecMultiply ? decryptEC(normalizedPassphrase) : decryptNoEC(normalizedPassphrase);
|
||||
Sha256Hash hash = Sha256Hash.twiceOf(LegacyAddress.fromKey(params, key).toString().getBytes(StandardCharsets.US_ASCII));
|
||||
Sha256Hash hash = Sha256Hash.twiceOf(key.toAddress(ScriptType.P2PKH, params.network()).toString().getBytes(StandardCharsets.US_ASCII));
|
||||
byte[] actualAddressHash = Arrays.copyOfRange(hash.getBytes(), 0, 4);
|
||||
if (!Arrays.equals(actualAddressHash, addressHash))
|
||||
throw new BadPassphraseException();
|
||||
|
|
|
@ -21,7 +21,6 @@ import com.google.common.annotations.VisibleForTesting;
|
|||
import com.google.common.base.MoreObjects;
|
||||
import org.bitcoinj.base.ScriptType;
|
||||
import org.bitcoinj.base.utils.ByteUtils;
|
||||
import org.bitcoinj.core.Address;
|
||||
import org.bitcoinj.base.Base58;
|
||||
import org.bitcoinj.core.ECKey;
|
||||
import org.bitcoinj.core.NetworkParameters;
|
||||
|
@ -677,7 +676,7 @@ public class DeterministicKey extends ECKey {
|
|||
@Override
|
||||
public void formatKeyWithAddress(boolean includePrivateKeys, @Nullable KeyParameter aesKey, StringBuilder builder,
|
||||
NetworkParameters params, ScriptType outputScriptType, @Nullable String comment) {
|
||||
builder.append(" addr:").append(Address.fromKey(params, this, outputScriptType).toString());
|
||||
builder.append(" addr:").append(toAddress(outputScriptType, params.network()).toString());
|
||||
builder.append(" hash160:").append(ByteUtils.HEX.encode(getPubKeyHash()));
|
||||
builder.append(" (").append(getPathAsString());
|
||||
if (comment != null)
|
||||
|
|
|
@ -398,7 +398,7 @@ public class Script {
|
|||
else if (ScriptPattern.isP2SH(this))
|
||||
return LegacyAddress.fromScriptHash(params, ScriptPattern.extractHashFromP2SH(this));
|
||||
else if (forcePayToPubKey && ScriptPattern.isP2PK(this))
|
||||
return LegacyAddress.fromKey(params, ECKey.fromPublicOnly(ScriptPattern.extractKeyFromP2PK(this)));
|
||||
return ECKey.fromPublicOnly(ScriptPattern.extractKeyFromP2PK(this)).toAddress(ScriptType.P2PKH, params.network());
|
||||
else if (ScriptPattern.isP2WH(this))
|
||||
return SegwitAddress.fromHash(params, ScriptPattern.extractHashFromP2WH(this));
|
||||
else if (ScriptPattern.isP2TR(this))
|
||||
|
|
|
@ -23,7 +23,6 @@ import org.bitcoinj.core.Address;
|
|||
import org.bitcoinj.core.Block;
|
||||
import org.bitcoinj.base.Coin;
|
||||
import org.bitcoinj.core.ECKey;
|
||||
import org.bitcoinj.core.LegacyAddress;
|
||||
import org.bitcoinj.core.NetworkParameters;
|
||||
import org.bitcoinj.core.ProtocolException;
|
||||
import org.bitcoinj.base.Sha256Hash;
|
||||
|
@ -1158,7 +1157,7 @@ public abstract class DatabaseFullPrunedBlockStore implements FullPrunedBlockSto
|
|||
s = conn.get().prepareStatement(getTransactionOutputSelectSQL());
|
||||
for (ECKey key : keys) {
|
||||
// TODO switch to pubKeyHash in order to support native segwit addresses
|
||||
s.setString(1, LegacyAddress.fromKey(params, key).toString());
|
||||
s.setString(1, key.toAddress(ScriptType.P2PKH, params.network()).toString());
|
||||
ResultSet rs = s.executeQuery();
|
||||
while (rs.next()) {
|
||||
Sha256Hash hash = Sha256Hash.wrap(rs.getBytes(1));
|
||||
|
|
|
@ -17,9 +17,9 @@
|
|||
package org.bitcoinj.store;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import org.bitcoinj.base.ScriptType;
|
||||
import org.bitcoinj.core.Address;
|
||||
import org.bitcoinj.core.ECKey;
|
||||
import org.bitcoinj.core.LegacyAddress;
|
||||
import org.bitcoinj.core.NetworkParameters;
|
||||
import org.bitcoinj.base.Sha256Hash;
|
||||
import org.bitcoinj.core.StoredBlock;
|
||||
|
@ -434,7 +434,7 @@ public class MemoryFullPrunedBlockStore implements FullPrunedBlockStore {
|
|||
for (UTXO output : outputsList) {
|
||||
for (ECKey key : keys) {
|
||||
// TODO switch to pubKeyHash in order to support native segwit addresses
|
||||
Address address = LegacyAddress.fromKey(params, key);
|
||||
Address address = key.toAddress(ScriptType.P2PKH, params.network());
|
||||
if (output.getAddress().equals(address.toString())) {
|
||||
foundOutputs.add(output);
|
||||
}
|
||||
|
|
|
@ -373,7 +373,7 @@ public class KeyChainGroup implements KeyBag {
|
|||
}
|
||||
return current;
|
||||
} else if (outputScriptType == ScriptType.P2PKH || outputScriptType == ScriptType.P2WPKH) {
|
||||
return Address.fromKey(params, currentKey(purpose), outputScriptType);
|
||||
return currentKey(purpose).toAddress(outputScriptType, params.network());
|
||||
} else {
|
||||
throw new IllegalStateException(chain.getOutputScriptType().toString());
|
||||
}
|
||||
|
@ -425,7 +425,7 @@ public class KeyChainGroup implements KeyBag {
|
|||
*/
|
||||
public Address freshAddress(KeyChain.KeyPurpose purpose, ScriptType outputScriptType, long keyRotationTimeSecs) {
|
||||
DeterministicKeyChain chain = getActiveKeyChain(outputScriptType, keyRotationTimeSecs);
|
||||
return Address.fromKey(params, chain.getKey(purpose), outputScriptType);
|
||||
return chain.getKey(purpose).toAddress(outputScriptType, params.network());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -443,7 +443,7 @@ public class KeyChainGroup implements KeyBag {
|
|||
currentAddresses.put(purpose, freshAddress);
|
||||
return freshAddress;
|
||||
} else if (outputScriptType == ScriptType.P2PKH || outputScriptType == ScriptType.P2WPKH) {
|
||||
return Address.fromKey(params, freshKey(purpose), outputScriptType);
|
||||
return freshKey(purpose).toAddress(outputScriptType, params.network());
|
||||
} else {
|
||||
throw new IllegalStateException(chain.getOutputScriptType().toString());
|
||||
}
|
||||
|
|
|
@ -724,7 +724,7 @@ public class Wallet extends BaseTaggableObject
|
|||
for (final DeterministicKeyChain chain : keyChainGroup.getActiveKeyChains(keyRotationTimeSecs)) {
|
||||
ScriptType outputScriptType = chain.getOutputScriptType();
|
||||
for (ECKey key : chain.getIssuedReceiveKeys())
|
||||
addresses.add(Address.fromKey(getParams(), key, outputScriptType));
|
||||
addresses.add(key.toAddress(outputScriptType, network()));
|
||||
}
|
||||
return addresses;
|
||||
} finally {
|
||||
|
|
|
@ -274,7 +274,7 @@ public abstract class AbstractFullPrunedBlockChainTest {
|
|||
// Create bitcoin spend of 1 BTC.
|
||||
ECKey toKey = new ECKey();
|
||||
Coin amount = Coin.valueOf(100000000);
|
||||
Address address = LegacyAddress.fromKey(PARAMS, toKey);
|
||||
Address address = toKey.toAddress(ScriptType.P2PKH, PARAMS.network());
|
||||
Coin totalAmount = Coin.ZERO;
|
||||
|
||||
Transaction t = new Transaction(PARAMS);
|
||||
|
@ -342,7 +342,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);
|
||||
Address address2 = LegacyAddress.fromKey(PARAMS, toKey2);
|
||||
Address address2 = toKey2.toAddress(ScriptType.P2PKH, PARAMS.network());
|
||||
SendRequest req = SendRequest.to(address2, amount2);
|
||||
wallet.completeTx(req);
|
||||
wallet.commitTx(req.tx);
|
||||
|
|
|
@ -106,7 +106,7 @@ public class BlockChainTest {
|
|||
resetBlockStore();
|
||||
chain = new BlockChain(UNITTEST, wallet, blockStore);
|
||||
|
||||
coinbaseTo = LegacyAddress.fromKey(UNITTEST, wallet.currentReceiveKey());
|
||||
coinbaseTo = wallet.currentReceiveKey().toAddress(ScriptType.P2PKH, UNITTEST.network());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -142,7 +142,7 @@ public class BlockChainTest {
|
|||
// Quick check that we can actually receive coins.
|
||||
Transaction tx1 = createFakeTx(UNITTEST,
|
||||
COIN,
|
||||
LegacyAddress.fromKey(UNITTEST, wallet.currentReceiveKey()));
|
||||
wallet.currentReceiveKey().toAddress(ScriptType.P2PKH, UNITTEST.network()));
|
||||
Block b1 = createFakeBlock(blockStore, height, tx1).block;
|
||||
chain.add(b1);
|
||||
assertTrue(wallet.getBalance().signum() > 0);
|
||||
|
@ -305,10 +305,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.
|
||||
Address somebodyElse = LegacyAddress.fromKey(UNITTEST, new ECKey());
|
||||
Address somebodyElse = new ECKey().toAddress(ScriptType.P2PKH, UNITTEST.network());
|
||||
Block b1 = UNITTEST.getGenesisBlock().createNextBlock(somebodyElse);
|
||||
ECKey key = wallet.freshReceiveKey();
|
||||
Address addr = LegacyAddress.fromKey(UNITTEST, key);
|
||||
Address addr = key.toAddress(ScriptType.P2PKH, UNITTEST.network());
|
||||
// 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);
|
||||
|
@ -331,7 +331,7 @@ public class BlockChainTest {
|
|||
int height = 1;
|
||||
chain.addWallet(wallet2);
|
||||
|
||||
Address addressToSendTo = LegacyAddress.fromKey(UNITTEST, receiveKey);
|
||||
Address addressToSendTo = receiveKey.toAddress(ScriptType.P2PKH, UNITTEST.network());
|
||||
|
||||
// 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++);
|
||||
|
@ -355,7 +355,7 @@ public class BlockChainTest {
|
|||
// Check that the coinbase is unavailable to spend for the next spendableCoinbaseDepth - 2 blocks.
|
||||
for (int i = 0; i < UNITTEST.getSpendableCoinbaseDepth() - 2; i++) {
|
||||
// Non relevant tx - just for fake block creation.
|
||||
Transaction tx2 = createFakeTx(UNITTEST, COIN, LegacyAddress.fromKey(UNITTEST, new ECKey()));
|
||||
Transaction tx2 = createFakeTx(UNITTEST, COIN, new ECKey().toAddress(ScriptType.P2PKH, UNITTEST.network()));
|
||||
|
||||
Block b2 = createFakeBlock(blockStore, height++, tx2).block;
|
||||
chain.add(b2);
|
||||
|
@ -376,7 +376,7 @@ public class BlockChainTest {
|
|||
}
|
||||
|
||||
// Give it one more block - should now be able to spend coinbase transaction. Non relevant tx.
|
||||
Transaction tx3 = createFakeTx(UNITTEST, COIN, LegacyAddress.fromKey(UNITTEST, new ECKey()));
|
||||
Transaction tx3 = createFakeTx(UNITTEST, COIN, new ECKey().toAddress(ScriptType.P2PKH, UNITTEST.network()));
|
||||
Block b3 = createFakeBlock(blockStore, height++, tx3).block;
|
||||
chain.add(b3);
|
||||
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
|
||||
package org.bitcoinj.core;
|
||||
|
||||
import org.bitcoinj.base.BitcoinNetwork;
|
||||
import org.bitcoinj.base.ScriptType;
|
||||
import org.bitcoinj.params.MainNetParams;
|
||||
import org.bitcoinj.wallet.KeyChainGroup;
|
||||
import org.bitcoinj.wallet.Wallet;
|
||||
|
@ -74,7 +76,7 @@ public class BloomFilterTest {
|
|||
|
||||
DumpedPrivateKey privKey = DumpedPrivateKey.fromBase58(MAINNET, "5Kg1gnAjaLfKiwhhPpGS3QfRg2m6awQvaj98JCZBZQ5SuS2F15C");
|
||||
|
||||
Address addr = LegacyAddress.fromKey(MAINNET, privKey.getKey());
|
||||
Address addr = privKey.getKey().toAddress(ScriptType.P2PKH, BitcoinNetwork.MAINNET);
|
||||
assertEquals("17Wx1GQfyPTNWpQMHrTwRSMTCAonSiZx9e", addr.toString());
|
||||
|
||||
KeyChainGroup group = KeyChainGroup.builder(MAINNET).build();
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
|
||||
package org.bitcoinj.core;
|
||||
|
||||
import org.bitcoinj.base.BitcoinNetwork;
|
||||
import org.bitcoinj.base.Coin;
|
||||
import org.bitcoinj.base.ScriptType;
|
||||
import org.bitcoinj.base.Sha256Hash;
|
||||
|
@ -71,9 +72,9 @@ public class ChainSplitTest {
|
|||
ECKey key1 = wallet.freshReceiveKey();
|
||||
ECKey key2 = wallet.freshReceiveKey();
|
||||
chain = new BlockChain(TESTNET, wallet, blockStore);
|
||||
coinsTo = LegacyAddress.fromKey(TESTNET, key1);
|
||||
coinsTo2 = LegacyAddress.fromKey(TESTNET, key2);
|
||||
someOtherGuy = LegacyAddress.fromKey(TESTNET, new ECKey());
|
||||
coinsTo = key1.toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET);
|
||||
coinsTo2 = key2.toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET);
|
||||
someOtherGuy = new ECKey().toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -181,7 +182,7 @@ public class ChainSplitTest {
|
|||
Block b1 = TESTNET.getGenesisBlock().createNextBlock(coinsTo);
|
||||
chain.add(b1);
|
||||
assertEquals(FIFTY_COINS, wallet.getBalance());
|
||||
Address dest = LegacyAddress.fromKey(TESTNET, new ECKey());
|
||||
Address dest = new ECKey().toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET);
|
||||
Transaction spend = wallet.createSend(dest, valueOf(10, 0));
|
||||
wallet.commitTx(spend);
|
||||
// Waiting for confirmation ... make it eligible for selection.
|
||||
|
@ -215,7 +216,7 @@ public class ChainSplitTest {
|
|||
Block b1 = TESTNET.getGenesisBlock().createNextBlock(coinsTo);
|
||||
chain.add(b1);
|
||||
assertEquals(FIFTY_COINS, wallet.getBalance());
|
||||
Address dest = LegacyAddress.fromKey(TESTNET, new ECKey());
|
||||
Address dest = new ECKey().toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET);
|
||||
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.
|
||||
|
@ -303,21 +304,21 @@ public class ChainSplitTest {
|
|||
chain.add(b1);
|
||||
|
||||
Transaction t1 = wallet.createSend(someOtherGuy, valueOf(10, 0));
|
||||
Address yetAnotherGuy = LegacyAddress.fromKey(TESTNET, new ECKey());
|
||||
Address yetAnotherGuy = new ECKey().toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET);
|
||||
Transaction t2 = wallet.createSend(yetAnotherGuy, valueOf(20, 0));
|
||||
wallet.commitTx(t1);
|
||||
// Receive t1 as confirmed by the network.
|
||||
Block b2 = b1.createNextBlock(LegacyAddress.fromKey(TESTNET, new ECKey()));
|
||||
Block b2 = b1.createNextBlock(new ECKey().toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET));
|
||||
b2.addTransaction(t1);
|
||||
b2.solve();
|
||||
chain.add(roundtrip(b2));
|
||||
|
||||
// Now we make a double spend become active after a re-org.
|
||||
Block b3 = b1.createNextBlock(LegacyAddress.fromKey(TESTNET, new ECKey()));
|
||||
Block b3 = b1.createNextBlock(new ECKey().toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET));
|
||||
b3.addTransaction(t2);
|
||||
b3.solve();
|
||||
chain.add(roundtrip(b3)); // Side chain.
|
||||
Block b4 = b3.createNextBlock(LegacyAddress.fromKey(TESTNET, new ECKey()));
|
||||
Block b4 = b3.createNextBlock(new ECKey().toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET));
|
||||
chain.add(b4); // New best chain.
|
||||
Threading.waitForUserCode();
|
||||
// Should have seen a double spend.
|
||||
|
@ -343,11 +344,11 @@ public class ChainSplitTest {
|
|||
chain.add(b1);
|
||||
|
||||
Transaction t1 = checkNotNull(wallet.createSend(someOtherGuy, valueOf(10, 0)));
|
||||
Address yetAnotherGuy = LegacyAddress.fromKey(TESTNET, new ECKey());
|
||||
Address yetAnotherGuy = new ECKey().toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET);
|
||||
Transaction t2 = checkNotNull(wallet.createSend(yetAnotherGuy, valueOf(20, 0)));
|
||||
wallet.commitTx(t1);
|
||||
// t1 is still pending ...
|
||||
Block b2 = b1.createNextBlock(LegacyAddress.fromKey(TESTNET, new ECKey()));
|
||||
Block b2 = b1.createNextBlock(new ECKey().toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET));
|
||||
chain.add(b2);
|
||||
assertEquals(ZERO, wallet.getBalance());
|
||||
assertEquals(valueOf(40, 0), wallet.getBalance(Wallet.BalanceType.ESTIMATED));
|
||||
|
@ -355,11 +356,11 @@ public class ChainSplitTest {
|
|||
// Now we make a double spend become active after a re-org.
|
||||
// genesis -> b1 -> b2 [t1 pending]
|
||||
// \-> b3 (t2) -> b4
|
||||
Block b3 = b1.createNextBlock(LegacyAddress.fromKey(TESTNET, new ECKey()));
|
||||
Block b3 = b1.createNextBlock(new ECKey().toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET));
|
||||
b3.addTransaction(t2);
|
||||
b3.solve();
|
||||
chain.add(roundtrip(b3)); // Side chain.
|
||||
Block b4 = b3.createNextBlock(LegacyAddress.fromKey(TESTNET, new ECKey()));
|
||||
Block b4 = b3.createNextBlock(new ECKey().toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET));
|
||||
chain.add(b4); // New best chain.
|
||||
Threading.waitForUserCode();
|
||||
// Should have seen a double spend against the pending pool.
|
||||
|
@ -370,9 +371,9 @@ public class ChainSplitTest {
|
|||
assertEquals(valueOf(30, 0), wallet.getBalance());
|
||||
|
||||
// ... and back to our own parallel universe.
|
||||
Block b5 = b2.createNextBlock(LegacyAddress.fromKey(TESTNET, new ECKey()));
|
||||
Block b5 = b2.createNextBlock(new ECKey().toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET));
|
||||
chain.add(b5);
|
||||
Block b6 = b5.createNextBlock(LegacyAddress.fromKey(TESTNET, new ECKey()));
|
||||
Block b6 = b5.createNextBlock(new ECKey().toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET));
|
||||
chain.add(b6);
|
||||
// genesis -> b1 -> b2 -> b5 -> b6 [t1 still dead]
|
||||
// \-> b3 [t2 resurrected and now pending] -> b4
|
||||
|
@ -513,9 +514,9 @@ public class ChainSplitTest {
|
|||
chain.add(b1);
|
||||
|
||||
// Send a couple of payments one after the other (so the second depends on the change output of the first).
|
||||
Transaction t2 = checkNotNull(wallet.createSend(LegacyAddress.fromKey(TESTNET, new ECKey()), CENT, true));
|
||||
Transaction t2 = checkNotNull(wallet.createSend(new ECKey().toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET), CENT, true));
|
||||
wallet.commitTx(t2);
|
||||
Transaction t3 = checkNotNull(wallet.createSend(LegacyAddress.fromKey(TESTNET, new ECKey()), CENT, true));
|
||||
Transaction t3 = checkNotNull(wallet.createSend(new ECKey().toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET), CENT, true));
|
||||
wallet.commitTx(t3);
|
||||
chain.add(FakeTxBuilder.makeSolvedTestBlock(b1, t2, t3));
|
||||
|
||||
|
@ -578,7 +579,7 @@ public class ChainSplitTest {
|
|||
chain.add(firstTip);
|
||||
}
|
||||
// ... and spend.
|
||||
Transaction fodder = wallet.createSend(LegacyAddress.fromKey(TESTNET, new ECKey()), FIFTY_COINS);
|
||||
Transaction fodder = wallet.createSend(new ECKey().toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET), FIFTY_COINS);
|
||||
wallet.commitTx(fodder);
|
||||
final AtomicBoolean fodderIsDead = new AtomicBoolean(false);
|
||||
fodder.getConfidence().addEventListener(Threading.SAME_THREAD, (confidence, reason) -> fodderIsDead.set(confidence.getConfidenceType() == ConfidenceType.DEAD));
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
package org.bitcoinj.core;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import org.bitcoinj.base.BitcoinNetwork;
|
||||
import org.bitcoinj.base.ScriptType;
|
||||
import org.bitcoinj.base.Sha256Hash;
|
||||
import org.bitcoinj.base.utils.ByteUtils;
|
||||
import org.bitcoinj.core.ECKey.ECDSASignature;
|
||||
|
@ -185,7 +187,7 @@ public class ECKeyTest {
|
|||
String privkey = "92shANodC6Y4evT5kFzjNFQAdjqTtHAnDTLzqBBq4BbKUPyx6CD";
|
||||
ECKey key = DumpedPrivateKey.fromBase58(TESTNET, privkey).getKey();
|
||||
assertEquals(privkey, key.getPrivateKeyEncoded(TESTNET).toString());
|
||||
assertEquals(addr, LegacyAddress.fromKey(TESTNET, key).toString());
|
||||
assertEquals(addr, key.toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET).toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -213,7 +215,7 @@ public class ECKeyTest {
|
|||
ECKey key = new ECKey();
|
||||
String message = "聡中本";
|
||||
String signatureBase64 = key.signMessage(message);
|
||||
log.info("Message signed with " + LegacyAddress.fromKey(MAINNET, key) + ": " + signatureBase64);
|
||||
log.info("Message signed with " + key.toAddress(ScriptType.P2PKH, BitcoinNetwork.MAINNET) + ": " + signatureBase64);
|
||||
// Should verify correctly.
|
||||
key.verifyMessage(message, signatureBase64);
|
||||
try {
|
||||
|
@ -231,7 +233,7 @@ public class ECKeyTest {
|
|||
String sigBase64 = "HxNZdo6ggZ41hd3mM3gfJRqOQPZYcO8z8qdX2BwmpbF11CaOQV+QiZGGQxaYOncKoNW61oRuSMMF8udfK54XqI8=";
|
||||
Address expectedAddress = LegacyAddress.fromBase58(MAINNET, "14YPSNPi6NSXnUxtPAsyJSuw3pv7AU3Cag");
|
||||
ECKey key = ECKey.signedMessageToKey(message, sigBase64);
|
||||
Address gotAddress = LegacyAddress.fromKey(MAINNET, key);
|
||||
Address gotAddress = key.toAddress(ScriptType.P2PKH, BitcoinNetwork.MAINNET);
|
||||
assertEquals(expectedAddress, gotAddress);
|
||||
}
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
|
||||
package org.bitcoinj.core;
|
||||
|
||||
import org.bitcoinj.base.BitcoinNetwork;
|
||||
import org.bitcoinj.base.ScriptType;
|
||||
import org.bitcoinj.base.utils.ByteUtils;
|
||||
import org.bitcoinj.params.MainNetParams;
|
||||
|
@ -98,17 +99,17 @@ public class ParseByteCacheTest {
|
|||
|
||||
Transaction tx1 = createFakeTx(TESTNET,
|
||||
valueOf(2, 0),
|
||||
LegacyAddress.fromKey(TESTNET, wallet.currentReceiveKey()));
|
||||
wallet.currentReceiveKey().toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET));
|
||||
|
||||
// add a second input so can test granularity of byte cache.
|
||||
Transaction prevTx = new Transaction(TESTNET);
|
||||
TransactionOutput prevOut = new TransactionOutput(TESTNET, prevTx, COIN, LegacyAddress.fromKey(TESTNET, wallet.currentReceiveKey()));
|
||||
TransactionOutput prevOut = new TransactionOutput(TESTNET, prevTx, COIN, wallet.currentReceiveKey().toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET));
|
||||
prevTx.addOutput(prevOut);
|
||||
// Connect it.
|
||||
tx1.addInput(prevOut);
|
||||
|
||||
Transaction tx2 = createFakeTx(TESTNET, COIN,
|
||||
LegacyAddress.fromKey(TESTNET, new ECKey()));
|
||||
new ECKey().toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET));
|
||||
|
||||
Block b1 = createFakeBlock(blockStore, BLOCK_HEIGHT_GENESIS, tx1, tx2).block;
|
||||
|
||||
|
|
|
@ -16,7 +16,9 @@
|
|||
|
||||
package org.bitcoinj.core;
|
||||
|
||||
import org.bitcoinj.base.BitcoinNetwork;
|
||||
import org.bitcoinj.base.Coin;
|
||||
import org.bitcoinj.base.ScriptType;
|
||||
import org.bitcoinj.script.Script;
|
||||
import org.bitcoinj.script.ScriptBuilder;
|
||||
import org.bitcoinj.script.ScriptPattern;
|
||||
|
@ -93,9 +95,11 @@ public class TransactionOutputTest extends TestWithWallet {
|
|||
public void getMinNonDustValue() {
|
||||
TransactionOutput p2pk = new TransactionOutput(TESTNET, null, Coin.COIN, myKey);
|
||||
assertEquals(Coin.valueOf(576), p2pk.getMinNonDustValue());
|
||||
TransactionOutput p2pkh = new TransactionOutput(TESTNET, null, Coin.COIN, LegacyAddress.fromKey(TESTNET, myKey));
|
||||
TransactionOutput p2pkh = new TransactionOutput(TESTNET, null, Coin.COIN, myKey.toAddress(ScriptType.P2PKH,
|
||||
BitcoinNetwork.TESTNET));
|
||||
assertEquals(Coin.valueOf(546), p2pkh.getMinNonDustValue());
|
||||
TransactionOutput p2wpkh = new TransactionOutput(TESTNET, null, Coin.COIN, SegwitAddress.fromKey(TESTNET, myKey));
|
||||
TransactionOutput p2wpkh = new TransactionOutput(TESTNET, null, Coin.COIN, myKey.toAddress(ScriptType.P2WPKH,
|
||||
BitcoinNetwork.TESTNET));
|
||||
assertEquals(Coin.valueOf(294), p2wpkh.getMinNonDustValue());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -67,7 +67,7 @@ import static org.junit.Assert.fail;
|
|||
*/
|
||||
public class TransactionTest {
|
||||
private static final NetworkParameters TESTNET = TestNet3Params.get();
|
||||
private static final Address ADDRESS = LegacyAddress.fromKey(TESTNET, new ECKey());
|
||||
private static final Address ADDRESS = new ECKey().toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET);
|
||||
|
||||
private Transaction tx;
|
||||
|
||||
|
@ -193,13 +193,13 @@ public class TransactionTest {
|
|||
|
||||
@Test
|
||||
public void addSignedInput_P2PKH() {
|
||||
final Address toAddr = Address.fromKey(TESTNET, new ECKey(), ScriptType.P2PKH);
|
||||
final Address toAddr = new ECKey().toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET);
|
||||
final Sha256Hash utxo_id = Sha256Hash.wrap("81b4c832d70cb56ff957589752eb4125a4cab78a25a8fc52d6a09e5bd4404d48");
|
||||
final Coin inAmount = Coin.ofSat(91234);
|
||||
final Coin outAmount = Coin.ofSat(91234);
|
||||
|
||||
ECKey fromKey = new ECKey();
|
||||
Address fromAddress = Address.fromKey(TESTNET, fromKey, ScriptType.P2PKH);
|
||||
Address fromAddress = fromKey.toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET);
|
||||
Transaction tx = new Transaction(TESTNET);
|
||||
TransactionOutPoint outPoint = new TransactionOutPoint(TESTNET, 0, utxo_id);
|
||||
TransactionOutput output = new TransactionOutput(TESTNET, null, inAmount, fromAddress);
|
||||
|
@ -216,13 +216,13 @@ public class TransactionTest {
|
|||
|
||||
@Test
|
||||
public void addSignedInput_P2WPKH() {
|
||||
final Address toAddr = Address.fromKey(TESTNET, new ECKey(), ScriptType.P2WPKH);
|
||||
final Address toAddr = new ECKey().toAddress(ScriptType.P2WPKH, BitcoinNetwork.TESTNET);
|
||||
final Sha256Hash utxo_id = Sha256Hash.wrap("81b4c832d70cb56ff957589752eb4125a4cab78a25a8fc52d6a09e5bd4404d48");
|
||||
final Coin inAmount = Coin.ofSat(91234);
|
||||
final Coin outAmount = Coin.ofSat(91234);
|
||||
|
||||
ECKey fromKey = new ECKey();
|
||||
Address fromAddress = Address.fromKey(TESTNET, fromKey, ScriptType.P2WPKH);
|
||||
Address fromAddress = fromKey.toAddress(ScriptType.P2WPKH, BitcoinNetwork.TESTNET);
|
||||
Transaction tx = new Transaction(TESTNET);
|
||||
TransactionOutPoint outPoint = new TransactionOutPoint(TESTNET, 0, utxo_id);
|
||||
tx.addOutput(outAmount, toAddr);
|
||||
|
@ -532,7 +532,7 @@ public class TransactionTest {
|
|||
@Test(expected = ScriptException.class)
|
||||
public void testAddSignedInputThrowsExceptionWhenScriptIsNotToRawPubKeyAndIsNotToAddress() {
|
||||
ECKey key = new ECKey();
|
||||
Address addr = LegacyAddress.fromKey(TESTNET, key);
|
||||
Address addr = key.toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET);
|
||||
TransactionOutput fakeOutput = FakeTxBuilder.createFakeTx(TESTNET, Coin.COIN, addr).getOutput(0);
|
||||
|
||||
Transaction tx = new Transaction(TESTNET);
|
||||
|
@ -598,7 +598,7 @@ public class TransactionTest {
|
|||
public void testHashForSignatureThreadSafety() throws Exception {
|
||||
Context.propagate(new Context(100, Transaction.DEFAULT_TX_FEE, false, true));
|
||||
Block genesis = TESTNET.getGenesisBlock();
|
||||
Block block1 = genesis.createNextBlock(LegacyAddress.fromKey(TESTNET, new ECKey()),
|
||||
Block block1 = genesis.createNextBlock(new ECKey().toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET),
|
||||
genesis.getTransactions().get(0).getOutput(0).getOutPointFor());
|
||||
|
||||
final Transaction tx = block1.getTransactions().get(1);
|
||||
|
@ -691,13 +691,13 @@ public class TransactionTest {
|
|||
setSerializer(serializer.withProtocolVersion(
|
||||
NetworkParameters.ProtocolVersion.WITNESS_VERSION.getBitcoinProtocolVersion()));
|
||||
Transaction inputTx = new Transaction(params);
|
||||
inputTx.addOutput(Coin.FIFTY_COINS, LegacyAddress.fromKey(params, ECKey.fromPrivate(BigInteger.valueOf(123456))));
|
||||
inputTx.addOutput(Coin.FIFTY_COINS, ECKey.fromPrivate(BigInteger.valueOf(123456)).toAddress(ScriptType.P2PKH, params.network()));
|
||||
this.addInput(inputTx.getOutput(0));
|
||||
this.getInput(0).disconnect();
|
||||
TransactionWitness witness = new TransactionWitness(1);
|
||||
witness.setPush(0, new byte[] {0});
|
||||
this.getInput(0).setWitness(witness);
|
||||
Address to = LegacyAddress.fromKey(params, ECKey.fromPrivate(BigInteger.valueOf(1000)));
|
||||
Address to = ECKey.fromPrivate(BigInteger.valueOf(1000)).toAddress(ScriptType.P2PKH, params.network());
|
||||
this.addOutput(Coin.COIN, to);
|
||||
|
||||
this.hackInputsSize = hackInputsSize;
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
|
||||
package org.bitcoinj.core;
|
||||
|
||||
import org.bitcoinj.base.BitcoinNetwork;
|
||||
import org.bitcoinj.base.ScriptType;
|
||||
import org.bitcoinj.base.Sha256Hash;
|
||||
import org.bitcoinj.params.TestNet3Params;
|
||||
import org.bitcoinj.testing.FakeTxBuilder;
|
||||
|
@ -49,8 +51,8 @@ public class TxConfidenceTableTest {
|
|||
Context.propagate(context);
|
||||
table = context.getConfidenceTable();
|
||||
|
||||
Address to = LegacyAddress.fromKey(TESTNET, new ECKey());
|
||||
Address change = LegacyAddress.fromKey(TESTNET, new ECKey());
|
||||
Address to = new ECKey().toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET);
|
||||
Address change = new ECKey().toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET);
|
||||
|
||||
tx1 = FakeTxBuilder.createFakeTxWithChangeAddress(TESTNET, COIN, to, change);
|
||||
tx2 = FakeTxBuilder.createFakeTxWithChangeAddress(TESTNET, COIN, to, change);
|
||||
|
|
|
@ -20,10 +20,11 @@ import org.bitcoin.protocols.payments.Protos;
|
|||
import org.bitcoin.protocols.payments.Protos.Payment;
|
||||
import org.bitcoin.protocols.payments.Protos.PaymentACK;
|
||||
import org.bitcoin.protocols.payments.Protos.PaymentRequest;
|
||||
import org.bitcoinj.base.BitcoinNetwork;
|
||||
import org.bitcoinj.base.ScriptType;
|
||||
import org.bitcoinj.core.Address;
|
||||
import org.bitcoinj.base.Coin;
|
||||
import org.bitcoinj.core.ECKey;
|
||||
import org.bitcoinj.core.LegacyAddress;
|
||||
import org.bitcoinj.core.NetworkParameters;
|
||||
import org.bitcoinj.core.Transaction;
|
||||
import org.bitcoinj.core.Utils;
|
||||
|
@ -52,7 +53,7 @@ public class PaymentProtocolTest {
|
|||
|
||||
// static test data
|
||||
private static final Coin AMOUNT = Coin.SATOSHI;
|
||||
private static final Address TO_ADDRESS = LegacyAddress.fromKey(TESTNET, new ECKey());
|
||||
private static final Address TO_ADDRESS = new ECKey().toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET);
|
||||
private static final String MEMO = "memo";
|
||||
private static final String PAYMENT_URL = "https://example.com";
|
||||
private static final byte[] MERCHANT_DATA = { 0, 1, 2 };
|
||||
|
@ -131,7 +132,7 @@ public class PaymentProtocolTest {
|
|||
List<Transaction> transactions = new LinkedList<>();
|
||||
transactions.add(FakeTxBuilder.createFakeTx(TESTNET, AMOUNT, TO_ADDRESS));
|
||||
Coin refundAmount = Coin.SATOSHI;
|
||||
Address refundAddress = LegacyAddress.fromKey(TESTNET, new ECKey());
|
||||
Address refundAddress = new ECKey().toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET);
|
||||
Payment payment = PaymentProtocol.createPaymentMessage(transactions, refundAmount, refundAddress, MEMO,
|
||||
MERCHANT_DATA);
|
||||
byte[] paymentBytes = payment.toByteArray();
|
||||
|
|
|
@ -19,10 +19,11 @@ package org.bitcoinj.protocols.payments;
|
|||
|
||||
import com.google.protobuf.ByteString;
|
||||
import org.bitcoin.protocols.payments.Protos;
|
||||
import org.bitcoinj.base.BitcoinNetwork;
|
||||
import org.bitcoinj.base.ScriptType;
|
||||
import org.bitcoinj.core.Address;
|
||||
import org.bitcoinj.base.Coin;
|
||||
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;
|
||||
|
@ -88,7 +89,7 @@ public class PaymentSessionTest {
|
|||
tx.addInput(new TransactionInput(TESTNET, tx, outputToMe.getScriptBytes()));
|
||||
ArrayList<Transaction> txns = new ArrayList<>();
|
||||
txns.add(tx);
|
||||
Address refundAddr = LegacyAddress.fromKey(TESTNET, serverKey);
|
||||
Address refundAddr = serverKey.toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET);
|
||||
paymentSession.sendPayment(txns, refundAddr, paymentMemo);
|
||||
assertEquals(1, paymentSession.getPaymentLog().size());
|
||||
assertEquals(simplePaymentUrl, paymentSession.getPaymentLog().get(0).getUrl().toString());
|
||||
|
@ -167,7 +168,7 @@ public class PaymentSessionTest {
|
|||
tx.addInput(new TransactionInput(TESTNET, tx, outputToMe.getScriptBytes()));
|
||||
ArrayList<Transaction> txns = new ArrayList<>();
|
||||
txns.add(tx);
|
||||
Address refundAddr = LegacyAddress.fromKey(TESTNET, serverKey);
|
||||
Address refundAddr = serverKey.toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET);
|
||||
try {
|
||||
paymentSession.sendPayment(txns, refundAddr, paymentMemo).get();
|
||||
} catch (InterruptedException e) {
|
||||
|
|
|
@ -21,6 +21,8 @@ package org.bitcoinj.script;
|
|||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.google.common.collect.Lists;
|
||||
import org.bitcoinj.base.BitcoinNetwork;
|
||||
import org.bitcoinj.base.ScriptType;
|
||||
import org.bitcoinj.base.utils.ByteUtils;
|
||||
import org.bitcoinj.core.Address;
|
||||
import org.bitcoinj.base.Coin;
|
||||
|
@ -466,7 +468,7 @@ public class ScriptTest {
|
|||
public void getToAddress() {
|
||||
// P2PK
|
||||
ECKey toKey = new ECKey();
|
||||
Address toAddress = LegacyAddress.fromKey(TESTNET, toKey);
|
||||
Address toAddress = toKey.toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET);
|
||||
assertEquals(toAddress, ScriptBuilder.createP2PKOutputScript(toKey).getToAddress(TESTNET, true));
|
||||
// pay to pubkey hash
|
||||
assertEquals(toAddress, ScriptBuilder.createOutputScript(toAddress).getToAddress(TESTNET));
|
||||
|
@ -476,7 +478,7 @@ public class ScriptTest {
|
|||
ScriptPattern.extractHashFromP2SH(p2shScript));
|
||||
assertEquals(scriptAddress, p2shScript.getToAddress(TESTNET));
|
||||
// P2WPKH
|
||||
toAddress = SegwitAddress.fromKey(TESTNET, toKey);
|
||||
toAddress = toKey.toAddress(ScriptType.P2WPKH, BitcoinNetwork.TESTNET);
|
||||
assertEquals(toAddress, ScriptBuilder.createOutputScript(toAddress).getToAddress(TESTNET));
|
||||
// P2WSH
|
||||
Script p2wshScript = ScriptBuilder.createP2WSHOutputScript(new byte[32]);
|
||||
|
|
|
@ -18,11 +18,12 @@
|
|||
package org.bitcoinj.store;
|
||||
|
||||
import com.google.common.base.Stopwatch;
|
||||
import org.bitcoinj.base.BitcoinNetwork;
|
||||
import org.bitcoinj.base.ScriptType;
|
||||
import org.bitcoinj.core.Address;
|
||||
import org.bitcoinj.core.Block;
|
||||
import org.bitcoinj.core.Context;
|
||||
import org.bitcoinj.core.ECKey;
|
||||
import org.bitcoinj.core.LegacyAddress;
|
||||
import org.bitcoinj.core.NetworkParameters;
|
||||
import org.bitcoinj.base.Sha256Hash;
|
||||
import org.bitcoinj.core.StoredBlock;
|
||||
|
@ -64,7 +65,7 @@ public class SPVBlockStoreTest {
|
|||
Context.propagate(new Context(100, Transaction.DEFAULT_TX_FEE, false, true));
|
||||
SPVBlockStore store = new SPVBlockStore(TESTNET, blockStoreFile);
|
||||
|
||||
Address to = LegacyAddress.fromKey(TESTNET, new ECKey());
|
||||
Address to = new ECKey().toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET);
|
||||
// Check the first block in a new store is the genesis block.
|
||||
StoredBlock genesis = store.getChainHead();
|
||||
assertEquals(TESTNET.getGenesisBlock(), genesis.getHeader());
|
||||
|
@ -109,7 +110,7 @@ public class SPVBlockStoreTest {
|
|||
@Test
|
||||
public void twoStores_sequentially_grow() throws Exception {
|
||||
Context.propagate(new Context(100, Transaction.DEFAULT_TX_FEE, false, true));
|
||||
Address to = LegacyAddress.fromKey(TESTNET, new ECKey());
|
||||
Address to = new ECKey().toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET);
|
||||
SPVBlockStore store = new SPVBlockStore(TESTNET, blockStoreFile, 10, true);
|
||||
final StoredBlock block0 = store.getChainHead();
|
||||
final StoredBlock block1 = block0.build(block0.getHeader().createNextBlock(to).cloneAsHeader());
|
||||
|
@ -164,7 +165,7 @@ public class SPVBlockStoreTest {
|
|||
SPVBlockStore store = new SPVBlockStore(TESTNET, blockStoreFile);
|
||||
|
||||
// Build a new block.
|
||||
Address to = LegacyAddress.fromKey(TESTNET, new ECKey());
|
||||
Address to = new ECKey().toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET);
|
||||
StoredBlock genesis = store.getChainHead();
|
||||
StoredBlock b1 = genesis.build(genesis.getHeader().createNextBlock(to).cloneAsHeader());
|
||||
store.put(b1);
|
||||
|
|
|
@ -19,6 +19,7 @@ package org.bitcoinj.store;
|
|||
|
||||
import com.google.common.io.ByteStreams;
|
||||
import com.google.protobuf.ByteString;
|
||||
import org.bitcoinj.base.BitcoinNetwork;
|
||||
import org.bitcoinj.base.ScriptType;
|
||||
import org.bitcoinj.base.utils.ByteUtils;
|
||||
import org.bitcoinj.core.Address;
|
||||
|
@ -28,7 +29,6 @@ import org.bitcoinj.core.BlockTest;
|
|||
import org.bitcoinj.base.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.base.Sha256Hash;
|
||||
|
@ -106,11 +106,11 @@ public class WalletProtobufSerializerTest {
|
|||
myWatchedKey = new ECKey();
|
||||
myKey = new ECKey();
|
||||
myKey.setCreationTimeSeconds(123456789L);
|
||||
myAddress = LegacyAddress.fromKey(TESTNET, myKey);
|
||||
myAddress = myKey.toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET);
|
||||
myWallet = new Wallet(TESTNET, KeyChainGroup.builder(TESTNET).fromRandom(ScriptType.P2PKH).build());
|
||||
myWallet.importKey(myKey);
|
||||
mScriptCreationTime = new Date().getTime() / 1000 - 1234;
|
||||
myWallet.addWatchedAddress(LegacyAddress.fromKey(TESTNET, myWatchedKey), mScriptCreationTime);
|
||||
myWallet.addWatchedAddress(myWatchedKey.toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET), mScriptCreationTime);
|
||||
myWallet.setDescription(WALLET_DESCRIPTION);
|
||||
}
|
||||
|
||||
|
@ -127,7 +127,7 @@ public class WalletProtobufSerializerTest {
|
|||
assertEquals(mScriptCreationTime,
|
||||
wallet1.getWatchedScripts().get(0).getCreationTimeSeconds());
|
||||
assertEquals(1, wallet1.getWatchedScripts().size());
|
||||
assertEquals(ScriptBuilder.createOutputScript(LegacyAddress.fromKey(TESTNET, myWatchedKey)),
|
||||
assertEquals(ScriptBuilder.createOutputScript(myWatchedKey.toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET)),
|
||||
wallet1.getWatchedScripts().get(0));
|
||||
assertEquals(WALLET_DESCRIPTION, wallet1.getDescription());
|
||||
}
|
||||
|
@ -202,7 +202,7 @@ public class WalletProtobufSerializerTest {
|
|||
public void testKeys() throws Exception {
|
||||
for (int i = 0 ; i < 20 ; i++) {
|
||||
myKey = new ECKey();
|
||||
myAddress = LegacyAddress.fromKey(TESTNET, myKey);
|
||||
myAddress = myKey.toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET);
|
||||
myWallet = Wallet.createDeterministic(TESTNET, ScriptType.P2PKH);
|
||||
myWallet.importKey(myKey);
|
||||
Wallet wallet1 = roundTrip(myWallet);
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
package org.bitcoinj.wallet;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import org.bitcoinj.base.BitcoinNetwork;
|
||||
import org.bitcoinj.base.ScriptType;
|
||||
import org.bitcoinj.core.Address;
|
||||
import org.bitcoinj.core.BloomFilter;
|
||||
|
@ -95,8 +96,8 @@ public class DeterministicKeyChainTest {
|
|||
assertFalse(key2.isPubKeyOnly());
|
||||
|
||||
final Address address = LegacyAddress.fromBase58(TESTNET, "n1bQNoEx8uhmCzzA5JPG6sFdtsUQhwiQJV");
|
||||
assertEquals(address, LegacyAddress.fromKey(TESTNET, key1));
|
||||
assertEquals("mnHUcqUVvrfi5kAaXJDQzBb9HsWs78b42R", LegacyAddress.fromKey(TESTNET, key2).toString());
|
||||
assertEquals(address, key1.toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET));
|
||||
assertEquals("mnHUcqUVvrfi5kAaXJDQzBb9HsWs78b42R", key2.toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET).toString());
|
||||
assertEquals(key1, chain.findKeyFromPubHash(address.getHash()));
|
||||
assertEquals(key2, chain.findKeyFromPubKey(key2.getPubKey()));
|
||||
|
||||
|
@ -105,7 +106,7 @@ public class DeterministicKeyChainTest {
|
|||
|
||||
ECKey key3 = chain.getKey(KeyChain.KeyPurpose.CHANGE);
|
||||
assertFalse(key3.isPubKeyOnly());
|
||||
assertEquals("mqumHgVDqNzuXNrszBmi7A2UpmwaPMx4HQ", LegacyAddress.fromKey(TESTNET, key3).toString());
|
||||
assertEquals("mqumHgVDqNzuXNrszBmi7A2UpmwaPMx4HQ", key3.toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET).toString());
|
||||
key3.sign(Sha256Hash.ZERO_HASH);
|
||||
assertFalse(key3.isPubKeyOnly());
|
||||
}
|
||||
|
@ -128,15 +129,15 @@ public class DeterministicKeyChainTest {
|
|||
ECKey key2 = chain1.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS);
|
||||
|
||||
final Address address = LegacyAddress.fromBase58(TESTNET, "n2nHHRHs7TiZScTuVhZUkzZfTfVgGYwy6X");
|
||||
assertEquals(address, LegacyAddress.fromKey(TESTNET, key1));
|
||||
assertEquals("mnp2j9za5zMuz44vNxrJCXXhZsCdh89QXn", LegacyAddress.fromKey(TESTNET, key2).toString());
|
||||
assertEquals(address, key1.toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET));
|
||||
assertEquals("mnp2j9za5zMuz44vNxrJCXXhZsCdh89QXn", key2.toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET).toString());
|
||||
assertEquals(key1, chain1.findKeyFromPubHash(address.getHash()));
|
||||
assertEquals(key2, chain1.findKeyFromPubKey(key2.getPubKey()));
|
||||
|
||||
key1.sign(Sha256Hash.ZERO_HASH);
|
||||
|
||||
ECKey key3 = chain1.getKey(KeyChain.KeyPurpose.CHANGE);
|
||||
assertEquals("mpjRhk13rvV7vmnszcUQVYVQzy4HLTPTQU", LegacyAddress.fromKey(TESTNET, key3).toString());
|
||||
assertEquals("mpjRhk13rvV7vmnszcUQVYVQzy4HLTPTQU", key3.toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET).toString());
|
||||
key3.sign(Sha256Hash.ZERO_HASH);
|
||||
}
|
||||
|
||||
|
@ -149,7 +150,7 @@ public class DeterministicKeyChainTest {
|
|||
ECKey key1 = chain1.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS);
|
||||
|
||||
final Address address = LegacyAddress.fromBase58(TESTNET, "n2nHHRHs7TiZScTuVhZUkzZfTfVgGYwy6X");
|
||||
assertEquals(address, LegacyAddress.fromKey(TESTNET, key1));
|
||||
assertEquals(address, key1.toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET));
|
||||
|
||||
DeterministicKey watching = chain1.getWatchingKey();
|
||||
|
||||
|
@ -158,14 +159,14 @@ public class DeterministicKeyChainTest {
|
|||
assertEquals(accountOne, chain1.getAccountPath());
|
||||
|
||||
ECKey key2 = chain1.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS);
|
||||
assertEquals("mnp2j9za5zMuz44vNxrJCXXhZsCdh89QXn", LegacyAddress.fromKey(TESTNET, key2).toString());
|
||||
assertEquals("mnp2j9za5zMuz44vNxrJCXXhZsCdh89QXn", key2.toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET).toString());
|
||||
assertEquals(key1, chain1.findKeyFromPubHash(address.getHash()));
|
||||
assertEquals(key2, chain1.findKeyFromPubKey(key2.getPubKey()));
|
||||
|
||||
key1.sign(Sha256Hash.ZERO_HASH);
|
||||
|
||||
ECKey key3 = chain1.getKey(KeyChain.KeyPurpose.CHANGE);
|
||||
assertEquals("mpjRhk13rvV7vmnszcUQVYVQzy4HLTPTQU", LegacyAddress.fromKey(TESTNET, key3).toString());
|
||||
assertEquals("mpjRhk13rvV7vmnszcUQVYVQzy4HLTPTQU", key3.toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET).toString());
|
||||
key3.sign(Sha256Hash.ZERO_HASH);
|
||||
|
||||
assertEquals(watching, chain1.getWatchingKey());
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
package org.bitcoinj.wallet;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import org.bitcoinj.base.BitcoinNetwork;
|
||||
import org.bitcoinj.base.ScriptType;
|
||||
import org.bitcoinj.base.utils.ByteUtils;
|
||||
import org.bitcoinj.core.AbstractBlockChain;
|
||||
|
@ -29,7 +30,6 @@ import org.bitcoinj.core.ECKey;
|
|||
import org.bitcoinj.core.InsufficientMoneyException;
|
||||
import org.bitcoinj.core.LegacyAddress;
|
||||
import org.bitcoinj.core.PeerAddress;
|
||||
import org.bitcoinj.core.SegwitAddress;
|
||||
import org.bitcoinj.base.Sha256Hash;
|
||||
import org.bitcoinj.core.StoredBlock;
|
||||
import org.bitcoinj.core.Transaction;
|
||||
|
@ -129,8 +129,8 @@ 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 Address OTHER_ADDRESS = LegacyAddress.fromKey(TESTNET, new ECKey());
|
||||
private final Address OTHER_SEGWIT_ADDRESS = SegwitAddress.fromKey(TESTNET, new ECKey());
|
||||
private final Address OTHER_ADDRESS = new ECKey().toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET);
|
||||
private final Address OTHER_SEGWIT_ADDRESS = new ECKey().toAddress(ScriptType.P2WPKH, BitcoinNetwork.TESTNET);
|
||||
|
||||
@Before
|
||||
@Override
|
||||
|
@ -209,7 +209,7 @@ public class WalletTest extends TestWithWallet {
|
|||
public void basicSpendingWithEncryptedWallet() throws Exception {
|
||||
Wallet encryptedWallet = Wallet.createDeterministic(TESTNET, ScriptType.P2PKH);
|
||||
encryptedWallet.encrypt(PASSWORD1);
|
||||
Address myEncryptedAddress = LegacyAddress.fromKey(TESTNET, encryptedWallet.freshReceiveKey());
|
||||
Address myEncryptedAddress = encryptedWallet.freshReceiveKey().toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET);
|
||||
basicSpendingCommon(encryptedWallet, myEncryptedAddress, OTHER_ADDRESS, encryptedWallet);
|
||||
}
|
||||
|
||||
|
@ -831,7 +831,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.
|
||||
Address BAD_GUY = LegacyAddress.fromKey(TESTNET, new ECKey());
|
||||
Address BAD_GUY = new ECKey().toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET);
|
||||
Transaction send2 = wallet.createSend(BAD_GUY, COIN);
|
||||
send2 = TESTNET.getDefaultSerializer().makeTransaction(send2.bitcoinSerialize());
|
||||
// Broadcast send1, it's now pending.
|
||||
|
@ -913,7 +913,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.
|
||||
Address BAD_GUY = LegacyAddress.fromKey(TESTNET, new ECKey());
|
||||
Address BAD_GUY = new ECKey().toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET);
|
||||
Transaction send2 = wallet.createSend(BAD_GUY, valueOf(0, 50));
|
||||
send2 = TESTNET.getDefaultSerializer().makeTransaction(send2.bitcoinSerialize());
|
||||
// Broadcast send1.
|
||||
|
@ -1397,7 +1397,7 @@ public class WalletTest extends TestWithWallet {
|
|||
Coin nanos = COIN;
|
||||
|
||||
// Create two transactions that share the same input tx.
|
||||
Address badGuy = LegacyAddress.fromKey(TESTNET, new ECKey());
|
||||
Address badGuy = new ECKey().toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET);
|
||||
Transaction doubleSpentTx = new Transaction(TESTNET);
|
||||
TransactionOutput doubleSpentOut = new TransactionOutput(TESTNET, doubleSpentTx, nanos, badGuy);
|
||||
doubleSpentTx.addOutput(doubleSpentOut);
|
||||
|
@ -1603,7 +1603,7 @@ public class WalletTest extends TestWithWallet {
|
|||
// Expected
|
||||
}
|
||||
|
||||
receiveATransaction(watchingWallet, LegacyAddress.fromKey(TESTNET, myKey));
|
||||
receiveATransaction(watchingWallet, myKey.toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET));
|
||||
assertEquals(COIN, watchingWallet.getBalance());
|
||||
assertEquals(COIN, watchingWallet.getBalance(Wallet.BalanceType.AVAILABLE));
|
||||
assertEquals(ZERO, watchingWallet.getBalance(Wallet.BalanceType.AVAILABLE_SPENDABLE));
|
||||
|
@ -1627,7 +1627,7 @@ public class WalletTest extends TestWithWallet {
|
|||
@Test
|
||||
public void watchingScripts() {
|
||||
// Verify that pending transactions to watched addresses are relevant
|
||||
Address watchedAddress = LegacyAddress.fromKey(TESTNET, new ECKey());
|
||||
Address watchedAddress = new ECKey().toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET);
|
||||
wallet.addWatchedAddress(watchedAddress);
|
||||
Coin value = valueOf(5, 0);
|
||||
Transaction t1 = createFakeTx(TESTNET, value, watchedAddress);
|
||||
|
@ -1637,7 +1637,7 @@ public class WalletTest extends TestWithWallet {
|
|||
|
||||
@Test(expected = InsufficientMoneyException.class)
|
||||
public void watchingScriptsConfirmed() throws Exception {
|
||||
Address watchedAddress = LegacyAddress.fromKey(TESTNET, new ECKey());
|
||||
Address watchedAddress = new ECKey().toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET);
|
||||
wallet.addWatchedAddress(watchedAddress);
|
||||
sendMoneyToWallet(BlockChain.NewBlockType.BEST_CHAIN, CENT, watchedAddress);
|
||||
assertEquals(CENT, wallet.getBalance());
|
||||
|
@ -1650,7 +1650,7 @@ public class WalletTest extends TestWithWallet {
|
|||
public void watchingScriptsSentFrom() {
|
||||
int baseElements = wallet.getBloomFilterElementCount();
|
||||
|
||||
Address watchedAddress = LegacyAddress.fromKey(TESTNET, new ECKey());
|
||||
Address watchedAddress = new ECKey().toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET);
|
||||
wallet.addWatchedAddress(watchedAddress);
|
||||
assertEquals(baseElements + 1, wallet.getBloomFilterElementCount());
|
||||
|
||||
|
@ -1670,7 +1670,7 @@ public class WalletTest extends TestWithWallet {
|
|||
|
||||
@Test
|
||||
public void watchingScriptsBloomFilter() {
|
||||
Address watchedAddress = LegacyAddress.fromKey(TESTNET, new ECKey());
|
||||
Address watchedAddress = new ECKey().toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET);
|
||||
Transaction t1 = createFakeTx(TESTNET, CENT, watchedAddress);
|
||||
TransactionOutPoint outPoint = new TransactionOutPoint(TESTNET, 0, t1);
|
||||
wallet.addWatchedAddress(watchedAddress);
|
||||
|
@ -1684,7 +1684,7 @@ public class WalletTest extends TestWithWallet {
|
|||
|
||||
@Test
|
||||
public void getWatchedAddresses() {
|
||||
Address watchedAddress = LegacyAddress.fromKey(TESTNET, new ECKey());
|
||||
Address watchedAddress = new ECKey().toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET);
|
||||
wallet.addWatchedAddress(watchedAddress);
|
||||
List<Address> watchedAddresses = wallet.getWatchedAddresses();
|
||||
assertEquals(1, watchedAddresses.size());
|
||||
|
@ -1695,7 +1695,7 @@ public class WalletTest extends TestWithWallet {
|
|||
public void removeWatchedAddresses() {
|
||||
List<Address> addressesForRemoval = new ArrayList<>();
|
||||
for (int i = 0; i < 10; i++) {
|
||||
Address watchedAddress = LegacyAddress.fromKey(TESTNET, new ECKey());
|
||||
Address watchedAddress = new ECKey().toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET);
|
||||
addressesForRemoval.add(watchedAddress);
|
||||
wallet.addWatchedAddress(watchedAddress);
|
||||
}
|
||||
|
@ -1707,7 +1707,7 @@ public class WalletTest extends TestWithWallet {
|
|||
|
||||
@Test
|
||||
public void removeWatchedAddress() {
|
||||
Address watchedAddress = LegacyAddress.fromKey(TESTNET, new ECKey());
|
||||
Address watchedAddress = new ECKey().toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET);
|
||||
wallet.addWatchedAddress(watchedAddress);
|
||||
wallet.removeWatchedAddress(watchedAddress);
|
||||
assertFalse(wallet.isAddressWatched(watchedAddress));
|
||||
|
@ -1717,7 +1717,7 @@ public class WalletTest extends TestWithWallet {
|
|||
public void removeScriptsBloomFilter() {
|
||||
List<Address> addressesForRemoval = new ArrayList<>();
|
||||
for (int i = 0; i < 10; i++) {
|
||||
Address watchedAddress = LegacyAddress.fromKey(TESTNET, new ECKey());
|
||||
Address watchedAddress = new ECKey().toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET);
|
||||
addressesForRemoval.add(watchedAddress);
|
||||
wallet.addWatchedAddress(watchedAddress);
|
||||
}
|
||||
|
@ -1846,7 +1846,7 @@ public class WalletTest extends TestWithWallet {
|
|||
ECKey k2 = wallet.freshReceiveKey();
|
||||
Coin v2 = valueOf(0, 50);
|
||||
Transaction t2 = new Transaction(TESTNET);
|
||||
TransactionOutput o2 = new TransactionOutput(TESTNET, t2, v2, LegacyAddress.fromKey(TESTNET, k2));
|
||||
TransactionOutput o2 = new TransactionOutput(TESTNET, t2, v2, k2.toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET));
|
||||
t2.addOutput(o2);
|
||||
SendRequest req = SendRequest.forTx(t2);
|
||||
wallet.completeTx(req);
|
||||
|
@ -1861,7 +1861,7 @@ public class WalletTest extends TestWithWallet {
|
|||
ECKey k3 = new ECKey();
|
||||
Coin v3 = valueOf(0, 25);
|
||||
Transaction t3 = new Transaction(TESTNET);
|
||||
t3.addOutput(v3, LegacyAddress.fromKey(TESTNET, k3));
|
||||
t3.addOutput(v3, k3.toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET));
|
||||
t3.addInput(o2);
|
||||
wallet.signTransaction(SendRequest.forTx(t3));
|
||||
|
||||
|
@ -2086,7 +2086,7 @@ public class WalletTest extends TestWithWallet {
|
|||
encryptedWallet.importKeysAndEncrypt(Collections.singletonList(key), PASSWORD1);
|
||||
assertEquals(1, encryptedWallet.getImportedKeys().size());
|
||||
assertEquals(key.getPubKeyPoint(), encryptedWallet.getImportedKeys().get(0).getPubKeyPoint());
|
||||
sendMoneyToWallet(encryptedWallet, AbstractBlockChain.NewBlockType.BEST_CHAIN, Coin.COIN, LegacyAddress.fromKey(TESTNET, key));
|
||||
sendMoneyToWallet(encryptedWallet, AbstractBlockChain.NewBlockType.BEST_CHAIN, Coin.COIN, key.toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET));
|
||||
assertEquals(Coin.COIN, encryptedWallet.getBalance());
|
||||
SendRequest req = SendRequest.emptyWallet(OTHER_ADDRESS);
|
||||
req.aesKey = checkNotNull(encryptedWallet.getKeyCrypter()).deriveKey(PASSWORD1);
|
||||
|
@ -2905,9 +2905,9 @@ public class WalletTest extends TestWithWallet {
|
|||
key2.setCreationTimeSeconds(Utils.currentTimeSeconds() - 86400);
|
||||
wallet.importKey(key1);
|
||||
wallet.importKey(key2);
|
||||
sendMoneyToWallet(wallet, AbstractBlockChain.NewBlockType.BEST_CHAIN, CENT, LegacyAddress.fromKey(TESTNET, key1));
|
||||
sendMoneyToWallet(wallet, AbstractBlockChain.NewBlockType.BEST_CHAIN, CENT, LegacyAddress.fromKey(TESTNET, key2));
|
||||
sendMoneyToWallet(wallet, AbstractBlockChain.NewBlockType.BEST_CHAIN, CENT, LegacyAddress.fromKey(TESTNET, key2));
|
||||
sendMoneyToWallet(wallet, AbstractBlockChain.NewBlockType.BEST_CHAIN, CENT, key1.toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET));
|
||||
sendMoneyToWallet(wallet, AbstractBlockChain.NewBlockType.BEST_CHAIN, CENT, key2.toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET));
|
||||
sendMoneyToWallet(wallet, AbstractBlockChain.NewBlockType.BEST_CHAIN, CENT, key2.toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET));
|
||||
Date compromiseTime = Utils.now();
|
||||
assertEquals(0, broadcaster.size());
|
||||
assertFalse(wallet.isKeyRotating(key1));
|
||||
|
@ -2938,7 +2938,7 @@ public class WalletTest extends TestWithWallet {
|
|||
assertEquals(0, broadcaster.size());
|
||||
|
||||
// Receive money via a new block on key1 and ensure it shows up as a maintenance task.
|
||||
sendMoneyToWallet(wallet, AbstractBlockChain.NewBlockType.BEST_CHAIN, CENT, LegacyAddress.fromKey(TESTNET, key1));
|
||||
sendMoneyToWallet(wallet, AbstractBlockChain.NewBlockType.BEST_CHAIN, CENT, key1.toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET));
|
||||
wallet.doMaintenance(null, true);
|
||||
tx = broadcaster.waitForTransactionAndSucceed();
|
||||
assertNotNull(wallet.findKeyFromPubKeyHash(tx.getOutput(0).getScriptPubKey().getPubKeyHash(),
|
||||
|
@ -3002,8 +3002,8 @@ public class WalletTest extends TestWithWallet {
|
|||
wallet = Wallet.createDeterministic(TESTNET, ScriptType.P2PKH);
|
||||
ECKey key1 = wallet.freshReceiveKey();
|
||||
ECKey key2 = wallet.freshReceiveKey();
|
||||
sendMoneyToWallet(wallet, AbstractBlockChain.NewBlockType.BEST_CHAIN, CENT, LegacyAddress.fromKey(TESTNET, key1));
|
||||
sendMoneyToWallet(wallet, AbstractBlockChain.NewBlockType.BEST_CHAIN, CENT, LegacyAddress.fromKey(TESTNET, key2));
|
||||
sendMoneyToWallet(wallet, AbstractBlockChain.NewBlockType.BEST_CHAIN, CENT, key1.toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET));
|
||||
sendMoneyToWallet(wallet, AbstractBlockChain.NewBlockType.BEST_CHAIN, CENT, key2.toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET));
|
||||
DeterministicKey watchKey1 = wallet.getWatchingKey();
|
||||
|
||||
// A day later, we get compromised.
|
||||
|
@ -3025,7 +3025,7 @@ public class WalletTest extends TestWithWallet {
|
|||
public void fragmentedReKeying() {
|
||||
// Send lots of small coins and check the fee is correct.
|
||||
ECKey key = wallet.freshReceiveKey();
|
||||
Address address = LegacyAddress.fromKey(TESTNET, key);
|
||||
Address address = key.toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET);
|
||||
Utils.setMockClock();
|
||||
Utils.rollMockClock(86400);
|
||||
for (int i = 0; i < 800; i++) {
|
||||
|
@ -3136,7 +3136,7 @@ public class WalletTest extends TestWithWallet {
|
|||
// Send three transactions, with one being an address type and the other being a raw CHECKSIG type pubkey only,
|
||||
// and the final one being a key we do have. We expect the first two inputs to be dummy values and the last
|
||||
// to be signed correctly.
|
||||
Transaction t1 = sendMoneyToWallet(AbstractBlockChain.NewBlockType.BEST_CHAIN, CENT, LegacyAddress.fromKey(TESTNET, pub));
|
||||
Transaction t1 = sendMoneyToWallet(AbstractBlockChain.NewBlockType.BEST_CHAIN, CENT, pub.toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET));
|
||||
Transaction t2 = sendMoneyToWallet(AbstractBlockChain.NewBlockType.BEST_CHAIN, CENT, pub);
|
||||
Transaction t3 = sendMoneyToWallet(AbstractBlockChain.NewBlockType.BEST_CHAIN, CENT, priv2);
|
||||
|
||||
|
@ -3506,22 +3506,22 @@ public class WalletTest extends TestWithWallet {
|
|||
ECKey p2wpkhKey = p2wpkhChain.getKey(KeyPurpose.RECEIVE_FUNDS);
|
||||
|
||||
// Test imported key: it's not limited to script type.
|
||||
assertTrue(wallet.isAddressMine(LegacyAddress.fromKey(TESTNET, importedKey)));
|
||||
assertTrue(wallet.isAddressMine(SegwitAddress.fromKey(TESTNET, importedKey)));
|
||||
assertEquals(importedKey, wallet.findKeyFromAddress(LegacyAddress.fromKey(TESTNET, importedKey)));
|
||||
assertEquals(importedKey, wallet.findKeyFromAddress(SegwitAddress.fromKey(TESTNET, importedKey)));
|
||||
assertTrue(wallet.isAddressMine(importedKey.toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET)));
|
||||
assertTrue(wallet.isAddressMine(importedKey.toAddress(ScriptType.P2WPKH, BitcoinNetwork.TESTNET)));
|
||||
assertEquals(importedKey, wallet.findKeyFromAddress(importedKey.toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET)));
|
||||
assertEquals(importedKey, wallet.findKeyFromAddress(importedKey.toAddress(ScriptType.P2WPKH, BitcoinNetwork.TESTNET)));
|
||||
|
||||
// Test key from P2PKH chain: it's limited to P2PKH addresses
|
||||
assertTrue(wallet.isAddressMine(LegacyAddress.fromKey(TESTNET, p2pkhKey)));
|
||||
assertFalse(wallet.isAddressMine(SegwitAddress.fromKey(TESTNET, p2pkhKey)));
|
||||
assertEquals(p2pkhKey, wallet.findKeyFromAddress(LegacyAddress.fromKey(TESTNET, p2pkhKey)));
|
||||
assertNull(wallet.findKeyFromAddress(SegwitAddress.fromKey(TESTNET, p2pkhKey)));
|
||||
assertTrue(wallet.isAddressMine(p2pkhKey.toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET)));
|
||||
assertFalse(wallet.isAddressMine(p2pkhKey.toAddress(ScriptType.P2WPKH, BitcoinNetwork.TESTNET)));
|
||||
assertEquals(p2pkhKey, wallet.findKeyFromAddress(p2pkhKey.toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET)));
|
||||
assertNull(wallet.findKeyFromAddress(p2pkhKey.toAddress(ScriptType.P2WPKH, BitcoinNetwork.TESTNET)));
|
||||
|
||||
// Test key from P2WPKH chain: it's limited to P2WPKH addresses
|
||||
assertFalse(wallet.isAddressMine(LegacyAddress.fromKey(TESTNET, p2wpkhKey)));
|
||||
assertTrue(wallet.isAddressMine(SegwitAddress.fromKey(TESTNET, p2wpkhKey)));
|
||||
assertNull(wallet.findKeyFromAddress(LegacyAddress.fromKey(TESTNET, p2wpkhKey)));
|
||||
assertEquals(p2wpkhKey, wallet.findKeyFromAddress(SegwitAddress.fromKey(TESTNET, p2wpkhKey)));
|
||||
assertFalse(wallet.isAddressMine(p2wpkhKey.toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET)));
|
||||
assertTrue(wallet.isAddressMine(p2wpkhKey.toAddress(ScriptType.P2WPKH, BitcoinNetwork.TESTNET)));
|
||||
assertNull(wallet.findKeyFromAddress(p2wpkhKey.toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET)));
|
||||
assertEquals(p2wpkhKey, wallet.findKeyFromAddress(p2wpkhKey.toAddress(ScriptType.P2WPKH, BitcoinNetwork.TESTNET)));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -27,7 +27,6 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
|||
|
||||
import org.bitcoinj.base.ScriptType;
|
||||
import org.bitcoinj.base.utils.ByteUtils;
|
||||
import org.bitcoinj.core.LegacyAddress;
|
||||
import org.bitcoinj.base.Coin;
|
||||
import org.bitcoinj.core.ECKey;
|
||||
import org.bitcoinj.core.NetworkParameters;
|
||||
|
@ -87,11 +86,11 @@ public class GenerateLowSTests {
|
|||
|
||||
final Transaction outputTransaction = new Transaction(params);
|
||||
final Transaction inputTransaction = new Transaction(params);
|
||||
final TransactionOutput output = new TransactionOutput(params, inputTransaction, Coin.ZERO, LegacyAddress.fromKey(params, key));
|
||||
final TransactionOutput output = new TransactionOutput(params, inputTransaction, Coin.ZERO, key.toAddress(ScriptType.P2PKH, params.network()));
|
||||
|
||||
inputTransaction.addOutput(output);
|
||||
outputTransaction.addInput(output);
|
||||
outputTransaction.addOutput(Coin.ZERO, LegacyAddress.fromKey(params, new ECKey(secureRandom)));
|
||||
outputTransaction.addOutput(Coin.ZERO, new ECKey(secureRandom).toAddress(ScriptType.P2PKH, params.network()));
|
||||
|
||||
addOutputs(outputTransaction, bag);
|
||||
|
||||
|
|
|
@ -26,7 +26,6 @@ import org.bitcoinj.core.ECKey;
|
|||
import org.bitcoinj.core.NetworkParameters;
|
||||
import org.bitcoinj.core.PeerAddress;
|
||||
import org.bitcoinj.core.PeerGroup;
|
||||
import org.bitcoinj.core.SegwitAddress;
|
||||
import org.bitcoinj.params.MainNetParams;
|
||||
import org.bitcoinj.store.MemoryBlockStore;
|
||||
import org.bitcoinj.wallet.Wallet;
|
||||
|
@ -59,7 +58,7 @@ public class PrivateKeys {
|
|||
BigInteger privKey = Base58.decodeToBigInteger(args[0]);
|
||||
key = ECKey.fromPrivate(privKey);
|
||||
}
|
||||
System.out.println("Address from private key is: " + SegwitAddress.fromKey(params, key).toString());
|
||||
System.out.println("Address from private key is: " + key.toAddress(ScriptType.P2WPKH, params.network()).toString());
|
||||
|
||||
// Import the private key to a fresh wallet.
|
||||
Wallet wallet = Wallet.createDeterministic(params, ScriptType.P2PKH);
|
||||
|
|
|
@ -17,7 +17,9 @@
|
|||
|
||||
package org.bitcoinj.core;
|
||||
|
||||
import org.bitcoinj.base.BitcoinNetwork;
|
||||
import org.bitcoinj.base.Coin;
|
||||
import org.bitcoinj.base.ScriptType;
|
||||
import org.bitcoinj.base.Sha256Hash;
|
||||
import org.bitcoinj.base.utils.ByteUtils;
|
||||
import org.bitcoinj.core.TransactionConfidence.ConfidenceType;
|
||||
|
@ -111,7 +113,8 @@ public class FilteredBlockAndPartialMerkleTreeTest extends TestWithPeerGroup {
|
|||
ECKey key1 = new ECKey();
|
||||
ECKey key2 = new ECKey();
|
||||
Transaction tx1 = FakeTxBuilder.createFakeTx(TESTNET, Coin.COIN, key1);
|
||||
Transaction tx2 = FakeTxBuilder.createFakeTx(TESTNET, Coin.FIFTY_COINS, LegacyAddress.fromKey(TESTNET, key2));
|
||||
Transaction tx2 = FakeTxBuilder.createFakeTx(TESTNET, Coin.FIFTY_COINS, key2.toAddress(ScriptType.P2PKH,
|
||||
BitcoinNetwork.TESTNET));
|
||||
Block block = FakeTxBuilder.makeSolvedTestBlock(TESTNET.getGenesisBlock(), LegacyAddress.fromBase58(TESTNET, "msg2t2V2sWNd85LccoddtWysBTR8oPnkzW"), tx1, tx2);
|
||||
BloomFilter filter = new BloomFilter(4, 0.1, 1);
|
||||
filter.insert(key1);
|
||||
|
|
|
@ -270,7 +270,7 @@ public class PeerGroupTest extends TestWithPeerGroup {
|
|||
|
||||
Wallet wallet2 = Wallet.createDeterministic(UNITTEST, ScriptType.P2PKH);
|
||||
ECKey key2 = wallet2.freshReceiveKey();
|
||||
Address address2 = LegacyAddress.fromKey(UNITTEST, key2);
|
||||
Address address2 = key2.toAddress(ScriptType.P2PKH, UNITTEST.network());
|
||||
|
||||
peerGroup.addWallet(wallet2);
|
||||
blockChain.addWallet(wallet2);
|
||||
|
@ -811,7 +811,7 @@ public class PeerGroupTest extends TestWithPeerGroup {
|
|||
Coin expectedBalance = Coin.ZERO;
|
||||
Block prev = blockStore.getChainHead().getHeader();
|
||||
for (ECKey key1 : keys) {
|
||||
Address addr = LegacyAddress.fromKey(UNITTEST, key1);
|
||||
Address addr = key1.toAddress(ScriptType.P2PKH, UNITTEST.network());
|
||||
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);
|
||||
|
|
|
@ -18,6 +18,7 @@ package org.bitcoinj.core;
|
|||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.util.concurrent.Uninterruptibles;
|
||||
import org.bitcoinj.base.BitcoinNetwork;
|
||||
import org.bitcoinj.base.Coin;
|
||||
import org.bitcoinj.base.ScriptType;
|
||||
import org.bitcoinj.base.Sha256Hash;
|
||||
|
@ -817,7 +818,7 @@ public class PeerTest extends TestWithNetworkConnections {
|
|||
connect();
|
||||
Transaction t1 = new Transaction(TESTNET);
|
||||
t1.addInput(new TransactionInput(TESTNET, t1, new byte[]{}));
|
||||
t1.addOutput(COIN, LegacyAddress.fromKey(TESTNET, new ECKey()));
|
||||
t1.addOutput(COIN, new ECKey().toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET));
|
||||
Transaction t2 = new Transaction(TESTNET);
|
||||
t2.addInput(t1.getOutput(0));
|
||||
t2.addOutput(COIN, wallet.currentChangeAddress());
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
package org.bitcoinj.core;
|
||||
|
||||
import com.google.common.util.concurrent.AtomicDouble;
|
||||
import org.bitcoinj.base.BitcoinNetwork;
|
||||
import org.bitcoinj.base.ScriptType;
|
||||
import org.bitcoinj.testing.FakeTxBuilder;
|
||||
import org.bitcoinj.testing.InboundMessageQueuer;
|
||||
import org.bitcoinj.testing.TestWithPeerGroup;
|
||||
|
@ -163,7 +165,7 @@ public class TransactionBroadcastTest extends TestWithPeerGroup {
|
|||
assertEquals(FIFTY_COINS, wallet.getBalance());
|
||||
|
||||
// Now create a spend, and expect the announcement on p1.
|
||||
Address dest = LegacyAddress.fromKey(TESTNET, new ECKey());
|
||||
Address dest = new ECKey().toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET);
|
||||
Wallet.SendResult sendResult = wallet.sendCoins(peerGroup, dest, COIN);
|
||||
assertFalse(sendResult.broadcastComplete.isDone());
|
||||
Transaction t1;
|
||||
|
@ -207,7 +209,7 @@ public class TransactionBroadcastTest extends TestWithPeerGroup {
|
|||
wallet.addTransactionConfidenceEventListener((wallet, tx) -> transactions[0] = tx);
|
||||
|
||||
// Now create a spend, and expect the announcement on p1.
|
||||
Address dest = LegacyAddress.fromKey(TESTNET, new ECKey());
|
||||
Address dest = new ECKey().toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET);
|
||||
Wallet.SendResult sendResult = wallet.sendCoins(peerGroup, dest, COIN);
|
||||
assertNotNull(sendResult.tx);
|
||||
Threading.waitForUserCode();
|
||||
|
|
|
@ -23,7 +23,6 @@ import org.bitcoinj.core.BlockChain;
|
|||
import org.bitcoinj.base.Coin;
|
||||
import org.bitcoinj.core.Context;
|
||||
import org.bitcoinj.core.ECKey;
|
||||
import org.bitcoinj.core.LegacyAddress;
|
||||
import org.bitcoinj.core.Message;
|
||||
import org.bitcoinj.core.NetworkParameters;
|
||||
import org.bitcoinj.core.Peer;
|
||||
|
@ -113,7 +112,7 @@ public class TestWithNetworkConnections {
|
|||
.fromRandom(ScriptType.P2PKH).build();
|
||||
wallet = new Wallet(UNITTEST, kcg);
|
||||
key = wallet.freshReceiveKey();
|
||||
address = LegacyAddress.fromKey(UNITTEST, key);
|
||||
address = key.toAddress(ScriptType.P2PKH, UNITTEST.network());
|
||||
}
|
||||
blockChain = new BlockChain(UNITTEST, wallet, blockStore);
|
||||
|
||||
|
|
|
@ -73,7 +73,7 @@ public class SendMoneyController implements OverlayController<SendMoneyControlle
|
|||
new TextFieldValidator(amountEdit, text ->
|
||||
!WTUtils.didThrow(() -> checkState(Coin.parseCoin(text).compareTo(balance) <= 0)));
|
||||
amountEdit.setText(balance.toPlainString());
|
||||
address.setPromptText(Address.fromKey(NetworkParameters.of(app.network()), new ECKey(), app.preferredOutputScriptType()).toString());
|
||||
address.setPromptText(new ECKey().toAddress(app.preferredOutputScriptType(), app.network()).toString());
|
||||
}
|
||||
|
||||
public void cancel(ActionEvent event) {
|
||||
|
|
|
@ -58,7 +58,6 @@ import org.bitcoinj.core.NetworkParameters;
|
|||
import org.bitcoinj.core.Peer;
|
||||
import org.bitcoinj.core.PeerAddress;
|
||||
import org.bitcoinj.core.PeerGroup;
|
||||
import org.bitcoinj.core.SegwitAddress;
|
||||
import org.bitcoinj.core.StoredBlock;
|
||||
import org.bitcoinj.core.Transaction;
|
||||
import org.bitcoinj.core.TransactionBroadcast;
|
||||
|
@ -1171,9 +1170,9 @@ public class WalletTool implements Callable<Integer> {
|
|||
if (!key.isCompressed())
|
||||
System.out.println("WARNING: Importing an uncompressed key");
|
||||
wallet.importKey(key);
|
||||
System.out.print("Addresses: " + LegacyAddress.fromKey(params, key));
|
||||
System.out.print("Addresses: " + key.toAddress(ScriptType.P2PKH, params.network()));
|
||||
if (key.isCompressed())
|
||||
System.out.print("," + SegwitAddress.fromKey(params, key));
|
||||
System.out.print("," + key.toAddress(ScriptType.P2WPKH, params.network()));
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue