Skip to content

Commit

Permalink
Merge pull request bisq-network#4884 from ghubstan/01-refactor-getdust
Browse files Browse the repository at this point in the history
Refactor: move getDust(Transaction transaction)
  • Loading branch information
sqrrm authored Dec 7, 2020
2 parents 6d01bc9 + 74261b1 commit 74485f0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
14 changes: 14 additions & 0 deletions core/src/main/java/bisq/core/btc/wallet/WalletService.java
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,20 @@ public boolean isAddressUnused(Address address) {
return getNumTxOutputsForAddress(address) == 0;
}

// BISQ issue #4039: Prevent dust outputs from being created.
// Check the outputs of a proposed transaction. If any are below the dust threshold,
// add up the dust, log the details, and return the cumulative dust amount.
public Coin getDust(Transaction proposedTransaction) {
Coin dust = Coin.ZERO;
for (TransactionOutput transactionOutput : proposedTransaction.getOutputs()) {
if (transactionOutput.getValue().isLessThan(Restrictions.getMinNonDustOutput())) {
dust = dust.add(transactionOutput.getValue());
log.info("Dust TXO = {}", transactionOutput.toString());
}
}
return dust;
}


///////////////////////////////////////////////////////////////////////////////////////////
// Empty complete Wallet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
import org.bitcoinj.core.Coin;
import org.bitcoinj.core.InsufficientMoneyException;
import org.bitcoinj.core.Transaction;
import org.bitcoinj.core.TransactionOutput;
import org.bitcoinj.wallet.Wallet;

import javax.inject.Inject;
Expand Down Expand Up @@ -334,9 +333,9 @@ private void onWithdraw() {
}
checkNotNull(feeEstimationTransaction, "feeEstimationTransaction must not be null");

Coin dust = getDust(feeEstimationTransaction);
Coin dust = btcWalletService.getDust(feeEstimationTransaction);
Coin fee = feeEstimationTransaction.getFee().add(dust);
Coin receiverAmount = Coin.ZERO;
Coin receiverAmount;
// amountAsCoin is what the user typed into the withdrawal field.
// this can be interpreted as either the senders amount or receivers amount depending
// on a radio button "fee excluded / fee included".
Expand Down Expand Up @@ -669,21 +668,6 @@ public void updateItem(final WithdrawalListItem item, boolean empty) {
}
});
}

// BISQ issue #4039: prevent dust outputs from being created.
// check the outputs of a proposed transaction, if any are below the dust threshold
// add up the dust, noting the details in the log.
// returns the 'dust amount' to indicate if any dust was detected.
private Coin getDust(Transaction transaction) {
Coin dust = Coin.ZERO;
for (TransactionOutput transactionOutput : transaction.getOutputs()) {
if (transactionOutput.getValue().isLessThan(Restrictions.getMinNonDustOutput())) {
dust = dust.add(transactionOutput.getValue());
log.info("dust TXO = {}", transactionOutput.toString());
}
}
return dust;
}
}


0 comments on commit 74485f0

Please sign in to comment.