Пример #1
0
 /** Creates an UNSIGNED input that links to the given output */
 TransactionInput(
     NetworkParameters params, Transaction parentTransaction, TransactionOutput output) {
   super(params);
   long outputIndex = output.getIndex();
   if (output.getParentTransaction() != null) {
     outpoint = new TransactionOutPoint(params, outputIndex, output.getParentTransaction());
   } else {
     outpoint = new TransactionOutPoint(params, output);
   }
   scriptBytes = EMPTY_ARRAY;
   sequence = NO_SEQUENCE;
   setParent(parentTransaction);
   this.value = output.getValue();
   length = 41;
 }
 private boolean isConfirmed(TransactionOutput output) {
   return output
       .getParentTransaction()
       .getConfidence()
       .getConfidenceType()
       .equals(TransactionConfidence.ConfidenceType.BUILDING);
 }
Пример #3
0
 /**
  * Verifies that this input can spend the given output. Note that this input must be a part of a
  * transaction. Also note that the consistency of the outpoint will be checked, even if this input
  * has not been connected.
  *
  * @param output the output that this input is supposed to spend.
  * @throws ScriptException If the script doesn't verify.
  * @throws VerificationException If the outpoint doesn't match the given output.
  */
 public void verify(TransactionOutput output) throws VerificationException {
   if (output.parent != null) {
     if (!getOutpoint().getHash().equals(output.getParentTransaction().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 = getParentTransaction().getInputs().indexOf(this);
   getScriptSig().correctlySpends(getParentTransaction(), myIndex, pubKey);
 }
Пример #4
0
 /**
  * Connects this input to the relevant output of the referenced transaction. Connecting means
  * updating the internal pointers and spent flags. If the mode is to ABORT_ON_CONFLICT then the
  * spent output won't be changed, but the outpoint.fromTx pointer will still be updated.
  *
  * @param transaction The transaction to try.
  * @param mode Whether to abort if there's a pre-existing connection or not.
  * @return NO_SUCH_TX if transaction is not the prevtx, ALREADY_SPENT if there was a conflict,
  *     SUCCESS if not.
  */
 public ConnectionResult connect(Transaction transaction, ConnectMode mode) {
   if (!transaction.getHash().equals(outpoint.getHash())) return ConnectionResult.NO_SUCH_TX;
   checkElementIndex(
       (int) outpoint.getIndex(), transaction.getOutputs().size(), "Corrupt transaction");
   TransactionOutput out = transaction.getOutput((int) outpoint.getIndex());
   if (!out.isAvailableForSpending()) {
     if (getParentTransaction().equals(outpoint.fromTx)) {
       // Already connected.
       return ConnectionResult.SUCCESS;
     } else if (mode == ConnectMode.DISCONNECT_ON_CONFLICT) {
       out.markAsUnspent();
     } else if (mode == ConnectMode.ABORT_ON_CONFLICT) {
       outpoint.fromTx = out.getParentTransaction();
       return TransactionInput.ConnectionResult.ALREADY_SPENT;
     }
   }
   connect(out);
   return TransactionInput.ConnectionResult.SUCCESS;
 }
Пример #5
0
 /**
  * Internal use only: connects this TransactionInput to the given output (updates pointers and
  * spent flags)
  */
 public void connect(TransactionOutput out) {
   outpoint.fromTx = out.getParentTransaction();
   out.markAsSpent(this);
   value = out.getValue();
 }