From b865e6a51091389a239eb09f0d53e69d508ba48a Mon Sep 17 00:00:00 2001 From: Mike Hearn Date: Tue, 11 Jun 2013 12:24:14 +0200 Subject: [PATCH] Make Transaction.addInput(TransactionOutput) return the created input. Use it to make a minor simplification. --- core/src/main/java/com/google/bitcoin/core/Transaction.java | 6 ++++-- core/src/main/java/com/google/bitcoin/core/Wallet.java | 6 +++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/com/google/bitcoin/core/Transaction.java b/core/src/main/java/com/google/bitcoin/core/Transaction.java index d7ef7e9a..9f8653e8 100644 --- a/core/src/main/java/com/google/bitcoin/core/Transaction.java +++ b/core/src/main/java/com/google/bitcoin/core/Transaction.java @@ -665,8 +665,10 @@ public class Transaction extends ChildMessage implements Serializable { * signInputs() must be called to finalize the transaction and finish the inputs off. Otherwise it won't be * accepted by the network. */ - public void addInput(TransactionOutput from) { - addInput(new TransactionInput(params, this, from)); + public TransactionInput addInput(TransactionOutput from) { + final TransactionInput input = new TransactionInput(params, this, from); + addInput(input); + return input; } /** diff --git a/core/src/main/java/com/google/bitcoin/core/Wallet.java b/core/src/main/java/com/google/bitcoin/core/Wallet.java index d7bf4fe0..77b5de7d 100644 --- a/core/src/main/java/com/google/bitcoin/core/Wallet.java +++ b/core/src/main/java/com/google/bitcoin/core/Wallet.java @@ -3171,9 +3171,9 @@ public class Wallet implements Serializable, BlockChainListener { } for (TransactionOutput output : selection.gathered) { - req.tx.addInput(output); - // If the scriptBytes don't default to none, our size calculations will be thrown off - checkState(req.tx.getInput(req.tx.getInputs().size()-1).getScriptBytes().length == 0); + TransactionInput input = req.tx.addInput(output); + // If the scriptBytes don't default to none, our size calculations will be thrown off. + checkState(input.getScriptBytes().length == 0); try { if (output.getScriptPubKey().isSentToAddress()) { // Send-to-address spends usually take maximum pubkey.length (as it may be compressed or not) + 75 bytes