Search in sources :

Example 1 with PayoutTxPublishedMessage

use of bisq.core.trade.messages.PayoutTxPublishedMessage in project bisq-core by bisq-network.

the class BuyerAsMakerProtocol method doApplyMailboxMessage.

// /////////////////////////////////////////////////////////////////////////////////////////
// Mailbox
// /////////////////////////////////////////////////////////////////////////////////////////
@Override
public void doApplyMailboxMessage(NetworkEnvelope networkEnvelop, Trade trade) {
    this.trade = trade;
    if (networkEnvelop instanceof MailboxMessage) {
        MailboxMessage mailboxMessage = (MailboxMessage) networkEnvelop;
        NodeAddress peerNodeAddress = mailboxMessage.getSenderNodeAddress();
        if (networkEnvelop instanceof DepositTxPublishedMessage)
            handle((DepositTxPublishedMessage) networkEnvelop, peerNodeAddress);
        else if (networkEnvelop instanceof PayoutTxPublishedMessage)
            handle((PayoutTxPublishedMessage) networkEnvelop, peerNodeAddress);
        else
            log.error("We received an unhandled MailboxMessage" + networkEnvelop.toString());
    }
}
Also used : MakerProcessDepositTxPublishedMessage(bisq.core.trade.protocol.tasks.maker.MakerProcessDepositTxPublishedMessage) DepositTxPublishedMessage(bisq.core.trade.messages.DepositTxPublishedMessage) PayoutTxPublishedMessage(bisq.core.trade.messages.PayoutTxPublishedMessage) BuyerProcessPayoutTxPublishedMessage(bisq.core.trade.protocol.tasks.buyer.BuyerProcessPayoutTxPublishedMessage) NodeAddress(bisq.network.p2p.NodeAddress) MailboxMessage(bisq.network.p2p.MailboxMessage)

Example 2 with PayoutTxPublishedMessage

use of bisq.core.trade.messages.PayoutTxPublishedMessage 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 3 with PayoutTxPublishedMessage

use of bisq.core.trade.messages.PayoutTxPublishedMessage in project bisq-core by bisq-network.

the class BuyerProcessPayoutTxPublishedMessage method run.

@Override
protected void run() {
    try {
        runInterceptHook();
        log.debug("current trade state " + trade.getState());
        PayoutTxPublishedMessage message = (PayoutTxPublishedMessage) processModel.getTradeMessage();
        Validator.checkTradeId(processModel.getOfferId(), message);
        checkNotNull(message);
        checkArgument(message.getPayoutTx() != null);
        // update to the latest peer address of our peer if the message is correct
        trade.setTradingPeerNodeAddress(processModel.getTempTradingPeerNodeAddress());
        if (trade.getPayoutTx() == null) {
            Transaction walletTx = processModel.getTradeWalletService().addTxToWallet(message.getPayoutTx());
            trade.setPayoutTx(walletTx);
            BtcWalletService.printTx("payoutTx received from peer", walletTx);
            trade.setState(Trade.State.BUYER_RECEIVED_PAYOUT_TX_PUBLISHED_MSG);
            processModel.getBtcWalletService().swapTradeEntryToAvailableEntry(trade.getId(), AddressEntry.Context.MULTI_SIG);
        } else {
            log.info("We got the payout tx already set from BuyerSetupPayoutTxListener and do nothing here. trade ID={}", trade.getId());
        }
        processModel.removeMailboxMessageAfterProcessing(trade);
        complete();
    } catch (Throwable t) {
        failed(t);
    }
}
Also used : Transaction(org.bitcoinj.core.Transaction) PayoutTxPublishedMessage(bisq.core.trade.messages.PayoutTxPublishedMessage)

Example 4 with PayoutTxPublishedMessage

use of bisq.core.trade.messages.PayoutTxPublishedMessage in project bisq-core by bisq-network.

the class BuyerAsTakerProtocol method doApplyMailboxMessage.

// /////////////////////////////////////////////////////////////////////////////////////////
// Mailbox
// /////////////////////////////////////////////////////////////////////////////////////////
@Override
public void doApplyMailboxMessage(NetworkEnvelope networkEnvelop, Trade trade) {
    this.trade = trade;
    final NodeAddress senderNodeAddress = ((MailboxMessage) networkEnvelop).getSenderNodeAddress();
    if (networkEnvelop instanceof PublishDepositTxRequest)
        handle((PublishDepositTxRequest) networkEnvelop, senderNodeAddress);
    else if (networkEnvelop instanceof PayoutTxPublishedMessage) {
        handle((PayoutTxPublishedMessage) networkEnvelop, senderNodeAddress);
    } else
        log.error("We received an unhandled MailboxMessage" + networkEnvelop.toString());
}
Also used : PayoutTxPublishedMessage(bisq.core.trade.messages.PayoutTxPublishedMessage) BuyerProcessPayoutTxPublishedMessage(bisq.core.trade.protocol.tasks.buyer.BuyerProcessPayoutTxPublishedMessage) NodeAddress(bisq.network.p2p.NodeAddress) MailboxMessage(bisq.network.p2p.MailboxMessage) TakerProcessPublishDepositTxRequest(bisq.core.trade.protocol.tasks.taker.TakerProcessPublishDepositTxRequest) PublishDepositTxRequest(bisq.core.trade.messages.PublishDepositTxRequest)

Aggregations

PayoutTxPublishedMessage (bisq.core.trade.messages.PayoutTxPublishedMessage)4 BuyerProcessPayoutTxPublishedMessage (bisq.core.trade.protocol.tasks.buyer.BuyerProcessPayoutTxPublishedMessage)2 MailboxMessage (bisq.network.p2p.MailboxMessage)2 NodeAddress (bisq.network.p2p.NodeAddress)2 DepositTxPublishedMessage (bisq.core.trade.messages.DepositTxPublishedMessage)1 PublishDepositTxRequest (bisq.core.trade.messages.PublishDepositTxRequest)1 MakerProcessDepositTxPublishedMessage (bisq.core.trade.protocol.tasks.maker.MakerProcessDepositTxPublishedMessage)1 TakerProcessPublishDepositTxRequest (bisq.core.trade.protocol.tasks.taker.TakerProcessPublishDepositTxRequest)1 SendMailboxMessageListener (bisq.network.p2p.SendMailboxMessageListener)1 Transaction (org.bitcoinj.core.Transaction)1