Skip to content

Commit

Permalink
Add some convenience methods to Transaction for signing.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikehearn committed May 20, 2014
1 parent 1fe0e7f commit dfb3a76
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
16 changes: 16 additions & 0 deletions core/src/main/java/com/google/bitcoin/core/Transaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,22 @@ public TransactionInput addSignedInput(TransactionOutPoint prevOut, Script scrip
return addSignedInput(prevOut, scriptPubKey, sigKey, SigHash.ALL, false);
}

/**
* Adds an input that points to the given output and contains a valid signature for it, calculated using the
* signing key.
*/
public TransactionInput addSignedInput(TransactionOutput output, ECKey signingKey) {
return addSignedInput(output.getOutPointFor(), output.getScriptPubKey(), signingKey);
}

/**
* Adds an input that points to the given output and contains a valid signature for it, calculated using the
* signing key.
*/
public TransactionInput addSignedInput(TransactionOutput output, ECKey signingKey, SigHash sigHash, boolean anyoneCanPay) {
return addSignedInput(output.getOutPointFor(), output.getScriptPubKey(), signingKey, sigHash, anyoneCanPay);
}

/**
* Removes all the inputs from this transaction.
* Note that this also invalidates the length attribute
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,14 @@ private void writeObject(ObjectOutputStream out) throws IOException {
out.defaultWriteObject();
}

/**
* Returns a new {@link TransactionOutPoint}, which is essentially a structure pointing to this output.
* Requires that this output is not detached.
*/
public TransactionOutPoint getOutPointFor() {
return new TransactionOutPoint(params, getIndex(), getParentTransaction());
}

/** Returns a copy of the output detached from its containing transaction, if need be. */
public TransactionOutput duplicateDetached() {
return new TransactionOutput(params, null, value, org.spongycastle.util.Arrays.clone(scriptBytes));
Expand Down

0 comments on commit dfb3a76

Please sign in to comment.