Search in sources :

Example 1 with PayoutTxFinalizedMessage

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

Example 2 with PayoutTxFinalizedMessage

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

the class ProcessPayoutTxFinalizedMessage method run.

@Override
protected void run() {
    try {
        runInterceptHook();
        log.debug("current trade state " + trade.getState());
        PayoutTxFinalizedMessage message = (PayoutTxFinalizedMessage) processModel.getTradeMessage();
        checkTradeId(processModel.getId(), message);
        checkNotNull(message);
        checkArgument(message.payoutTx != null);
        trade.setPayoutTx(processModel.getTradeWalletService().addTransactionToWallet(message.payoutTx));
        // update to the latest peer address of our peer if the message is correct
        trade.setTradingPeerNodeAddress(processModel.getTempTradingPeerNodeAddress());
        removeMailboxMessageAfterProcessing();
        trade.setState(Trade.State.SELLER_RECEIVED_AND_COMMITTED_PAYOUT_TX);
        complete();
    } catch (Throwable t) {
        failed(t);
    }
}
Also used : PayoutTxFinalizedMessage(io.bitsquare.trade.protocol.trade.messages.PayoutTxFinalizedMessage)

Aggregations

PayoutTxFinalizedMessage (io.bitsquare.trade.protocol.trade.messages.PayoutTxFinalizedMessage)2 SendMailboxMessageListener (io.bitsquare.p2p.messaging.SendMailboxMessageListener)1