mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-08-02 00:31:24 +00:00
TransactionInput: Add getIndex() helper.
This commit is contained in:
@@ -147,6 +147,17 @@ public class TransactionInput extends ChildMessage {
|
||||
this.value = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the index of this input in the parent transaction, or throws if this input is free standing. Iterates
|
||||
* over the parents list to discover this.
|
||||
*/
|
||||
public int getIndex() {
|
||||
final int myIndex = getParentTransaction().getInputs().indexOf(this);
|
||||
if (myIndex < 0)
|
||||
throw new IllegalStateException("Input linked to wrong parent transaction?");
|
||||
return myIndex;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void parse() throws ProtocolException {
|
||||
outpoint = new TransactionOutPoint(params, payload, cursor, this, serializer);
|
||||
@@ -464,7 +475,7 @@ public class TransactionInput extends ChildMessage {
|
||||
}
|
||||
Script pubKey = output.getScriptPubKey();
|
||||
int myIndex = getParentTransaction().getInputs().indexOf(this);
|
||||
getScriptSig().correctlySpends(getParentTransaction(), myIndex, pubKey);
|
||||
getScriptSig().correctlySpends(getParentTransaction(), getIndex(), pubKey);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -295,9 +295,8 @@ public class WalletProtobufSerializer {
|
||||
final TransactionInput spentBy = output.getSpentBy();
|
||||
if (spentBy != null) {
|
||||
Sha256Hash spendingHash = spentBy.getParentTransaction().getHash();
|
||||
int spentByTransactionIndex = spentBy.getParentTransaction().getInputs().indexOf(spentBy);
|
||||
outputBuilder.setSpentByTransactionHash(hashToByteString(spendingHash))
|
||||
.setSpentByTransactionIndex(spentByTransactionIndex);
|
||||
.setSpentByTransactionIndex(spentBy.getIndex());
|
||||
}
|
||||
txBuilder.addTransactionOutput(outputBuilder);
|
||||
}
|
||||
|
Reference in New Issue
Block a user