diff --git a/common/src/main/java/bisq/common/taskrunner/Task.java b/common/src/main/java/bisq/common/taskrunner/Task.java index 79bff399ee..6e1b56852c 100644 --- a/common/src/main/java/bisq/common/taskrunner/Task.java +++ b/common/src/main/java/bisq/common/taskrunner/Task.java @@ -17,6 +17,8 @@ package bisq.common.taskrunner; +import java.io.PrintWriter; +import java.io.StringWriter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -64,7 +66,11 @@ public abstract class Task { } protected void failed(Throwable t) { - log.error(errorMessage, t); + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + t.printStackTrace(pw); + errorMessage = sw.toString(); + log.error(t.getMessage(), t); taskHandler.handleErrorMessage(errorMessage); } diff --git a/core/src/main/java/bisq/core/trade/TradeManager.java b/core/src/main/java/bisq/core/trade/TradeManager.java index 997a371eab..af3f9380c2 100644 --- a/core/src/main/java/bisq/core/trade/TradeManager.java +++ b/core/src/main/java/bisq/core/trade/TradeManager.java @@ -732,7 +732,13 @@ public class TradeManager implements PersistedDataHost, DecryptedDirectMessageLi initTradeAndProtocol(trade, tradeProtocol); - ((TakerProtocol) tradeProtocol).onTakeOffer(tradeResultHandler); + // take offer and persist trade on success + ((TakerProtocol) tradeProtocol).onTakeOffer(result -> { + tradeResultHandler.handleResult(trade); + }, errorMessage -> { + removeTrade(trade); + errorMessageHandler.handleErrorMessage(errorMessage); + }); requestPersistence(); } }, diff --git a/core/src/main/java/bisq/core/trade/protocol/BuyerAsTakerProtocol.java b/core/src/main/java/bisq/core/trade/protocol/BuyerAsTakerProtocol.java index 3d949277d3..36fd7dbc52 100644 --- a/core/src/main/java/bisq/core/trade/protocol/BuyerAsTakerProtocol.java +++ b/core/src/main/java/bisq/core/trade/protocol/BuyerAsTakerProtocol.java @@ -90,7 +90,7 @@ public class BuyerAsTakerProtocol extends BuyerProtocol implements TakerProtocol // TODO (woodser): this implementation is duplicated with SellerAsTakerProtocol @Override - public void onTakeOffer(TradeResultHandler tradeResultHandler) { + public void onTakeOffer(TradeResultHandler tradeResultHandler, ErrorMessageHandler errorMessageHandler) { System.out.println("onTakeOffer()"); this.tradeResultHandler = tradeResultHandler; @@ -101,6 +101,9 @@ public class BuyerAsTakerProtocol extends BuyerProtocol implements TakerProtocol ApplyFilter.class, TakerReservesTradeFunds.class, TakerSendsInitTradeRequestToArbitrator.class) // TODO (woodser): app hangs if this pipeline fails. use .using() like below + .using(new TradeTaskRunner(trade, + () -> { }, + errorMessageHandler)) .withTimeout(30)) .executeTasks(); } diff --git a/core/src/main/java/bisq/core/trade/protocol/SellerAsTakerProtocol.java b/core/src/main/java/bisq/core/trade/protocol/SellerAsTakerProtocol.java index 65cd88d9fc..8e4e0993a2 100644 --- a/core/src/main/java/bisq/core/trade/protocol/SellerAsTakerProtocol.java +++ b/core/src/main/java/bisq/core/trade/protocol/SellerAsTakerProtocol.java @@ -82,7 +82,8 @@ public class SellerAsTakerProtocol extends SellerProtocol implements TakerProtoc /////////////////////////////////////////////////////////////////////////////////////////// @Override - public void onTakeOffer(TradeResultHandler tradeResultHandler) { + public void onTakeOffer(TradeResultHandler tradeResultHandler, + ErrorMessageHandler errorMessageHandler) { System.out.println("onTakeOffer()"); this.tradeResultHandler = tradeResultHandler; @@ -93,6 +94,9 @@ public class SellerAsTakerProtocol extends SellerProtocol implements TakerProtoc ApplyFilter.class, TakerReservesTradeFunds.class, TakerSendsInitTradeRequestToArbitrator.class) + .using(new TradeTaskRunner(trade, + () -> { }, + errorMessageHandler)) .withTimeout(30)) .executeTasks(); } diff --git a/core/src/main/java/bisq/core/trade/protocol/TakerProtocol.java b/core/src/main/java/bisq/core/trade/protocol/TakerProtocol.java index a37e8af0a0..0642cb0cea 100644 --- a/core/src/main/java/bisq/core/trade/protocol/TakerProtocol.java +++ b/core/src/main/java/bisq/core/trade/protocol/TakerProtocol.java @@ -17,10 +17,11 @@ package bisq.core.trade.protocol; +import bisq.common.handlers.ErrorMessageHandler; import bisq.core.trade.handlers.TradeResultHandler; public interface TakerProtocol extends TraderProtocol { - void onTakeOffer(TradeResultHandler tradeResultHandler); + void onTakeOffer(TradeResultHandler tradeResultHandler, ErrorMessageHandler errorMessageHandler); enum TakerEvent implements FluentProtocol.Event { TAKE_OFFER diff --git a/daemon/src/main/java/bisq/daemon/grpc/GrpcErrorMessageHandler.java b/daemon/src/main/java/bisq/daemon/grpc/GrpcErrorMessageHandler.java index 4c139e1709..1254623af1 100644 --- a/daemon/src/main/java/bisq/daemon/grpc/GrpcErrorMessageHandler.java +++ b/daemon/src/main/java/bisq/daemon/grpc/GrpcErrorMessageHandler.java @@ -109,7 +109,6 @@ public class GrpcErrorMessageHandler implements ErrorMessageHandler { takeOfferResponseObserver.onNext(reply); takeOfferResponseObserver.onCompleted(); } catch (IllegalArgumentException ex) { - log.error("", ex); exceptionHandler.handleErrorMessage(log, errorMessage, responseObserver);