private void handleInitialTakeOfferRequest(TradeMessage message, Address peerAddress) { log.trace( "handleNewMessage: message = " + message.getClass().getSimpleName() + " from " + peerAddress); try { nonEmptyStringOf(message.tradeId); } catch (Throwable t) { log.warn("Invalid requestDepositTxInputsMessage " + message.toString()); return; } Optional<OpenOffer> openOfferOptional = openOfferManager.findOpenOffer(message.tradeId); if (openOfferOptional.isPresent() && openOfferOptional.get().getState() == OpenOffer.State.AVAILABLE) { Offer offer = openOfferOptional.get().getOffer(); openOfferManager.reserveOpenOffer(openOfferOptional.get()); Trade trade; if (offer.getDirection() == Offer.Direction.BUY) trade = new BuyerAsOffererTrade(offer, tradableListStorage); else trade = new SellerAsOffererTrade(offer, tradableListStorage); trade.setStorage(tradableListStorage); initTrade(trade); trades.add(trade); ((OffererTrade) trade).handleTakeOfferRequest(message, peerAddress); } else { // TODO respond // (RequestDepositTxInputsMessage)message. // messageService.sendEncryptedMessage(peerAddress,messageWithPubKey.getMessage().); log.info("We received a take offer request but don't have that offer anymore."); } }
private void initPendingTrades() { if (firstPeerAuthenticatedListener != null) p2PService.removeP2PServiceListener(firstPeerAuthenticatedListener); List<Trade> failedTrades = new ArrayList<>(); for (Trade trade : trades) { // We continue an interrupted trade. // TODO if the peer has changed its IP address, we need to make another findPeer request. At // the moment we use the peer stored in trade to // continue the trade, but that might fail. // TODO /* if (trade.isFailedState()) { failedTrades.add(trade); } else {*/ trade.setStorage(tradableListStorage); trade.updateDepositTxFromWallet(tradeWalletService); initTrade(trade); // after we are authenticated we remove mailbox messages. DecryptedMsgWithPubKey mailboxMessage = trade.getMailboxMessage(); if (mailboxMessage != null) { log.trace("initPendingTrades/removeEntryFromMailbox mailboxMessage = " + mailboxMessage); p2PService.removeEntryFromMailbox(mailboxMessage); trade.setMailboxMessage(null); } // } } pendingTradesInitialized.set(true); failedTrades.stream().filter(Trade::isTakerFeePaid).forEach(this::addTradeToFailedTrades); }