Maintain floor amount of 5.46 BSQ to prevent dust errors

When an offer is made using BSQ for trade fee, the BSQ amount
is burnt by doing a send-to-self.  However if the BSQ change
is below the bitcoin dust limit this causes an error.  We
fix this by maintaining a floor amount of 5.46 BSQ.

Fixes #4372
This commit is contained in:
jmacxx 2020-07-28 09:43:55 -05:00
parent 716947a799
commit 2d5ab2a8d7
No known key found for this signature in database
GPG Key ID: 155297BABFE94A1B
5 changed files with 32 additions and 12 deletions

View File

@ -140,6 +140,10 @@ public class OfferUtil {
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();
}
@ -171,6 +175,10 @@ public class OfferUtil {
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();
}

View File

@ -718,8 +718,14 @@ public abstract class MutableOfferDataModel extends OfferDataModel implements Bs
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) {

View File

@ -373,9 +373,9 @@ public abstract class MutableOfferView<M extends MutableOfferViewModel<?>> exten
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)
@ -1109,9 +1109,9 @@ public abstract class MutableOfferView<M extends MutableOfferViewModel<?>> exten
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");
}

View File

@ -639,8 +639,14 @@ class TakeOfferDataModel extends OfferDataModel {
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() {

View File

@ -927,9 +927,9 @@ public class TakeOfferView extends ActivatableViewAndModel<AnchorPane, TakeOffer
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");
}
@ -1225,9 +1225,9 @@ public class TakeOfferView extends ActivatableViewAndModel<AnchorPane, TakeOffer
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)