Search in sources :

Example 6 with OpenOffer

use of bisq.core.offer.OpenOffer 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)

Example 7 with OpenOffer

use of bisq.core.offer.OpenOffer in project bisq-core by bisq-network.

the class TradableListTest method protoTesting.

@Test
public void protoTesting(@Mocked OfferPayload offerPayload) {
    Storage<TradableList<OpenOffer>> storage = new Storage<>(null, null);
    TradableList<OpenOffer> openOfferTradableList = new TradableList<>(storage, "filename");
    PB.PersistableEnvelope message = (PB.PersistableEnvelope) openOfferTradableList.toProtoMessage();
    assertTrue(message.getMessageCase().equals(TRADABLE_LIST));
    // test adding an OpenOffer and convert toProto
    Offer offer = new Offer(offerPayload);
    OpenOffer openOffer = new OpenOffer(offer, storage);
    // openOfferTradableList = new TradableList<OpenOffer>(storage,Lists.newArrayList(openOffer));
    openOfferTradableList.add(openOffer);
    message = (PB.PersistableEnvelope) openOfferTradableList.toProtoMessage();
    assertTrue(message.getMessageCase().equals(TRADABLE_LIST));
    assertEquals(1, message.getTradableList().getTradableList().size());
}
Also used : PB(io.bisq.generated.protobuffer.PB) Storage(bisq.common.storage.Storage) Offer(bisq.core.offer.Offer) OpenOffer(bisq.core.offer.OpenOffer) OpenOffer(bisq.core.offer.OpenOffer) Test(org.junit.Test)

Example 8 with OpenOffer

use of bisq.core.offer.OpenOffer in project bisq-api by mrosseel.

the class BisqProxy method offerCancel.

public CompletableFuture<Void> offerCancel(String offerId) {
    final CompletableFuture<Void> futureResult = new CompletableFuture<>();
    Optional<OpenOffer> openOfferById = openOfferManager.getOpenOfferById(offerId);
    if (!openOfferById.isPresent()) {
        return failFuture(futureResult, new NotFoundException("Offer not found: " + offerId));
    }
    openOfferManager.removeOpenOffer(openOfferById.get(), () -> futureResult.complete(null), error -> futureResult.completeExceptionally(new RuntimeException(error)));
    return futureResult;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) OpenOffer(bisq.core.offer.OpenOffer) FileNotFoundException(java.io.FileNotFoundException)

Aggregations

OpenOffer (bisq.core.offer.OpenOffer)8 Res (bisq.core.locale.Res)4 Trade (bisq.core.trade.Trade)4 PrivateNotificationManager (bisq.core.alert.PrivateNotificationManager)3 AppOptionKeys (bisq.core.app.AppOptionKeys)3 DisputeManager (bisq.core.arbitration.DisputeManager)3 Offer (bisq.core.offer.Offer)3 Preferences (bisq.core.user.Preferences)3 BSFormatter (bisq.desktop.util.BSFormatter)3 GUIUtil (bisq.desktop.util.GUIUtil)3 ObservableList (javafx.collections.ObservableList)3 Coin (org.bitcoinj.core.Coin)3 Clock (bisq.common.Clock)2 Timer (bisq.common.Timer)2 UserThread (bisq.common.UserThread)2 DevEnv (bisq.common.app.DevEnv)2 Version (bisq.common.app.Version)2 CryptoException (bisq.common.crypto.CryptoException)2 KeyRing (bisq.common.crypto.KeyRing)2 SealedAndSigned (bisq.common.crypto.SealedAndSigned)2