Merge branch '02-modify-txinfo' into 03-add-long-running-trade-test

This commit is contained in:
ghubstan 2021-03-15 11:23:09 -03:00
commit a2b2313d19
No known key found for this signature in database
GPG Key ID: E35592D6800A861E
4 changed files with 45 additions and 44 deletions

View File

@ -53,6 +53,7 @@ import bisq.proto.grpc.SendBtcRequest;
import bisq.proto.grpc.SetTxFeeRatePreferenceRequest; import bisq.proto.grpc.SetTxFeeRatePreferenceRequest;
import bisq.proto.grpc.SetWalletPasswordRequest; import bisq.proto.grpc.SetWalletPasswordRequest;
import bisq.proto.grpc.StopRequest; import bisq.proto.grpc.StopRequest;
import bisq.proto.grpc.TakeOfferReply;
import bisq.proto.grpc.TakeOfferRequest; import bisq.proto.grpc.TakeOfferRequest;
import bisq.proto.grpc.TradeInfo; import bisq.proto.grpc.TradeInfo;
import bisq.proto.grpc.TxFeeRateInfo; import bisq.proto.grpc.TxFeeRateInfo;
@ -309,41 +310,21 @@ public final class GrpcClient {
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
public TradeInfo takeOffer(String offerId, String paymentAccountId, String takerFeeCurrencyCode) { public TakeOfferReply getTakeOfferReply(String offerId, String paymentAccountId, String takerFeeCurrencyCode) {
var request = TakeOfferRequest.newBuilder() var request = TakeOfferRequest.newBuilder()
.setOfferId(offerId) .setOfferId(offerId)
.setPaymentAccountId(paymentAccountId) .setPaymentAccountId(paymentAccountId)
.setTakerFeeCurrencyCode(takerFeeCurrencyCode) .setTakerFeeCurrencyCode(takerFeeCurrencyCode)
.build(); .build();
var reply = grpcStubs.tradesService.takeOffer(request); return grpcStubs.tradesService.takeOffer(request);
if (reply.hasTrade()) { }
public TradeInfo takeOffer(String offerId, String paymentAccountId, String takerFeeCurrencyCode) {
var reply = getTakeOfferReply(offerId, paymentAccountId, takerFeeCurrencyCode);
if (reply.hasTrade())
return reply.getTrade(); return reply.getTrade();
} else { else
// If there is no trade, there should be a reason in the AvailabilityResult. throw new IllegalStateException(reply.getAvailabilityResultDescription());
// Convert the enum to a user error message before throwing the exception.
switch (reply.getAvailabilityResult()) {
case MARKET_PRICE_NOT_AVAILABLE:
throw new IllegalStateException("could not take offer because market price for calculating trade price is unavailable");
case PRICE_OUT_OF_TOLERANCE:
throw new IllegalStateException("could not take offer because taker's price is outside tolerance");
case PRICE_CHECK_FAILED:
throw new IllegalStateException("could not take offer because trade price check failed");
case NO_ARBITRATORS:
throw new IllegalStateException("could not take offer because no arbitrators are available");
case NO_MEDIATORS:
throw new IllegalStateException("could not take offer because no mediators are available");
case NO_REFUND_AGENTS:
throw new IllegalStateException("could not take offer because no refund agents are available");
case USER_IGNORED:
throw new IllegalStateException("could not take offer from ignored user");
case MAKER_DENIED_API_USER:
throw new IllegalStateException("could not take offer because maker is api user");
case UNCONF_TX_LIMIT_HIT:
throw new IllegalStateException("could not take offer because you have too many unconfirmed transactions at this moment");
default:
throw new IllegalStateException("programmer error: could not take offer for unknown reason");
}
}
} }
public TradeInfo getTrade(String tradeId) { public TradeInfo getTrade(String tradeId) {

View File

@ -18,17 +18,31 @@
package bisq.core.offer; package bisq.core.offer;
public enum AvailabilityResult { public enum AvailabilityResult {
UNKNOWN_FAILURE, UNKNOWN_FAILURE("cannot take offer for unknown reason"),
AVAILABLE, AVAILABLE("offer available"),
OFFER_TAKEN, OFFER_TAKEN("offer taken"),
PRICE_OUT_OF_TOLERANCE, PRICE_OUT_OF_TOLERANCE("cannot take offer because taker's price is outside tolerance"),
MARKET_PRICE_NOT_AVAILABLE, MARKET_PRICE_NOT_AVAILABLE("cannot take offer because market price for calculating trade price is unavailable"),
@SuppressWarnings("unused") NO_ARBITRATORS, @SuppressWarnings("unused") NO_ARBITRATORS("cannot take offer because no arbitrators are available"),
NO_MEDIATORS, NO_MEDIATORS("cannot take offer because no mediators are available"),
USER_IGNORED, USER_IGNORED("cannot take offer because user is ignored"),
@SuppressWarnings("unused") MISSING_MANDATORY_CAPABILITY, @SuppressWarnings("unused") MISSING_MANDATORY_CAPABILITY("description not available"),
@SuppressWarnings("unused") NO_REFUND_AGENTS, @SuppressWarnings("unused") NO_REFUND_AGENTS("cannot take offer because no refund agents are available"),
UNCONF_TX_LIMIT_HIT, UNCONF_TX_LIMIT_HIT("cannot take offer because you have too many unconfirmed transactions at this moment"),
MAKER_DENIED_API_USER, MAKER_DENIED_API_USER("cannot take offer because maker is api user"),
PRICE_CHECK_FAILED PRICE_CHECK_FAILED("cannot take offer because trade price check failed");
private final String description;
AvailabilityResult(String description) {
this.description = description;
}
public String description() {
return description;
}
public static AvailabilityResult fromProto(protobuf.AvailabilityResult proto) {
return AvailabilityResult.valueOf(proto.name());
}
} }

View File

@ -92,9 +92,10 @@ public class GrpcErrorMessageHandler implements ErrorMessageHandler {
// The client should look at the grpc reply object's AvailabilityResult // The client should look at the grpc reply object's AvailabilityResult
// field if reply.hasTrade = false, and use it give the user a human readable msg. // field if reply.hasTrade = false, and use it give the user a human readable msg.
try { try {
AvailabilityResult availabilityResult = getAvailabilityResult(errorMessage); AvailabilityResult availabilityResultProto = getAvailabilityResult(errorMessage);
var reply = TakeOfferReply.newBuilder() var reply = TakeOfferReply.newBuilder()
.setAvailabilityResult(availabilityResult) .setAvailabilityResult(availabilityResultProto)
.setAvailabilityResultDescription(getAvailabilityResultDescription(availabilityResultProto))
.build(); .build();
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
var takeOfferResponseObserver = (StreamObserver<TakeOfferReply>) responseObserver; var takeOfferResponseObserver = (StreamObserver<TakeOfferReply>) responseObserver;
@ -116,6 +117,10 @@ public class GrpcErrorMessageHandler implements ErrorMessageHandler {
format("Could not find an AvailabilityResult in error message:%n%s", errorMessage))); format("Could not find an AvailabilityResult in error message:%n%s", errorMessage)));
} }
private String getAvailabilityResultDescription(AvailabilityResult proto) {
return bisq.core.offer.AvailabilityResult.fromProto(proto).description();
}
private boolean isTakeOfferError() { private boolean isTakeOfferError() {
return fullMethodName.equals(getTakeOfferMethod().getFullMethodName()); return fullMethodName.equals(getTakeOfferMethod().getFullMethodName());
} }

View File

@ -278,6 +278,7 @@ message TakeOfferRequest {
message TakeOfferReply { message TakeOfferReply {
TradeInfo trade = 1; TradeInfo trade = 1;
AvailabilityResult availabilityResult = 2; AvailabilityResult availabilityResult = 2;
string availabilityResultDescription = 3;
} }
message ConfirmPaymentStartedRequest { message ConfirmPaymentStartedRequest {