/** * Gets the sum of the outputs of the transaction. If the outputs are less than the inputs, it does not count the fee. * @return the sum of the outputs regardless of who owns them. */ public Coin getOutputSum() { Coin totalOut = Coin.ZERO; for (TransactionOutput output: outputs) { totalOut = totalOut.add(output.getValue()); } return totalOut; }
/** * Gets the sum of the outputs of the transaction. If the outputs are less than the inputs, it does not count the fee. * @return the sum of the outputs regardless of who owns them. */ public Coin getOutputSum() { Coin totalOut = Coin.ZERO; for (TransactionOutput output: outputs) { totalOut = totalOut.add(output.getValue()); } return totalOut; }
@Override public Coin getBalance () { final long[] value = {0}; this.outputs.stream().forEach(transactionOutput -> value[0] += transactionOutput.getValue().value); return Coin.valueOf(value[0]); }
PaymentChannelV2ClientState(StoredClientChannel storedClientChannel, Wallet wallet) throws VerificationException { super(storedClientChannel, wallet); // The PaymentChannelClientConnection handles storedClientChannel.active and ensures we aren't resuming channels this.contract = checkNotNull(storedClientChannel.contract); this.expiryTime = storedClientChannel.expiryTime; this.totalValue = contract.getOutput(0).getValue(); this.valueToMe = checkNotNull(storedClientChannel.valueToMe); this.refundTx = checkNotNull(storedClientChannel.refund); this.refundFees = checkNotNull(storedClientChannel.refundFees); stateMachine.transition(State.READY); initWalletListeners(); }
PaymentChannelV2ClientState(StoredClientChannel storedClientChannel, Wallet wallet) throws VerificationException { super(storedClientChannel, wallet); // The PaymentChannelClientConnection handles storedClientChannel.active and ensures we aren't resuming channels this.contract = checkNotNull(storedClientChannel.contract); this.expiryTime = storedClientChannel.expiryTime; this.totalValue = contract.getOutput(0).getValue(); this.valueToMe = checkNotNull(storedClientChannel.valueToMe); this.refundTx = checkNotNull(storedClientChannel.refund); this.refundFees = checkNotNull(storedClientChannel.refundFees); stateMachine.transition(State.READY); initWalletListeners(); }
/** 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(); }
public TrimmedOutput(TransactionOutput output, long index, Sha256Hash txHash) { super(output.getParams(), null, output.getValue(), output.getScriptBytes()); this.index = index; this.txHash = txHash; }
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; }
PaymentChannelV1ClientState(StoredClientChannel storedClientChannel, Wallet wallet) throws VerificationException { super(storedClientChannel, wallet); // The PaymentChannelClientConnection handles storedClientChannel.active and ensures we aren't resuming channels this.multisigContract = checkNotNull(storedClientChannel.contract); this.multisigScript = multisigContract.getOutput(0).getScriptPubKey(); this.refundTx = checkNotNull(storedClientChannel.refund); this.refundFees = checkNotNull(storedClientChannel.refundFees); this.expiryTime = refundTx.getLockTime(); this.totalValue = multisigContract.getOutput(0).getValue(); stateMachine.transition(State.READY); initWalletListeners(); }
public TrimmedOutput(TransactionOutput output, long index, TrimmedTransaction tx) { super(output.getParams(), checkNotNull(tx), output.getValue(), output.getScriptBytes()); this.index = index; this.txHash = null; }
public TrimmedOutput(TransactionOutput output, long index, TrimmedTransaction tx) { super(output.getParams(), checkNotNull(tx), output.getValue(), output.getScriptBytes()); this.index = index; this.txHash = null; }
PaymentChannelV1ClientState(StoredClientChannel storedClientChannel, Wallet wallet) throws VerificationException { super(storedClientChannel, wallet); // The PaymentChannelClientConnection handles storedClientChannel.active and ensures we aren't resuming channels this.multisigContract = checkNotNull(storedClientChannel.contract); this.multisigScript = multisigContract.getOutput(0).getScriptPubKey(); this.refundTx = checkNotNull(storedClientChannel.refund); this.refundFees = checkNotNull(storedClientChannel.refundFees); this.expiryTime = refundTx.getLockTime(); this.totalValue = multisigContract.getOutput(0).getValue(); stateMachine.transition(State.READY); initWalletListeners(); }
/** * 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()); }
/** * Checks the output to see if the script violates a standardness rule. Not complete. */ public static RuleViolation isOutputStandard(TransactionOutput output) { if (output.getValue().compareTo(MIN_ANALYSIS_NONDUST_OUTPUT) < 0) return RuleViolation.DUST; for (ScriptChunk chunk : output.getScriptPubKey().getChunks()) { if (chunk.isPushData() && !chunk.isShortestPossiblePushData()) return RuleViolation.SHORTEST_POSSIBLE_PUSHDATA; } return RuleViolation.NONE; }
/** * Checks the output to see if the script violates a standardness rule. Not complete. */ public static RuleViolation isOutputStandard(TransactionOutput output) { if (output.getValue().compareTo(output.getParams().isDIP0001ActiveAtTip() ? MIN_ANALYSIS_NONDUST_OUTPUT.div(10) : MIN_ANALYSIS_NONDUST_OUTPUT) < 0) return RuleViolation.DUST; for (ScriptChunk chunk : output.getScriptPubKey().getChunks()) { if (chunk.isPushData() && !chunk.isShortestPossiblePushData()) return RuleViolation.SHORTEST_POSSIBLE_PUSHDATA; } return RuleViolation.NONE; }
/** Reduce the value of the first output of a transaction to pay the given feePerKb as appropriate for its size. */ private boolean adjustOutputDownwardsForFee(Transaction tx, CoinSelection coinSelection, Coin feePerKb, boolean ensureMinRequiredFee) { final int size = tx.unsafeBitcoinSerialize().length + estimateBytesForSigning(coinSelection); Coin fee = feePerKb.multiply(size).divide(1000); if (ensureMinRequiredFee && fee.compareTo(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE) < 0) fee = Transaction.REFERENCE_DEFAULT_MIN_TX_FEE; TransactionOutput output = tx.getOutput(0); output.setValue(output.getValue().subtract(fee)); return !output.isDust(); }
/** Reduce the value of the first output of a transaction to pay the given feePerKb as appropriate for its size. */ private boolean adjustOutputDownwardsForFee(Transaction tx, CoinSelection coinSelection, Coin feePerKb, boolean ensureMinRequiredFee) { final int size = tx.unsafeBitcoinSerialize().length + estimateBytesForSigning(coinSelection); Coin fee = feePerKb.multiply(size).divide(1000); if (ensureMinRequiredFee && fee.compareTo(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE) < 0) fee = Transaction.REFERENCE_DEFAULT_MIN_TX_FEE; TransactionOutput output = tx.getOutput(0); output.setValue(output.getValue().subtract(fee)); return !output.isDust(); }
/** Reduce the value of the first output of a transaction to pay the given feePerKb as appropriate for its size. */ private boolean adjustOutputDownwardsForFee(Transaction tx, CoinSelection coinSelection, Coin feePerKb, boolean ensureMinRequiredFee) { final int size = tx.unsafeBitcoinSerialize().length + estimateBytesForSigning(coinSelection); Coin fee = feePerKb.multiply(size).divide(1000); if (ensureMinRequiredFee && fee.compareTo(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE) < 0) fee = Transaction.REFERENCE_DEFAULT_MIN_TX_FEE; TransactionOutput output = tx.getOutput(0); output.setValue(output.getValue().subtract(fee)); return !output.isDust(); }
private void basicSanityChecks(Wallet wallet, Transaction t, Address destination) throws VerificationException { assertEquals("Wrong number of tx inputs", 1, t.getInputs().size()); assertEquals("Wrong number of tx outputs",2, t.getOutputs().size()); assertEquals(destination, t.getOutput(0).getScriptPubKey().getToAddress(PARAMS)); assertEquals(wallet.currentChangeAddress(), t.getOutputs().get(1).getScriptPubKey().getToAddress(PARAMS)); assertEquals(valueOf(0, 50), t.getOutputs().get(1).getValue()); // Check the script runs and signatures verify. t.getInputs().get(0).verify(); }