Skip to content

Commit

Permalink
TransactionInput: verify(): don't crash if the given output has no pa…
Browse files Browse the repository at this point in the history
…rent. Clears a static analysis warning.
  • Loading branch information
mikehearn committed Apr 7, 2014
1 parent 782edd8 commit fbf7003
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 6 additions & 4 deletions core/src/main/java/com/google/bitcoin/core/TransactionInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -402,10 +402,12 @@ public void verify() throws VerificationException {
* @throws VerificationException If the outpoint doesn't match the given output.
*/
public void verify(TransactionOutput output) throws VerificationException {
if (!getOutpoint().getHash().equals(output.parentTransaction.getHash()))
throw new VerificationException("This input does not refer to the tx containing the output.");
if (getOutpoint().getIndex() != output.getIndex())
throw new VerificationException("This input refers to a different output on the given tx.");
if (output.parentTransaction != null) {
if (!getOutpoint().getHash().equals(output.parentTransaction.getHash()))
throw new VerificationException("This input does not refer to the tx containing the output.");
if (getOutpoint().getIndex() != output.getIndex())
throw new VerificationException("This input refers to a different output on the given tx.");
}
Script pubKey = output.getScriptPubKey();
int myIndex = parentTransaction.getInputs().indexOf(this);
getScriptSig().correctlySpends(parentTransaction, myIndex, pubKey, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public void setValue(BigInteger value) {
}

int getIndex() {
checkNotNull(parentTransaction);
checkNotNull(parentTransaction, "This output is not attached to a parent transaction.");
for (int i = 0; i < parentTransaction.getOutputs().size(); i++) {
if (parentTransaction.getOutputs().get(i) == this)
return i;
Expand Down

0 comments on commit fbf7003

Please sign in to comment.