Transaction.addSignedInput: catch API usage error.

This commit is contained in:
Mike Hearn
2014-09-01 15:33:58 +02:00
parent 6579d72bd8
commit 4d18a477dd

View File

@@ -36,6 +36,7 @@ import java.text.SimpleDateFormat;
import java.util.*;
import static com.google.bitcoin.core.Utils.*;
import static com.google.common.base.Preconditions.checkState;
/**
* <p>A transaction represents the movement of coins from some addresses to some other addresses. It can also represent
@@ -744,6 +745,8 @@ public class Transaction extends ChildMessage implements Serializable {
*/
public TransactionInput addSignedInput(TransactionOutPoint prevOut, Script scriptPubKey, ECKey sigKey,
SigHash sigHash, boolean anyoneCanPay) throws ScriptException {
// Verify the API user didn't try to do operations out of order.
checkState(!outputs.isEmpty(), "Attempting to sign tx without outputs.");
TransactionInput input = new TransactionInput(params, this, new byte[]{}, prevOut);
addInput(input);
Sha256Hash hash = hashForSignature(inputs.size() - 1, scriptPubKey, sigHash, anyoneCanPay);