Search in sources :

Example 1 with FinalizePayoutTxRequest

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

Example 2 with FinalizePayoutTxRequest

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

the class SendFinalizePayoutTxRequest method run.

@Override
protected void run() {
    try {
        runInterceptHook();
        if (trade.getTradingPeerNodeAddress() != null) {
            WalletService walletService = processModel.getWalletService();
            AddressEntry sellerPayoutAddressEntry = walletService.getOrCreateAddressEntry(processModel.getOffer().getId(), AddressEntry.Context.TRADE_PAYOUT);
            FinalizePayoutTxRequest message = new FinalizePayoutTxRequest(processModel.getId(), processModel.getPayoutTxSignature(), sellerPayoutAddressEntry.getAddressString(), trade.getLockTimeAsBlockHeight(), processModel.getMyNodeAddress());
            processModel.getP2PService().sendEncryptedMailboxMessage(trade.getTradingPeerNodeAddress(), processModel.tradingPeer.getPubKeyRing(), message, new SendMailboxMessageListener() {

                @Override
                public void onArrived() {
                    log.trace("Message arrived at peer.");
                    trade.setState(Trade.State.SELLER_SENT_FIAT_PAYMENT_RECEIPT_MSG);
                    complete();
                }

                @Override
                public void onStoredInMailbox() {
                    log.trace("Message stored in mailbox.");
                    trade.setState(Trade.State.SELLER_SENT_FIAT_PAYMENT_RECEIPT_MSG);
                    complete();
                }

                @Override
                public void onFault(String errorMessage) {
                    appendToErrorMessage("FinalizePayoutTxRequest sending failed. errorMessage=" + errorMessage);
                    failed(errorMessage);
                }
            });
        } else {
            log.error("trade.getTradingPeerAddress() = " + trade.getTradingPeerNodeAddress());
            failed("A needed dependency is null");
        }
    } catch (Throwable t) {
        failed(t);
    }
}
Also used : AddressEntry(io.bitsquare.btc.AddressEntry) FinalizePayoutTxRequest(io.bitsquare.trade.protocol.trade.messages.FinalizePayoutTxRequest) SendMailboxMessageListener(io.bitsquare.p2p.messaging.SendMailboxMessageListener) WalletService(io.bitsquare.btc.WalletService)

Example 3 with FinalizePayoutTxRequest

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

the class ProcessFinalizePayoutTxRequest method run.

@Override
protected void run() {
    try {
        runInterceptHook();
        log.debug("current trade state " + trade.getState());
        FinalizePayoutTxRequest message = (FinalizePayoutTxRequest) processModel.getTradeMessage();
        checkTradeId(processModel.getId(), message);
        checkNotNull(message);
        processModel.tradingPeer.setSignature(checkNotNull(message.sellerSignature));
        processModel.tradingPeer.setPayoutAddressString(nonEmptyStringOf(message.sellerPayoutAddress));
        trade.setLockTimeAsBlockHeight(nonNegativeLongOf(message.lockTimeAsBlockHeight));
        // update to the latest peer address of our peer if the message is correct
        trade.setTradingPeerNodeAddress(processModel.getTempTradingPeerNodeAddress());
        removeMailboxMessageAfterProcessing();
        trade.setState(Trade.State.BUYER_RECEIVED_FIAT_PAYMENT_RECEIPT_MSG);
        complete();
    } catch (Throwable t) {
        failed(t);
    }
}
Also used : FinalizePayoutTxRequest(io.bitsquare.trade.protocol.trade.messages.FinalizePayoutTxRequest)

Aggregations

FinalizePayoutTxRequest (io.bitsquare.trade.protocol.trade.messages.FinalizePayoutTxRequest)3 AddressEntry (io.bitsquare.btc.AddressEntry)1 WalletService (io.bitsquare.btc.WalletService)1 NodeAddress (io.bitsquare.p2p.NodeAddress)1 MailboxMessage (io.bitsquare.p2p.messaging.MailboxMessage)1 SendMailboxMessageListener (io.bitsquare.p2p.messaging.SendMailboxMessageListener)1 DepositTxPublishedMessage (io.bitsquare.trade.protocol.trade.messages.DepositTxPublishedMessage)1