validate payment method id and improve error message

This commit is contained in:
woodser 2023-08-29 10:31:01 -04:00
parent e6853d2e76
commit 4cde0103b3
4 changed files with 9 additions and 4 deletions

View File

@ -771,7 +771,7 @@ public class AccountAgeWitnessService {
boolean isFiltered = filterManager.isNodeAddressBanned(dispute.getContract().getBuyerNodeAddress()) || boolean isFiltered = filterManager.isNodeAddressBanned(dispute.getContract().getBuyerNodeAddress()) ||
filterManager.isNodeAddressBanned(dispute.getContract().getSellerNodeAddress()) || filterManager.isNodeAddressBanned(dispute.getContract().getSellerNodeAddress()) ||
filterManager.isCurrencyBanned(dispute.getContract().getOfferPayload().getCurrencyCode()) || filterManager.isCurrencyBanned(dispute.getContract().getOfferPayload().getCurrencyCode()) ||
filterManager.isPaymentMethodBanned(PaymentMethod.getPaymentMethod(dispute.getContract().getPaymentMethodId())) || filterManager.isPaymentMethodBanned(PaymentMethod.getPaymentMethodOrNA(dispute.getContract().getPaymentMethodId())) ||
filterManager.arePeersPaymentAccountDataBanned(dispute.getBuyerPaymentAccountPayload()) || filterManager.arePeersPaymentAccountDataBanned(dispute.getBuyerPaymentAccountPayload()) ||
filterManager.arePeersPaymentAccountDataBanned(dispute.getSellerPaymentAccountPayload()) || filterManager.arePeersPaymentAccountDataBanned(dispute.getSellerPaymentAccountPayload()) ||
filterManager.isWitnessSignerPubKeyBanned(Utils.HEX.encode(dispute.getContract().getBuyerPubKeyRing().getSignaturePubKeyBytes())) || filterManager.isWitnessSignerPubKeyBanned(Utils.HEX.encode(dispute.getContract().getBuyerPubKeyRing().getSignaturePubKeyBytes())) ||

View File

@ -318,7 +318,7 @@ public class Offer implements NetworkPayload, PersistablePayload {
} }
public PaymentMethod getPaymentMethod() { public PaymentMethod getPaymentMethod() {
return PaymentMethod.getPaymentMethod(offerPayload.getPaymentMethodId()); return PaymentMethod.getPaymentMethodOrNA(offerPayload.getPaymentMethodId());
} }
// utils // utils

View File

@ -169,7 +169,7 @@ public abstract class PaymentAccount implements PersistablePayload {
ngnTwOptional.ifPresent(tradeCurrencies::remove); ngnTwOptional.ifPresent(tradeCurrencies::remove);
try { try {
PaymentAccount account = PaymentAccountFactory.getPaymentAccount(PaymentMethod.getPaymentMethod(paymentMethodId)); PaymentAccount account = PaymentAccountFactory.getPaymentAccount(PaymentMethod.getPaymentMethodOrNA(paymentMethodId));
account.getTradeCurrencies().clear(); account.getTradeCurrencies().clear();
account.setId(proto.getId()); account.setId(proto.getId());
account.setCreationDate(proto.getCreationDate()); account.setCreationDate(proto.getCreationDate());
@ -348,7 +348,7 @@ public abstract class PaymentAccount implements PersistablePayload {
} }
private static Class<? extends PaymentAccount> getPaymentAccountClass(String paymentMethodId) { private static Class<? extends PaymentAccount> getPaymentAccountClass(String paymentMethodId) {
PaymentMethod paymentMethod = PaymentMethod.getPaymentMethod(paymentMethodId); PaymentMethod paymentMethod = PaymentMethod.getPaymentMethodOrNA(paymentMethodId);
return PaymentAccountFactory.getPaymentAccount(paymentMethod).getClass(); return PaymentAccountFactory.getPaymentAccount(paymentMethod).getClass();
} }

View File

@ -448,6 +448,11 @@ public final class PaymentMethod implements PersistablePayload, Comparable<Payme
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
public static PaymentMethod getPaymentMethod(String id) { public static PaymentMethod getPaymentMethod(String id) {
return getActivePaymentMethod(id)
.orElseThrow(() -> new IllegalArgumentException("Invalid payment method id: " + id));
}
public static PaymentMethod getPaymentMethodOrNA(String id) {
return getActivePaymentMethod(id) return getActivePaymentMethod(id)
.orElseGet(() -> new PaymentMethod(Res.get("shared.na"))); .orElseGet(() -> new PaymentMethod(Res.get("shared.na")));
} }