diff --git a/src/main/java/io/bitsquare/trade/protocol/createoffer/CreateOfferCoordinator.java b/src/main/java/io/bitsquare/trade/protocol/createoffer/CreateOfferCoordinator.java index 0919a3dd97..8e5b101776 100644 --- a/src/main/java/io/bitsquare/trade/protocol/createoffer/CreateOfferCoordinator.java +++ b/src/main/java/io/bitsquare/trade/protocol/createoffer/CreateOfferCoordinator.java @@ -51,31 +51,12 @@ public class CreateOfferCoordinator this.faultHandler = faultHandler; state = State.INIT; - ValidateOffer.run(this::onOfferValidated, this::onFailed, walletFacade, offer); - PayOfferFee.run(this::onOfferFeePaid, this::onFailed, walletFacade, offer); + ValidateOffer.run(this::onOfferValidated, this::onFailed, offer); } + private void onOfferValidated() { - - } - public void recover(State lastState, String transactionId, PublishTransactionResultHandler resultHandler, FaultHandler faultHandler) - { - this.transactionId = transactionId; - this.resultHandler = resultHandler; - this.faultHandler = faultHandler; - switch (lastState) - { - case INIT: - PayOfferFee.run(this::onOfferFeePaid, this::onFailed, walletFacade, offer); - break; - case OFFER_FEE_PAID: - PublishOfferToDHT.run(this::onOfferPublishedToDHT, this::onFailed, messageFacade, offer); - break; - case OFFER_PUBLISHED_TO_DHT: - // should be impossible - resultHandler.onResult(transactionId); - break; - } + PayOfferFee.run(this::onOfferFeePaid, this::onFailed, walletFacade, offer); } private void onOfferFeePaid(String transactionId) @@ -101,6 +82,31 @@ public class CreateOfferCoordinator } + /////////////////////////////////////////////////////////////////////////////////////////// + // Recovery + /////////////////////////////////////////////////////////////////////////////////////////// + + public void recover(State lastState, String transactionId, PublishTransactionResultHandler resultHandler, FaultHandler faultHandler) + { + this.transactionId = transactionId; + this.resultHandler = resultHandler; + this.faultHandler = faultHandler; + switch (lastState) + { + case INIT: + PayOfferFee.run(this::onOfferFeePaid, this::onFailed, walletFacade, offer); + break; + case OFFER_FEE_PAID: + PublishOfferToDHT.run(this::onOfferPublishedToDHT, this::onFailed, messageFacade, offer); + break; + case OFFER_PUBLISHED_TO_DHT: + // should be impossible + resultHandler.onResult(transactionId); + break; + } + } + + /////////////////////////////////////////////////////////////////////////////////////////// // Getters for persisting state /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/main/java/io/bitsquare/trade/protocol/createoffer/tasks/ValidateOffer.java b/src/main/java/io/bitsquare/trade/protocol/createoffer/tasks/ValidateOffer.java index 28fff02880..60aa923136 100644 --- a/src/main/java/io/bitsquare/trade/protocol/createoffer/tasks/ValidateOffer.java +++ b/src/main/java/io/bitsquare/trade/protocol/createoffer/tasks/ValidateOffer.java @@ -1,7 +1,7 @@ package io.bitsquare.trade.protocol.createoffer.tasks; import io.bitsquare.trade.Offer; -import io.bitsquare.trade.handlers.ErrorMessageHandler; +import io.bitsquare.trade.handlers.FaultHandler; import io.bitsquare.trade.handlers.ResultHandler; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -10,18 +10,18 @@ public class ValidateOffer { private static final Logger log = LoggerFactory.getLogger(ValidateOffer.class); - public static void run(ResultHandler resultHandler, ErrorMessageHandler faultHandler, Offer offer) + public static void run(ResultHandler resultHandler, FaultHandler faultHandler, Offer offer) { boolean isValid = offer.getAmount().isGreaterThan(offer.getAmount()); if (offer.getAmount().compareTo(offer.getMinAmount()) >= 0) { - faultHandler.onFault("Offer validation failed: Min. amount is larger than amount."); + faultHandler.onFault("Offer validation failed: Min. amount is larger than amount.", new Exception("Offer validation failed: Min. amount is larger than amount.")); } else if (offer.getAcceptedCountries() == null || offer.getAcceptedCountries().size() == 0) { - faultHandler.onFault("Offer validation failed: No accepted countries are defined"); + faultHandler.onFault("Offer validation failed: No accepted countries are defined.", new Exception("Offer validation failed: No accepted countries are defined.")); } //TODO... else {