cancel offer waits for result

This commit is contained in:
woodser 2024-03-15 10:07:31 -04:00
parent 4a57b26469
commit 216260da85
4 changed files with 20 additions and 21 deletions

View file

@ -458,8 +458,8 @@ public class CoreApi {
paymentAccount);
}
public void cancelOffer(String id) {
coreOffersService.cancelOffer(id);
public void cancelOffer(String id, ResultHandler resultHandler, ErrorMessageHandler errorMessageHandler) {
coreOffersService.cancelOffer(id, resultHandler, errorMessageHandler);
}
///////////////////////////////////////////////////////////////////////////////////////////

View file

@ -38,6 +38,7 @@ import com.google.inject.Inject;
import com.google.inject.Singleton;
import haveno.common.crypto.KeyRing;
import haveno.common.handlers.ErrorMessageHandler;
import haveno.common.handlers.ResultHandler;
import static haveno.common.util.MathUtils.exactMultiply;
import static haveno.common.util.MathUtils.roundDoubleToLong;
import static haveno.common.util.MathUtils.scaleUpByPowerOf10;
@ -236,14 +237,9 @@ public class CoreOffersService {
paymentAccount);
}
void cancelOffer(String id) {
void cancelOffer(String id, ResultHandler resultHandler, ErrorMessageHandler errorMessageHandler) {
Offer offer = getMyOffer(id).getOffer();
openOfferManager.removeOffer(offer,
() -> {
},
errorMessage -> {
throw new IllegalStateException(errorMessage);
});
openOfferManager.removeOffer(offer, resultHandler, errorMessageHandler);
}
// -------------------------- PRIVATE HELPERS -----------------------------

View file

@ -620,9 +620,13 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe
if (!offersToBeEdited.containsKey(openOffer.getId())) {
if (openOffer.isDeactivated()) {
onCancelled(openOffer);
resultHandler.handleResult();
} else {
offerBookService.removeOffer(openOffer.getOffer().getOfferPayload(),
() -> onCancelled(openOffer),
() -> {
onCancelled(openOffer);
resultHandler.handleResult();
},
errorMessageHandler);
}
} else {

View file

@ -140,11 +140,7 @@ class GrpcOffersService extends OffersImplBase {
@Override
public void postOffer(PostOfferRequest req,
StreamObserver<PostOfferReply> responseObserver) {
GrpcErrorMessageHandler errorMessageHandler =
new GrpcErrorMessageHandler(getPostOfferMethod().getFullMethodName(),
responseObserver,
exceptionHandler,
log);
GrpcErrorMessageHandler errorMessageHandler = new GrpcErrorMessageHandler(getPostOfferMethod().getFullMethodName(), responseObserver, exceptionHandler, log);
try {
coreApi.postOffer(
req.getCurrencyCode(),
@ -170,8 +166,7 @@ class GrpcOffersService extends OffersImplBase {
responseObserver.onCompleted();
},
errorMessage -> {
if (!errorMessageHandler.isErrorHandled())
errorMessageHandler.handleErrorMessage(errorMessage);
if (!errorMessageHandler.isErrorHandled()) errorMessageHandler.handleErrorMessage(errorMessage);
});
} catch (Throwable cause) {
exceptionHandler.handleException(log, cause, responseObserver);
@ -181,11 +176,15 @@ class GrpcOffersService extends OffersImplBase {
@Override
public void cancelOffer(CancelOfferRequest req,
StreamObserver<CancelOfferReply> responseObserver) {
GrpcErrorMessageHandler errorMessageHandler = new GrpcErrorMessageHandler(getCancelOfferMethod().getFullMethodName(), responseObserver, exceptionHandler, log);
try {
coreApi.cancelOffer(req.getId());
var reply = CancelOfferReply.newBuilder().build();
responseObserver.onNext(reply);
responseObserver.onCompleted();
coreApi.cancelOffer(req.getId(), () -> {
var reply = CancelOfferReply.newBuilder().build();
responseObserver.onNext(reply);
responseObserver.onCompleted();
}, errorMessage -> {
if (!errorMessageHandler.isErrorHandled()) errorMessageHandler.handleErrorMessage(errorMessage);
});
} catch (Throwable cause) {
exceptionHandler.handleException(log, cause, responseObserver);
}