Search in sources :

Example 1 with SendMailboxMessageListener

use of io.bitsquare.p2p.messaging.SendMailboxMessageListener in project bitsquare by bitsquare.

the class SendDepositTxPublishedMessage method run.

@Override
protected void run() {
    try {
        runInterceptHook();
        if (trade.getDepositTx() != null) {
            DepositTxPublishedMessage tradeMessage = new DepositTxPublishedMessage(processModel.getId(), trade.getDepositTx().bitcoinSerialize(), processModel.getMyNodeAddress());
            processModel.getP2PService().sendEncryptedMailboxMessage(trade.getTradingPeerNodeAddress(), processModel.tradingPeer.getPubKeyRing(), tradeMessage, new SendMailboxMessageListener() {

                @Override
                public void onArrived() {
                    log.trace("Message arrived at peer.");
                    trade.setState(Trade.State.TAKER_SENT_DEPOSIT_TX_PUBLISHED_MSG);
                    complete();
                }

                @Override
                public void onStoredInMailbox() {
                    log.trace("Message stored in mailbox.");
                    trade.setState(Trade.State.TAKER_SENT_DEPOSIT_TX_PUBLISHED_MSG);
                    complete();
                }

                @Override
                public void onFault(String errorMessage) {
                    appendToErrorMessage("DepositTxPublishedMessage sending failed");
                    failed();
                }
            });
        } else {
            log.error("trade.getDepositTx() = " + trade.getDepositTx());
            failed("DepositTx is null");
        }
    } catch (Throwable t) {
        failed(t);
    }
}
Also used : DepositTxPublishedMessage(io.bitsquare.trade.protocol.trade.messages.DepositTxPublishedMessage) SendMailboxMessageListener(io.bitsquare.p2p.messaging.SendMailboxMessageListener)

Example 2 with SendMailboxMessageListener

use of io.bitsquare.p2p.messaging.SendMailboxMessageListener in project bitsquare by bitsquare.

the class SendFinalizePayoutTxRequest method run.

@Override
protected void run() {
    try {
        runInterceptHook();
        if (trade.getTradingPeerNodeAddress() != null) {
            WalletService walletService = processModel.getWalletService();
            AddressEntry sellerPayoutAddressEntry = walletService.getOrCreateAddressEntry(processModel.getOffer().getId(), AddressEntry.Context.TRADE_PAYOUT);
            FinalizePayoutTxRequest message = new FinalizePayoutTxRequest(processModel.getId(), processModel.getPayoutTxSignature(), sellerPayoutAddressEntry.getAddressString(), trade.getLockTimeAsBlockHeight(), processModel.getMyNodeAddress());
            processModel.getP2PService().sendEncryptedMailboxMessage(trade.getTradingPeerNodeAddress(), processModel.tradingPeer.getPubKeyRing(), message, new SendMailboxMessageListener() {

                @Override
                public void onArrived() {
                    log.trace("Message arrived at peer.");
                    trade.setState(Trade.State.SELLER_SENT_FIAT_PAYMENT_RECEIPT_MSG);
                    complete();
                }

                @Override
                public void onStoredInMailbox() {
                    log.trace("Message stored in mailbox.");
                    trade.setState(Trade.State.SELLER_SENT_FIAT_PAYMENT_RECEIPT_MSG);
                    complete();
                }

                @Override
                public void onFault(String errorMessage) {
                    appendToErrorMessage("FinalizePayoutTxRequest sending failed. errorMessage=" + errorMessage);
                    failed(errorMessage);
                }
            });
        } else {
            log.error("trade.getTradingPeerAddress() = " + trade.getTradingPeerNodeAddress());
            failed("A needed dependency is null");
        }
    } catch (Throwable t) {
        failed(t);
    }
}
Also used : AddressEntry(io.bitsquare.btc.AddressEntry) FinalizePayoutTxRequest(io.bitsquare.trade.protocol.trade.messages.FinalizePayoutTxRequest) SendMailboxMessageListener(io.bitsquare.p2p.messaging.SendMailboxMessageListener) WalletService(io.bitsquare.btc.WalletService)

Example 3 with SendMailboxMessageListener

use of io.bitsquare.p2p.messaging.SendMailboxMessageListener in project bitsquare by bitsquare.

the class SendPrivateNotificationWindow method addContent.

private void addContent() {
    InputTextField keyInputTextField = addLabelInputTextField(gridPane, ++rowIndex, "Key for private notification:", 10).second;
    Tuple2<Label, TextArea> labelTextAreaTuple2 = addLabelTextArea(gridPane, ++rowIndex, "Private notification:", "Enter notification");
    TextArea alertMessageTextArea = labelTextAreaTuple2.second;
    Label first = labelTextAreaTuple2.first;
    first.setMinWidth(200);
    sendButton = new Button("Send private notification");
    sendButton.setOnAction(e -> {
        if (alertMessageTextArea.getText().length() > 0 && keyInputTextField.getText().length() > 0) {
            if (!sendPrivateNotificationHandler.handle(new PrivateNotification(alertMessageTextArea.getText()), pubKeyRing, nodeAddress, keyInputTextField.getText(), new SendMailboxMessageListener() {

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

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

                @Override
                public void onFault(String errorMessage) {
                    new Popup<>().feedback("Message sending failed. error=" + errorMessage).onClose(SendPrivateNotificationWindow.this::hide).show();
                }
            }))
                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, 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(io.bitsquare.gui.util.FormBuilder.addLabelTextArea) Button(javafx.scene.control.Button) FormBuilder.addLabelInputTextField(io.bitsquare.gui.util.FormBuilder.addLabelInputTextField) InputTextField(io.bitsquare.gui.components.InputTextField) Popup(io.bitsquare.gui.main.overlays.popups.Popup) Label(javafx.scene.control.Label) PrivateNotification(io.bitsquare.alert.PrivateNotification) SendMailboxMessageListener(io.bitsquare.p2p.messaging.SendMailboxMessageListener)

Example 4 with SendMailboxMessageListener

use of io.bitsquare.p2p.messaging.SendMailboxMessageListener in project bitsquare by bitsquare.

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, p2PService.getAddress());
    disputeCommunicationMessage.addAllAttachments(attachments);
    PubKeyRing receiverPubKeyRing = null;
    NodeAddress peerNodeAddress = null;
    if (isTrader(dispute)) {
        dispute.addDisputeMessage(disputeCommunicationMessage);
        receiverPubKeyRing = dispute.getArbitratorPubKeyRing();
        peerNodeAddress = dispute.getContract().arbitratorNodeAddress;
    } 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() {
                disputeCommunicationMessage.setArrived(true);
            }

            @Override
            public void onStoredInMailbox() {
                disputeCommunicationMessage.setStoredInMailbox(true);
            }

            @Override
            public void onFault(String errorMessage) {
                log.error("sendEncryptedMessage failed");
            }
        });
    }
    return disputeCommunicationMessage;
}
Also used : PubKeyRing(io.bitsquare.common.crypto.PubKeyRing) NodeAddress(io.bitsquare.p2p.NodeAddress) SendMailboxMessageListener(io.bitsquare.p2p.messaging.SendMailboxMessageListener) Contract(io.bitsquare.trade.Contract)

Example 5 with SendMailboxMessageListener

use of io.bitsquare.p2p.messaging.SendMailboxMessageListener in project bitsquare by bitsquare.

the class DisputeManager method sendPeerPublishedPayoutTxMessage.

// winner (or buyer in case of 50/50) sends tx to other peer
private void sendPeerPublishedPayoutTxMessage(Transaction transaction, Dispute dispute, Contract contract) {
    PubKeyRing peersPubKeyRing = dispute.isDisputeOpenerIsBuyer() ? contract.getSellerPubKeyRing() : contract.getBuyerPubKeyRing();
    NodeAddress peerNodeAddress = dispute.isDisputeOpenerIsBuyer() ? contract.getSellerNodeAddress() : contract.getBuyerNodeAddress();
    log.trace("sendPeerPublishedPayoutTxMessage to peerAddress " + peerNodeAddress);
    p2PService.sendEncryptedMailboxMessage(peerNodeAddress, peersPubKeyRing, new PeerPublishedPayoutTxMessage(transaction.bitcoinSerialize(), dispute.getTradeId(), p2PService.getAddress()), new SendMailboxMessageListener() {

        @Override
        public void onArrived() {
        }

        @Override
        public void onStoredInMailbox() {
        }

        @Override
        public void onFault(String errorMessage) {
            log.error("sendEncryptedMessage failed");
        }
    });
}
Also used : PubKeyRing(io.bitsquare.common.crypto.PubKeyRing) NodeAddress(io.bitsquare.p2p.NodeAddress) SendMailboxMessageListener(io.bitsquare.p2p.messaging.SendMailboxMessageListener)

Aggregations

SendMailboxMessageListener (io.bitsquare.p2p.messaging.SendMailboxMessageListener)11 NodeAddress (io.bitsquare.p2p.NodeAddress)4 AddressEntry (io.bitsquare.btc.AddressEntry)3 WalletService (io.bitsquare.btc.WalletService)3 PubKeyRing (io.bitsquare.common.crypto.PubKeyRing)3 Contract (io.bitsquare.trade.Contract)3 PrivateNotification (io.bitsquare.alert.PrivateNotification)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 FormBuilder.addLabelTextArea (io.bitsquare.gui.util.FormBuilder.addLabelTextArea)1 DepositTxPublishedMessage (io.bitsquare.trade.protocol.trade.messages.DepositTxPublishedMessage)1 FiatTransferStartedMessage (io.bitsquare.trade.protocol.trade.messages.FiatTransferStartedMessage)1 FinalizePayoutTxRequest (io.bitsquare.trade.protocol.trade.messages.FinalizePayoutTxRequest)1 PayDepositRequest (io.bitsquare.trade.protocol.trade.messages.PayDepositRequest)1 PayoutTxFinalizedMessage (io.bitsquare.trade.protocol.trade.messages.PayoutTxFinalizedMessage)1 Insets (javafx.geometry.Insets)1 Button (javafx.scene.control.Button)1 Label (javafx.scene.control.Label)1 TextArea (javafx.scene.control.TextArea)1