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.");
}
}
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());
}
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;
}
Aggregations