mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-19 18:03:12 +01:00
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:
parent
716947a799
commit
2d5ab2a8d7
@ -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();
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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");
|
||||
}
|
||||
|
||||
|
@ -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() {
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user