Search in sources :

Example 11 with SendMailboxMessageListener

use of io.bitsquare.p2p.messaging.SendMailboxMessageListener in project bitsquare by bitsquare.

the class SendPayDepositRequest method run.

@Override
protected void run() {
    try {
        runInterceptHook();
        checkNotNull(trade.getTradeAmount(), "TradeAmount must not be null");
        checkNotNull(trade.getTakeOfferFeeTxId(), "TakeOfferFeeTxId must not be null");
        WalletService walletService = processModel.getWalletService();
        AddressEntry takerMultiSigPubKeyAddressEntry = walletService.getOrCreateAddressEntry(processModel.getOffer().getId(), AddressEntry.Context.MULTI_SIG);
        AddressEntry takerPayoutAddressEntry = walletService.getOrCreateAddressEntry(processModel.getOffer().getId(), AddressEntry.Context.TRADE_PAYOUT);
        byte[] takerMultiSigPubKey = takerMultiSigPubKeyAddressEntry.getPubKey();
        String takerPayoutAddressString = takerPayoutAddressEntry.getAddressString();
        PayDepositRequest payDepositRequest = new PayDepositRequest(processModel.getMyNodeAddress(), processModel.getId(), trade.getTradeAmount().value, trade.getTradePrice().value, processModel.getRawTransactionInputs(), processModel.getChangeOutputValue(), processModel.getChangeOutputAddress(), takerMultiSigPubKey, takerPayoutAddressString, processModel.getPubKeyRing(), processModel.getPaymentAccountContractData(trade), processModel.getAccountId(), trade.getTakeOfferFeeTxId(), new ArrayList<>(processModel.getUser().getAcceptedArbitratorAddresses()), trade.getArbitratorNodeAddress());
        processModel.getP2PService().sendEncryptedMailboxMessage(trade.getTradingPeerNodeAddress(), processModel.tradingPeer.getPubKeyRing(), payDepositRequest, 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("PayDepositRequest sending failed");
                failed();
            }
        });
    } catch (Throwable t) {
        failed(t);
    }
}
Also used : PayDepositRequest(io.bitsquare.trade.protocol.trade.messages.PayDepositRequest) AddressEntry(io.bitsquare.btc.AddressEntry) SendMailboxMessageListener(io.bitsquare.p2p.messaging.SendMailboxMessageListener) WalletService(io.bitsquare.btc.WalletService)

Aggregations

SendMailboxMessageListener (io.bitsquare.p2p.messaging.SendMailboxMessageListener)11 NodeAddress (io.bitsquare.p2p.NodeAddress)4 AddressEntry (io.bitsquare.btc.AddressEntry)3 WalletService (io.bitsquare.btc.WalletService)3 PubKeyRing (io.bitsquare.common.crypto.PubKeyRing)3 Contract (io.bitsquare.trade.Contract)3 PrivateNotification (io.bitsquare.alert.PrivateNotification)1 InputTextField (io.bitsquare.gui.components.InputTextField)1 Popup (io.bitsquare.gui.main.overlays.popups.Popup)1 FormBuilder.addLabelInputTextField (io.bitsquare.gui.util.FormBuilder.addLabelInputTextField)1 FormBuilder.addLabelTextArea (io.bitsquare.gui.util.FormBuilder.addLabelTextArea)1 DepositTxPublishedMessage (io.bitsquare.trade.protocol.trade.messages.DepositTxPublishedMessage)1 FiatTransferStartedMessage (io.bitsquare.trade.protocol.trade.messages.FiatTransferStartedMessage)1 FinalizePayoutTxRequest (io.bitsquare.trade.protocol.trade.messages.FinalizePayoutTxRequest)1 PayDepositRequest (io.bitsquare.trade.protocol.trade.messages.PayDepositRequest)1 PayoutTxFinalizedMessage (io.bitsquare.trade.protocol.trade.messages.PayoutTxFinalizedMessage)1 Insets (javafx.geometry.Insets)1 Button (javafx.scene.control.Button)1 Label (javafx.scene.control.Label)1 TextArea (javafx.scene.control.TextArea)1