예제 #1
0
  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.");
    }
  }
예제 #2
0
 // 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);
       });
 }
예제 #3
0
  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);
  }
예제 #4
0
 public Offer.Direction getDirection(Offer offer) {
   // gets called earlier than onSelectTrade event handler
   isOfferer = tradeManager.isMyOffer(offer);
   return isOfferer ? offer.getDirection() : offer.getMirroredDirection();
 }
예제 #5
0
 public boolean isMyOffer(Offer offer) {
   return offer.isMyOffer(keyRing);
 }
예제 #6
0
 // 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();
 }
예제 #7
0
 public void checkOfferAvailability(Offer offer, ResultHandler resultHandler) {
   offer.checkOfferAvailability(getOfferAvailabilityModel(offer), resultHandler);
 }
예제 #8
0
 public void onOfferRemovedFromRemoteOfferBook(Offer offer) {
   offer.cancelAvailabilityRequest();
 }