@Override public Transaction getChannelTransaction (TransactionOutPoint anchor, ChannelStatus channelStatus, ECKey client, ECKey server) { Transaction transaction = new Transaction(Constants.getNetwork()); transaction.addInput(anchor.getHash(), anchor.getIndex(), Tools.getDummyScript()); transaction.addOutput(Coin.valueOf(0), ScriptTools.getChannelTxOutputRevocation(channelStatus.revocationHashClient, client, server, Constants.ESCAPE_REVOCATION_TIME)); transaction.addOutput(Coin.valueOf(0), channelStatus.addressServer); transaction = addPayments(transaction, channelStatus, channelStatus.revocationHashClient, client, server); //Missing two signatures, max 146B long fee = (long) Math.ceil((transaction.getMessageSize() + 146) * channelStatus.feePerByte / 2); transaction.getOutput(0).setValue(Coin.valueOf(channelStatus.amountClient - fee)); transaction.getOutput(1).setValue(Coin.valueOf(channelStatus.amountServer - fee)); return transaction; }
@Test(expected = VerificationException.NegativeValueOutput.class) public void negativeOutput() throws Exception { tx.getOutput(0).setValue(Coin.NEGATIVE_SATOSHI); tx.verify(); }
/** 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(); }
throw new RuntimeException("Unknown fee policy: " + coinType.getFeePolicy()); output.setValue(output.getValue().subtract(fee)); case AT_LEAST_BASE_FEE_IF_SOFT_DUST_TXO_PRESENT: if (fee.compareTo(feePerTxSize) < 0) { output.setValue(output.getValue().subtract(feePerTxSize.subtract(fee))); output.setValue(output.getValue().subtract(feePerTxSize)); break; case NO_POLICY:
throw new RuntimeException("Unknown fee policy: " + coinType.getFeePolicy()); output.setValue(output.getValue().subtract(fee)); case AT_LEAST_BASE_FEE_IF_SOFT_DUST_TXO_PRESENT: if (fee.compareTo(feePerTxSize) < 0) { output.setValue(output.getValue().subtract(feePerTxSize.subtract(fee))); output.setValue(output.getValue().subtract(feePerTxSize)); break; case NO_POLICY:
/** 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, boolean useInstantSend) { final int size = tx.unsafeBitcoinSerialize().length + estimateBytesForSigning(coinSelection); Coin fee = feePerKb.multiply(size).divide(1000); if (ensureMinRequiredFee && fee.compareTo(params.isDIP0001ActiveAtTip() ? Transaction.REFERENCE_DEFAULT_MIN_TX_FEE.div(10) : Transaction.REFERENCE_DEFAULT_MIN_TX_FEE) < 0) fee = params.isDIP0001ActiveAtTip() ? Transaction.REFERENCE_DEFAULT_MIN_TX_FEE.div(10) : Transaction.REFERENCE_DEFAULT_MIN_TX_FEE; if(useInstantSend) fee = TransactionLockRequest.MIN_FEE.multiply(tx.getInputs().size()); TransactionOutput output = tx.getOutput(0); output.setValue(output.getValue().subtract(fee)); return !output.isDust(); }
if (req.recipientsPayFees) { output.setValue(output.getValue().subtract(fee.divide(req.tx.getOutputs().size()))); output.setValue( output.getValue().subtract(fee.divideAndRemainder(req.tx.getOutputs().size())[1])); // Subtract fee equally from each selected recipient changeOutput.setValue(changeOutput.getValue().add(missingToNotBeDust)); TransactionOutput firstOutput = tx.getOutputs().get(0); firstOutput.setValue(firstOutput.getValue().subtract(missingToNotBeDust)); result.updatedOutputValues.set(0, firstOutput.getValue()); if (firstOutput.isDust()) {
bestCoinSelection = selector.select(params.getMaxMoney(), candidates); req.tx.getOutput(0).setValue(bestCoinSelection.valueGathered); log.info(" emptying {}", bestCoinSelection.valueGathered.toFriendlyString());
bestCoinSelection = selector.select(params.getMaxMoney(), candidates); req.tx.getOutput(0).setValue(bestCoinSelection.valueGathered); log.info(" emptying {}", bestCoinSelection.valueGathered.toFriendlyString());
bestCoinSelection = selector.select(params.getMaxMoney(), candidates); req.tx.getOutput(0).setValue(bestCoinSelection.valueGathered); log.info(" emptying {}", bestCoinSelection.valueGathered.toFriendlyString());
@Test(expected = VerificationException.ExcessiveValue.class) public void exceedsMaxMoney2() throws Exception { Coin half = PARAMS.getMaxMoney().divide(2).add(Coin.SATOSHI); tx.getOutput(0).setValue(half); tx.addOutput(half, ADDRESS); tx.verify(); }
bestCoinSelection = selector.select(NetworkParameters.MAX_MONEY, candidates); tx.getOutput(0).setValue(bestCoinSelection.valueGathered); log.info(" emptying {}", bestCoinSelection.valueGathered.toFriendlyString());
bestCoinSelection = selector.select(NetworkParameters.MAX_MONEY, candidates); tx.getOutput(0).setValue(bestCoinSelection.valueGathered); log.info(" emptying {}", bestCoinSelection.valueGathered.toFriendlyString());