From b6b2d939a12d9d139c7207e673b74add56e20fa9 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Mon, 22 Nov 2021 22:41:32 +0100 Subject: [PATCH 1/6] Only apply maxTradeLimit from PaymentMethod if the PaymentMethod is found in the active list. Otherwise the 2 BTC default is used. We get TradeStatistics3 objects from old retired PaymentMethods which are not found in the active list. --- .../bisq/core/payment/payload/PaymentMethod.java | 14 +++++++++++--- .../core/trade/statistics/TradeStatistics3.java | 7 ++++++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/bisq/core/payment/payload/PaymentMethod.java b/core/src/main/java/bisq/core/payment/payload/PaymentMethod.java index 9850aac2e9c..20e62d7676d 100644 --- a/core/src/main/java/bisq/core/payment/payload/PaymentMethod.java +++ b/core/src/main/java/bisq/core/payment/payload/PaymentMethod.java @@ -29,6 +29,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Optional; import java.util.concurrent.TimeUnit; import lombok.EqualsAndHashCode; @@ -364,10 +365,15 @@ public static PaymentMethod fromProto(protobuf.PaymentMethod proto) { /////////////////////////////////////////////////////////////////////////////////////////// public static PaymentMethod getPaymentMethodById(String id) { + return getActivePaymentMethodById(id) + .orElseGet(() -> new PaymentMethod(Res.get("shared.na"))); + } + + // We look up only our active payment methods not retired ones. + public static Optional getActivePaymentMethodById(String id) { return paymentMethods.stream() .filter(e -> e.getId().equals(id)) - .findFirst() - .orElseGet(() -> new PaymentMethod(Res.get("shared.na"))); + .findFirst(); } public Coin getMaxTradeLimitAsCoin(String currencyCode) { @@ -391,7 +397,9 @@ else if (maxTradeLimit == DEFAULT_TRADE_LIMIT_HIGH_RISK.value) riskFactor = 8; else { riskFactor = 8; - log.error("maxTradeLimit is not matching one of our default values. maxTradeLimit=" + Coin.valueOf(maxTradeLimit).toFriendlyString()); + log.warn("maxTradeLimit is not matching one of our default values. We use highest risk factor. " + + "maxTradeLimit={}. PaymentMethod={}", + Coin.valueOf(maxTradeLimit).toFriendlyString(), this); } TradeLimits tradeLimits = TradeLimits.getINSTANCE(); diff --git a/core/src/main/java/bisq/core/trade/statistics/TradeStatistics3.java b/core/src/main/java/bisq/core/trade/statistics/TradeStatistics3.java index 5e57ec2545f..3a489bf6b2b 100644 --- a/core/src/main/java/bisq/core/trade/statistics/TradeStatistics3.java +++ b/core/src/main/java/bisq/core/trade/statistics/TradeStatistics3.java @@ -437,7 +437,12 @@ public boolean isValid() { } long maxTradeLimit = Coin.COIN.multiply(2).value; try { - maxTradeLimit = PaymentMethod.getPaymentMethodById(getPaymentMethod()).getMaxTradeLimitAsCoin(currency).value; + // We cover only active payment methods. Retired ones will not be found by getActivePaymentMethodById. + String paymentMethod = getPaymentMethod(); + Optional optionalPaymentMethodById = PaymentMethod.getActivePaymentMethodById(paymentMethod); + if (optionalPaymentMethodById.isPresent()) { + maxTradeLimit = optionalPaymentMethodById.get().getMaxTradeLimitAsCoin(currency).value; + } } catch (Exception ignore) { } return amount > 0 && From 9d52ddbf96079543b8fb53793f3ecd441a063762 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Tue, 23 Nov 2021 00:34:12 +0100 Subject: [PATCH 2/6] Add warn log --- .../main/java/bisq/core/trade/statistics/TradeStatistics3.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/bisq/core/trade/statistics/TradeStatistics3.java b/core/src/main/java/bisq/core/trade/statistics/TradeStatistics3.java index 3a489bf6b2b..deaab2b9324 100644 --- a/core/src/main/java/bisq/core/trade/statistics/TradeStatistics3.java +++ b/core/src/main/java/bisq/core/trade/statistics/TradeStatistics3.java @@ -443,7 +443,8 @@ public boolean isValid() { if (optionalPaymentMethodById.isPresent()) { maxTradeLimit = optionalPaymentMethodById.get().getMaxTradeLimitAsCoin(currency).value; } - } catch (Exception ignore) { + } catch (Exception e) { + log.warn("Error at isValid(). " + e.toString(), e); } return amount > 0 && amount <= maxTradeLimit && From 9569e5a600717956325afc492be880ef4d3092cc Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Tue, 23 Nov 2021 00:39:18 +0100 Subject: [PATCH 3/6] Rename getActivePaymentMethodById to getActivePaymentMethod Rename variables --- .../java/bisq/core/payment/payload/PaymentMethod.java | 4 ++-- .../java/bisq/core/trade/statistics/TradeStatistics3.java | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/bisq/core/payment/payload/PaymentMethod.java b/core/src/main/java/bisq/core/payment/payload/PaymentMethod.java index 20e62d7676d..8942089daf5 100644 --- a/core/src/main/java/bisq/core/payment/payload/PaymentMethod.java +++ b/core/src/main/java/bisq/core/payment/payload/PaymentMethod.java @@ -365,12 +365,12 @@ public static PaymentMethod fromProto(protobuf.PaymentMethod proto) { /////////////////////////////////////////////////////////////////////////////////////////// public static PaymentMethod getPaymentMethodById(String id) { - return getActivePaymentMethodById(id) + return getActivePaymentMethod(id) .orElseGet(() -> new PaymentMethod(Res.get("shared.na"))); } // We look up only our active payment methods not retired ones. - public static Optional getActivePaymentMethodById(String id) { + public static Optional getActivePaymentMethod(String id) { return paymentMethods.stream() .filter(e -> e.getId().equals(id)) .findFirst(); diff --git a/core/src/main/java/bisq/core/trade/statistics/TradeStatistics3.java b/core/src/main/java/bisq/core/trade/statistics/TradeStatistics3.java index deaab2b9324..06c7712ac3e 100644 --- a/core/src/main/java/bisq/core/trade/statistics/TradeStatistics3.java +++ b/core/src/main/java/bisq/core/trade/statistics/TradeStatistics3.java @@ -438,10 +438,10 @@ public boolean isValid() { long maxTradeLimit = Coin.COIN.multiply(2).value; try { // We cover only active payment methods. Retired ones will not be found by getActivePaymentMethodById. - String paymentMethod = getPaymentMethod(); - Optional optionalPaymentMethodById = PaymentMethod.getActivePaymentMethodById(paymentMethod); - if (optionalPaymentMethodById.isPresent()) { - maxTradeLimit = optionalPaymentMethodById.get().getMaxTradeLimitAsCoin(currency).value; + String paymentMethodId = getPaymentMethod(); + Optional optionalPaymentMethod = PaymentMethod.getActivePaymentMethod(paymentMethodId); + if (optionalPaymentMethod.isPresent()) { + maxTradeLimit = optionalPaymentMethod.get().getMaxTradeLimitAsCoin(currency).value; } } catch (Exception e) { log.warn("Error at isValid(). " + e.toString(), e); From 091f82477bbedd52a7916dc8235c887b6802a3d9 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Tue, 23 Nov 2021 00:39:38 +0100 Subject: [PATCH 4/6] Rename getPaymentMethod to getPaymentMethodId --- .../java/bisq/core/trade/statistics/TradeStatistics3.java | 4 ++-- .../bisq/core/trade/statistics/TradeStatisticsForJson.java | 2 +- .../src/main/java/bisq/desktop/main/market/MarketView.java | 2 +- .../desktop/main/market/trades/TradeStatistics3ListItem.java | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/bisq/core/trade/statistics/TradeStatistics3.java b/core/src/main/java/bisq/core/trade/statistics/TradeStatistics3.java index 06c7712ac3e..8614678d574 100644 --- a/core/src/main/java/bisq/core/trade/statistics/TradeStatistics3.java +++ b/core/src/main/java/bisq/core/trade/statistics/TradeStatistics3.java @@ -398,7 +398,7 @@ public void pruneOptionalData() { refundAgent = null; } - public String getPaymentMethod() { + public String getPaymentMethodId() { try { return PaymentMethodMapper.values()[Integer.parseInt(paymentMethod)].name(); } catch (Throwable ignore) { @@ -438,7 +438,7 @@ public boolean isValid() { long maxTradeLimit = Coin.COIN.multiply(2).value; try { // We cover only active payment methods. Retired ones will not be found by getActivePaymentMethodById. - String paymentMethodId = getPaymentMethod(); + String paymentMethodId = getPaymentMethodId(); Optional optionalPaymentMethod = PaymentMethod.getActivePaymentMethod(paymentMethodId); if (optionalPaymentMethod.isPresent()) { maxTradeLimit = optionalPaymentMethod.get().getMaxTradeLimitAsCoin(currency).value; diff --git a/core/src/main/java/bisq/core/trade/statistics/TradeStatisticsForJson.java b/core/src/main/java/bisq/core/trade/statistics/TradeStatisticsForJson.java index 34fde08f839..730930e1c46 100644 --- a/core/src/main/java/bisq/core/trade/statistics/TradeStatisticsForJson.java +++ b/core/src/main/java/bisq/core/trade/statistics/TradeStatisticsForJson.java @@ -52,7 +52,7 @@ public final class TradeStatisticsForJson { public TradeStatisticsForJson(TradeStatistics3 tradeStatistics) { this.currency = tradeStatistics.getCurrency(); - this.paymentMethod = tradeStatistics.getPaymentMethod(); + this.paymentMethod = tradeStatistics.getPaymentMethodId(); this.tradePrice = tradeStatistics.getPrice(); this.tradeAmount = tradeStatistics.getAmount(); this.tradeDate = tradeStatistics.getDateAsLong(); diff --git a/desktop/src/main/java/bisq/desktop/main/market/MarketView.java b/desktop/src/main/java/bisq/desktop/main/market/MarketView.java index 66f9d66171f..dee00d6b1fd 100644 --- a/desktop/src/main/java/bisq/desktop/main/market/MarketView.java +++ b/desktop/src/main/java/bisq/desktop/main/market/MarketView.java @@ -200,7 +200,7 @@ private String getAllTradesWithReferralId() { .append("Price: ").append(FormattingUtils.formatPrice(tradeStatistics3.getTradePrice())).append("\n") .append("Amount: ").append(formatter.formatCoin(tradeStatistics3.getTradeAmount())).append("\n") .append("Volume: ").append(VolumeUtil.formatVolume(tradeStatistics3.getTradeVolume())).append("\n") - .append("Payment method: ").append(Res.get(tradeStatistics3.getPaymentMethod())).append("\n") + .append("Payment method: ").append(Res.get(tradeStatistics3.getPaymentMethodId())).append("\n") .append("ReferralID: ").append(tradeStatistics3.getExtraDataMap().get(OfferPayload.REFERRAL_ID)); return sb.toString(); }) diff --git a/desktop/src/main/java/bisq/desktop/main/market/trades/TradeStatistics3ListItem.java b/desktop/src/main/java/bisq/desktop/main/market/trades/TradeStatistics3ListItem.java index f15fe7f4385..db4fdb47627 100644 --- a/desktop/src/main/java/bisq/desktop/main/market/trades/TradeStatistics3ListItem.java +++ b/desktop/src/main/java/bisq/desktop/main/market/trades/TradeStatistics3ListItem.java @@ -83,7 +83,7 @@ public String getVolumeString() { public String getPaymentMethodString() { if (paymentMethodString == null) { - paymentMethodString = tradeStatistics3 != null ? Res.get(tradeStatistics3.getPaymentMethod()) : ""; + paymentMethodString = tradeStatistics3 != null ? Res.get(tradeStatistics3.getPaymentMethodId()) : ""; } return paymentMethodString; } From cb474c57dafbbc45805a6da0e9ea1971448973d5 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Tue, 23 Nov 2021 00:40:59 +0100 Subject: [PATCH 5/6] Rename getPaymentMethodById to getPaymentMethod --- .../java/bisq/apitest/scenario/bot/AbstractBotTest.java | 4 ++-- apitest/src/test/java/bisq/apitest/scenario/bot/Bot.java | 4 ++-- .../bisq/core/account/witness/AccountAgeWitnessService.java | 2 +- .../main/java/bisq/core/api/model/PaymentAccountForm.java | 6 +++--- core/src/main/java/bisq/core/offer/Offer.java | 2 +- core/src/main/java/bisq/core/payment/PaymentAccount.java | 3 +-- .../main/java/bisq/core/payment/payload/PaymentMethod.java | 2 +- .../core/account/witness/AccountAgeWitnessServiceTest.java | 4 ++-- 8 files changed, 13 insertions(+), 14 deletions(-) diff --git a/apitest/src/test/java/bisq/apitest/scenario/bot/AbstractBotTest.java b/apitest/src/test/java/bisq/apitest/scenario/bot/AbstractBotTest.java index 763dbac9e2f..818a66d0c25 100644 --- a/apitest/src/test/java/bisq/apitest/scenario/bot/AbstractBotTest.java +++ b/apitest/src/test/java/bisq/apitest/scenario/bot/AbstractBotTest.java @@ -32,7 +32,7 @@ import static bisq.core.locale.CountryUtil.findCountryByCode; import static bisq.core.payment.payload.PaymentMethod.CLEAR_X_CHANGE_ID; -import static bisq.core.payment.payload.PaymentMethod.getPaymentMethodById; +import static bisq.core.payment.payload.PaymentMethod.getPaymentMethod; import static java.lang.String.format; import static java.lang.System.getProperty; import static java.nio.file.Files.readAllBytes; @@ -74,7 +74,7 @@ private PaymentAccount createAlicesPaymentAccount() { } else { throw new UnsupportedOperationException( format("This test harness bot does not work with %s payment accounts yet.", - getPaymentMethodById(paymentMethodId).getDisplayString())); + getPaymentMethod(paymentMethodId).getDisplayString())); } } else { String countryCode = botScript.getCountryCode(); diff --git a/apitest/src/test/java/bisq/apitest/scenario/bot/Bot.java b/apitest/src/test/java/bisq/apitest/scenario/bot/Bot.java index 2e8a248a4c3..1fb46e717f4 100644 --- a/apitest/src/test/java/bisq/apitest/scenario/bot/Bot.java +++ b/apitest/src/test/java/bisq/apitest/scenario/bot/Bot.java @@ -8,7 +8,7 @@ import static bisq.core.locale.CountryUtil.findCountryByCode; import static bisq.core.payment.payload.PaymentMethod.CLEAR_X_CHANGE_ID; -import static bisq.core.payment.payload.PaymentMethod.getPaymentMethodById; +import static bisq.core.payment.payload.PaymentMethod.getPaymentMethod; import static java.lang.String.format; import static java.util.concurrent.TimeUnit.MINUTES; @@ -62,7 +62,7 @@ private PaymentAccount createBotPaymentAccount(BotScript botScript) { } else { throw new UnsupportedOperationException( format("This bot test does not work with %s payment accounts yet.", - getPaymentMethodById(paymentMethodId).getDisplayString())); + getPaymentMethod(paymentMethodId).getDisplayString())); } } else { Country country = findCountry(botScript.getCountryCode()); diff --git a/core/src/main/java/bisq/core/account/witness/AccountAgeWitnessService.java b/core/src/main/java/bisq/core/account/witness/AccountAgeWitnessService.java index 685088aa88a..925b227d0e9 100644 --- a/core/src/main/java/bisq/core/account/witness/AccountAgeWitnessService.java +++ b/core/src/main/java/bisq/core/account/witness/AccountAgeWitnessService.java @@ -773,7 +773,7 @@ private boolean isNotFiltered(Dispute dispute) { filterManager.isNodeAddressBanned(dispute.getContract().getSellerNodeAddress()) || filterManager.isCurrencyBanned(dispute.getContract().getOfferPayload().getCurrencyCode()) || filterManager.isPaymentMethodBanned( - PaymentMethod.getPaymentMethodById(dispute.getContract().getPaymentMethodId())) || + PaymentMethod.getPaymentMethod(dispute.getContract().getPaymentMethodId())) || filterManager.arePeersPaymentAccountDataBanned(dispute.getContract().getBuyerPaymentAccountPayload()) || filterManager.arePeersPaymentAccountDataBanned( dispute.getContract().getSellerPaymentAccountPayload()) || diff --git a/core/src/main/java/bisq/core/api/model/PaymentAccountForm.java b/core/src/main/java/bisq/core/api/model/PaymentAccountForm.java index 5de59e7c0f0..2b4610572c9 100644 --- a/core/src/main/java/bisq/core/api/model/PaymentAccountForm.java +++ b/core/src/main/java/bisq/core/api/model/PaymentAccountForm.java @@ -47,7 +47,7 @@ import lombok.extern.slf4j.Slf4j; -import static bisq.core.payment.payload.PaymentMethod.getPaymentMethodById; +import static bisq.core.payment.payload.PaymentMethod.getPaymentMethod; import static com.google.common.base.Preconditions.checkNotNull; import static java.lang.String.format; import static java.lang.System.getProperty; @@ -148,7 +148,7 @@ public class PaymentAccountForm { * @return A uniquely named tmp file used to define new payment account details. */ public File getPaymentAccountForm(String paymentMethodId) { - PaymentMethod paymentMethod = getPaymentMethodById(paymentMethodId); + PaymentMethod paymentMethod = getPaymentMethod(paymentMethodId); File file = getTmpJsonFile(paymentMethodId); try (OutputStreamWriter outputStreamWriter = new OutputStreamWriter(new FileOutputStream(checkNotNull(file), false), UTF_8)) { PaymentAccount paymentAccount = PaymentAccountFactory.getPaymentAccount(paymentMethod); @@ -244,7 +244,7 @@ private Class getPaymentAccountClassFromJson(String js } private Class getPaymentAccountClass(String paymentMethodId) { - PaymentMethod paymentMethod = getPaymentMethodById(paymentMethodId); + PaymentMethod paymentMethod = getPaymentMethod(paymentMethodId); return PaymentAccountFactory.getPaymentAccount(paymentMethod).getClass(); } } diff --git a/core/src/main/java/bisq/core/offer/Offer.java b/core/src/main/java/bisq/core/offer/Offer.java index 88c2963b0e3..121d5108e47 100644 --- a/core/src/main/java/bisq/core/offer/Offer.java +++ b/core/src/main/java/bisq/core/offer/Offer.java @@ -347,7 +347,7 @@ public Date getDate() { } public PaymentMethod getPaymentMethod() { - return PaymentMethod.getPaymentMethodById(offerPayloadBase.getPaymentMethodId()); + return PaymentMethod.getPaymentMethod(offerPayloadBase.getPaymentMethodId()); } // utils diff --git a/core/src/main/java/bisq/core/payment/PaymentAccount.java b/core/src/main/java/bisq/core/payment/PaymentAccount.java index 631f3ba915b..0bcb93104f3 100644 --- a/core/src/main/java/bisq/core/payment/PaymentAccount.java +++ b/core/src/main/java/bisq/core/payment/PaymentAccount.java @@ -42,7 +42,6 @@ import javax.annotation.Nullable; import static bisq.core.payment.payload.PaymentMethod.TRANSFERWISE_ID; -import static bisq.core.payment.payload.PaymentMethod.getPaymentMethodById; import static com.google.common.base.Preconditions.checkNotNull; @EqualsAndHashCode @@ -113,7 +112,7 @@ public static PaymentAccount fromProto(protobuf.PaymentAccount proto, CoreProtoR ngnTwOptional.ifPresent(tradeCurrencies::remove); try { - PaymentAccount account = PaymentAccountFactory.getPaymentAccount(getPaymentMethodById(paymentMethodId)); + PaymentAccount account = PaymentAccountFactory.getPaymentAccount(PaymentMethod.getPaymentMethod(paymentMethodId)); account.getTradeCurrencies().clear(); account.setId(proto.getId()); account.setCreationDate(proto.getCreationDate()); diff --git a/core/src/main/java/bisq/core/payment/payload/PaymentMethod.java b/core/src/main/java/bisq/core/payment/payload/PaymentMethod.java index 8942089daf5..32d212d3441 100644 --- a/core/src/main/java/bisq/core/payment/payload/PaymentMethod.java +++ b/core/src/main/java/bisq/core/payment/payload/PaymentMethod.java @@ -364,7 +364,7 @@ public static PaymentMethod fromProto(protobuf.PaymentMethod proto) { // API /////////////////////////////////////////////////////////////////////////////////////////// - public static PaymentMethod getPaymentMethodById(String id) { + public static PaymentMethod getPaymentMethod(String id) { return getActivePaymentMethod(id) .orElseGet(() -> new PaymentMethod(Res.get("shared.na"))); } diff --git a/core/src/test/java/bisq/core/account/witness/AccountAgeWitnessServiceTest.java b/core/src/test/java/bisq/core/account/witness/AccountAgeWitnessServiceTest.java index c75f093f2e0..937aa31482e 100644 --- a/core/src/test/java/bisq/core/account/witness/AccountAgeWitnessServiceTest.java +++ b/core/src/test/java/bisq/core/account/witness/AccountAgeWitnessServiceTest.java @@ -65,7 +65,7 @@ import org.junit.Ignore; import org.junit.Test; -import static bisq.core.payment.payload.PaymentMethod.getPaymentMethodById; +import static bisq.core.payment.payload.PaymentMethod.getPaymentMethod; import static bisq.core.support.dispute.DisputeResult.PayoutSuggestion.UNKNOWN; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -232,7 +232,7 @@ public void testArbitratorSignWitness() { when(contract.getBuyerPaymentAccountPayload()).thenReturn(buyerPaymentAccountPayload); when(contract.getSellerPaymentAccountPayload()).thenReturn(sellerPaymentAccountPayload); when(contract.getOfferPayload()).thenReturn(mock(OfferPayload.class)); - List items = service.getTraderPaymentAccounts(now, getPaymentMethodById(PaymentMethod.SEPA_ID), disputes); + List items = service.getTraderPaymentAccounts(now, getPaymentMethod(PaymentMethod.SEPA_ID), disputes); assertEquals(2, items.size()); // Setup a mocked arbitrator key From 0e1030845a659d5f193961d0613b1b70f47869aa Mon Sep 17 00:00:00 2001 From: Christoph Atteneder Date: Tue, 23 Nov 2021 09:48:10 +0100 Subject: [PATCH 6/6] Simplify warn logging --- .../main/java/bisq/core/trade/statistics/TradeStatistics3.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/bisq/core/trade/statistics/TradeStatistics3.java b/core/src/main/java/bisq/core/trade/statistics/TradeStatistics3.java index 8614678d574..243c83ffa53 100644 --- a/core/src/main/java/bisq/core/trade/statistics/TradeStatistics3.java +++ b/core/src/main/java/bisq/core/trade/statistics/TradeStatistics3.java @@ -444,7 +444,7 @@ public boolean isValid() { maxTradeLimit = optionalPaymentMethod.get().getMaxTradeLimitAsCoin(currency).value; } } catch (Exception e) { - log.warn("Error at isValid(). " + e.toString(), e); + log.warn("Error at isValid().", e); } return amount > 0 && amount <= maxTradeLimit &&