Search in sources :

Example 6 with SendMailboxMessageListener

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

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, p2PService.getAddress());
    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()), 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");
        }
    });
}
Also used : NodeAddress(io.bitsquare.p2p.NodeAddress) SendMailboxMessageListener(io.bitsquare.p2p.messaging.SendMailboxMessageListener) Contract(io.bitsquare.trade.Contract)

Example 7 with SendMailboxMessageListener

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

the class DisputeManager method sendOpenNewDisputeMessage.

public void sendOpenNewDisputeMessage(Dispute dispute, boolean reOpen, ResultHandler resultHandler, FaultHandler faultHandler) {
    if (!disputes.contains(dispute)) {
        final Optional<Dispute> storedDisputeOptional = findDispute(dispute.getTradeId(), dispute.getTraderId());
        if (!storedDisputeOptional.isPresent() || reOpen) {
            DisputeCommunicationMessage disputeCommunicationMessage = new DisputeCommunicationMessage(dispute.getTradeId(), keyRing.getPubKeyRing().hashCode(), true, "System message: " + (dispute.isSupportTicket() ? "You opened a request for support." : "You opened a request for a dispute.\n\n" + disputeInfo), p2PService.getAddress());
            disputeCommunicationMessage.setIsSystemMessage(true);
            dispute.addDisputeMessage(disputeCommunicationMessage);
            if (!reOpen) {
                disputes.add(dispute);
                disputesObservableList.add(dispute);
            }
            p2PService.sendEncryptedMailboxMessage(dispute.getContract().arbitratorNodeAddress, dispute.getArbitratorPubKeyRing(), new OpenNewDisputeMessage(dispute, p2PService.getAddress()), new SendMailboxMessageListener() {

                @Override
                public void onArrived() {
                    disputeCommunicationMessage.setArrived(true);
                    resultHandler.handleResult();
                }

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

                @Override
                public void onFault(String errorMessage) {
                    log.error("sendEncryptedMessage failed");
                    faultHandler.handleFault("Sending dispute message failed: " + errorMessage, new MessageDeliveryFailedException());
                }
            });
        } else {
            final String msg = "We got a dispute already open for that trade and trading peer.\n" + "TradeId = " + dispute.getTradeId();
            log.warn(msg);
            faultHandler.handleFault(msg, new DisputeAlreadyOpenException());
        }
    } else {
        final String msg = "We got a dispute msg what we have already stored. TradeId = " + dispute.getTradeId();
        log.warn(msg);
        faultHandler.handleFault(msg, new DisputeAlreadyOpenException());
    }
}
Also used : SendMailboxMessageListener(io.bitsquare.p2p.messaging.SendMailboxMessageListener)

Example 8 with SendMailboxMessageListener

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

the class DisputeManager method sendPeerOpenedDisputeMessage.

// arbitrator sends that to trading peer when he received openDispute request
private void sendPeerOpenedDisputeMessage(Dispute disputeFromOpener) {
    Contract contractFromOpener = disputeFromOpener.getContract();
    PubKeyRing pubKeyRing = disputeFromOpener.isDisputeOpenerIsBuyer() ? contractFromOpener.getSellerPubKeyRing() : contractFromOpener.getBuyerPubKeyRing();
    Dispute dispute = new Dispute(disputeStorage, disputeFromOpener.getTradeId(), pubKeyRing.hashCode(), !disputeFromOpener.isDisputeOpenerIsBuyer(), !disputeFromOpener.isDisputeOpenerIsOfferer(), pubKeyRing, disputeFromOpener.getTradeDate(), contractFromOpener, disputeFromOpener.getContractHash(), disputeFromOpener.getDepositTxSerialized(), disputeFromOpener.getPayoutTxSerialized(), disputeFromOpener.getDepositTxId(), disputeFromOpener.getPayoutTxId(), disputeFromOpener.getContractAsJson(), disputeFromOpener.getOffererContractSignature(), disputeFromOpener.getTakerContractSignature(), disputeFromOpener.getArbitratorPubKeyRing(), disputeFromOpener.isSupportTicket());
    final Optional<Dispute> storedDisputeOptional = findDispute(dispute.getTradeId(), dispute.getTraderId());
    if (!storedDisputeOptional.isPresent()) {
        DisputeCommunicationMessage disputeCommunicationMessage = new DisputeCommunicationMessage(dispute.getTradeId(), keyRing.getPubKeyRing().hashCode(), true, "System message: " + (dispute.isSupportTicket() ? "Your trading peer has requested support due technical problems. Please wait for further instructions." : "Your trading peer has requested a dispute.\n\n" + disputeInfo), p2PService.getAddress());
        disputeCommunicationMessage.setIsSystemMessage(true);
        dispute.addDisputeMessage(disputeCommunicationMessage);
        disputes.add(dispute);
        disputesObservableList.add(dispute);
        // we mirrored dispute already!
        Contract contract = dispute.getContract();
        PubKeyRing peersPubKeyRing = dispute.isDisputeOpenerIsBuyer() ? contract.getBuyerPubKeyRing() : contract.getSellerPubKeyRing();
        NodeAddress peerNodeAddress = dispute.isDisputeOpenerIsBuyer() ? contract.getBuyerNodeAddress() : contract.getSellerNodeAddress();
        log.trace("sendPeerOpenedDisputeMessage to peerAddress " + peerNodeAddress);
        p2PService.sendEncryptedMailboxMessage(peerNodeAddress, peersPubKeyRing, new PeerOpenedDisputeMessage(dispute, p2PService.getAddress()), 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");
            }
        });
    } else {
        log.warn("We got a dispute already open for that trade and trading peer.\n" + "TradeId = " + dispute.getTradeId());
    }
}
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 9 with SendMailboxMessageListener

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

the class SendFiatTransferStartedMessage method run.

@Override
protected void run() {
    try {
        runInterceptHook();
        WalletService walletService = processModel.getWalletService();
        AddressEntry payoutAddressEntry = walletService.getOrCreateAddressEntry(processModel.getOffer().getId(), AddressEntry.Context.TRADE_PAYOUT);
        processModel.getP2PService().sendEncryptedMailboxMessage(trade.getTradingPeerNodeAddress(), processModel.tradingPeer.getPubKeyRing(), new FiatTransferStartedMessage(processModel.getId(), payoutAddressEntry.getAddressString(), processModel.getMyNodeAddress()), new SendMailboxMessageListener() {

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

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

            @Override
            public void onFault(String errorMessage) {
                appendToErrorMessage("FiatTransferStartedMessage sending failed");
                failed(errorMessage);
            }
        });
    } catch (Throwable t) {
        failed(t);
    }
}
Also used : AddressEntry(io.bitsquare.btc.AddressEntry) FiatTransferStartedMessage(io.bitsquare.trade.protocol.trade.messages.FiatTransferStartedMessage) SendMailboxMessageListener(io.bitsquare.p2p.messaging.SendMailboxMessageListener) WalletService(io.bitsquare.btc.WalletService)

Example 10 with SendMailboxMessageListener

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

the class SendPayoutTxFinalizedMessage method run.

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

                @Override
                public void onArrived() {
                    log.trace("Message arrived at peer.");
                    complete();
                }

                @Override
                public void onStoredInMailbox() {
                    log.trace("Message stored in mailbox.");
                    complete();
                }

                @Override
                public void onFault(String errorMessage) {
                    appendToErrorMessage("PayoutTxFinalizedMessage sending failed. errorMessage=" + errorMessage);
                    failed(errorMessage);
                }
            });
            // state must not be set in onArrived or onStoredInMailbox handlers as we would get that 
            // called delayed and would overwrite the broad cast state set by the next task
            trade.setState(Trade.State.BUYER_STARTED_SEND_PAYOUT_TX);
        } else {
            log.error("trade.getPayoutTx() = " + trade.getPayoutTx());
            failed("PayoutTx is null");
        }
    } catch (Throwable t) {
        failed(t);
    }
}
Also used : SendMailboxMessageListener(io.bitsquare.p2p.messaging.SendMailboxMessageListener) PayoutTxFinalizedMessage(io.bitsquare.trade.protocol.trade.messages.PayoutTxFinalizedMessage)

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