Search in sources :

Example 1 with DepositTxPublishedMessage

use of io.bitsquare.trade.protocol.trade.messages.DepositTxPublishedMessage 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 DepositTxPublishedMessage

use of io.bitsquare.trade.protocol.trade.messages.DepositTxPublishedMessage in project bitsquare by bitsquare.

the class ProcessDepositTxPublishedMessage method run.

@Override
protected void run() {
    try {
        runInterceptHook();
        log.debug("current trade state " + trade.getState());
        DepositTxPublishedMessage message = (DepositTxPublishedMessage) processModel.getTradeMessage();
        checkTradeId(processModel.getId(), message);
        checkNotNull(message);
        checkArgument(message.depositTx != null);
        // To access tx confidence we need to add that tx into our wallet.
        Transaction transactionFromSerializedTx = processModel.getWalletService().getTransactionFromSerializedTx(message.depositTx);
        // update with full tx
        trade.setDepositTx(processModel.getTradeWalletService().addTransactionToWallet(transactionFromSerializedTx));
        if (trade instanceof OffererTrade)
            processModel.getOpenOfferManager().closeOpenOffer(trade.getOffer());
        // update to the latest peer address of our peer if the message is correct
        trade.setTradingPeerNodeAddress(processModel.getTempTradingPeerNodeAddress());
        removeMailboxMessageAfterProcessing();
        trade.setState(Trade.State.OFFERER_RECEIVED_DEPOSIT_TX_PUBLISHED_MSG);
        complete();
    } catch (Throwable t) {
        failed(t);
    }
}
Also used : Transaction(org.bitcoinj.core.Transaction) DepositTxPublishedMessage(io.bitsquare.trade.protocol.trade.messages.DepositTxPublishedMessage) OffererTrade(io.bitsquare.trade.OffererTrade)

Example 3 with DepositTxPublishedMessage

use of io.bitsquare.trade.protocol.trade.messages.DepositTxPublishedMessage in project bitsquare by bitsquare.

the class BuyerAsOffererProtocol method doApplyMailboxMessage.

///////////////////////////////////////////////////////////////////////////////////////////
// Mailbox
///////////////////////////////////////////////////////////////////////////////////////////
@Override
public void doApplyMailboxMessage(Message message, Trade trade) {
    this.trade = trade;
    if (message instanceof MailboxMessage) {
        MailboxMessage mailboxMessage = (MailboxMessage) message;
        NodeAddress peerNodeAddress = mailboxMessage.getSenderNodeAddress();
        if (message instanceof FinalizePayoutTxRequest) {
            handle((FinalizePayoutTxRequest) message, peerNodeAddress);
        } else if (message instanceof DepositTxPublishedMessage) {
            handle((DepositTxPublishedMessage) message, peerNodeAddress);
        }
    }
}
Also used : FinalizePayoutTxRequest(io.bitsquare.trade.protocol.trade.messages.FinalizePayoutTxRequest) DepositTxPublishedMessage(io.bitsquare.trade.protocol.trade.messages.DepositTxPublishedMessage) NodeAddress(io.bitsquare.p2p.NodeAddress) MailboxMessage(io.bitsquare.p2p.messaging.MailboxMessage)

Aggregations

DepositTxPublishedMessage (io.bitsquare.trade.protocol.trade.messages.DepositTxPublishedMessage)3 NodeAddress (io.bitsquare.p2p.NodeAddress)1 MailboxMessage (io.bitsquare.p2p.messaging.MailboxMessage)1 SendMailboxMessageListener (io.bitsquare.p2p.messaging.SendMailboxMessageListener)1 OffererTrade (io.bitsquare.trade.OffererTrade)1 FinalizePayoutTxRequest (io.bitsquare.trade.protocol.trade.messages.FinalizePayoutTxRequest)1 Transaction (org.bitcoinj.core.Transaction)1