Skip to content

Commit 0d63742

Browse files
committed
always use accessors to get restrictions
1 parent b3610b8 commit 0d63742

File tree

12 files changed

+59
-51
lines changed

12 files changed

+59
-51
lines changed

apitest/src/test/java/haveno/apitest/method/MethodTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
import static haveno.apitest.config.ApiTestConfig.BTC;
4444
import static haveno.apitest.config.ApiTestRateMeterInterceptorConfig.getTestRateMeterInterceptorConfig;
4545
import static haveno.cli.table.builder.TableType.BTC_BALANCE_TBL;
46-
import static haveno.core.xmr.wallet.Restrictions.getDefaultSecurityDepositAsPercent;
46+
import static haveno.core.xmr.wallet.Restrictions.getDefaultSecurityDepositPct;
4747
import static java.lang.String.format;
4848
import static java.nio.charset.StandardCharsets.UTF_8;
4949
import static java.util.Arrays.stream;
@@ -158,7 +158,7 @@ protected final haveno.core.payment.PaymentAccount createPaymentAccount(GrpcClie
158158
}
159159

160160
public static final Supplier<Double> defaultSecurityDepositPct = () -> {
161-
var defaultPct = BigDecimal.valueOf(getDefaultSecurityDepositAsPercent());
161+
var defaultPct = BigDecimal.valueOf(getDefaultSecurityDepositPct());
162162
if (defaultPct.precision() != 2)
163163
throw new IllegalStateException(format(
164164
"Unexpected decimal precision, expected 2 but actual is %d%n."

core/src/main/java/haveno/core/offer/OfferBookService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ private void validateOfferPayload(OfferPayload offerPayload) {
404404
}
405405

406406
// validate max offers with same key images
407-
if (numOffersWithSharedKeyImages > Restrictions.MAX_OFFERS_WITH_SHARED_FUNDS) throw new RuntimeException("More than " + Restrictions.MAX_OFFERS_WITH_SHARED_FUNDS + " offers exist with same same key images as new offerId=" + offerPayload.getId());
407+
if (numOffersWithSharedKeyImages > Restrictions.getMaxOffersWithSharedFunds()) throw new RuntimeException("More than " + Restrictions.getMaxOffersWithSharedFunds() + " offers exist with same same key images as new offerId=" + offerPayload.getId());
408408
}
409409
}
410410

core/src/main/java/haveno/core/offer/OfferUtil.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@
6060
import haveno.core.user.AutoConfirmSettings;
6161
import haveno.core.user.Preferences;
6262
import haveno.core.util.coin.CoinFormatter;
63-
import static haveno.core.xmr.wallet.Restrictions.getMaxSecurityDepositAsPercent;
64-
import static haveno.core.xmr.wallet.Restrictions.getMinSecurityDepositAsPercent;
63+
import static haveno.core.xmr.wallet.Restrictions.getMaxSecurityDepositPct;
64+
import static haveno.core.xmr.wallet.Restrictions.getMinSecurityDepositPct;
6565
import haveno.network.p2p.P2PService;
6666
import java.math.BigInteger;
6767
import java.util.HashMap;
@@ -239,12 +239,12 @@ public void validateOfferData(double securityDeposit,
239239
PaymentAccount paymentAccount,
240240
String currencyCode) {
241241
checkNotNull(p2PService.getAddress(), "Address must not be null");
242-
checkArgument(securityDeposit <= getMaxSecurityDepositAsPercent(),
242+
checkArgument(securityDeposit <= getMaxSecurityDepositPct(),
243243
"securityDeposit must not exceed " +
244-
getMaxSecurityDepositAsPercent());
245-
checkArgument(securityDeposit >= getMinSecurityDepositAsPercent(),
244+
getMaxSecurityDepositPct());
245+
checkArgument(securityDeposit >= getMinSecurityDepositPct(),
246246
"securityDeposit must not be less than " +
247-
getMinSecurityDepositAsPercent() + " but was " + securityDeposit);
247+
getMinSecurityDepositPct() + " but was " + securityDeposit);
248248
checkArgument(!filterManager.isCurrencyBanned(currencyCode),
249249
Res.get("offerbook.warning.currencyBanned"));
250250
checkArgument(!filterManager.isPaymentMethodBanned(paymentAccount.getPaymentMethod()),

core/src/main/java/haveno/core/offer/OpenOfferManager.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -533,8 +533,8 @@ public void placeOffer(Offer offer,
533533

534534
// check clone limit
535535
int numClones = getOpenOfferGroup(sourceOffer.getGroupId()).size();
536-
if (numClones >= Restrictions.MAX_OFFERS_WITH_SHARED_FUNDS) {
537-
errorMessageHandler.handleErrorMessage("Cannot create offer because maximum number of " + Restrictions.MAX_OFFERS_WITH_SHARED_FUNDS + " cloned offers with shared funds reached.");
536+
if (numClones >= Restrictions.getMaxOffersWithSharedFunds()) {
537+
errorMessageHandler.handleErrorMessage("Cannot create offer because maximum number of " + Restrictions.getMaxOffersWithSharedFunds() + " cloned offers with shared funds reached.");
538538
return;
539539
}
540540
}
@@ -1557,8 +1557,8 @@ private void handleSignOfferRequest(SignOfferRequest request, NodeAddress peer)
15571557
}
15581558

15591559
// verify max length of extra info
1560-
if (offer.getOfferPayload().getExtraInfo() != null && offer.getOfferPayload().getExtraInfo().length() > Restrictions.MAX_EXTRA_INFO_LENGTH) {
1561-
errorMessage = "Extra info is too long for offer " + request.offerId + ". Max length is " + Restrictions.MAX_EXTRA_INFO_LENGTH + " but got " + offer.getOfferPayload().getExtraInfo().length();
1560+
if (offer.getOfferPayload().getExtraInfo() != null && offer.getOfferPayload().getExtraInfo().length() > Restrictions.getMaxExtraInfoLength()) {
1561+
errorMessage = "Extra info is too long for offer " + request.offerId + ". Max length is " + Restrictions.getMaxExtraInfoLength() + " but got " + offer.getOfferPayload().getExtraInfo().length();
15621562
log.warn(errorMessage);
15631563
sendAckMessage(request.getClass(), peer, request.getPubKeyRing(), request.getOfferId(), request.getUid(), false, errorMessage);
15641564
return;
@@ -1603,8 +1603,8 @@ private void handleSignOfferRequest(SignOfferRequest request, NodeAddress peer)
16031603
}
16041604

16051605
// verify maker security deposit
1606-
if (offer.getSellerSecurityDepositPct() != Restrictions.MIN_SECURITY_DEPOSIT_PCT) {
1607-
errorMessage = "Wrong seller security deposit for offer " + request.offerId + ". Expected " + Restrictions.MIN_SECURITY_DEPOSIT_PCT + " but got " + offer.getSellerSecurityDepositPct();
1606+
if (offer.getSellerSecurityDepositPct() != Restrictions.getMinSecurityDepositPct()) {
1607+
errorMessage = "Wrong seller security deposit for offer " + request.offerId + ". Expected " + Restrictions.getMinSecurityDepositPct() + " but got " + offer.getSellerSecurityDepositPct();
16081608
log.warn(errorMessage);
16091609
sendAckMessage(request.getClass(), peer, request.getPubKeyRing(), request.getOfferId(), request.getUid(), false, errorMessage);
16101610
return;
@@ -1644,16 +1644,16 @@ private void handleSignOfferRequest(SignOfferRequest request, NodeAddress peer)
16441644
}
16451645

16461646
// verify seller's security deposit
1647-
if (offer.getSellerSecurityDepositPct() < Restrictions.MIN_SECURITY_DEPOSIT_PCT) {
1648-
errorMessage = "Insufficient seller security deposit for offer " + request.offerId + ". Expected at least " + Restrictions.MIN_SECURITY_DEPOSIT_PCT + " but got " + offer.getSellerSecurityDepositPct();
1647+
if (offer.getSellerSecurityDepositPct() < Restrictions.getMinSecurityDepositPct()) {
1648+
errorMessage = "Insufficient seller security deposit for offer " + request.offerId + ". Expected at least " + Restrictions.getMinSecurityDepositPct() + " but got " + offer.getSellerSecurityDepositPct();
16491649
log.warn(errorMessage);
16501650
sendAckMessage(request.getClass(), peer, request.getPubKeyRing(), request.getOfferId(), request.getUid(), false, errorMessage);
16511651
return;
16521652
}
16531653

16541654
// verify buyer's security deposit
1655-
if (offer.getBuyerSecurityDepositPct() < Restrictions.MIN_SECURITY_DEPOSIT_PCT) {
1656-
errorMessage = "Insufficient buyer security deposit for offer " + request.offerId + ". Expected at least " + Restrictions.MIN_SECURITY_DEPOSIT_PCT + " but got " + offer.getBuyerSecurityDepositPct();
1655+
if (offer.getBuyerSecurityDepositPct() < Restrictions.getMinSecurityDepositPct()) {
1656+
errorMessage = "Insufficient buyer security deposit for offer " + request.offerId + ". Expected at least " + Restrictions.getMinSecurityDepositPct() + " but got " + offer.getBuyerSecurityDepositPct();
16571657
log.warn(errorMessage);
16581658
sendAckMessage(request.getClass(), peer, request.getPubKeyRing(), request.getOfferId(), request.getUid(), false, errorMessage);
16591659
return;

core/src/main/java/haveno/core/payment/validation/SecurityDepositValidator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public ValidationResult validate(String input) {
5959
private ValidationResult validateIfNotTooLowPercentageValue(String input) {
6060
try {
6161
double percentage = ParsingUtils.parsePercentStringToDouble(input);
62-
double minPercentage = Restrictions.getMinSecurityDepositAsPercent();
62+
double minPercentage = Restrictions.getMinSecurityDepositPct();
6363
if (percentage < minPercentage)
6464
return new ValidationResult(false,
6565
Res.get("validation.inputTooSmall", FormattingUtils.formatToPercentWithSymbol(minPercentage)));
@@ -73,7 +73,7 @@ private ValidationResult validateIfNotTooLowPercentageValue(String input) {
7373
private ValidationResult validateIfNotTooHighPercentageValue(String input) {
7474
try {
7575
double percentage = ParsingUtils.parsePercentStringToDouble(input);
76-
double maxPercentage = Restrictions.getMaxSecurityDepositAsPercent();
76+
double maxPercentage = Restrictions.getMaxSecurityDepositPct();
7777
if (percentage > maxPercentage)
7878
return new ValidationResult(false,
7979
Res.get("validation.inputTooLarge", FormattingUtils.formatToPercentWithSymbol(maxPercentage)));

core/src/main/java/haveno/core/user/Preferences.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -619,8 +619,8 @@ public void setWithdrawalTxFeeInVbytes(long withdrawalTxFeeInVbytes) {
619619
}
620620

621621
public void setSecurityDepositAsPercent(double securityDepositAsPercent, PaymentAccount paymentAccount) {
622-
double max = Restrictions.getMaxSecurityDepositAsPercent();
623-
double min = Restrictions.getMinSecurityDepositAsPercent();
622+
double max = Restrictions.getMaxSecurityDepositPct();
623+
double min = Restrictions.getMinSecurityDepositPct();
624624

625625
if (PaymentAccountUtil.isCryptoCurrencyAccount(paymentAccount))
626626
prefPayload.setSecurityDepositAsPercentForCrypto(Math.min(max, Math.max(min, securityDepositAsPercent)));
@@ -849,12 +849,12 @@ public double getSecurityDepositAsPercent(PaymentAccount paymentAccount) {
849849
double value = PaymentAccountUtil.isCryptoCurrencyAccount(paymentAccount) ?
850850
prefPayload.getSecurityDepositAsPercentForCrypto() : prefPayload.getSecurityDepositAsPercent();
851851

852-
if (value < Restrictions.getMinSecurityDepositAsPercent()) {
853-
value = Restrictions.getMinSecurityDepositAsPercent();
852+
if (value < Restrictions.getMinSecurityDepositPct()) {
853+
value = Restrictions.getMinSecurityDepositPct();
854854
setSecurityDepositAsPercent(value, paymentAccount);
855855
}
856856

857-
return value == 0 ? Restrictions.getDefaultSecurityDepositAsPercent() : value;
857+
return value == 0 ? Restrictions.getDefaultSecurityDepositPct() : value;
858858
}
859859

860860
@Override

core/src/main/java/haveno/core/user/PreferencesPayload.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
import java.util.Optional;
4242
import java.util.stream.Collectors;
4343

44-
import static haveno.core.xmr.wallet.Restrictions.getDefaultSecurityDepositAsPercent;
44+
import static haveno.core.xmr.wallet.Restrictions.getDefaultSecurityDepositPct;
4545

4646
@Slf4j
4747
@Data
@@ -120,10 +120,10 @@ public final class PreferencesPayload implements PersistableEnvelope {
120120
private String rpcPw;
121121
@Nullable
122122
private String takeOfferSelectedPaymentAccountId;
123-
private double securityDepositAsPercent = getDefaultSecurityDepositAsPercent();
123+
private double securityDepositAsPercent = getDefaultSecurityDepositPct();
124124
private int ignoreDustThreshold = 600;
125125
private int clearDataAfterDays = Preferences.CLEAR_DATA_AFTER_DAYS_INITIAL;
126-
private double securityDepositAsPercentForCrypto = getDefaultSecurityDepositAsPercent();
126+
private double securityDepositAsPercentForCrypto = getDefaultSecurityDepositPct();
127127
private int blockNotifyPort;
128128
private boolean tacAcceptedV120;
129129
private double bsqAverageTrimThreshold = 0.05;

core/src/main/java/haveno/core/xmr/wallet/Restrictions.java

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@
2626
public class Restrictions {
2727

2828
// configure restrictions
29-
public static final double MIN_SECURITY_DEPOSIT_PCT = 0.15;
30-
public static final double MAX_SECURITY_DEPOSIT_PCT = 0.5;
31-
public static final BigInteger MIN_TRADE_AMOUNT = HavenoUtils.xmrToAtomicUnits(0.05);
32-
public static final BigInteger MIN_SECURITY_DEPOSIT = HavenoUtils.xmrToAtomicUnits(0.05);
33-
public static final int MAX_EXTRA_INFO_LENGTH = 1500;
34-
public static final int MAX_OFFERS_WITH_SHARED_FUNDS = 10;
29+
private static final double MIN_SECURITY_DEPOSIT_PCT = 0.15;
30+
private static final double MAX_SECURITY_DEPOSIT_PCT = 0.5;
31+
private static final BigInteger MIN_TRADE_AMOUNT = HavenoUtils.xmrToAtomicUnits(0.05);
32+
private static final BigInteger MIN_SECURITY_DEPOSIT = HavenoUtils.xmrToAtomicUnits(0.05);
33+
private static final int MAX_EXTRA_INFO_LENGTH = 1500;
34+
private static final int MAX_OFFERS_WITH_SHARED_FUNDS = 10;
3535

3636
// At mediation we require a min. payout to the losing party to keep incentive for the trader to accept the
3737
// mediated payout. For Refund agent cases we do not have that restriction.
@@ -57,22 +57,30 @@ public static BigInteger getMinTradeAmount() {
5757
return MIN_TRADE_AMOUNT;
5858
}
5959

60-
public static double getDefaultSecurityDepositAsPercent() {
60+
public static double getDefaultSecurityDepositPct() {
6161
return MIN_SECURITY_DEPOSIT_PCT;
6262
}
6363

64-
public static double getMinSecurityDepositAsPercent() {
64+
public static double getMinSecurityDepositPct() {
6565
return MIN_SECURITY_DEPOSIT_PCT;
6666
}
6767

68-
public static double getMaxSecurityDepositAsPercent() {
68+
public static double getMaxSecurityDepositPct() {
6969
return MAX_SECURITY_DEPOSIT_PCT;
7070
}
7171

7272
public static BigInteger getMinSecurityDeposit() {
7373
return MIN_SECURITY_DEPOSIT;
7474
}
7575

76+
public static int getMaxExtraInfoLength() {
77+
return MAX_EXTRA_INFO_LENGTH;
78+
}
79+
80+
public static int getMaxOffersWithSharedFunds() {
81+
return MAX_OFFERS_WITH_SHARED_FUNDS;
82+
}
83+
7684
// This value must be lower than MIN_BUYER_SECURITY_DEPOSIT and SELLER_SECURITY_DEPOSIT
7785
public static BigInteger getMinRefundAtMediatedDispute() {
7886
if (MIN_REFUND_AT_MEDIATED_DISPUTE == null)

core/src/test/java/haveno/core/util/coin/CoinUtilTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public void testGetAdjustedAmount() {
7979
HavenoUtils.xmrToAtomicUnits(0.2).longValueExact(),
8080
1);
8181
assertEquals(
82-
HavenoUtils.formatXmr(Restrictions.MIN_TRADE_AMOUNT, true),
82+
HavenoUtils.formatXmr(Restrictions.getMinTradeAmount(), true),
8383
HavenoUtils.formatXmr(result, true),
8484
"Minimum trade amount allowed should be adjusted to the smallest trade allowed."
8585
);

desktop/src/main/java/haveno/desktop/main/offer/MutableOfferDataModel.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public MutableOfferDataModel(CreateOfferService createOfferService,
168168
reserveExactAmount = preferences.getSplitOfferOutput();
169169

170170
useMarketBasedPrice.set(preferences.isUsePercentageBasedPrice());
171-
securityDepositPct.set(Restrictions.getMinSecurityDepositAsPercent());
171+
securityDepositPct.set(Restrictions.getMinSecurityDepositPct());
172172

173173
paymentAccountsChangeListener = change -> fillPaymentAccounts();
174174
}
@@ -338,7 +338,7 @@ void onPaymentAccountSelected(PaymentAccount paymentAccount) {
338338
}
339339

340340
private void setSuggestedSecurityDeposit(PaymentAccount paymentAccount) {
341-
var minSecurityDeposit = Restrictions.getMinSecurityDepositAsPercent();
341+
var minSecurityDeposit = Restrictions.getMinSecurityDepositPct();
342342
try {
343343
if (getTradeCurrency() == null) {
344344
setSecurityDepositPct(minSecurityDeposit);
@@ -369,7 +369,7 @@ private void setSuggestedSecurityDeposit(PaymentAccount paymentAccount) {
369369
}
370370
// Suggested deposit is double the trade range over the previous lock time period, bounded by min/max deposit
371371
var suggestedSecurityDeposit =
372-
Math.min(2 * (max - min) / max, Restrictions.getMaxSecurityDepositAsPercent());
372+
Math.min(2 * (max - min) / max, Restrictions.getMaxSecurityDepositPct());
373373
securityDepositPct.set(Math.max(suggestedSecurityDeposit, minSecurityDeposit));
374374
} catch (Throwable t) {
375375
log.error(t.toString());
@@ -693,7 +693,7 @@ protected double getSecurityAsPercent(Offer offer) {
693693
double offerSellerSecurityDepositAsPercent = CoinUtil.getAsPercentPerXmr(offerSellerSecurityDeposit,
694694
offer.getAmount());
695695
return Math.min(offerSellerSecurityDepositAsPercent,
696-
Restrictions.getMaxSecurityDepositAsPercent());
696+
Restrictions.getMaxSecurityDepositPct());
697697
}
698698

699699
ReadOnlyObjectProperty<BigInteger> totalToPayAsProperty() {

0 commit comments

Comments
 (0)