Search in sources :

Example 1 with PayDepositRequest

use of bisq.core.trade.messages.PayDepositRequest in project bisq-core by bisq-network.

the class MakerProcessPayDepositRequest method run.

@Override
protected void run() {
    try {
        runInterceptHook();
        log.debug("current trade state " + trade.getState());
        PayDepositRequest payDepositRequest = (PayDepositRequest) processModel.getTradeMessage();
        checkNotNull(payDepositRequest);
        checkTradeId(processModel.getOfferId(), payDepositRequest);
        final TradingPeer tradingPeer = processModel.getTradingPeer();
        tradingPeer.setPaymentAccountPayload(checkNotNull(payDepositRequest.getTakerPaymentAccountPayload()));
        tradingPeer.setRawTransactionInputs(checkNotNull(payDepositRequest.getRawTransactionInputs()));
        checkArgument(payDepositRequest.getRawTransactionInputs().size() > 0);
        tradingPeer.setChangeOutputValue(payDepositRequest.getChangeOutputValue());
        tradingPeer.setChangeOutputAddress(payDepositRequest.getChangeOutputAddress());
        tradingPeer.setMultiSigPubKey(checkNotNull(payDepositRequest.getTakerMultiSigPubKey()));
        tradingPeer.setPayoutAddressString(nonEmptyStringOf(payDepositRequest.getTakerPayoutAddressString()));
        tradingPeer.setPubKeyRing(checkNotNull(payDepositRequest.getTakerPubKeyRing()));
        tradingPeer.setAccountId(nonEmptyStringOf(payDepositRequest.getTakerAccountId()));
        trade.setTakerFeeTxId(nonEmptyStringOf(payDepositRequest.getTakerFeeTxId()));
        processModel.setTakerAcceptedArbitratorNodeAddresses(checkNotNull(payDepositRequest.getAcceptedArbitratorNodeAddresses()));
        processModel.setTakerAcceptedMediatorNodeAddresses(checkNotNull(payDepositRequest.getAcceptedMediatorNodeAddresses()));
        if (payDepositRequest.getAcceptedArbitratorNodeAddresses().isEmpty())
            failed("acceptedArbitratorNodeAddresses must not be empty");
        // Taker has to sign offerId (he cannot manipulate that - so we avoid to have a challenge protocol for passing the nonce we want to get signed)
        tradingPeer.setAccountAgeWitnessNonce(trade.getOffer().getId().getBytes());
        tradingPeer.setAccountAgeWitnessSignature(payDepositRequest.getAccountAgeWitnessSignatureOfOfferId());
        tradingPeer.setCurrentDate(payDepositRequest.getCurrentDate());
        trade.setArbitratorNodeAddress(checkNotNull(payDepositRequest.getArbitratorNodeAddress()));
        trade.setMediatorNodeAddress(checkNotNull(payDepositRequest.getMediatorNodeAddress()));
        try {
            long takersTradePrice = payDepositRequest.getTradePrice();
            trade.getOffer().checkTradePriceTolerance(takersTradePrice);
            trade.setTradePrice(takersTradePrice);
        } catch (TradePriceOutOfToleranceException e) {
            failed(e.getMessage());
        } catch (Throwable e2) {
            failed(e2);
        }
        checkArgument(payDepositRequest.getTradeAmount() > 0);
        trade.setTradeAmount(Coin.valueOf(payDepositRequest.getTradeAmount()));
        trade.setTradingPeerNodeAddress(processModel.getTempTradingPeerNodeAddress());
        processModel.removeMailboxMessageAfterProcessing(trade);
        complete();
    } catch (Throwable t) {
        failed(t);
    }
}
Also used : PayDepositRequest(bisq.core.trade.messages.PayDepositRequest) TradingPeer(bisq.core.trade.protocol.TradingPeer) TradePriceOutOfToleranceException(bisq.core.exceptions.TradePriceOutOfToleranceException)

Example 2 with PayDepositRequest

use of bisq.core.trade.messages.PayDepositRequest in project bisq-core by bisq-network.

the class TakerSendPayDepositRequest method run.

@Override
protected void run() {
    try {
        runInterceptHook();
        checkNotNull(trade.getTradeAmount(), "TradeAmount must not be null");
        checkNotNull(trade.getTakerFeeTxId(), "TakeOfferFeeTxId must not be null");
        final User user = processModel.getUser();
        checkNotNull(user, "User must not be null");
        final List<NodeAddress> acceptedArbitratorAddresses = user.getAcceptedArbitratorAddresses();
        final List<NodeAddress> acceptedMediatorAddresses = user.getAcceptedMediatorAddresses();
        checkNotNull(acceptedArbitratorAddresses, "acceptedArbitratorAddresses must not be null");
        checkNotNull(acceptedMediatorAddresses, "acceptedMediatorAddresses must not be null");
        BtcWalletService walletService = processModel.getBtcWalletService();
        String id = processModel.getOffer().getId();
        checkArgument(!walletService.getAddressEntry(id, AddressEntry.Context.MULTI_SIG).isPresent(), "addressEntry must not be set here.");
        AddressEntry addressEntry = walletService.getOrCreateAddressEntry(id, AddressEntry.Context.MULTI_SIG);
        byte[] takerMultiSigPubKey = addressEntry.getPubKey();
        processModel.setMyMultiSigPubKey(takerMultiSigPubKey);
        AddressEntry takerPayoutAddressEntry = walletService.getOrCreateAddressEntry(id, AddressEntry.Context.TRADE_PAYOUT);
        String takerPayoutAddressString = takerPayoutAddressEntry.getAddressString();
        final String offerId = processModel.getOfferId();
        // Taker has to use offerId as nonce (he cannot manipulate that - so we avoid to have a challenge protocol for passing the nonce we want to get signed)
        // He cannot manipulate the offerId - so we avoid to have a challenge protocol for passing the nonce we want to get signed.
        final PaymentAccountPayload paymentAccountPayload = checkNotNull(processModel.getPaymentAccountPayload(trade), "processModel.getPaymentAccountPayload(trade) must not be null");
        byte[] sig = Sig.sign(processModel.getKeyRing().getSignatureKeyPair().getPrivate(), offerId.getBytes());
        PayDepositRequest message = new PayDepositRequest(offerId, processModel.getMyNodeAddress(), trade.getTradeAmount().value, trade.getTradePrice().getValue(), trade.getTxFee().getValue(), trade.getTakerFee().getValue(), trade.isCurrencyForTakerFeeBtc(), processModel.getRawTransactionInputs(), processModel.getChangeOutputValue(), processModel.getChangeOutputAddress(), takerMultiSigPubKey, takerPayoutAddressString, processModel.getPubKeyRing(), paymentAccountPayload, processModel.getAccountId(), trade.getTakerFeeTxId(), new ArrayList<>(acceptedArbitratorAddresses), new ArrayList<>(acceptedMediatorAddresses), trade.getArbitratorNodeAddress(), trade.getMediatorNodeAddress(), UUID.randomUUID().toString(), Version.getP2PMessageVersion(), sig, new Date().getTime());
        processModel.getP2PService().sendEncryptedDirectMessage(trade.getTradingPeerNodeAddress(), processModel.getTradingPeer().getPubKeyRing(), message, new SendDirectMessageListener() {

            @Override
            public void onArrived() {
                log.debug("Message arrived at peer. tradeId={}, message{}", id, message);
                complete();
            }

            @Override
            public void onFault() {
                appendToErrorMessage("Sending message failed: message=" + message + "\nerrorMessage=" + errorMessage);
                failed();
            }
        });
    } catch (Throwable t) {
        failed(t);
    }
}
Also used : User(bisq.core.user.User) AddressEntry(bisq.core.btc.AddressEntry) PaymentAccountPayload(bisq.core.payment.payload.PaymentAccountPayload) SendDirectMessageListener(bisq.network.p2p.SendDirectMessageListener) Date(java.util.Date) PayDepositRequest(bisq.core.trade.messages.PayDepositRequest) BtcWalletService(bisq.core.btc.wallet.BtcWalletService) NodeAddress(bisq.network.p2p.NodeAddress)

Example 3 with PayDepositRequest

use of bisq.core.trade.messages.PayDepositRequest in project bisq-core by bisq-network.

the class TradeManager method handleInitialTakeOfferRequest.

private void handleInitialTakeOfferRequest(TradeMessage message, NodeAddress peerNodeAddress) {
    log.trace("handleNewMessage: message = " + message.getClass().getSimpleName() + " from " + peerNodeAddress);
    try {
        Validator.nonEmptyStringOf(message.getTradeId());
    } catch (Throwable t) {
        log.warn("Invalid requestDepositTxInputsMessage " + message.toString());
        return;
    }
    Optional<OpenOffer> openOfferOptional = openOfferManager.findOpenOffer(message.getTradeId());
    if (openOfferOptional.isPresent() && openOfferOptional.get().getState() == OpenOffer.State.AVAILABLE) {
        Offer offer = openOfferOptional.get().getOffer();
        openOfferManager.reserveOpenOffer(openOfferOptional.get());
        checkArgument(message instanceof PayDepositRequest, "message must be PayDepositRequest");
        PayDepositRequest payDepositRequest = (PayDepositRequest) message;
        Trade trade;
        if (offer.isBuyOffer())
            trade = new BuyerAsMakerTrade(offer, Coin.valueOf(payDepositRequest.getTxFee()), Coin.valueOf(payDepositRequest.getTakerFee()), payDepositRequest.isCurrencyForTakerFeeBtc(), tradableListStorage, btcWalletService);
        else
            trade = new SellerAsMakerTrade(offer, Coin.valueOf(payDepositRequest.getTxFee()), Coin.valueOf(payDepositRequest.getTakerFee()), payDepositRequest.isCurrencyForTakerFeeBtc(), tradableListStorage, btcWalletService);
        initTrade(trade, trade.getProcessModel().isUseSavingsWallet(), trade.getProcessModel().getFundsNeededForTradeAsLong());
        tradableList.add(trade);
        ((MakerTrade) trade).handleTakeOfferRequest(message, peerNodeAddress, errorMessage -> {
            if (takeOfferRequestErrorMessageHandler != null)
                takeOfferRequestErrorMessageHandler.handleErrorMessage(errorMessage);
        });
    } else {
        // TODO respond
        // (RequestDepositTxInputsMessage)message.
        // messageService.sendEncryptedMessage(peerAddress,messageWithPubKey.getMessage().);
        log.debug("We received a take offer request but don't have that offer anymore.");
    }
}
Also used : PayDepositRequest(bisq.core.trade.messages.PayDepositRequest) OpenOffer(bisq.core.offer.OpenOffer) Offer(bisq.core.offer.Offer) OpenOffer(bisq.core.offer.OpenOffer)

Aggregations

PayDepositRequest (bisq.core.trade.messages.PayDepositRequest)3 AddressEntry (bisq.core.btc.AddressEntry)1 BtcWalletService (bisq.core.btc.wallet.BtcWalletService)1 TradePriceOutOfToleranceException (bisq.core.exceptions.TradePriceOutOfToleranceException)1 Offer (bisq.core.offer.Offer)1 OpenOffer (bisq.core.offer.OpenOffer)1 PaymentAccountPayload (bisq.core.payment.payload.PaymentAccountPayload)1 TradingPeer (bisq.core.trade.protocol.TradingPeer)1 User (bisq.core.user.User)1 NodeAddress (bisq.network.p2p.NodeAddress)1 SendDirectMessageListener (bisq.network.p2p.SendDirectMessageListener)1 Date (java.util.Date)1