Search in sources :

Example 6 with SendMailboxMessageListener

use of bisq.network.p2p.SendMailboxMessageListener in project bisq-core by bisq-network.

the class DisputeManager method sendDisputeDirectMessage.

// traders send msg to the arbitrator or arbitrator to 1 trader (trader to trader is not allowed)
public DisputeCommunicationMessage sendDisputeDirectMessage(Dispute dispute, String text, ArrayList<Attachment> attachments) {
    DisputeCommunicationMessage disputeCommunicationMessage = new DisputeCommunicationMessage(dispute.getTradeId(), dispute.getTraderPubKeyRing().hashCode(), isTrader(dispute), text, null, p2PService.getAddress(), new Date().getTime(), false, false, UUID.randomUUID().toString());
    disputeCommunicationMessage.addAllAttachments(attachments);
    PubKeyRing receiverPubKeyRing = null;
    NodeAddress peerNodeAddress = null;
    if (isTrader(dispute)) {
        dispute.addDisputeMessage(disputeCommunicationMessage);
        receiverPubKeyRing = dispute.getArbitratorPubKeyRing();
        peerNodeAddress = dispute.getContract().getArbitratorNodeAddress();
    } else if (isArbitrator(dispute)) {
        if (!disputeCommunicationMessage.isSystemMessage())
            dispute.addDisputeMessage(disputeCommunicationMessage);
        receiverPubKeyRing = dispute.getTraderPubKeyRing();
        Contract contract = dispute.getContract();
        if (contract.getBuyerPubKeyRing().equals(receiverPubKeyRing))
            peerNodeAddress = contract.getBuyerNodeAddress();
        else
            peerNodeAddress = contract.getSellerNodeAddress();
    } else {
        log.error("That must not happen. Trader cannot communicate to other trader.");
    }
    if (receiverPubKeyRing != null) {
        log.trace("sendDisputeDirectMessage to peerAddress " + peerNodeAddress);
        p2PService.sendEncryptedMailboxMessage(peerNodeAddress, receiverPubKeyRing, disputeCommunicationMessage, new SendMailboxMessageListener() {

            @Override
            public void onArrived() {
                log.info("Message arrived at peer. tradeId={}", disputeCommunicationMessage.getTradeId());
                disputeCommunicationMessage.setArrived(true);
            }

            @Override
            public void onStoredInMailbox() {
                log.info("Message stored in mailbox. tradeId={}", disputeCommunicationMessage.getTradeId());
                disputeCommunicationMessage.setStoredInMailbox(true);
            }

            @Override
            public void onFault(String errorMessage) {
                log.error("sendEncryptedMailboxMessage failed. disputeCommunicationMessage=" + disputeCommunicationMessage);
            }
        });
    }
    return disputeCommunicationMessage;
}
Also used : PubKeyRing(bisq.common.crypto.PubKeyRing) NodeAddress(bisq.network.p2p.NodeAddress) SendMailboxMessageListener(bisq.network.p2p.SendMailboxMessageListener) Contract(bisq.core.trade.Contract) DisputeCommunicationMessage(bisq.core.arbitration.messages.DisputeCommunicationMessage) Date(java.util.Date)

Example 7 with SendMailboxMessageListener

use of bisq.network.p2p.SendMailboxMessageListener in project bisq-core by bisq-network.

the class DisputeManager method sendDisputeResultMessage.

// arbitrator send result to trader
public void sendDisputeResultMessage(DisputeResult disputeResult, Dispute dispute, String text) {
    DisputeCommunicationMessage disputeCommunicationMessage = new DisputeCommunicationMessage(dispute.getTradeId(), dispute.getTraderPubKeyRing().hashCode(), false, text, null, p2PService.getAddress(), new Date().getTime(), false, false, UUID.randomUUID().toString());
    dispute.addDisputeMessage(disputeCommunicationMessage);
    disputeResult.setDisputeCommunicationMessage(disputeCommunicationMessage);
    NodeAddress peerNodeAddress;
    Contract contract = dispute.getContract();
    if (contract.getBuyerPubKeyRing().equals(dispute.getTraderPubKeyRing()))
        peerNodeAddress = contract.getBuyerNodeAddress();
    else
        peerNodeAddress = contract.getSellerNodeAddress();
    p2PService.sendEncryptedMailboxMessage(peerNodeAddress, dispute.getTraderPubKeyRing(), new DisputeResultMessage(disputeResult, p2PService.getAddress(), UUID.randomUUID().toString()), new SendMailboxMessageListener() {

        @Override
        public void onArrived() {
            log.info("Message arrived at peer. tradeId={}", disputeCommunicationMessage.getTradeId());
            disputeCommunicationMessage.setArrived(true);
        }

        @Override
        public void onStoredInMailbox() {
            log.info("Message stored in mailbox. tradeId={}", disputeCommunicationMessage.getTradeId());
            disputeCommunicationMessage.setStoredInMailbox(true);
        }

        @Override
        public void onFault(String errorMessage) {
            log.error("sendEncryptedMailboxMessage failed. disputeCommunicationMessage=" + disputeCommunicationMessage);
        }
    });
}
Also used : DisputeResultMessage(bisq.core.arbitration.messages.DisputeResultMessage) NodeAddress(bisq.network.p2p.NodeAddress) SendMailboxMessageListener(bisq.network.p2p.SendMailboxMessageListener) Contract(bisq.core.trade.Contract) DisputeCommunicationMessage(bisq.core.arbitration.messages.DisputeCommunicationMessage) Date(java.util.Date)

Example 8 with SendMailboxMessageListener

use of bisq.network.p2p.SendMailboxMessageListener in project bisq-desktop by bisq-network.

the class SendPrivateNotificationWindow method addContent.

private void addContent() {
    InputTextField keyInputTextField = addLabelInputTextField(gridPane, ++rowIndex, Res.get("shared.unlock"), 10).second;
    if (useDevPrivilegeKeys)
        keyInputTextField.setText(DevEnv.DEV_PRIVILEGE_PRIV_KEY);
    Tuple2<Label, TextArea> labelTextAreaTuple2 = addLabelTextArea(gridPane, ++rowIndex, Res.get("sendPrivateNotificationWindow.privateNotification"), Res.get("sendPrivateNotificationWindow.enterNotification"));
    TextArea alertMessageTextArea = labelTextAreaTuple2.second;
    Label first = labelTextAreaTuple2.first;
    first.setMinWidth(200);
    Button sendButton = new AutoTooltipButton(Res.get("sendPrivateNotificationWindow.send"));
    sendButton.setOnAction(e -> {
        if (alertMessageTextArea.getText().length() > 0 && keyInputTextField.getText().length() > 0) {
            if (!sendPrivateNotificationHandler.handle(new PrivateNotificationPayload(alertMessageTextArea.getText()), pubKeyRing, nodeAddress, keyInputTextField.getText(), new SendMailboxMessageListener() {

                @Override
                public void onArrived() {
                    log.info("PrivateNotificationMessage arrived at peer.");
                    new Popup<>().feedback(Res.get("shared.messageArrived")).onClose(SendPrivateNotificationWindow.this::hide).show();
                }

                @Override
                public void onStoredInMailbox() {
                    log.info("PrivateNotificationMessage was stored in mailbox.");
                    new Popup<>().feedback(Res.get("shared.messageStoredInMailbox")).onClose(SendPrivateNotificationWindow.this::hide).show();
                }

                @Override
                public void onFault(String errorMessage) {
                    log.error("sendEncryptedMailboxMessage failed. message=" + message);
                    new Popup<>().feedback(Res.get("shared.messageSendingFailed", errorMessage)).onClose(SendPrivateNotificationWindow.this::hide).show();
                }
            }))
                new Popup<>().warning(Res.get("shared.invalidKey")).width(300).onClose(this::blurAgain).show();
        }
    });
    closeButton = new AutoTooltipButton(Res.get("shared.close"));
    closeButton.setOnAction(e -> {
        hide();
        closeHandlerOptional.ifPresent(Runnable::run);
    });
    HBox hBox = new HBox();
    hBox.setSpacing(10);
    GridPane.setRowIndex(hBox, ++rowIndex);
    GridPane.setColumnIndex(hBox, 1);
    hBox.getChildren().addAll(sendButton, 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) TextArea(javafx.scene.control.TextArea) FormBuilder.addLabelTextArea(bisq.desktop.util.FormBuilder.addLabelTextArea) FormBuilder.addLabelInputTextField(bisq.desktop.util.FormBuilder.addLabelInputTextField) InputTextField(bisq.desktop.components.InputTextField) Label(javafx.scene.control.Label) AutoTooltipButton(bisq.desktop.components.AutoTooltipButton) Button(javafx.scene.control.Button) AutoTooltipButton(bisq.desktop.components.AutoTooltipButton) PrivateNotificationPayload(bisq.core.alert.PrivateNotificationPayload) SendMailboxMessageListener(bisq.network.p2p.SendMailboxMessageListener)

Example 9 with SendMailboxMessageListener

use of bisq.network.p2p.SendMailboxMessageListener in project bisq-core by bisq-network.

the class SellerSendPayoutTxPublishedMessage method run.

@Override
protected void run() {
    try {
        runInterceptHook();
        if (trade.getPayoutTx() != null) {
            final String id = processModel.getOfferId();
            final PayoutTxPublishedMessage message = new PayoutTxPublishedMessage(id, trade.getPayoutTx().bitcoinSerialize(), processModel.getMyNodeAddress(), UUID.randomUUID().toString());
            trade.setState(Trade.State.SELLER_SENT_PAYOUT_TX_PUBLISHED_MSG);
            processModel.getP2PService().sendEncryptedMailboxMessage(trade.getTradingPeerNodeAddress(), processModel.getTradingPeer().getPubKeyRing(), message, new SendMailboxMessageListener() {

                @Override
                public void onArrived() {
                    log.info("Message arrived at peer. tradeId={}", id);
                    trade.setState(Trade.State.SELLER_SAW_ARRIVED_PAYOUT_TX_PUBLISHED_MSG);
                    complete();
                }

                @Override
                public void onStoredInMailbox() {
                    log.info("Message stored in mailbox. tradeId={}", id);
                    trade.setState(Trade.State.SELLER_STORED_IN_MAILBOX_PAYOUT_TX_PUBLISHED_MSG);
                    complete();
                }

                @Override
                public void onFault(String errorMessage) {
                    log.error("sendEncryptedMailboxMessage failed. message=" + message);
                    trade.setState(Trade.State.SELLER_SEND_FAILED_PAYOUT_TX_PUBLISHED_MSG);
                    appendToErrorMessage("Sending message failed: message=" + message + "\nerrorMessage=" + errorMessage);
                    failed(errorMessage);
                }
            });
        } else {
            log.error("trade.getPayoutTx() = " + trade.getPayoutTx());
            failed("PayoutTx is null");
        }
    } catch (Throwable t) {
        failed(t);
    }
}
Also used : PayoutTxPublishedMessage(bisq.core.trade.messages.PayoutTxPublishedMessage) SendMailboxMessageListener(bisq.network.p2p.SendMailboxMessageListener)

Example 10 with SendMailboxMessageListener

use of bisq.network.p2p.SendMailboxMessageListener in project bisq-core by bisq-network.

the class BuyerSendCounterCurrencyTransferStartedMessage method run.

@Override
protected void run() {
    try {
        runInterceptHook();
        BtcWalletService walletService = processModel.getBtcWalletService();
        final String id = processModel.getOfferId();
        AddressEntry payoutAddressEntry = walletService.getOrCreateAddressEntry(id, AddressEntry.Context.TRADE_PAYOUT);
        final CounterCurrencyTransferStartedMessage message = new CounterCurrencyTransferStartedMessage(id, payoutAddressEntry.getAddressString(), processModel.getMyNodeAddress(), processModel.getPayoutTxSignature(), trade.getCounterCurrencyTxId(), UUID.randomUUID().toString());
        log.info("Send message to peer. tradeId={}, message{}", id, message);
        trade.setState(Trade.State.BUYER_SENT_FIAT_PAYMENT_INITIATED_MSG);
        processModel.getP2PService().sendEncryptedMailboxMessage(trade.getTradingPeerNodeAddress(), processModel.getTradingPeer().getPubKeyRing(), message, new SendMailboxMessageListener() {

            @Override
            public void onArrived() {
                log.info("Message arrived at peer. tradeId={}", id);
                trade.setState(Trade.State.BUYER_SAW_ARRIVED_FIAT_PAYMENT_INITIATED_MSG);
                complete();
            }

            @Override
            public void onStoredInMailbox() {
                log.info("Message stored in mailbox. tradeId={}", id);
                trade.setState(Trade.State.BUYER_STORED_IN_MAILBOX_FIAT_PAYMENT_INITIATED_MSG);
                complete();
            }

            @Override
            public void onFault(String errorMessage) {
                log.error("sendEncryptedMailboxMessage failed. message=" + message);
                trade.setState(Trade.State.BUYER_SEND_FAILED_FIAT_PAYMENT_INITIATED_MSG);
                appendToErrorMessage("Sending message failed: message=" + message + "\nerrorMessage=" + errorMessage);
                failed(errorMessage);
            }
        });
    } catch (Throwable t) {
        failed(t);
    }
}
Also used : BtcWalletService(bisq.core.btc.wallet.BtcWalletService) AddressEntry(bisq.core.btc.AddressEntry) CounterCurrencyTransferStartedMessage(bisq.core.trade.messages.CounterCurrencyTransferStartedMessage) SendMailboxMessageListener(bisq.network.p2p.SendMailboxMessageListener)

Aggregations

SendMailboxMessageListener (bisq.network.p2p.SendMailboxMessageListener)10 Date (java.util.Date)5 DisputeCommunicationMessage (bisq.core.arbitration.messages.DisputeCommunicationMessage)4 NodeAddress (bisq.network.p2p.NodeAddress)4 PubKeyRing (bisq.common.crypto.PubKeyRing)3 Contract (bisq.core.trade.Contract)3 AddressEntry (bisq.core.btc.AddressEntry)2 BtcWalletService (bisq.core.btc.wallet.BtcWalletService)2 PrivateNotificationPayload (bisq.core.alert.PrivateNotificationPayload)1 DisputeResultMessage (bisq.core.arbitration.messages.DisputeResultMessage)1 OpenNewDisputeMessage (bisq.core.arbitration.messages.OpenNewDisputeMessage)1 PeerOpenedDisputeMessage (bisq.core.arbitration.messages.PeerOpenedDisputeMessage)1 PeerPublishedDisputePayoutTxMessage (bisq.core.arbitration.messages.PeerPublishedDisputePayoutTxMessage)1 PaymentAccountPayload (bisq.core.payment.payload.PaymentAccountPayload)1 CounterCurrencyTransferStartedMessage (bisq.core.trade.messages.CounterCurrencyTransferStartedMessage)1 DepositTxPublishedMessage (bisq.core.trade.messages.DepositTxPublishedMessage)1 PayoutTxPublishedMessage (bisq.core.trade.messages.PayoutTxPublishedMessage)1 PublishDepositTxRequest (bisq.core.trade.messages.PublishDepositTxRequest)1 AutoTooltipButton (bisq.desktop.components.AutoTooltipButton)1 InputTextField (bisq.desktop.components.InputTextField)1