use of bisq.core.trade.protocol.TradeProtocol in project bisq-api by mrosseel.
the class BisqProxy method paymentReceived.
public CompletableFuture<Void> paymentReceived(String tradeId) {
final CompletableFuture<Void> futureResult = new CompletableFuture<>();
Trade trade;
try {
trade = getTrade(tradeId);
} catch (NotFoundException e) {
return failFuture(futureResult, e);
}
if (!Trade.State.SELLER_RECEIVED_FIAT_PAYMENT_INITIATED_MSG.equals(trade.getState())) {
return failFuture(futureResult, new ValidationException("Trade is not in the correct state to receive payment: " + trade.getState()));
}
TradeProtocol tradeProtocol = trade.getTradeProtocol();
if (!(tradeProtocol instanceof SellerAsTakerProtocol || tradeProtocol instanceof SellerAsMakerProtocol)) {
return failFuture(futureResult, new ValidationException("Trade is not in the correct state to receive payment: " + trade.getState()));
}
ResultHandler resultHandler = () -> futureResult.complete(null);
ErrorMessageHandler errorResultHandler = message -> futureResult.completeExceptionally(new RuntimeException(message));
// TODO I think we should check instance of tradeProtocol here instead of trade
if (trade instanceof SellerAsMakerTrade) {
((SellerAsMakerProtocol) tradeProtocol).onFiatPaymentReceived(resultHandler, errorResultHandler);
} else {
((SellerAsTakerProtocol) tradeProtocol).onFiatPaymentReceived(resultHandler, errorResultHandler);
}
return futureResult;
}
use of bisq.core.trade.protocol.TradeProtocol in project bisq-api by mrosseel.
the class BisqProxy method paymentStarted.
public CompletableFuture<Void> paymentStarted(String tradeId) {
final CompletableFuture<Void> futureResult = new CompletableFuture<>();
Trade trade;
try {
trade = getTrade(tradeId);
} catch (NotFoundException e) {
return failFuture(futureResult, e);
}
if (!Trade.State.DEPOSIT_CONFIRMED_IN_BLOCK_CHAIN.equals(trade.getState())) {
return failFuture(futureResult, new ValidationException("Trade is not in the correct state to start payment: " + trade.getState()));
}
TradeProtocol tradeProtocol = trade.getTradeProtocol();
ResultHandler resultHandler = () -> futureResult.complete(null);
ErrorMessageHandler errorResultHandler = message -> futureResult.completeExceptionally(new RuntimeException(message));
if (trade instanceof BuyerAsMakerTrade) {
((BuyerAsMakerProtocol) tradeProtocol).onFiatPaymentStarted(resultHandler, errorResultHandler);
} else {
((BuyerAsTakerProtocol) tradeProtocol).onFiatPaymentStarted(resultHandler, errorResultHandler);
}
return futureResult;
}
Aggregations