Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Account Signing: Don't sign filtered accounts #3415

Merged
merged 1 commit into from
Oct 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

import bisq.core.account.sign.SignedWitness;
import bisq.core.account.sign.SignedWitnessService;
import bisq.core.filter.FilterManager;
import bisq.core.filter.PaymentAccountFilter;
import bisq.core.locale.CurrencyUtil;
import bisq.core.locale.Res;
import bisq.core.offer.Offer;
Expand Down Expand Up @@ -104,13 +106,14 @@ public String getPresentation() {
return presentation;
}

}
}

private final KeyRing keyRing;
private final P2PService p2PService;
private final User user;
private final SignedWitnessService signedWitnessService;
private final ChargeBackRisk chargeBackRisk;
private final FilterManager filterManager;

private final Map<P2PDataStorage.ByteArray, AccountAgeWitness> accountAgeWitnessMap = new HashMap<>();

Expand All @@ -127,12 +130,14 @@ public AccountAgeWitnessService(KeyRing keyRing,
SignedWitnessService signedWitnessService,
ChargeBackRisk chargeBackRisk,
AccountAgeWitnessStorageService accountAgeWitnessStorageService,
AppendOnlyDataStoreService appendOnlyDataStoreService) {
AppendOnlyDataStoreService appendOnlyDataStoreService,
FilterManager filterManager) {
this.keyRing = keyRing;
this.p2PService = p2PService;
this.user = user;
this.signedWitnessService = signedWitnessService;
this.chargeBackRisk = chargeBackRisk;
this.filterManager = filterManager;

// We need to add that early (before onAllServicesInitialized) as it will be used at startup.
appendOnlyDataStoreService.addService(accountAgeWitnessStorageService);
Expand Down Expand Up @@ -608,6 +613,7 @@ public List<TraderDataItem> getTraderPaymentAccounts(long safeDate, PaymentMetho
List<Dispute> disputes) {
return disputes.stream()
.filter(dispute -> dispute.getContract().getPaymentMethodId().equals(paymentMethod.getId()))
.filter(this::isNotFiltered)
.filter(this::hasChargebackRisk)
.filter(this::isBuyerWinner)
.flatMap(this::getTraderData)
Expand All @@ -618,6 +624,19 @@ public List<TraderDataItem> getTraderPaymentAccounts(long safeDate, PaymentMetho
.collect(Collectors.toList());
}

private boolean isNotFiltered(Dispute dispute) {
boolean isFiltered = filterManager.isNodeAddressBanned(dispute.getContract().getBuyerNodeAddress()) ||
filterManager.isNodeAddressBanned(dispute.getContract().getSellerNodeAddress()) ||
filterManager.isCurrencyBanned(dispute.getContract().getOfferPayload().getCurrencyCode()) ||
filterManager.isPaymentMethodBanned(
PaymentMethod.getPaymentMethodById(dispute.getContract().getPaymentMethodId())) ||
filterManager.isPeersPaymentAccountDataAreBanned(dispute.getContract().getBuyerPaymentAccountPayload(),
new PaymentAccountFilter[1]) ||
filterManager.isPeersPaymentAccountDataAreBanned(dispute.getContract().getSellerPaymentAccountPayload(),
new PaymentAccountFilter[1]);
return !isFiltered;
}

private boolean hasChargebackRisk(Dispute dispute) {
return chargeBackRisk.hasChargebackRisk(dispute.getContract().getPaymentMethodId(),
dispute.getContract().getOfferPayload().getCurrencyCode());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class AccountAgeWitnessServiceTest {
public void setup() throws CertificateException, NoSuchAlgorithmException, KeyStoreException, IOException, CryptoException {
SignedWitnessService signedWitnessService = mock(SignedWitnessService.class);
ChargeBackRisk chargeBackRisk = mock(ChargeBackRisk.class);
service = new AccountAgeWitnessService(null, null, null, signedWitnessService, chargeBackRisk, null, null);
service = new AccountAgeWitnessService(null, null, null, signedWitnessService, chargeBackRisk, null, null, null);
keypair = Sig.generateKeyPair();
publicKey = keypair.getPublic();
}
Expand Down