handle errors making or taking offers with insufficient funds
This commit is contained in:
parent
abfc0503fa
commit
dd68760f27
@ -17,6 +17,8 @@
|
|||||||
|
|
||||||
package bisq.common.taskrunner;
|
package bisq.common.taskrunner;
|
||||||
|
|
||||||
|
import java.io.PrintWriter;
|
||||||
|
import java.io.StringWriter;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@ -64,7 +66,11 @@ public abstract class Task<T extends Model> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void failed(Throwable t) {
|
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);
|
taskHandler.handleErrorMessage(errorMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -732,7 +732,13 @@ public class TradeManager implements PersistedDataHost, DecryptedDirectMessageLi
|
|||||||
|
|
||||||
initTradeAndProtocol(trade, tradeProtocol);
|
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();
|
requestPersistence();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -90,7 +90,7 @@ public class BuyerAsTakerProtocol extends BuyerProtocol implements TakerProtocol
|
|||||||
|
|
||||||
// TODO (woodser): this implementation is duplicated with SellerAsTakerProtocol
|
// TODO (woodser): this implementation is duplicated with SellerAsTakerProtocol
|
||||||
@Override
|
@Override
|
||||||
public void onTakeOffer(TradeResultHandler tradeResultHandler) {
|
public void onTakeOffer(TradeResultHandler tradeResultHandler, ErrorMessageHandler errorMessageHandler) {
|
||||||
System.out.println("onTakeOffer()");
|
System.out.println("onTakeOffer()");
|
||||||
this.tradeResultHandler = tradeResultHandler;
|
this.tradeResultHandler = tradeResultHandler;
|
||||||
|
|
||||||
@ -101,6 +101,9 @@ public class BuyerAsTakerProtocol extends BuyerProtocol implements TakerProtocol
|
|||||||
ApplyFilter.class,
|
ApplyFilter.class,
|
||||||
TakerReservesTradeFunds.class,
|
TakerReservesTradeFunds.class,
|
||||||
TakerSendsInitTradeRequestToArbitrator.class) // TODO (woodser): app hangs if this pipeline fails. use .using() like below
|
TakerSendsInitTradeRequestToArbitrator.class) // TODO (woodser): app hangs if this pipeline fails. use .using() like below
|
||||||
|
.using(new TradeTaskRunner(trade,
|
||||||
|
() -> { },
|
||||||
|
errorMessageHandler))
|
||||||
.withTimeout(30))
|
.withTimeout(30))
|
||||||
.executeTasks();
|
.executeTasks();
|
||||||
}
|
}
|
||||||
|
@ -82,7 +82,8 @@ public class SellerAsTakerProtocol extends SellerProtocol implements TakerProtoc
|
|||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTakeOffer(TradeResultHandler tradeResultHandler) {
|
public void onTakeOffer(TradeResultHandler tradeResultHandler,
|
||||||
|
ErrorMessageHandler errorMessageHandler) {
|
||||||
System.out.println("onTakeOffer()");
|
System.out.println("onTakeOffer()");
|
||||||
this.tradeResultHandler = tradeResultHandler;
|
this.tradeResultHandler = tradeResultHandler;
|
||||||
|
|
||||||
@ -93,6 +94,9 @@ public class SellerAsTakerProtocol extends SellerProtocol implements TakerProtoc
|
|||||||
ApplyFilter.class,
|
ApplyFilter.class,
|
||||||
TakerReservesTradeFunds.class,
|
TakerReservesTradeFunds.class,
|
||||||
TakerSendsInitTradeRequestToArbitrator.class)
|
TakerSendsInitTradeRequestToArbitrator.class)
|
||||||
|
.using(new TradeTaskRunner(trade,
|
||||||
|
() -> { },
|
||||||
|
errorMessageHandler))
|
||||||
.withTimeout(30))
|
.withTimeout(30))
|
||||||
.executeTasks();
|
.executeTasks();
|
||||||
}
|
}
|
||||||
|
@ -17,10 +17,11 @@
|
|||||||
|
|
||||||
package bisq.core.trade.protocol;
|
package bisq.core.trade.protocol;
|
||||||
|
|
||||||
|
import bisq.common.handlers.ErrorMessageHandler;
|
||||||
import bisq.core.trade.handlers.TradeResultHandler;
|
import bisq.core.trade.handlers.TradeResultHandler;
|
||||||
|
|
||||||
public interface TakerProtocol extends TraderProtocol {
|
public interface TakerProtocol extends TraderProtocol {
|
||||||
void onTakeOffer(TradeResultHandler tradeResultHandler);
|
void onTakeOffer(TradeResultHandler tradeResultHandler, ErrorMessageHandler errorMessageHandler);
|
||||||
|
|
||||||
enum TakerEvent implements FluentProtocol.Event {
|
enum TakerEvent implements FluentProtocol.Event {
|
||||||
TAKE_OFFER
|
TAKE_OFFER
|
||||||
|
@ -109,7 +109,6 @@ public class GrpcErrorMessageHandler implements ErrorMessageHandler {
|
|||||||
takeOfferResponseObserver.onNext(reply);
|
takeOfferResponseObserver.onNext(reply);
|
||||||
takeOfferResponseObserver.onCompleted();
|
takeOfferResponseObserver.onCompleted();
|
||||||
} catch (IllegalArgumentException ex) {
|
} catch (IllegalArgumentException ex) {
|
||||||
log.error("", ex);
|
|
||||||
exceptionHandler.handleErrorMessage(log,
|
exceptionHandler.handleErrorMessage(log,
|
||||||
errorMessage,
|
errorMessage,
|
||||||
responseObserver);
|
responseObserver);
|
||||||
|
Loading…
Reference in New Issue
Block a user