Inline BroadCastOfferFeeTx#run into CreateOfferCoordinator

This commit is contained in:
Chris Beams 2014-11-05 14:07:55 +01:00
parent 2adac9475e
commit 40d7da8d10
No known key found for this signature in database
GPG Key ID: 3D214F8F5BC5ED73
2 changed files with 29 additions and 71 deletions

View File

@ -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<Transaction>() {
@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() {

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
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<Transaction>() {
@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);
}
}
}