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

Maintain floor amount of 5.46 BSQ to prevent dust errors #4383

Merged
merged 1 commit into from Jul 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 8 additions & 0 deletions core/src/main/java/bisq/core/offer/OfferUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ public static boolean isBsqForMakerFeeAvailable(BsqWalletService bsqWalletServic
if (makerFee == null)
return true;

Coin surplusFunds = availableBalance.subtract(makerFee);
if (Restrictions.isDust(surplusFunds)) {
return false; // we can't be left with dust
}
return !availableBalance.subtract(makerFee).isNegative();
}

Expand Down Expand Up @@ -171,6 +175,10 @@ public static boolean isBsqForTakerFeeAvailable(BsqWalletService bsqWalletServic
if (takerFee == null)
return true;

Coin surplusFunds = availableBalance.subtract(takerFee);
if (Restrictions.isDust(surplusFunds)) {
return false; // we can't be left with dust
}
return !availableBalance.subtract(takerFee).isNegative();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -718,8 +718,14 @@ ReadOnlyObjectProperty<Coin> totalToPayAsCoinProperty() {
return totalToPayAsCoin;
}

Coin getBsqBalance() {
return bsqWalletService.getAvailableConfirmedBalance();
Coin getUsableBsqBalance() {
// we have to keep a minimum amount of BSQ == bitcoin dust limit
// otherwise there would be dust violations for change UTXOs
// essentially means the minimum usable balance of BSQ is 5.46
Coin usableBsqBalance = bsqWalletService.getAvailableConfirmedBalance().subtract(Restrictions.getMinNonDustOutput());
if (usableBsqBalance.isNegative())
usableBsqBalance = Coin.ZERO;
return usableBsqBalance;
}

public void setMarketPriceAvailable(boolean marketPriceAvailable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -373,9 +373,9 @@ private void showInsufficientBsqFundsForBtcFeePaymentPopup() {
String message = null;
if (makerFee != null) {
message = Res.get("popup.warning.insufficientBsqFundsForBtcFeePayment",
bsqFormatter.formatCoinWithCode(makerFee.subtract(model.getDataModel().getBsqBalance())));
bsqFormatter.formatCoinWithCode(makerFee.subtract(model.getDataModel().getUsableBsqBalance())));

} else if (model.getDataModel().getBsqBalance().isZero())
} else if (model.getDataModel().getUsableBsqBalance().isZero())
message = Res.get("popup.warning.noBsqFundsForBtcFeePayment");

if (message != null)
Expand Down Expand Up @@ -1109,9 +1109,9 @@ private void showFeeOption() {
String missingBsq = null;
if (makerFee != null) {
missingBsq = Res.get("popup.warning.insufficientBsqFundsForBtcFeePayment",
bsqFormatter.formatCoinWithCode(makerFee.subtract(model.getDataModel().getBsqBalance())));
bsqFormatter.formatCoinWithCode(makerFee.subtract(model.getDataModel().getUsableBsqBalance())));

} else if (model.getDataModel().getBsqBalance().isZero()) {
} else if (model.getDataModel().getUsableBsqBalance().isZero()) {
missingBsq = Res.get("popup.warning.noBsqFundsForBtcFeePayment");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -639,8 +639,14 @@ public Coin getSellerSecurityDeposit() {
return offer.getSellerSecurityDeposit();
}

public Coin getBsqBalance() {
return bsqWalletService.getAvailableConfirmedBalance();
public Coin getUsableBsqBalance() {
// we have to keep a minimum amount of BSQ == bitcoin dust limit
// otherwise there would be dust violations for change UTXOs
// essentially means the minimum usable balance of BSQ is 5.46
Coin usableBsqBalance = bsqWalletService.getAvailableConfirmedBalance().subtract(Restrictions.getMinNonDustOutput());
if (usableBsqBalance.isNegative())
usableBsqBalance = Coin.ZERO;
return usableBsqBalance;
}

public boolean isHalCashAccount() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -927,9 +927,9 @@ private void showFeeOption() {
String missingBsq = null;
if (takerFee != null) {
missingBsq = Res.get("popup.warning.insufficientBsqFundsForBtcFeePayment",
bsqFormatter.formatCoinWithCode(takerFee.subtract(model.dataModel.getBsqBalance())));
bsqFormatter.formatCoinWithCode(takerFee.subtract(model.dataModel.getUsableBsqBalance())));

} else if (model.dataModel.getBsqBalance().isZero()) {
} else if (model.dataModel.getUsableBsqBalance().isZero()) {
missingBsq = Res.get("popup.warning.noBsqFundsForBtcFeePayment");
}

Expand Down Expand Up @@ -1225,9 +1225,9 @@ private void showInsufficientBsqFundsForBtcFeePaymentPopup() {
String message = null;
if (takerFee != null)
message = Res.get("popup.warning.insufficientBsqFundsForBtcFeePayment",
bsqFormatter.formatCoinWithCode(takerFee.subtract(model.dataModel.getBsqBalance())));
bsqFormatter.formatCoinWithCode(takerFee.subtract(model.dataModel.getUsableBsqBalance())));

else if (model.dataModel.getBsqBalance().isZero())
else if (model.dataModel.getUsableBsqBalance().isZero())
message = Res.get("popup.warning.noBsqFundsForBtcFeePayment");

if (message != null)
Expand Down