From 40d7da8d1098d8b792ced8b2652d3b41b4ac17d9 Mon Sep 17 00:00:00 2001 From: Chris Beams Date: Wed, 5 Nov 2014 14:07:55 +0100 Subject: [PATCH] Inline BroadCastOfferFeeTx#run into CreateOfferCoordinator --- .../createoffer/CreateOfferCoordinator.java | 35 ++++++++-- .../tasks/BroadCastOfferFeeTx.java | 65 ------------------- 2 files changed, 29 insertions(+), 71 deletions(-) delete mode 100644 src/main/java/io/bitsquare/trade/protocol/createoffer/tasks/BroadCastOfferFeeTx.java 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 45de559c3e..d2f9be3873 100644 --- a/src/main/java/io/bitsquare/trade/protocol/createoffer/CreateOfferCoordinator.java +++ b/src/main/java/io/bitsquare/trade/protocol/createoffer/CreateOfferCoordinator.java @@ -23,12 +23,13 @@ import io.bitsquare.offer.Offer; 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.util.task.FaultHandler; import org.bitcoinj.core.InsufficientMoneyException; import org.bitcoinj.core.Transaction; +import com.google.common.util.concurrent.FutureCallback; + import java.io.Serializable; import javax.annotation.concurrent.Immutable; @@ -136,12 +137,34 @@ public class CreateOfferCoordinator { return; } - BroadCastOfferFeeTx.run(this::onOfferFeeTxBroadCasted, faultHandler, walletFacade, model.transaction); - } + try { + walletFacade.broadcastCreateOfferFeeTx(model.transaction, new FutureCallback() { + @Override + public void onSuccess(Transaction transaction) { + log.info("sendResult onSuccess:" + transaction); + if (transaction == null) { + faultHandler.handleFault("Offer fee payment failed.", + new Exception("Offer fee payment failed. Transaction = null.")); + return; + } - private void onOfferFeeTxBroadCasted() { - model.setState(State.OFFER_FEE_BROAD_CASTED); - offerRepository.addOffer(offer, this::addOfferResultHandler, faultHandler); + try { + model.setState(State.OFFER_FEE_BROAD_CASTED); + offerRepository.addOffer(offer, CreateOfferCoordinator.this::addOfferResultHandler, faultHandler); + } catch (Exception e) { + faultHandler.handleFault("Offer fee payment failed.", e); + } + } + + @Override + public void onFailure(Throwable t) { + faultHandler.handleFault("Offer fee payment failed with an exception.", t); + } + }); + } catch (Throwable t) { + faultHandler.handleFault("Offer fee payment failed because an exception occurred.", t); + return; + } } private void addOfferResultHandler() { diff --git a/src/main/java/io/bitsquare/trade/protocol/createoffer/tasks/BroadCastOfferFeeTx.java b/src/main/java/io/bitsquare/trade/protocol/createoffer/tasks/BroadCastOfferFeeTx.java deleted file mode 100644 index eeac649317..0000000000 --- a/src/main/java/io/bitsquare/trade/protocol/createoffer/tasks/BroadCastOfferFeeTx.java +++ /dev/null @@ -1,65 +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.util.task.ResultHandler; - -import org.bitcoinj.core.Transaction; - -import com.google.common.util.concurrent.FutureCallback; - -import org.jetbrains.annotations.NotNull; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class BroadCastOfferFeeTx { - private static final Logger log = LoggerFactory.getLogger(BroadCastOfferFeeTx.class); - - public static void run(ResultHandler resultHandler, FaultHandler faultHandler, WalletFacade walletFacade, - Transaction tx) { - try { - walletFacade.broadcastCreateOfferFeeTx(tx, new FutureCallback() { - @Override - public void onSuccess(@javax.annotation.Nullable Transaction transaction) { - log.info("sendResult onSuccess:" + transaction); - if (transaction != null) { - try { - resultHandler.handleResult(); - } catch (Exception e) { - faultHandler.handleFault("Offer fee payment failed.", e); - } - } - else { - faultHandler.handleFault("Offer fee payment failed.", - new Exception("Offer fee payment failed. Transaction = null.")); - } - } - - @Override - public void onFailure(@NotNull Throwable t) { - faultHandler.handleFault("Offer fee payment failed with an exception.", t); - } - }); - } catch (Throwable t) { - faultHandler.handleFault("Offer fee payment failed because an exception occurred.", t); - } - } -}