From 52afdc629e343bfdd033a2b714b3653ad9704bab Mon Sep 17 00:00:00 2001
From: Andreas Schildbach Be very careful when value is smaller than {@link Transaction#MIN_NONDUST_OUTPUT} as the transaction will
* likely be rejected by the network in this case. Be careful to check the output's value is reasonable using
* {@link TransactionOutput#getMinNonDustValue(Coin)} afterwards or you risk having the transaction
- * rejected by the network. Note that using {@link SendRequest#to(LegacyAddress, Coin)} will result
+ * rejected by the network. Note that using {@link SendRequest#to(Address, Coin)} will result
* in a smaller output, and thus the ability to use a smaller output value without rejection.
If you just want to send money quickly, you probably want - * {@link Wallet#sendCoins(TransactionBroadcaster, LegacyAddress, Coin)} instead. That will create the sending + * {@link Wallet#sendCoins(TransactionBroadcaster, Address, Coin)} instead. That will create the sending * transaction, commit to the wallet and broadcast it to the network all in one go. This method is lower level * and lets you see the proposed transaction before anything is done with it.
* - *This is a helper method that is equivalent to using {@link SendRequest#to(LegacyAddress, Coin)} + *
This is a helper method that is equivalent to using {@link SendRequest#to(Address, Coin)} * followed by {@link Wallet#completeTx(SendRequest)} and returning the requests transaction object. * Note that this means a fee may be automatically added if required, if you want more control over the process, * just do those two steps yourself.
@@ -3805,7 +3806,7 @@ public class Wallet extends BaseTaggableObject * @throws ExceededMaxTransactionSize if the resultant transaction is too big for Bitcoin to process. * @throws MultipleOpReturnRequested if there is more than one OP_RETURN output for the resultant transaction. */ - public Transaction createSend(LegacyAddress address, Coin value) throws InsufficientMoneyException { + public Transaction createSend(Address address, Coin value) throws InsufficientMoneyException { SendRequest req = SendRequest.to(address, value); if (params.getId().equals(NetworkParameters.ID_UNITTESTNET)) req.shuffleOutputs = false; @@ -3864,7 +3865,7 @@ public class Wallet extends BaseTaggableObject * @throws ExceededMaxTransactionSize if the resultant transaction is too big for Bitcoin to process. * @throws MultipleOpReturnRequested if there is more than one OP_RETURN output for the resultant transaction. */ - public SendResult sendCoins(TransactionBroadcaster broadcaster, LegacyAddress to, Coin value) throws InsufficientMoneyException { + public SendResult sendCoins(TransactionBroadcaster broadcaster, Address to, Coin value) throws InsufficientMoneyException { SendRequest request = SendRequest.to(to, value); return sendCoins(broadcaster, request); } diff --git a/core/src/test/java/org/bitcoinj/testing/FakeTxBuilder.java b/core/src/test/java/org/bitcoinj/testing/FakeTxBuilder.java index 922b6873..37b1965d 100644 --- a/core/src/test/java/org/bitcoinj/testing/FakeTxBuilder.java +++ b/core/src/test/java/org/bitcoinj/testing/FakeTxBuilder.java @@ -17,7 +17,23 @@ package org.bitcoinj.testing; -import org.bitcoinj.core.*; +import org.bitcoinj.core.Address; +import org.bitcoinj.core.Block; +import org.bitcoinj.core.Coin; +import org.bitcoinj.core.ECKey; +import org.bitcoinj.core.LegacyAddress; +import org.bitcoinj.core.MessageSerializer; +import org.bitcoinj.core.NetworkParameters; +import org.bitcoinj.core.ProtocolException; +import org.bitcoinj.core.Sha256Hash; +import org.bitcoinj.core.StoredBlock; +import org.bitcoinj.core.Transaction; +import org.bitcoinj.core.TransactionConfidence; +import org.bitcoinj.core.TransactionInput; +import org.bitcoinj.core.TransactionOutPoint; +import org.bitcoinj.core.TransactionOutput; +import org.bitcoinj.core.Utils; +import org.bitcoinj.core.VerificationException; import org.bitcoinj.crypto.TransactionSignature; import org.bitcoinj.script.ScriptBuilder; import org.bitcoinj.store.BlockStore; @@ -64,7 +80,7 @@ public class FakeTxBuilder { * Create a fake TX of sufficient realism to exercise the unit tests. Two outputs, one to us, one to somewhere * else to simulate change. There is one random input. */ - public static Transaction createFakeTxWithChangeAddress(NetworkParameters params, Coin value, LegacyAddress to, LegacyAddress changeOutput) { + public static Transaction createFakeTxWithChangeAddress(NetworkParameters params, Coin value, Address to, Address changeOutput) { Transaction t = new Transaction(params); TransactionOutput outputToMe = new TransactionOutput(params, t, value, to); t.addOutput(outputToMe); @@ -86,7 +102,7 @@ public class FakeTxBuilder { * Create a fake TX for unit tests, for use with unit tests that need greater control. One outputs, 2 random inputs, * split randomly to create randomness. */ - public static Transaction createFakeTxWithoutChangeAddress(NetworkParameters params, Coin value, LegacyAddress to) { + public static Transaction createFakeTxWithoutChangeAddress(NetworkParameters params, Coin value, Address to) { Transaction t = new Transaction(params); TransactionOutput outputToMe = new TransactionOutput(params, t, value, to); t.addOutput(outputToMe); @@ -122,7 +138,7 @@ public class FakeTxBuilder { * Create a fake TX of sufficient realism to exercise the unit tests. Two outputs, one to us, one to somewhere * else to simulate change. There is one random input. */ - public static Transaction createFakeTx(NetworkParameters params, Coin value, LegacyAddress to) { + public static Transaction createFakeTx(NetworkParameters params, Coin value, Address to) { return createFakeTxWithChangeAddress(params, value, to, LegacyAddress.fromKey(params, new ECKey())); } @@ -151,7 +167,7 @@ public class FakeTxBuilder { * Transaction[0] is a feeder transaction, supplying BTC to Transaction[1] */ public static Transaction[] createFakeTx(NetworkParameters params, Coin value, - LegacyAddress to, LegacyAddress from) { + Address to, Address from) { // Create fake TXes of sufficient realism to exercise the unit tests. This transaction send BTC from the // from address, to the to address with to one to somewhere else to simulate change. Transaction t = new Transaction(params); @@ -200,7 +216,7 @@ public class FakeTxBuilder { * Creates two transactions that spend the same (fake) output. t1 spends to "to". t2 spends somewhere else. * The fake output goes to the same address as t2. */ - public static DoubleSpends createFakeDoubleSpendTxns(NetworkParameters params, LegacyAddress to) { + public static DoubleSpends createFakeDoubleSpendTxns(NetworkParameters params, Address to) { DoubleSpends doubleSpends = new DoubleSpends(); Coin value = COIN; LegacyAddress someBadGuy = LegacyAddress.fromKey(params, new ECKey()); @@ -290,7 +306,7 @@ public class FakeTxBuilder { return createFakeBlock(blockStore, Block.BLOCK_VERSION_GENESIS, Utils.currentTimeSeconds(), 0, transactions); } - public static Block makeSolvedTestBlock(BlockStore blockStore, LegacyAddress coinsTo) throws BlockStoreException { + public static Block makeSolvedTestBlock(BlockStore blockStore, Address coinsTo) throws BlockStoreException { Block b = blockStore.getChainHead().getHeader().createNextBlock(coinsTo); b.solve(); return b; @@ -307,7 +323,7 @@ public class FakeTxBuilder { return b; } - public static Block makeSolvedTestBlock(Block prev, LegacyAddress to, Transaction... transactions) throws BlockStoreException { + public static Block makeSolvedTestBlock(Block prev, Address to, Transaction... transactions) throws BlockStoreException { Block b = prev.createNextBlock(to); // Coinbase tx already exists. for (Transaction tx : transactions) { diff --git a/tools/src/main/java/org/bitcoinj/tools/WalletTool.java b/tools/src/main/java/org/bitcoinj/tools/WalletTool.java index f93d3dcd..c04c8a2c 100644 --- a/tools/src/main/java/org/bitcoinj/tools/WalletTool.java +++ b/tools/src/main/java/org/bitcoinj/tools/WalletTool.java @@ -680,7 +680,7 @@ public class WalletTool { static class OutputSpec { public final Coin value; - public final LegacyAddress addr; + public final Address addr; public final ECKey key; public OutputSpec(String spec) throws IllegalArgumentException { @@ -700,7 +700,7 @@ public class WalletTool { addr = null; } else { // Treat as an address. - addr = LegacyAddress.fromBase58(params, destination); + addr = Address.fromString(params, destination); key = null; } } diff --git a/tools/src/main/resources/org/bitcoinj/tools/wallet-tool-help.txt b/tools/src/main/resources/org/bitcoinj/tools/wallet-tool-help.txt index ba1d2005..1dce207f 100644 --- a/tools/src/main/resources/org/bitcoinj/tools/wallet-tool-help.txt +++ b/tools/src/main/resources/org/bitcoinj/tools/wallet-tool-help.txt @@ -38,6 +38,7 @@ Usage: wallet-tool --flags action-name You can repeat --output=address:value multiple times. There is a magic value ALL which empties the wallet to that address, e.g.: --output=1GthXFQMktFLWdh5EPNGqbq3H6WdG8zsWj:ALL + The output destination can also be a native segwit address. If the output destination starts with 04 and is 65 or 33 bytes long it will be treated as a public key instead of an address and the send will use