3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-01-31 23:32:16 +00:00

Transactions: Make some methods public and add a couple of accessor methods.

This commit is contained in:
Mike Hearn 2013-04-12 15:29:33 +02:00
parent 30eb1f8043
commit 8fa8a195c1
2 changed files with 14 additions and 3 deletions

View File

@ -337,7 +337,7 @@ public class TransactionInput extends ChildMessage implements Serializable {
* *
* @return true if the disconnection took place, false if it was not connected. * @return true if the disconnection took place, false if it was not connected.
*/ */
boolean disconnect() { public boolean disconnect() {
if (outpoint.fromTx == null) return false; if (outpoint.fromTx == null) return false;
TransactionOutput output = outpoint.fromTx.getOutput((int) outpoint.getIndex()); TransactionOutput output = outpoint.fromTx.getOutput((int) outpoint.getIndex());
if (output.getSpentBy() == this) { if (output.getSpentBy() == this) {
@ -375,4 +375,13 @@ public class TransactionInput extends ChildMessage implements Serializable {
int myIndex = parentTransaction.getInputs().indexOf(this); int myIndex = parentTransaction.getInputs().indexOf(this);
sig.correctlySpends(parentTransaction, myIndex, pubKey, true); sig.correctlySpends(parentTransaction, myIndex, pubKey, true);
} }
/**
* Returns the connected output, assuming the input was connected with
* {@link TransactionInput#connect(TransactionOutput)} or variants at some point. If it wasn't connected, then
* this method returns null.
*/
public TransactionOutput getConnectedOutput() {
return getOutpoint().getConnectedOutput();
}
} }

View File

@ -112,7 +112,7 @@ public class TransactionOutPoint extends ChildMessage implements Serializable {
* sides in memory, and they have been linked together, this returns a pointer to the connected output, or null * sides in memory, and they have been linked together, this returns a pointer to the connected output, or null
* if there is no such connection. * if there is no such connection.
*/ */
TransactionOutput getConnectedOutput() { public TransactionOutput getConnectedOutput() {
if (fromTx == null) return null; if (fromTx == null) return null;
return fromTx.getOutputs().get((int) index); return fromTx.getOutputs().get((int) index);
} }
@ -139,7 +139,9 @@ public class TransactionOutPoint extends ChildMessage implements Serializable {
* @return an ECKey or null if the connected key cannot be found in the wallet. * @return an ECKey or null if the connected key cannot be found in the wallet.
*/ */
public ECKey getConnectedKey(Wallet wallet) throws ScriptException { public ECKey getConnectedKey(Wallet wallet) throws ScriptException {
Script connectedScript = getConnectedOutput().getScriptPubKey(); TransactionOutput connectedOutput = getConnectedOutput();
checkState(connectedOutput != null, "Input is not connected in wallet so cannot retrieve connected key");
Script connectedScript = connectedOutput.getScriptPubKey();
if (connectedScript.isSentToAddress()) { if (connectedScript.isSentToAddress()) {
byte[] addressBytes = connectedScript.getPubKeyHash(); byte[] addressBytes = connectedScript.getPubKeyHash();
return wallet.findKeyFromPubHash(addressBytes); return wallet.findKeyFromPubHash(addressBytes);