Search in sources :

Example 1 with PayDepositRequest

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

the class ProcessPayDepositRequest method run.

@Override
protected void run() {
    try {
        runInterceptHook();
        log.debug("current trade state " + trade.getState());
        PayDepositRequest payDepositRequest = (PayDepositRequest) processModel.getTradeMessage();
        checkNotNull(payDepositRequest);
        checkTradeId(processModel.getId(), payDepositRequest);
        PaymentAccountContractData paymentAccountContractData = checkNotNull(payDepositRequest.takerPaymentAccountContractData);
        final PaymentAccountFilter[] appliedPaymentAccountFilter = new PaymentAccountFilter[1];
        if (processModel.isPeersPaymentAccountDataAreBanned(paymentAccountContractData, appliedPaymentAccountFilter)) {
            failed("Other trader is banned by his trading account data.\n" + "paymentAccountContractData=" + paymentAccountContractData.getPaymentDetails() + "\n" + "banFilter=" + appliedPaymentAccountFilter[0].toString());
            return;
        }
        processModel.tradingPeer.setPaymentAccountContractData(paymentAccountContractData);
        processModel.tradingPeer.setRawTransactionInputs(checkNotNull(payDepositRequest.rawTransactionInputs));
        checkArgument(payDepositRequest.rawTransactionInputs.size() > 0);
        processModel.tradingPeer.setChangeOutputValue(payDepositRequest.changeOutputValue);
        if (payDepositRequest.changeOutputAddress != null)
            processModel.tradingPeer.setChangeOutputAddress(payDepositRequest.changeOutputAddress);
        processModel.tradingPeer.setMultiSigPubKey(checkNotNull(payDepositRequest.takerMultiSigPubKey));
        processModel.tradingPeer.setPayoutAddressString(nonEmptyStringOf(payDepositRequest.takerPayoutAddressString));
        processModel.tradingPeer.setPubKeyRing(checkNotNull(payDepositRequest.takerPubKeyRing));
        processModel.tradingPeer.setAccountId(nonEmptyStringOf(payDepositRequest.takerAccountId));
        trade.setTakeOfferFeeTxId(nonEmptyStringOf(payDepositRequest.takeOfferFeeTxId));
        processModel.setTakerAcceptedArbitratorNodeAddresses(checkNotNull(payDepositRequest.acceptedArbitratorNodeAddresses));
        if (payDepositRequest.acceptedArbitratorNodeAddresses.isEmpty())
            failed("acceptedArbitratorNames must not be empty");
        trade.applyArbitratorNodeAddress(checkNotNull(payDepositRequest.arbitratorNodeAddress));
        try {
            long takersTradePrice = payDepositRequest.tradePrice;
            trade.getOffer().checkTradePriceTolerance(takersTradePrice);
            trade.setTradePrice(takersTradePrice);
        } catch (TradePriceOutOfToleranceException e) {
            failed(e.getMessage());
        } catch (Throwable e2) {
            failed(e2);
        }
        checkArgument(payDepositRequest.tradeAmount > 0);
        trade.setTradeAmount(Coin.valueOf(payDepositRequest.tradeAmount));
        // check and update to the latest peer address of our peer if the payDepositRequest is correct
        checkArgument(payDepositRequest.getSenderNodeAddress().equals(processModel.getTempTradingPeerNodeAddress()));
        trade.setTradingPeerNodeAddress(processModel.getTempTradingPeerNodeAddress());
        removeMailboxMessageAfterProcessing();
        complete();
    } catch (Throwable t) {
        failed(t);
    }
}
Also used : PayDepositRequest(io.bitsquare.trade.protocol.trade.messages.PayDepositRequest) PaymentAccountContractData(io.bitsquare.payment.PaymentAccountContractData) TradePriceOutOfToleranceException(io.bitsquare.trade.exceptions.TradePriceOutOfToleranceException) PaymentAccountFilter(io.bitsquare.filter.PaymentAccountFilter)

Example 2 with PayDepositRequest

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

PayDepositRequest (io.bitsquare.trade.protocol.trade.messages.PayDepositRequest)2 AddressEntry (io.bitsquare.btc.AddressEntry)1 WalletService (io.bitsquare.btc.WalletService)1 PaymentAccountFilter (io.bitsquare.filter.PaymentAccountFilter)1 SendMailboxMessageListener (io.bitsquare.p2p.messaging.SendMailboxMessageListener)1 PaymentAccountContractData (io.bitsquare.payment.PaymentAccountContractData)1 TradePriceOutOfToleranceException (io.bitsquare.trade.exceptions.TradePriceOutOfToleranceException)1