/** 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(); }
/** * 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); }
/** * Creates an output that pays to the given pubkey directly (no address) with the given value, adds it to this * transaction, and returns the new output. */ public TransactionOutput addOutput(Coin value, ECKey pubkey) { return addOutput(new TransactionOutput(params, this, value, pubkey)); }
public TrimmedOutput(TransactionOutput output, long index, Sha256Hash txHash) { super(output.getParams(), null, output.getValue(), output.getScriptBytes()); this.index = index; this.txHash = txHash; }
@Override public List<AbstractOutput> getSentTo() { List<AbstractOutput> outputs = new ArrayList<>(); for (TransactionOutput output : getOutputs(false)) { try { AbstractAddress address = BitAddress.from(type, output.getScriptPubKey()); outputs.add(new AbstractOutput(address, type.value(output.getValue()))); } catch (Exception e) { /* ignore this output */ } } return outputs; }
try { TransactionOutput output = utxo.getOutput(); Script script = output.getScriptPubKey(); ECKey key = null; Script redeemScript = null; key = account.findKeyFromPubHash(script.getPubKeyHash()); if (key == null) { log.error("output.getIndex {}", output.getIndex()); log.error("output.getAddressFromP2SH {}", output.getAddressFromP2SH(coinType)); log.error("output.getAddressFromP2PKHScript {}", output.getAddressFromP2PKHScript(coinType)); log.error("output.getParentTransaction().getHash() {}", output.getParentTransaction().getHash());
/** * Construct a SendRequest for a CPFP (child-pays-for-parent) transaction. The resulting transaction is already * completed, so you should directly proceed to signing and broadcasting/committing the transaction. CPFP is * currently only supported by a few miners, so use with care. */ public static SendRequest childPaysForParent(Wallet wallet, Transaction parentTransaction, Coin feeRaise) { TransactionOutput outputToSpend = null; for (final TransactionOutput output : parentTransaction.getOutputs()) { if (output.isMine(wallet) && output.isAvailableForSpending() && output.getValue().isGreaterThan(feeRaise)) { outputToSpend = output; break; } } // TODO spend another confirmed output of own wallet if needed checkNotNull(outputToSpend, "Can't find adequately sized output that spends to us"); final Transaction tx = new Transaction(parentTransaction.getParams()); tx.addInput(outputToSpend); tx.addOutput(outputToSpend.getValue().subtract(feeRaise), wallet.freshAddress(KeyPurpose.CHANGE)); tx.setPurpose(Transaction.Purpose.RAISE_FEE); final SendRequest req = forTx(tx); req.completed = true; return req; }
/** * Returns the amount of bitcoin ever received via output. <b>This is not the balance!</b> If an output spends from a * transaction whose inputs are also to our wallet, the input amounts are deducted from the outputs contribution, with a minimum of zero * contribution. The idea behind this is we avoid double counting money sent to us. * @return the total amount of satoshis received, regardless of whether it was spent or not. */ public Coin getTotalReceived() { Coin total = Coin.ZERO; // Include outputs to us if they were not just change outputs, ie the inputs to us summed to less // than the outputs to us. for (Transaction tx: transactions.values()) { Coin txTotal = Coin.ZERO; for (TransactionOutput output : tx.getOutputs()) { if (output.isMine(this)) { txTotal = txTotal.add(output.getValue()); } } for (TransactionInput in : tx.getInputs()) { TransactionOutput prevOut = in.getConnectedOutput(); if (prevOut != null && prevOut.isMine(this)) { txTotal = txTotal.subtract(prevOut.getValue()); } } if (txTotal.isPositive()) { total = total.add(txTotal); } } return total; }
/** * Will this transaction be relayable and mined by default miners? */ public boolean isDust() { // Transactions that are OP_RETURN can't be dust regardless of their value. if (getScriptPubKey().isOpReturn()) return false; return getValue().isLessThan(getMinNonDustValue()); }
public TransactionOutPoint(NetworkParameters params, TransactionOutput connectedOutput) { this( params, connectedOutput.getIndex(), connectedOutput.getParentTransactionHash(), connectedOutput.getValue()); this.connectedOutput = connectedOutput; }
@Override public Coin getBalance () { final long[] value = {0}; this.outputs.stream().forEach(transactionOutput -> value[0] += transactionOutput.getValue().value); return Coin.valueOf(value[0]); }
/** * 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()); }
@Override public int compare(TransactionOutput o1, TransactionOutput o2) { long amountDiff = o1.getValue().getValue() - o2.getValue().value; if (amountDiff != 0) { return (int) amountDiff; } else { byte[] hash1 = o1.getScriptBytes(); byte[] hash2 = o2.getScriptBytes(); return LexicographicalComparator.getComparator().compare(hash1, hash2); } } });
if (output.getScriptPubKey().isSentToRawPubKey() && output.isMine(wallet)) { if (tx.getConfidence().getConfidenceType() == TransactionConfidence.ConfidenceType.BUILDING) recalculateFastCatchupAndFilter(FilterRecalculateMode.SEND_IF_CHANGED);
String addressP2pkh = output.getAddressFromP2PKHScript(netParams).toString(); if (address.equals(addressP2pkh)) { txAmount += output.getValue().value;
public TransactionOutPoint(NetworkParameters params, TransactionOutput connectedOutput) { this(params, connectedOutput.getIndex(), connectedOutput.getParentTransactionHash()); this.connectedOutput = connectedOutput; }
/** * Returns the pubkey script from the connected output. * @throws java.lang.NullPointerException if there is no connected output. */ public byte[] getConnectedPubKeyScript() { byte[] result = checkNotNull(getConnectedOutput()).getScriptBytes(); checkState(result.length > 0); return result; }
private boolean isTxOutputBloomFilterable(TransactionOutput out) { Script script = out.getScriptPubKey(); boolean isScriptTypeSupported = script.isSentToRawPubKey() || script.isPayToScriptHash(); return (isScriptTypeSupported && myUnspents.contains(out)) || watchedScripts.contains(script); }
/** * Gets the index of this output in the parent transaction, or throws if this output is free standing. Iterates * over the parents list to discover this. */ public int getIndex() { List<TransactionOutput> outputs = getParentTransaction().getOutputs(); for (int i = 0; i < outputs.size(); i++) { if (outputs.get(i) == this) return i; } throw new IllegalStateException("Output linked to wrong parent transaction?"); }