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."); } }
// First we check if offer is still available then we create the trade with the protocol public void onTakeOffer( Coin amount, Offer offer, String paymentAccountId, TradeResultHandler tradeResultHandler) { final OfferAvailabilityModel model = getOfferAvailabilityModel(offer); offer.checkOfferAvailability( model, () -> { if (offer.getState() == Offer.State.AVAILABLE) createTrade(amount, offer, paymentAccountId, model, tradeResultHandler); }); }
private void createTrade( Coin amount, Offer offer, String paymentAccountId, OfferAvailabilityModel model, TradeResultHandler tradeResultHandler) { Trade trade; if (offer.getDirection() == Offer.Direction.BUY) trade = new SellerAsTakerTrade(offer, amount, model.getPeerAddress(), tradableListStorage); else trade = new BuyerAsTakerTrade(offer, amount, model.getPeerAddress(), tradableListStorage); trade.setTakeOfferDate(new Date()); trade.setTakerPaymentAccountId(paymentAccountId); initTrade(trade); trades.add(trade); ((TakerTrade) trade).takeAvailableOffer(); tradeResultHandler.handleResult(trade); }
public Offer.Direction getDirection(Offer offer) { // gets called earlier than onSelectTrade event handler isOfferer = tradeManager.isMyOffer(offer); return isOfferer ? offer.getDirection() : offer.getMirroredDirection(); }
public boolean isMyOffer(Offer offer) { return offer.isMyOffer(keyRing); }
// When closing take offer view, we are not interested in the onCheckOfferAvailability result // anymore, so remove from the map public void onCancelAvailabilityRequest(Offer offer) { offer.cancelAvailabilityRequest(); }
public void checkOfferAvailability(Offer offer, ResultHandler resultHandler) { offer.checkOfferAvailability(getOfferAvailabilityModel(offer), resultHandler); }
public void onOfferRemovedFromRemoteOfferBook(Offer offer) { offer.cancelAvailabilityRequest(); }