From aed1e8027ebe62bc8b797c6d872ba28edac0d9b3 Mon Sep 17 00:00:00 2001 From: sqrrm Date: Tue, 30 Jul 2019 16:29:12 +0200 Subject: [PATCH 1/5] Publish signed witness --- .../core/account/sign/SignedWitnessService.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/bisq/core/account/sign/SignedWitnessService.java b/core/src/main/java/bisq/core/account/sign/SignedWitnessService.java index 07ff509e0fe..835f12bf2be 100644 --- a/core/src/main/java/bisq/core/account/sign/SignedWitnessService.java +++ b/core/src/main/java/bisq/core/account/sign/SignedWitnessService.java @@ -133,25 +133,29 @@ public List getVerifiedWitnessAgeList(AccountAgeWitness accountAgeWitness) public SignedWitness signAccountAgeWitness(Coin tradeAmount, AccountAgeWitness accountAgeWitness, ECKey key, PublicKey peersPubKey) { String accountAgeWitnessHashAsHex = Utilities.encodeToHex(accountAgeWitness.getHash()); String signatureBase64 = key.signMessage(accountAgeWitnessHashAsHex); - return new SignedWitness(true, + SignedWitness signedWitness = new SignedWitness(true, accountAgeWitness.getHash(), signatureBase64.getBytes(Charsets.UTF_8), key.getPubKey(), peersPubKey.getEncoded(), new Date().getTime(), tradeAmount.value); + publishSignedWitness(signedWitness); + return signedWitness; } // Any peer can sign with DSA key public SignedWitness signAccountAgeWitness(Coin tradeAmount, AccountAgeWitness accountAgeWitness, PublicKey peersPubKey) throws CryptoException { byte[] signature = Sig.sign(keyRing.getSignatureKeyPair().getPrivate(), accountAgeWitness.getHash()); - return new SignedWitness(false, + SignedWitness signedWitness = new SignedWitness(false, accountAgeWitness.getHash(), signature, keyRing.getSignatureKeyPair().getPublic().getEncoded(), peersPubKey.getEncoded(), new Date().getTime(), tradeAmount.value); + publishSignedWitness(signedWitness); + return signedWitness; } public boolean verifySignature(SignedWitness signedWitness) { @@ -286,7 +290,6 @@ private boolean verifyDate(SignedWitness signedWitness, long childSignedWitnessD return signedWitnessDateMillis <= childSignedWitnessDateMinusChargebackPeriodMillis; } - /////////////////////////////////////////////////////////////////////////////////////////// // Private /////////////////////////////////////////////////////////////////////////////////////////// @@ -295,4 +298,11 @@ private boolean verifyDate(SignedWitness signedWitness, long childSignedWitnessD void addToMap(SignedWitness signedWitness) { signedWitnessMap.putIfAbsent(signedWitness.getHashAsByteArray(), signedWitness); } + + private void publishSignedWitness(SignedWitness signedWitness) { + if (!signedWitnessMap.containsKey(signedWitness.getHashAsByteArray())) { + p2PService.addPersistableNetworkPayload(signedWitness, false); + } + } + } From 61895102fd60cae7069859f4bcae894bb7866afa Mon Sep 17 00:00:00 2001 From: sqrrm Date: Sat, 20 Jul 2019 17:51:54 +0200 Subject: [PATCH 2/5] Arbitrator sign accountAgeWitnesses Automatically filter to only sign accounts that - have chargeback risk - bought BTC - was winner in dispute --- .../account/sign/SignedWitnessService.java | 51 +++++++++++++++- .../main/java/bisq/core/app/BisqSetup.java | 5 ++ .../bisq/core/app/misc/AppSetupWithP2P.java | 5 ++ .../core/app/misc/AppSetupWithP2PAndDAO.java | 3 + .../bisq/core/arbitration/BuyerDataItem.java | 60 +++++++++++++++++++ .../core/payment/payload/PaymentMethod.java | 4 ++ .../sign/SignedWitnessServiceTest.java | 4 +- 7 files changed, 130 insertions(+), 2 deletions(-) create mode 100644 core/src/main/java/bisq/core/arbitration/BuyerDataItem.java diff --git a/core/src/main/java/bisq/core/account/sign/SignedWitnessService.java b/core/src/main/java/bisq/core/account/sign/SignedWitnessService.java index 835f12bf2be..6fc193316c2 100644 --- a/core/src/main/java/bisq/core/account/sign/SignedWitnessService.java +++ b/core/src/main/java/bisq/core/account/sign/SignedWitnessService.java @@ -20,7 +20,12 @@ import bisq.core.account.witness.AccountAgeWitness; import bisq.core.account.witness.AccountAgeWitnessService; import bisq.core.arbitration.ArbitratorManager; +import bisq.core.arbitration.BuyerDataItem; +import bisq.core.arbitration.Dispute; +import bisq.core.arbitration.DisputeManager; +import bisq.core.arbitration.DisputeResult; import bisq.core.payment.payload.PaymentAccountPayload; +import bisq.core.payment.payload.PaymentMethod; import bisq.network.p2p.P2PService; import bisq.network.p2p.storage.P2PDataStorage; @@ -28,6 +33,7 @@ import bisq.common.crypto.CryptoException; import bisq.common.crypto.KeyRing; +import bisq.common.crypto.PubKeyRing; import bisq.common.crypto.Sig; import bisq.common.util.Utilities; @@ -50,12 +56,17 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; +import java.util.Optional; import java.util.Set; import java.util.Stack; import java.util.stream.Collectors; +import lombok.Getter; import lombok.extern.slf4j.Slf4j; +import org.jetbrains.annotations.Nullable; + @Slf4j public class SignedWitnessService { public static final long CHARGEBACK_SAFETY_DAYS = 30; @@ -64,6 +75,8 @@ public class SignedWitnessService { private final P2PService p2PService; private final AccountAgeWitnessService accountAgeWitnessService; private final ArbitratorManager arbitratorManager; + private final DisputeManager disputeManager; + private final Map signedWitnessMap = new HashMap<>(); @@ -77,11 +90,13 @@ public SignedWitnessService(KeyRing keyRing, AccountAgeWitnessService accountAgeWitnessService, ArbitratorManager arbitratorManager, SignedWitnessStorageService signedWitnessStorageService, - AppendOnlyDataStoreService appendOnlyDataStoreService) { + AppendOnlyDataStoreService appendOnlyDataStoreService, + DisputeManager disputeManager) { this.keyRing = keyRing; this.p2PService = p2PService; this.accountAgeWitnessService = accountAgeWitnessService; this.arbitratorManager = arbitratorManager; + this.disputeManager = disputeManager; // We need to add that early (before onAllServicesInitialized) as it will be used at startup. appendOnlyDataStoreService.addService(signedWitnessStorageService); @@ -305,4 +320,38 @@ private void publishSignedWitness(SignedWitness signedWitness) { } } + // Arbitrator signing + public List getBuyerPaymentAccounts(long safeDate) { + return disputeManager.getDisputesAsObservableList().stream() + .filter(this::hasChargebackRisk) + .filter(this::isBuyerWinner) + .map(this::getBuyerData) + .filter(Objects::nonNull) + .filter(buyerDataItem -> buyerDataItem.getAccountAgeWitness().getDate() < safeDate) + .distinct() + .collect(Collectors.toList()); + } + + private boolean hasChargebackRisk(Dispute dispute) { + return PaymentMethod.hasChargebackRisk(dispute.getContract().getPaymentMethodId()); + } + + private boolean isBuyerWinner(Dispute dispute) { + return dispute.getDisputeResultProperty().get().getWinner() == DisputeResult.Winner.BUYER; + } + + @Nullable + private BuyerDataItem getBuyerData(Dispute dispute) { + PubKeyRing buyerPubKeyRing = dispute.getContract().getBuyerPubKeyRing(); + PaymentAccountPayload buyerPaymentAccountPaload = dispute.getContract().getBuyerPaymentAccountPayload(); + Optional optionalWitness = accountAgeWitnessService + .findWitness(buyerPaymentAccountPaload, buyerPubKeyRing); + return optionalWitness.map(witness -> new BuyerDataItem( + buyerPaymentAccountPaload, + witness, + dispute.getContract().getTradeAmount(), + dispute.getContract().getSellerPubKeyRing().getSignaturePubKey())) + .orElse(null); + } + } diff --git a/core/src/main/java/bisq/core/app/BisqSetup.java b/core/src/main/java/bisq/core/app/BisqSetup.java index f4c2b66839c..f1d9d9193fc 100644 --- a/core/src/main/java/bisq/core/app/BisqSetup.java +++ b/core/src/main/java/bisq/core/app/BisqSetup.java @@ -17,6 +17,7 @@ package bisq.core.app; +import bisq.core.account.sign.SignedWitnessService; import bisq.core.account.witness.AccountAgeWitnessService; import bisq.core.alert.Alert; import bisq.core.alert.AlertManager; @@ -143,6 +144,7 @@ public interface BisqSetupCompleteListener { private final KeyRing keyRing; private final BisqEnvironment bisqEnvironment; private final AccountAgeWitnessService accountAgeWitnessService; + private final SignedWitnessService signedWitnessService; private final MobileNotificationService mobileNotificationService; private final MyOfferTakenEvents myOfferTakenEvents; private final TradeEvents tradeEvents; @@ -221,6 +223,7 @@ public BisqSetup(P2PNetworkSetup p2PNetworkSetup, KeyRing keyRing, BisqEnvironment bisqEnvironment, AccountAgeWitnessService accountAgeWitnessService, + SignedWitnessService signedWitnessService, MobileNotificationService mobileNotificationService, MyOfferTakenEvents myOfferTakenEvents, TradeEvents tradeEvents, @@ -261,6 +264,7 @@ public BisqSetup(P2PNetworkSetup p2PNetworkSetup, this.keyRing = keyRing; this.bisqEnvironment = bisqEnvironment; this.accountAgeWitnessService = accountAgeWitnessService; + this.signedWitnessService = signedWitnessService; this.mobileNotificationService = mobileNotificationService; this.myOfferTakenEvents = myOfferTakenEvents; this.tradeEvents = tradeEvents; @@ -647,6 +651,7 @@ private void initDomainServices() { assetService.onAllServicesInitialized(); accountAgeWitnessService.onAllServicesInitialized(); + signedWitnessService.onAllServicesInitialized(); priceFeedService.setCurrencyCodeOnInit(); diff --git a/core/src/main/java/bisq/core/app/misc/AppSetupWithP2P.java b/core/src/main/java/bisq/core/app/misc/AppSetupWithP2P.java index c708552d1aa..8c9d54e20b2 100644 --- a/core/src/main/java/bisq/core/app/misc/AppSetupWithP2P.java +++ b/core/src/main/java/bisq/core/app/misc/AppSetupWithP2P.java @@ -17,6 +17,7 @@ package bisq.core.app.misc; +import bisq.core.account.sign.SignedWitnessService; import bisq.core.account.witness.AccountAgeWitnessService; import bisq.core.app.SetupUtils; import bisq.core.app.TorSetup; @@ -46,6 +47,7 @@ public class AppSetupWithP2P extends AppSetup { protected final P2PService p2PService; protected final AccountAgeWitnessService accountAgeWitnessService; + private final SignedWitnessService signedWitnessService; protected final FilterManager filterManager; private final TorSetup torSetup; protected BooleanProperty p2pNetWorkReady; @@ -58,12 +60,14 @@ public AppSetupWithP2P(EncryptionService encryptionService, P2PService p2PService, TradeStatisticsManager tradeStatisticsManager, AccountAgeWitnessService accountAgeWitnessService, + SignedWitnessService signedWitnessService, FilterManager filterManager, TorSetup torSetup) { super(encryptionService, keyRing); this.p2PService = p2PService; this.tradeStatisticsManager = tradeStatisticsManager; this.accountAgeWitnessService = accountAgeWitnessService; + this.signedWitnessService = signedWitnessService; this.filterManager = filterManager; this.torSetup = torSetup; this.persistedDataHosts = new ArrayList<>(); @@ -184,6 +188,7 @@ protected void onBasicServicesInitialized() { tradeStatisticsManager.onAllServicesInitialized(); accountAgeWitnessService.onAllServicesInitialized(); + signedWitnessService.onAllServicesInitialized(); filterManager.onAllServicesInitialized(); } diff --git a/core/src/main/java/bisq/core/app/misc/AppSetupWithP2PAndDAO.java b/core/src/main/java/bisq/core/app/misc/AppSetupWithP2PAndDAO.java index 9de90a9d09f..0b0bfa36bd6 100644 --- a/core/src/main/java/bisq/core/app/misc/AppSetupWithP2PAndDAO.java +++ b/core/src/main/java/bisq/core/app/misc/AppSetupWithP2PAndDAO.java @@ -17,6 +17,7 @@ package bisq.core.app.misc; +import bisq.core.account.sign.SignedWitnessService; import bisq.core.account.witness.AccountAgeWitnessService; import bisq.core.app.TorSetup; import bisq.core.dao.DaoOptionKeys; @@ -50,6 +51,7 @@ public AppSetupWithP2PAndDAO(EncryptionService encryptionService, P2PService p2PService, TradeStatisticsManager tradeStatisticsManager, AccountAgeWitnessService accountAgeWitnessService, + SignedWitnessService signedWitnessService, FilterManager filterManager, DaoSetup daoSetup, MyVoteListService myVoteListService, @@ -65,6 +67,7 @@ public AppSetupWithP2PAndDAO(EncryptionService encryptionService, p2PService, tradeStatisticsManager, accountAgeWitnessService, + signedWitnessService, filterManager, torSetup); diff --git a/core/src/main/java/bisq/core/arbitration/BuyerDataItem.java b/core/src/main/java/bisq/core/arbitration/BuyerDataItem.java new file mode 100644 index 00000000000..7f8215686fc --- /dev/null +++ b/core/src/main/java/bisq/core/arbitration/BuyerDataItem.java @@ -0,0 +1,60 @@ +/* + * This file is part of Bisq. + * + * Bisq is free software: you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or (at + * your option) any later version. + * + * Bisq is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + * License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Bisq. If not, see . + */ + +package bisq.core.arbitration; + +import bisq.core.account.witness.AccountAgeWitness; +import bisq.core.payment.payload.PaymentAccountPayload; + +import org.bitcoinj.core.Coin; + +import java.security.PublicKey; + +import java.util.Objects; + +import lombok.Getter; + +@Getter +public class BuyerDataItem { + private final PaymentAccountPayload paymentAccountPayload; + private final AccountAgeWitness accountAgeWitness; + private final Coin tradeAmount; + private final PublicKey sellerPubKey; + + public BuyerDataItem(PaymentAccountPayload paymentAccountPayload, + AccountAgeWitness accountAgeWitness, + Coin tradeAmount, + PublicKey sellerPubKey) { + this.paymentAccountPayload = paymentAccountPayload; + this.accountAgeWitness = accountAgeWitness; + this.tradeAmount = tradeAmount; + this.sellerPubKey = sellerPubKey; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof BuyerDataItem)) return false; + // Only distinguish data by AccountAgeWitness. Other details are irrelevant + return accountAgeWitness.equals(((BuyerDataItem) o).accountAgeWitness); + } + + @Override + public int hashCode() { + return Objects.hash(accountAgeWitness); + } +} 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 c69bf4a8c81..e883e00728a 100644 --- a/core/src/main/java/bisq/core/payment/payload/PaymentMethod.java +++ b/core/src/main/java/bisq/core/payment/payload/PaymentMethod.java @@ -321,6 +321,10 @@ public static boolean hasChargebackRisk(PaymentMethod paymentMethod) { return false; String id = paymentMethod.getId(); + return hasChargebackRisk(id); + } + + public static boolean hasChargebackRisk(String id) { return id.equals(PaymentMethod.SEPA_ID) || id.equals(PaymentMethod.SEPA_INSTANT_ID) || id.equals(PaymentMethod.INTERAC_E_TRANSFER_ID) || diff --git a/core/src/test/java/bisq/core/account/sign/SignedWitnessServiceTest.java b/core/src/test/java/bisq/core/account/sign/SignedWitnessServiceTest.java index 11286020e2a..1eab44cfbb7 100644 --- a/core/src/test/java/bisq/core/account/sign/SignedWitnessServiceTest.java +++ b/core/src/test/java/bisq/core/account/sign/SignedWitnessServiceTest.java @@ -20,6 +20,7 @@ import bisq.core.account.witness.AccountAgeWitness; import bisq.core.arbitration.ArbitratorManager; +import bisq.core.arbitration.DisputeManager; import bisq.network.p2p.storage.persistence.AppendOnlyDataStoreService; @@ -74,8 +75,9 @@ public class SignedWitnessServiceTest { public void setup() throws Exception { AppendOnlyDataStoreService appendOnlyDataStoreService = mock(AppendOnlyDataStoreService.class); ArbitratorManager arbitratorManager = mock(ArbitratorManager.class); + DisputeManager disputeManager = mock(DisputeManager.class); when(arbitratorManager.isPublicKeyInList(any())).thenReturn(true); - signedWitnessService = new SignedWitnessService(null, null, null, arbitratorManager, null, appendOnlyDataStoreService); + signedWitnessService = new SignedWitnessService(null, null, null, arbitratorManager, null, appendOnlyDataStoreService, disputeManager); account1DataHash = org.bitcoinj.core.Utils.sha256hash160(new byte[]{1}); account2DataHash = org.bitcoinj.core.Utils.sha256hash160(new byte[]{2}); account3DataHash = org.bitcoinj.core.Utils.sha256hash160(new byte[]{3}); From 972dda655b657c08f58c0c82ce8d57997259357d Mon Sep 17 00:00:00 2001 From: sqrrm Date: Mon, 26 Aug 2019 11:33:42 +0200 Subject: [PATCH 3/5] Test BuyerDataItem, use lombok generated equals and hash --- .../bisq/core/arbitration/BuyerDataItem.java | 18 +---- .../core/arbitration/BuyerDataItemTest.java | 66 +++++++++++++++++++ 2 files changed, 69 insertions(+), 15 deletions(-) create mode 100644 core/src/test/java/bisq/core/arbitration/BuyerDataItemTest.java diff --git a/core/src/main/java/bisq/core/arbitration/BuyerDataItem.java b/core/src/main/java/bisq/core/arbitration/BuyerDataItem.java index 7f8215686fc..5836c08961c 100644 --- a/core/src/main/java/bisq/core/arbitration/BuyerDataItem.java +++ b/core/src/main/java/bisq/core/arbitration/BuyerDataItem.java @@ -24,13 +24,14 @@ import java.security.PublicKey; -import java.util.Objects; - +import lombok.EqualsAndHashCode; import lombok.Getter; @Getter +@EqualsAndHashCode(onlyExplicitlyIncluded = true) public class BuyerDataItem { private final PaymentAccountPayload paymentAccountPayload; + @EqualsAndHashCode.Include private final AccountAgeWitness accountAgeWitness; private final Coin tradeAmount; private final PublicKey sellerPubKey; @@ -44,17 +45,4 @@ public BuyerDataItem(PaymentAccountPayload paymentAccountPayload, this.tradeAmount = tradeAmount; this.sellerPubKey = sellerPubKey; } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof BuyerDataItem)) return false; - // Only distinguish data by AccountAgeWitness. Other details are irrelevant - return accountAgeWitness.equals(((BuyerDataItem) o).accountAgeWitness); - } - - @Override - public int hashCode() { - return Objects.hash(accountAgeWitness); - } } diff --git a/core/src/test/java/bisq/core/arbitration/BuyerDataItemTest.java b/core/src/test/java/bisq/core/arbitration/BuyerDataItemTest.java new file mode 100644 index 00000000000..9c4078eef81 --- /dev/null +++ b/core/src/test/java/bisq/core/arbitration/BuyerDataItemTest.java @@ -0,0 +1,66 @@ +package bisq.core.arbitration; + +import bisq.core.account.witness.AccountAgeWitness; +import bisq.core.payment.payload.PaymentAccountPayload; + +import org.bitcoinj.core.Coin; + +import java.security.PublicKey; + +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.mockito.Mockito.mock; + +/* + * This file is part of Bisq. + * + * Bisq is free software: you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or (at + * your option) any later version. + * + * Bisq is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + * License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Bisq. If not, see . + */ +public class BuyerDataItemTest { + private BuyerDataItem buyerDataItem1; + private BuyerDataItem buyerDataItem2; + private BuyerDataItem buyerDataItem3; + private AccountAgeWitness accountAgeWitness1; + private AccountAgeWitness accountAgeWitness2; + private byte[] hash1 = "1".getBytes(); + private byte[] hash2 = "2".getBytes(); + + @Before + public void setup() { + accountAgeWitness1 = new AccountAgeWitness(hash1, 123); + accountAgeWitness2 = new AccountAgeWitness(hash2, 124); + buyerDataItem1 = new BuyerDataItem(mock(PaymentAccountPayload.class), accountAgeWitness1, Coin.valueOf(546), + mock(PublicKey.class)); + buyerDataItem2 = new BuyerDataItem(mock(PaymentAccountPayload.class), accountAgeWitness1, Coin.valueOf(547), + mock(PublicKey.class)); + buyerDataItem3 = new BuyerDataItem(mock(PaymentAccountPayload.class), accountAgeWitness2, Coin.valueOf(548), + mock(PublicKey.class)); + } + + @Test + public void testEquals() { + assertEquals(buyerDataItem1, buyerDataItem2); + assertNotEquals(buyerDataItem1, buyerDataItem3); + assertNotEquals(buyerDataItem2, buyerDataItem3); + } + + @Test + public void testHashCode() { + assertEquals(buyerDataItem1.hashCode(), buyerDataItem2.hashCode()); + assertNotEquals(buyerDataItem1.hashCode(), buyerDataItem3.hashCode()); + } +} From 74244c4ad940abf245fb8c0f69bc075516e0947e Mon Sep 17 00:00:00 2001 From: sqrrm Date: Mon, 26 Aug 2019 14:33:50 +0200 Subject: [PATCH 4/5] Add non static ChargeBackRisk wrapper --- .../account/sign/SignedWitnessService.java | 10 ++++--- .../bisq/core/payment/ChargeBackRisk.java | 29 +++++++++++++++++++ .../sign/SignedWitnessServiceTest.java | 2 +- 3 files changed, 36 insertions(+), 5 deletions(-) create mode 100644 core/src/main/java/bisq/core/payment/ChargeBackRisk.java diff --git a/core/src/main/java/bisq/core/account/sign/SignedWitnessService.java b/core/src/main/java/bisq/core/account/sign/SignedWitnessService.java index 6fc193316c2..6de14845efb 100644 --- a/core/src/main/java/bisq/core/account/sign/SignedWitnessService.java +++ b/core/src/main/java/bisq/core/account/sign/SignedWitnessService.java @@ -24,8 +24,8 @@ import bisq.core.arbitration.Dispute; import bisq.core.arbitration.DisputeManager; import bisq.core.arbitration.DisputeResult; +import bisq.core.payment.ChargeBackRisk; import bisq.core.payment.payload.PaymentAccountPayload; -import bisq.core.payment.payload.PaymentMethod; import bisq.network.p2p.P2PService; import bisq.network.p2p.storage.P2PDataStorage; @@ -62,7 +62,6 @@ import java.util.Stack; import java.util.stream.Collectors; -import lombok.Getter; import lombok.extern.slf4j.Slf4j; import org.jetbrains.annotations.Nullable; @@ -76,6 +75,7 @@ public class SignedWitnessService { private final AccountAgeWitnessService accountAgeWitnessService; private final ArbitratorManager arbitratorManager; private final DisputeManager disputeManager; + private final ChargeBackRisk chargeBackRisk; private final Map signedWitnessMap = new HashMap<>(); @@ -91,12 +91,14 @@ public SignedWitnessService(KeyRing keyRing, ArbitratorManager arbitratorManager, SignedWitnessStorageService signedWitnessStorageService, AppendOnlyDataStoreService appendOnlyDataStoreService, - DisputeManager disputeManager) { + DisputeManager disputeManager, + ChargeBackRisk chargeBackRisk) { this.keyRing = keyRing; this.p2PService = p2PService; this.accountAgeWitnessService = accountAgeWitnessService; this.arbitratorManager = arbitratorManager; this.disputeManager = disputeManager; + this.chargeBackRisk = chargeBackRisk; // We need to add that early (before onAllServicesInitialized) as it will be used at startup. appendOnlyDataStoreService.addService(signedWitnessStorageService); @@ -333,7 +335,7 @@ public List getBuyerPaymentAccounts(long safeDate) { } private boolean hasChargebackRisk(Dispute dispute) { - return PaymentMethod.hasChargebackRisk(dispute.getContract().getPaymentMethodId()); + return chargeBackRisk.hasChargebackRisk(dispute.getContract().getPaymentMethodId()); } private boolean isBuyerWinner(Dispute dispute) { diff --git a/core/src/main/java/bisq/core/payment/ChargeBackRisk.java b/core/src/main/java/bisq/core/payment/ChargeBackRisk.java new file mode 100644 index 00000000000..32ca2500c50 --- /dev/null +++ b/core/src/main/java/bisq/core/payment/ChargeBackRisk.java @@ -0,0 +1,29 @@ +/* + * This file is part of Bisq. + * + * Bisq is free software: you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or (at + * your option) any later version. + * + * Bisq is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + * License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Bisq. If not, see . + */ + +package bisq.core.payment; + +import bisq.core.payment.payload.PaymentMethod; + +import javax.inject.Singleton; + +@Singleton +public class ChargeBackRisk { + public boolean hasChargebackRisk(String id) { + return PaymentMethod.hasChargebackRisk(id); + } +} diff --git a/core/src/test/java/bisq/core/account/sign/SignedWitnessServiceTest.java b/core/src/test/java/bisq/core/account/sign/SignedWitnessServiceTest.java index 1eab44cfbb7..7ac3340a996 100644 --- a/core/src/test/java/bisq/core/account/sign/SignedWitnessServiceTest.java +++ b/core/src/test/java/bisq/core/account/sign/SignedWitnessServiceTest.java @@ -77,7 +77,7 @@ public void setup() throws Exception { ArbitratorManager arbitratorManager = mock(ArbitratorManager.class); DisputeManager disputeManager = mock(DisputeManager.class); when(arbitratorManager.isPublicKeyInList(any())).thenReturn(true); - signedWitnessService = new SignedWitnessService(null, null, null, arbitratorManager, null, appendOnlyDataStoreService, disputeManager); + signedWitnessService = new SignedWitnessService(null, null, null, arbitratorManager, null, appendOnlyDataStoreService, disputeManager, null); account1DataHash = org.bitcoinj.core.Utils.sha256hash160(new byte[]{1}); account2DataHash = org.bitcoinj.core.Utils.sha256hash160(new byte[]{2}); account3DataHash = org.bitcoinj.core.Utils.sha256hash160(new byte[]{3}); From ace881cc049673b15d56f8291a48ae894bbdf840 Mon Sep 17 00:00:00 2001 From: sqrrm Date: Tue, 27 Aug 2019 12:47:02 +0200 Subject: [PATCH 5/5] Fix test, add singleton check for ChargeBackRisk --- desktop/src/test/java/bisq/desktop/GuiceSetupTest.java | 2 ++ seednode/src/test/java/bisq/seednode/GuiceSetupTest.java | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/desktop/src/test/java/bisq/desktop/GuiceSetupTest.java b/desktop/src/test/java/bisq/desktop/GuiceSetupTest.java index 32a6298d9bb..482ab242333 100644 --- a/desktop/src/test/java/bisq/desktop/GuiceSetupTest.java +++ b/desktop/src/test/java/bisq/desktop/GuiceSetupTest.java @@ -32,6 +32,7 @@ import bisq.core.notifications.alerts.TradeEvents; import bisq.core.notifications.alerts.market.MarketAlerts; import bisq.core.notifications.alerts.price.PriceAlert; +import bisq.core.payment.ChargeBackRisk; import bisq.core.payment.TradeLimits; import bisq.core.proto.network.CoreNetworkProtoResolver; import bisq.core.proto.persistable.CorePersistenceProtoResolver; @@ -131,6 +132,7 @@ public void testGuiceSetup() { assertSingleton(TradeEvents.class); assertSingleton(PriceAlert.class); assertSingleton(MarketAlerts.class); + assertSingleton(ChargeBackRisk.class); assertNotSingleton(Storage.class); } diff --git a/seednode/src/test/java/bisq/seednode/GuiceSetupTest.java b/seednode/src/test/java/bisq/seednode/GuiceSetupTest.java index be70a48179f..f1a309f1ea2 100644 --- a/seednode/src/test/java/bisq/seednode/GuiceSetupTest.java +++ b/seednode/src/test/java/bisq/seednode/GuiceSetupTest.java @@ -3,6 +3,8 @@ import bisq.core.app.BisqEnvironment; import bisq.core.app.misc.AppSetupWithP2PAndDAO; import bisq.core.app.misc.ModuleForAppWithP2p; +import bisq.core.locale.CurrencyUtil; +import bisq.core.locale.Res; import org.springframework.mock.env.MockPropertySource; @@ -13,6 +15,9 @@ public class GuiceSetupTest { @Test public void testGuiceSetup() { + Res.setup(); + CurrencyUtil.setup(); + ModuleForAppWithP2p module = new ModuleForAppWithP2p(new BisqEnvironment(new MockPropertySource())); Guice.createInjector(module).getInstance(AppSetupWithP2PAndDAO.class); }