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 0bd14957ec..45de559c3e 100644 --- a/src/main/java/io/bitsquare/trade/protocol/createoffer/CreateOfferCoordinator.java +++ b/src/main/java/io/bitsquare/trade/protocol/createoffer/CreateOfferCoordinator.java @@ -24,9 +24,9 @@ import io.bitsquare.offer.OfferRepository; import io.bitsquare.persistence.Persistence; import io.bitsquare.trade.handlers.TransactionResultHandler; import io.bitsquare.trade.protocol.createoffer.tasks.BroadCastOfferFeeTx; -import io.bitsquare.trade.protocol.createoffer.tasks.CreateOfferFeeTx; import io.bitsquare.util.task.FaultHandler; +import org.bitcoinj.core.InsufficientMoneyException; import org.bitcoinj.core.Transaction; import java.io.Serializable; @@ -123,14 +123,20 @@ public class CreateOfferCoordinator { return; } - CreateOfferFeeTx.run(this::onOfferFeeTxCreated, faultHandler, walletFacade, offer.getId()); - } + try { + model.transaction = walletFacade.createOfferFeeTx(offer.getId()); + model.setState(State.OFFER_FEE_TX_CREATED); + offer.setOfferFeePaymentTxID(model.transaction.getHashAsString()); + } catch (InsufficientMoneyException ex) { + faultHandler.handleFault( + "Offer fee payment failed because there is insufficient money in the trade wallet", ex); + return; + } catch (Throwable ex) { + faultHandler.handleFault("Offer fee payment failed because of an exception occurred", ex); + return; + } - private void onOfferFeeTxCreated(Transaction transaction) { - model.transaction = transaction; - model.setState(State.OFFER_FEE_TX_CREATED); - offer.setOfferFeePaymentTxID(transaction.getHashAsString()); - BroadCastOfferFeeTx.run(this::onOfferFeeTxBroadCasted, faultHandler, walletFacade, transaction); + BroadCastOfferFeeTx.run(this::onOfferFeeTxBroadCasted, faultHandler, walletFacade, model.transaction); } private void onOfferFeeTxBroadCasted() { diff --git a/src/main/java/io/bitsquare/trade/protocol/createoffer/tasks/CreateOfferFeeTx.java b/src/main/java/io/bitsquare/trade/protocol/createoffer/tasks/CreateOfferFeeTx.java deleted file mode 100644 index 8d60fcc2a4..0000000000 --- a/src/main/java/io/bitsquare/trade/protocol/createoffer/tasks/CreateOfferFeeTx.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * This file is part of Bitsquare. - * - * Bitsquare is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * Bitsquare is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - * License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Bitsquare. If not, see . - */ - -package io.bitsquare.trade.protocol.createoffer.tasks; - -import io.bitsquare.btc.WalletFacade; -import io.bitsquare.util.task.FaultHandler; -import io.bitsquare.trade.handlers.TransactionResultHandler; - -import org.bitcoinj.core.InsufficientMoneyException; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class CreateOfferFeeTx { - private static final Logger log = LoggerFactory.getLogger(CreateOfferFeeTx.class); - - public static void run(TransactionResultHandler resultHandler, FaultHandler faultHandler, - WalletFacade walletFacade, String offerId) { - try { - resultHandler.onResult(walletFacade.createOfferFeeTx(offerId)); - } catch (InsufficientMoneyException e) { - faultHandler.handleFault("Offer fee payment failed because there is insufficient money in the trade " + - "wallet. " + - "", e); - } catch (Throwable t) { - faultHandler.handleFault("Offer fee payment failed because of an exception occurred. ", t); - } - } -}