Search in sources :

Example 1 with SendMailboxMessageListener

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

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) {
            String sysMsg = dispute.isSupportTicket() ? Res.get("support.youOpenedTicket") : Res.get("support.youOpenedDispute", disputeInfo);
            DisputeCommunicationMessage disputeCommunicationMessage = new DisputeCommunicationMessage(dispute.getTradeId(), keyRing.getPubKeyRing().hashCode(), false, Res.get("support.systemMsg", sysMsg), null, p2PService.getAddress(), new Date().getTime(), false, false, UUID.randomUUID().toString());
            disputeCommunicationMessage.setSystemMessage(true);
            dispute.addDisputeMessage(disputeCommunicationMessage);
            if (!reOpen) {
                disputes.add(dispute);
            }
            p2PService.sendEncryptedMailboxMessage(dispute.getContract().getArbitratorNodeAddress(), dispute.getArbitratorPubKeyRing(), new OpenNewDisputeMessage(dispute, p2PService.getAddress(), UUID.randomUUID().toString()), new SendMailboxMessageListener() {

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

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

                @Override
                public void onFault(String errorMessage) {
                    log.error("sendEncryptedMailboxMessage failed. disputeCommunicationMessage=" + disputeCommunicationMessage);
                    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 : OpenNewDisputeMessage(bisq.core.arbitration.messages.OpenNewDisputeMessage) SendMailboxMessageListener(bisq.network.p2p.SendMailboxMessageListener) DisputeCommunicationMessage(bisq.core.arbitration.messages.DisputeCommunicationMessage) Date(java.util.Date)

Example 2 with SendMailboxMessageListener

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

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);
    final PeerPublishedDisputePayoutTxMessage message = new PeerPublishedDisputePayoutTxMessage(transaction.bitcoinSerialize(), dispute.getTradeId(), p2PService.getAddress(), UUID.randomUUID().toString());
    p2PService.sendEncryptedMailboxMessage(peerNodeAddress, peersPubKeyRing, message, new SendMailboxMessageListener() {

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

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

        @Override
        public void onFault(String errorMessage) {
            log.error("sendEncryptedMailboxMessage failed. message=" + message);
        }
    });
}
Also used : PubKeyRing(bisq.common.crypto.PubKeyRing) NodeAddress(bisq.network.p2p.NodeAddress) SendMailboxMessageListener(bisq.network.p2p.SendMailboxMessageListener) PeerPublishedDisputePayoutTxMessage(bisq.core.arbitration.messages.PeerPublishedDisputePayoutTxMessage)

Example 3 with SendMailboxMessageListener

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

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.isDisputeOpenerIsMaker(), pubKeyRing, disputeFromOpener.getTradeDate().getTime(), contractFromOpener, disputeFromOpener.getContractHash(), disputeFromOpener.getDepositTxSerialized(), disputeFromOpener.getPayoutTxSerialized(), disputeFromOpener.getDepositTxId(), disputeFromOpener.getPayoutTxId(), disputeFromOpener.getContractAsJson(), disputeFromOpener.getMakerContractSignature(), disputeFromOpener.getTakerContractSignature(), disputeFromOpener.getArbitratorPubKeyRing(), disputeFromOpener.isSupportTicket());
    final Optional<Dispute> storedDisputeOptional = findDispute(dispute.getTradeId(), dispute.getTraderId());
    if (!storedDisputeOptional.isPresent()) {
        String sysMsg = dispute.isSupportTicket() ? Res.get("support.peerOpenedTicket") : Res.get("support.peerOpenedDispute", disputeInfo);
        DisputeCommunicationMessage disputeCommunicationMessage = new DisputeCommunicationMessage(dispute.getTradeId(), keyRing.getPubKeyRing().hashCode(), false, Res.get("support.systemMsg", sysMsg), null, p2PService.getAddress(), new Date().getTime(), false, false, UUID.randomUUID().toString());
        disputeCommunicationMessage.setSystemMessage(true);
        dispute.addDisputeMessage(disputeCommunicationMessage);
        disputes.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(), 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);
            }
        });
    } else {
        log.warn("We got a dispute already open for that trade and trading peer.\n" + "TradeId = " + dispute.getTradeId());
    }
}
Also used : PubKeyRing(bisq.common.crypto.PubKeyRing) PeerOpenedDisputeMessage(bisq.core.arbitration.messages.PeerOpenedDisputeMessage) 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 4 with SendMailboxMessageListener

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

the class MakerSendPublishDepositTxRequest method run.

@Override
protected void run() {
    try {
        runInterceptHook();
        BtcWalletService walletService = processModel.getBtcWalletService();
        String id = processModel.getOffer().getId();
        Optional<AddressEntry> addressEntryOptional = walletService.getAddressEntry(id, AddressEntry.Context.MULTI_SIG);
        checkArgument(addressEntryOptional.isPresent(), "addressEntry must be set here.");
        AddressEntry makerPayoutAddressEntry = walletService.getOrCreateAddressEntry(id, AddressEntry.Context.TRADE_PAYOUT);
        byte[] makerMultiSigPubKey = processModel.getMyMultiSigPubKey();
        checkArgument(Arrays.equals(makerMultiSigPubKey, addressEntryOptional.get().getPubKey()), "makerMultiSigPubKey from AddressEntry must match the one from the trade data. trade id =" + id);
        final byte[] preparedDepositTx = processModel.getPreparedDepositTx();
        // Maker has to use preparedDepositTx as nonce.
        // He cannot manipulate the preparedDepositTx - so we avoid to have a challenge protocol for passing the nonce we want to get signed.
        final PaymentAccountPayload paymentAccountPayload = checkNotNull(processModel.getPaymentAccountPayload(trade), "processModel.getPaymentAccountPayload(trade) must not be null");
        byte[] sig = Sig.sign(processModel.getKeyRing().getSignatureKeyPair().getPrivate(), preparedDepositTx);
        PublishDepositTxRequest message = new PublishDepositTxRequest(processModel.getOfferId(), paymentAccountPayload, processModel.getAccountId(), makerMultiSigPubKey, trade.getContractAsJson(), trade.getMakerContractSignature(), makerPayoutAddressEntry.getAddressString(), preparedDepositTx, processModel.getRawTransactionInputs(), processModel.getMyNodeAddress(), UUID.randomUUID().toString(), sig, new Date().getTime());
        trade.setState(Trade.State.MAKER_SENT_PUBLISH_DEPOSIT_TX_REQUEST);
        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.MAKER_SAW_ARRIVED_PUBLISH_DEPOSIT_TX_REQUEST);
                complete();
            }

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

            @Override
            public void onFault(String errorMessage) {
                log.error("sendEncryptedMailboxMessage failed. message=" + message);
                trade.setState(Trade.State.MAKER_SEND_FAILED_PUBLISH_DEPOSIT_TX_REQUEST);
                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) PaymentAccountPayload(bisq.core.payment.payload.PaymentAccountPayload) SendMailboxMessageListener(bisq.network.p2p.SendMailboxMessageListener) PublishDepositTxRequest(bisq.core.trade.messages.PublishDepositTxRequest) Date(java.util.Date)

Example 5 with SendMailboxMessageListener

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

the class TakerSendDepositTxPublishedMessage method run.

@Override
protected void run() {
    try {
        runInterceptHook();
        if (trade.getDepositTx() != null) {
            final String id = processModel.getOfferId();
            DepositTxPublishedMessage message = new DepositTxPublishedMessage(processModel.getOfferId(), trade.getDepositTx().bitcoinSerialize(), processModel.getMyNodeAddress(), UUID.randomUUID().toString());
            trade.setState(Trade.State.TAKER_SENT_DEPOSIT_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.TAKER_SAW_ARRIVED_DEPOSIT_TX_PUBLISHED_MSG);
                    complete();
                }

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

                @Override
                public void onFault(String errorMessage) {
                    log.error("sendEncryptedMailboxMessage failed. message=" + message);
                    trade.setState(Trade.State.TAKER_SEND_FAILED_DEPOSIT_TX_PUBLISHED_MSG);
                    appendToErrorMessage("Sending message failed: message=" + message + "\nerrorMessage=" + errorMessage);
                    failed();
                }
            });
        } else {
            log.error("trade.getDepositTx() = " + trade.getDepositTx());
            failed("DepositTx is null");
        }
    } catch (Throwable t) {
        failed(t);
    }
}
Also used : DepositTxPublishedMessage(bisq.core.trade.messages.DepositTxPublishedMessage) 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