Search in sources :

Example 1 with DepositTxPublishedMessage

use of bisq.core.trade.messages.DepositTxPublishedMessage 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)

Example 2 with DepositTxPublishedMessage

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

the class SellerAsMakerProtocol method doApplyMailboxMessage.

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

Example 3 with DepositTxPublishedMessage

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

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

the class MakerProcessDepositTxPublishedMessage method run.

@Override
protected void run() {
    try {
        runInterceptHook();
        log.debug("current trade state " + trade.getState());
        DepositTxPublishedMessage message = (DepositTxPublishedMessage) processModel.getTradeMessage();
        Validator.checkTradeId(processModel.getOfferId(), message);
        checkNotNull(message);
        checkArgument(message.getDepositTx() != null);
        // To access tx confidence we need to add that tx into our wallet.
        Transaction txFromSerializedTx = processModel.getBtcWalletService().getTxFromSerializedTx(message.getDepositTx());
        // update with full tx
        Transaction walletTx = processModel.getTradeWalletService().addTxToWallet(txFromSerializedTx);
        trade.setDepositTx(walletTx);
        BtcWalletService.printTx("depositTx received from peer", walletTx);
        // update to the latest peer address of our peer if the message is correct
        trade.setTradingPeerNodeAddress(processModel.getTempTradingPeerNodeAddress());
        processModel.removeMailboxMessageAfterProcessing(trade);
        // If we got already the confirmation we don't want to apply an earlier state
        if (trade.getState() != Trade.State.MAKER_SAW_DEPOSIT_TX_IN_NETWORK)
            trade.setState(Trade.State.MAKER_RECEIVED_DEPOSIT_TX_PUBLISHED_MSG);
        processModel.getBtcWalletService().swapTradeEntryToAvailableEntry(trade.getId(), AddressEntry.Context.RESERVED_FOR_TRADE);
        complete();
    } catch (Throwable t) {
        failed(t);
    }
}
Also used : Transaction(org.bitcoinj.core.Transaction) DepositTxPublishedMessage(bisq.core.trade.messages.DepositTxPublishedMessage)

Aggregations

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