Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent dust outputs from being created during withdraw from wallet #4093

Merged
merged 4 commits into from Apr 3, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
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 @@ -330,8 +331,9 @@ private void onWithdraw() {
feeEstimationTransaction = walletService.getFeeEstimationTransactionForMultipleAddresses(fromAddresses, sendersAmount);
}
checkNotNull(feeEstimationTransaction, "feeEstimationTransaction must not be null");
Coin fee = feeEstimationTransaction.getFee();
sendersAmount = feeExcluded ? amountAsCoin.add(fee) : amountAsCoin;
Coin dust = getDust(feeEstimationTransaction);
Coin fee = feeEstimationTransaction.getFee().add(dust);
sendersAmount = feeExcluded ? amountAsCoin.add(fee) : amountAsCoin.add(dust);
This conversation was marked as resolved.
Show resolved Hide resolved
Coin receiverAmount = feeExcluded ? amountAsCoin : amountAsCoin.subtract(fee);
if (areInputsValid()) {
int txSize = feeEstimationTransaction.bitcoinSerialize().length;
Expand Down Expand Up @@ -629,6 +631,17 @@ public void updateItem(final WithdrawalListItem item, boolean empty) {
}
});
}

private Coin getDust(Transaction tx) {
Coin dust = Coin.ZERO;
for (TransactionOutput txo: tx.getOutputs()) {
if (txo.getValue().value < 546) {
This conversation was marked as resolved.
Show resolved Hide resolved
dust = dust.add(txo.getValue());
log.info("dust TXO = {}", txo.getValue().toFriendlyString());
This conversation was marked as resolved.
Show resolved Hide resolved
}
}
return dust;
}
}