mirror of
https://github.com/bisq-network/bisq.git
synced 2025-02-23 15:00:30 +01:00
Merge pull request #4094 from jmacxx/fix_dust_trading
Prevent dust outputs from being created during the trade process
This commit is contained in:
commit
c54a5acbb0
1 changed files with 33 additions and 0 deletions
|
@ -177,6 +177,9 @@ public class TradeWalletService {
|
|||
|
||||
checkNotNull(wallet, "Wallet must not be null");
|
||||
wallet.completeTx(sendRequest);
|
||||
if (removeDust(tradingFeeTx)) {
|
||||
wallet.signTransaction(sendRequest);
|
||||
}
|
||||
WalletService.printTx("tradingFeeTx", tradingFeeTx);
|
||||
|
||||
if (doBroadcast && callback != null) {
|
||||
|
@ -257,6 +260,7 @@ public class TradeWalletService {
|
|||
checkNotNull(wallet, "Wallet must not be null");
|
||||
wallet.completeTx(sendRequest);
|
||||
Transaction resultTx = sendRequest.tx;
|
||||
removeDust(resultTx);
|
||||
|
||||
// Sign all BTC inputs
|
||||
for (int i = preparedBsqTxInputsSize; i < resultTx.getInputs().size(); i++) {
|
||||
|
@ -1216,4 +1220,33 @@ public class TradeWalletService {
|
|||
tx.getInputs().forEach(input -> input.setSequenceNumber(TransactionInput.NO_SEQUENCE - 1));
|
||||
tx.setLockTime(lockTime);
|
||||
}
|
||||
|
||||
// BISQ issue #4039: prevent dust outputs from being created.
|
||||
// check all the outputs in a proposed transaction, if any are below the dust threshold
|
||||
// remove them, noting the details in the log. returns 'true' to indicate if any dust was
|
||||
// removed.
|
||||
private boolean removeDust(Transaction transaction) {
|
||||
List<TransactionOutput> originalTransactionOutputs = transaction.getOutputs();
|
||||
List<TransactionOutput> keepTransactionOutputs = new ArrayList<>();
|
||||
for (TransactionOutput transactionOutput: originalTransactionOutputs) {
|
||||
if (transactionOutput.getValue().isLessThan(Restrictions.getMinNonDustOutput())) {
|
||||
log.info("your transaction would have contained a dust output of {}", transactionOutput.toString());
|
||||
}
|
||||
else {
|
||||
keepTransactionOutputs.add(transactionOutput);
|
||||
}
|
||||
}
|
||||
// if dust was detected, keepTransactionOutputs will have fewer elements than originalTransactionOutputs
|
||||
// set the transaction outputs to what we saved in keepTransactionOutputs, thus discarding dust.
|
||||
if (keepTransactionOutputs.size() != originalTransactionOutputs.size()) {
|
||||
log.info("dust output was detected and removed, the new output is as follows:");
|
||||
transaction.clearOutputs();
|
||||
for (TransactionOutput transactionOutput : keepTransactionOutputs) {
|
||||
transaction.addOutput(transactionOutput);
|
||||
log.info("{}", transactionOutput.toString());
|
||||
}
|
||||
return true; // dust was removed
|
||||
}
|
||||
return false; // no action necessary
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue