Search in sources :

Example 1 with PaymentAccountFilter

use of io.bitsquare.filter.PaymentAccountFilter in project bitsquare by bitsquare.

the class ProcessPublishDepositTxRequest method run.

@Override
protected void run() {
    try {
        runInterceptHook();
        log.debug("current trade state " + trade.getState());
        PublishDepositTxRequest publishDepositTxRequest = (PublishDepositTxRequest) processModel.getTradeMessage();
        checkTradeId(processModel.getId(), publishDepositTxRequest);
        checkNotNull(publishDepositTxRequest);
        PaymentAccountContractData paymentAccountContractData = checkNotNull(publishDepositTxRequest.offererPaymentAccountContractData);
        final PaymentAccountFilter[] appliedPaymentAccountFilter = new PaymentAccountFilter[1];
        if (processModel.isPeersPaymentAccountDataAreBanned(paymentAccountContractData, appliedPaymentAccountFilter)) {
            failed("Other trader is banned by his trading account data.\n" + "paymentAccountContractData=" + paymentAccountContractData.getPaymentDetails() + "\n" + "banFilter=" + appliedPaymentAccountFilter[0].toString());
            return;
        }
        processModel.tradingPeer.setPaymentAccountContractData(paymentAccountContractData);
        processModel.tradingPeer.setAccountId(nonEmptyStringOf(publishDepositTxRequest.offererAccountId));
        processModel.tradingPeer.setMultiSigPubKey(checkNotNull(publishDepositTxRequest.offererMultiSigPubKey));
        processModel.tradingPeer.setContractAsJson(nonEmptyStringOf(publishDepositTxRequest.offererContractAsJson));
        processModel.tradingPeer.setContractSignature(nonEmptyStringOf(publishDepositTxRequest.offererContractSignature));
        processModel.tradingPeer.setPayoutAddressString(nonEmptyStringOf(publishDepositTxRequest.offererPayoutAddressString));
        processModel.tradingPeer.setRawTransactionInputs(checkNotNull(publishDepositTxRequest.offererInputs));
        processModel.setPreparedDepositTx(checkNotNull(publishDepositTxRequest.preparedDepositTx));
        checkArgument(publishDepositTxRequest.offererInputs.size() > 0);
        // update to the latest peer address of our peer if the message is correct
        trade.setTradingPeerNodeAddress(processModel.getTempTradingPeerNodeAddress());
        complete();
    } catch (Throwable t) {
        failed(t);
    }
}
Also used : PaymentAccountContractData(io.bitsquare.payment.PaymentAccountContractData) PaymentAccountFilter(io.bitsquare.filter.PaymentAccountFilter) PublishDepositTxRequest(io.bitsquare.trade.protocol.trade.messages.PublishDepositTxRequest)

Example 2 with PaymentAccountFilter

use of io.bitsquare.filter.PaymentAccountFilter in project bitsquare by bitsquare.

the class ProcessPayDepositRequest method run.

@Override
protected void run() {
    try {
        runInterceptHook();
        log.debug("current trade state " + trade.getState());
        PayDepositRequest payDepositRequest = (PayDepositRequest) processModel.getTradeMessage();
        checkNotNull(payDepositRequest);
        checkTradeId(processModel.getId(), payDepositRequest);
        PaymentAccountContractData paymentAccountContractData = checkNotNull(payDepositRequest.takerPaymentAccountContractData);
        final PaymentAccountFilter[] appliedPaymentAccountFilter = new PaymentAccountFilter[1];
        if (processModel.isPeersPaymentAccountDataAreBanned(paymentAccountContractData, appliedPaymentAccountFilter)) {
            failed("Other trader is banned by his trading account data.\n" + "paymentAccountContractData=" + paymentAccountContractData.getPaymentDetails() + "\n" + "banFilter=" + appliedPaymentAccountFilter[0].toString());
            return;
        }
        processModel.tradingPeer.setPaymentAccountContractData(paymentAccountContractData);
        processModel.tradingPeer.setRawTransactionInputs(checkNotNull(payDepositRequest.rawTransactionInputs));
        checkArgument(payDepositRequest.rawTransactionInputs.size() > 0);
        processModel.tradingPeer.setChangeOutputValue(payDepositRequest.changeOutputValue);
        if (payDepositRequest.changeOutputAddress != null)
            processModel.tradingPeer.setChangeOutputAddress(payDepositRequest.changeOutputAddress);
        processModel.tradingPeer.setMultiSigPubKey(checkNotNull(payDepositRequest.takerMultiSigPubKey));
        processModel.tradingPeer.setPayoutAddressString(nonEmptyStringOf(payDepositRequest.takerPayoutAddressString));
        processModel.tradingPeer.setPubKeyRing(checkNotNull(payDepositRequest.takerPubKeyRing));
        processModel.tradingPeer.setAccountId(nonEmptyStringOf(payDepositRequest.takerAccountId));
        trade.setTakeOfferFeeTxId(nonEmptyStringOf(payDepositRequest.takeOfferFeeTxId));
        processModel.setTakerAcceptedArbitratorNodeAddresses(checkNotNull(payDepositRequest.acceptedArbitratorNodeAddresses));
        if (payDepositRequest.acceptedArbitratorNodeAddresses.isEmpty())
            failed("acceptedArbitratorNames must not be empty");
        trade.applyArbitratorNodeAddress(checkNotNull(payDepositRequest.arbitratorNodeAddress));
        try {
            long takersTradePrice = payDepositRequest.tradePrice;
            trade.getOffer().checkTradePriceTolerance(takersTradePrice);
            trade.setTradePrice(takersTradePrice);
        } catch (TradePriceOutOfToleranceException e) {
            failed(e.getMessage());
        } catch (Throwable e2) {
            failed(e2);
        }
        checkArgument(payDepositRequest.tradeAmount > 0);
        trade.setTradeAmount(Coin.valueOf(payDepositRequest.tradeAmount));
        // check and update to the latest peer address of our peer if the payDepositRequest is correct
        checkArgument(payDepositRequest.getSenderNodeAddress().equals(processModel.getTempTradingPeerNodeAddress()));
        trade.setTradingPeerNodeAddress(processModel.getTempTradingPeerNodeAddress());
        removeMailboxMessageAfterProcessing();
        complete();
    } catch (Throwable t) {
        failed(t);
    }
}
Also used : PayDepositRequest(io.bitsquare.trade.protocol.trade.messages.PayDepositRequest) PaymentAccountContractData(io.bitsquare.payment.PaymentAccountContractData) TradePriceOutOfToleranceException(io.bitsquare.trade.exceptions.TradePriceOutOfToleranceException) PaymentAccountFilter(io.bitsquare.filter.PaymentAccountFilter)

Example 3 with PaymentAccountFilter

use of io.bitsquare.filter.PaymentAccountFilter in project bitsquare by bitsquare.

the class FilterWindow method addContent.

private void addContent() {
    InputTextField keyInputTextField = addLabelInputTextField(gridPane, ++rowIndex, "Private key to unlock:", 10).second;
    InputTextField offerIdsInputTextField = addLabelInputTextField(gridPane, ++rowIndex, "Filtered offers (comma sep.):").second;
    InputTextField nodesInputTextField = addLabelInputTextField(gridPane, ++rowIndex, "Filtered onion addresses (comma sep.):").second;
    InputTextField paymentAccountFilterInputTextField = addLabelInputTextField(gridPane, ++rowIndex, "Filtered trading account data:\nFormat: comma sep. list of [payment method id | data field | value]").second;
    GridPane.setHalignment(paymentAccountFilterInputTextField, HPos.RIGHT);
    final Filter filter = filterManager.getDevelopersFilter();
    if (filter != null) {
        offerIdsInputTextField.setText(filter.bannedOfferIds.stream().collect(Collectors.joining(", ")));
        nodesInputTextField.setText(filter.bannedNodeAddress.stream().collect(Collectors.joining(", ")));
        if (filter.bannedPaymentAccounts != null) {
            StringBuilder sb = new StringBuilder();
            filter.bannedPaymentAccounts.stream().forEach(e -> {
                if (e != null && e.paymentMethodId != null) {
                    sb.append(e.paymentMethodId).append("|").append(e.getMethodName).append("|").append(e.value).append(", ");
                }
            });
            paymentAccountFilterInputTextField.setText(sb.toString());
        }
    }
    sendButton = new Button("Add filter");
    sendButton.setOnAction(e -> {
        ArrayList<String> offerIds = new ArrayList<>();
        ArrayList<String> nodes = new ArrayList<>();
        ArrayList<PaymentAccountFilter> paymentAccountFilters = new ArrayList<>();
        if (!offerIdsInputTextField.getText().isEmpty())
            offerIds = new ArrayList<>(Arrays.asList(offerIdsInputTextField.getText().replace(" ", "").replace(", ", ",").split(",")));
        if (!nodesInputTextField.getText().isEmpty())
            nodes = new ArrayList<>(Arrays.asList(nodesInputTextField.getText().replace(":9999", "").replace(".onion", "").replace(" ", "").replace(", ", ",").split(",")));
        if (!paymentAccountFilterInputTextField.getText().isEmpty())
            paymentAccountFilters = new ArrayList<>(Arrays.asList(paymentAccountFilterInputTextField.getText().replace(", ", ",").split(",")).stream().map(item -> {
                String[] list = item.split("\\|");
                if (list.length == 3)
                    return new PaymentAccountFilter(list[0], list[1], list[2]);
                else
                    return new PaymentAccountFilter("", "", "");
            }).collect(Collectors.toList()));
        if (sendFilterMessageHandler.handle(new Filter(offerIds, nodes, paymentAccountFilters), keyInputTextField.getText()))
            hide();
        else
            new Popup().warning("The key you entered was not correct.").width(300).onClose(() -> blurAgain()).show();
    });
    Button removeFilterMessageButton = new Button("Remove filter");
    removeFilterMessageButton.setOnAction(e -> {
        if (keyInputTextField.getText().length() > 0) {
            if (removeFilterMessageHandler.handle(keyInputTextField.getText()))
                hide();
            else
                new Popup().warning("The key you entered was not correct.").width(300).onClose(() -> blurAgain()).show();
        }
    });
    closeButton = new Button("Close");
    closeButton.setOnAction(e -> {
        hide();
        closeHandlerOptional.ifPresent(closeHandler -> closeHandler.run());
    });
    HBox hBox = new HBox();
    hBox.setSpacing(10);
    GridPane.setRowIndex(hBox, ++rowIndex);
    GridPane.setColumnIndex(hBox, 1);
    hBox.getChildren().addAll(sendButton, removeFilterMessageButton, closeButton);
    gridPane.getChildren().add(hBox);
    GridPane.setMargin(hBox, new Insets(10, 0, 0, 0));
}
Also used : HBox(javafx.scene.layout.HBox) Insets(javafx.geometry.Insets) FormBuilder.addLabelInputTextField(io.bitsquare.gui.util.FormBuilder.addLabelInputTextField) InputTextField(io.bitsquare.gui.components.InputTextField) ArrayList(java.util.ArrayList) PaymentAccountFilter(io.bitsquare.filter.PaymentAccountFilter) Filter(io.bitsquare.filter.Filter) Button(javafx.scene.control.Button) Popup(io.bitsquare.gui.main.overlays.popups.Popup) PaymentAccountFilter(io.bitsquare.filter.PaymentAccountFilter)

Aggregations

PaymentAccountFilter (io.bitsquare.filter.PaymentAccountFilter)3 PaymentAccountContractData (io.bitsquare.payment.PaymentAccountContractData)2 Filter (io.bitsquare.filter.Filter)1 InputTextField (io.bitsquare.gui.components.InputTextField)1 Popup (io.bitsquare.gui.main.overlays.popups.Popup)1 FormBuilder.addLabelInputTextField (io.bitsquare.gui.util.FormBuilder.addLabelInputTextField)1 TradePriceOutOfToleranceException (io.bitsquare.trade.exceptions.TradePriceOutOfToleranceException)1 PayDepositRequest (io.bitsquare.trade.protocol.trade.messages.PayDepositRequest)1 PublishDepositTxRequest (io.bitsquare.trade.protocol.trade.messages.PublishDepositTxRequest)1 ArrayList (java.util.ArrayList)1 Insets (javafx.geometry.Insets)1 Button (javafx.scene.control.Button)1 HBox (javafx.scene.layout.HBox)1