Fix missing tx confidence update

This commit is contained in:
Manfred Karrer 2015-03-26 17:45:43 +01:00
parent 689d60b854
commit 0ddd025b93
7 changed files with 40 additions and 31 deletions

View file

@ -113,8 +113,8 @@ public class BitsquareApp extends Application {
primaryStage.setTitle(env.getRequiredProperty(APP_NAME_KEY)); primaryStage.setTitle(env.getRequiredProperty(APP_NAME_KEY));
primaryStage.setScene(scene); primaryStage.setScene(scene);
primaryStage.setMinWidth(75); primaryStage.setMinWidth(750);
primaryStage.setMinHeight(50); primaryStage.setMinHeight(500);
// on windows the title icon is also used as task bar icon in a larger size // on windows the title icon is also used as task bar icon in a larger size
// on Linux no title icon is supported but also a large task bar icon is derived form that title icon // on Linux no title icon is supported but also a large task bar icon is derived form that title icon

View file

@ -398,13 +398,13 @@ public class TradeWalletService {
Futures.addCallback(broadcastComplete, callback); Futures.addCallback(broadcastComplete, callback);
} }
// Returns local transaction which has a different state as the serialized publishedOffererDepositTx we get from the offerer // Returns local transaction which has a different state as the serialized publishedDepositTx we get from the offerer
public Transaction takerCommitsDepositTx(Transaction publishedOffererDepositTx) throws VerificationException { public Transaction commitsDepositTx(Transaction publishedDepositTx) throws VerificationException {
log.trace("takerCommitsDepositTx called"); log.trace("takerCommitsDepositTx called");
log.trace("publishedOffererDepositTx " + publishedOffererDepositTx.toString()); log.trace("publishedDepositTx " + publishedDepositTx.toString());
// We need to recreate the tx we get a null pointer otherwise // We need to recreate the tx we get a null pointer otherwise
Transaction depositTx = new Transaction(params, publishedOffererDepositTx.bitcoinSerialize()); Transaction depositTx = new Transaction(params, publishedDepositTx.bitcoinSerialize());
log.trace("depositTx " + depositTx.toString()); log.trace("depositTx " + depositTx.toString());
wallet.receivePending(depositTx, null, true); wallet.receivePending(depositTx, null, true);

View file

@ -20,7 +20,6 @@ package io.bitsquare.trade;
import io.bitsquare.offer.Offer; import io.bitsquare.offer.Offer;
import io.bitsquare.trade.protocol.trade.offerer.OffererAsBuyerProtocol; import io.bitsquare.trade.protocol.trade.offerer.OffererAsBuyerProtocol;
import org.bitcoinj.core.Transaction;
import org.bitcoinj.core.TransactionConfidence; import org.bitcoinj.core.TransactionConfidence;
import com.google.common.base.Throwables; import com.google.common.base.Throwables;
@ -58,11 +57,11 @@ public class OffererTrade extends Trade implements Serializable {
public enum OffererProcessState implements ProcessState { public enum OffererProcessState implements ProcessState {
DEPOSIT_PUBLISHED, DEPOSIT_PUBLISHED,
DEPOSIT_CONFIRMED, DEPOSIT_CONFIRMED,
FIAT_PAYMENT_STARTED, FIAT_PAYMENT_STARTED,
PAYOUT_PUBLISHED, PAYOUT_PUBLISHED,
MESSAGE_SENDING_FAILED, MESSAGE_SENDING_FAILED,
EXCEPTION EXCEPTION
} }
@ -124,10 +123,6 @@ public class OffererTrade extends Trade implements Serializable {
lifeCycleStateProperty.set(lifeCycleState); lifeCycleStateProperty.set(lifeCycleState);
} }
public void setDepositTx(Transaction tx) {
this.depositTx = tx;
setConfidenceListener();
}
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
@ -155,6 +150,7 @@ public class OffererTrade extends Trade implements Serializable {
// Private // Private
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
@Override
protected void setConfidenceListener() { protected void setConfidenceListener() {
TransactionConfidence transactionConfidence = depositTx.getConfidence(); TransactionConfidence transactionConfidence = depositTx.getConfidence();
ListenableFuture<TransactionConfidence> future = transactionConfidence.getDepthFuture(1); ListenableFuture<TransactionConfidence> future = transactionConfidence.getDepthFuture(1);

View file

@ -20,7 +20,6 @@ package io.bitsquare.trade;
import io.bitsquare.offer.Offer; import io.bitsquare.offer.Offer;
import io.bitsquare.trade.protocol.trade.taker.TakerAsSellerProtocol; import io.bitsquare.trade.protocol.trade.taker.TakerAsSellerProtocol;
import org.bitcoinj.core.Transaction;
import org.bitcoinj.core.TransactionConfidence; import org.bitcoinj.core.TransactionConfidence;
import com.google.common.base.Throwables; import com.google.common.base.Throwables;
@ -58,15 +57,15 @@ public class TakerTrade extends Trade implements Serializable {
TAKE_OFFER_FEE_TX_CREATED, TAKE_OFFER_FEE_TX_CREATED,
TAKE_OFFER_FEE_PUBLISHED, TAKE_OFFER_FEE_PUBLISHED,
TAKE_OFFER_FEE_PUBLISH_FAILED, TAKE_OFFER_FEE_PUBLISH_FAILED,
DEPOSIT_PUBLISHED, DEPOSIT_PUBLISHED,
DEPOSIT_CONFIRMED, DEPOSIT_CONFIRMED,
FIAT_PAYMENT_STARTED, FIAT_PAYMENT_STARTED,
FIAT_PAYMENT_RECEIVED, FIAT_PAYMENT_RECEIVED,
PAYOUT_PUBLISHED, PAYOUT_PUBLISHED,
MESSAGE_SENDING_FAILED, MESSAGE_SENDING_FAILED,
EXCEPTION EXCEPTION
} }
@ -118,17 +117,12 @@ public class TakerTrade extends Trade implements Serializable {
} }
} }
public void setDepositTx(Transaction tx) {
this.depositTx = tx;
setConfidenceListener();
}
@Override @Override
public void setThrowable(Throwable throwable) { public void setThrowable(Throwable throwable) {
super.setThrowable(throwable); super.setThrowable(throwable);
setProcessState(TakerTrade.TakerProcessState.EXCEPTION); setProcessState(TakerTrade.TakerProcessState.EXCEPTION);
} }
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
// Getters // Getters
@ -146,7 +140,8 @@ public class TakerTrade extends Trade implements Serializable {
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
// Private // Private
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
@Override
protected void setConfidenceListener() { protected void setConfidenceListener() {
TransactionConfidence transactionConfidence = depositTx.getConfidence(); TransactionConfidence transactionConfidence = depositTx.getConfidence();
ListenableFuture<TransactionConfidence> future = transactionConfidence.getDepthFuture(1); ListenableFuture<TransactionConfidence> future = transactionConfidence.getDepthFuture(1);

View file

@ -17,6 +17,7 @@
package io.bitsquare.trade; package io.bitsquare.trade;
import io.bitsquare.btc.TradeWalletService;
import io.bitsquare.offer.Offer; import io.bitsquare.offer.Offer;
import io.bitsquare.p2p.MailboxMessage; import io.bitsquare.p2p.MailboxMessage;
import io.bitsquare.p2p.Peer; import io.bitsquare.p2p.Peer;
@ -44,7 +45,6 @@ abstract public class Trade implements Serializable {
transient protected static final Logger log = LoggerFactory.getLogger(Trade.class); transient protected static final Logger log = LoggerFactory.getLogger(Trade.class);
public interface ProcessState { public interface ProcessState {
} }
@ -92,6 +92,18 @@ abstract public class Trade implements Serializable {
tradeVolumeProperty = new SimpleObjectProperty<>(getTradeVolume()); tradeVolumeProperty = new SimpleObjectProperty<>(getTradeVolume());
} }
// The deserialized tx has not actual confidence data, so we need to get the fresh one from the wallet.
public void updateTxFromWallet(TradeWalletService tradeWalletService) {
if (depositTx != null) {
depositTx = tradeWalletService.commitsDepositTx(depositTx);
setConfidenceListener();
}
}
public void setDepositTx(Transaction tx) {
this.depositTx = tx;
setConfidenceListener();
}
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
// Protocol // Protocol
@ -235,10 +247,11 @@ abstract public class Trade implements Serializable {
return throwable; return throwable;
} }
abstract public ReadOnlyObjectProperty<? extends ProcessState> processStateProperty(); public abstract ReadOnlyObjectProperty<? extends ProcessState> processStateProperty();
abstract public ReadOnlyObjectProperty<? extends LifeCycleState> lifeCycleStateProperty(); public abstract ReadOnlyObjectProperty<? extends LifeCycleState> lifeCycleStateProperty();
protected abstract void setConfidenceListener();
@Override @Override
public String toString() { public String toString() {

View file

@ -20,6 +20,7 @@ package io.bitsquare.trade;
import io.bitsquare.arbitration.ArbitrationRepository; import io.bitsquare.arbitration.ArbitrationRepository;
import io.bitsquare.btc.AddressEntry; import io.bitsquare.btc.AddressEntry;
import io.bitsquare.btc.BlockChainService; import io.bitsquare.btc.BlockChainService;
import io.bitsquare.btc.TradeWalletService;
import io.bitsquare.btc.WalletService; import io.bitsquare.btc.WalletService;
import io.bitsquare.common.handlers.ErrorMessageHandler; import io.bitsquare.common.handlers.ErrorMessageHandler;
import io.bitsquare.common.handlers.FaultHandler; import io.bitsquare.common.handlers.FaultHandler;
@ -84,6 +85,7 @@ public class TradeManager {
private final AddressService addressService; private final AddressService addressService;
private final BlockChainService blockChainService; private final BlockChainService blockChainService;
private final WalletService walletService; private final WalletService walletService;
private TradeWalletService tradeWalletService;
private final SignatureService signatureService; private final SignatureService signatureService;
private final EncryptionService<MailboxMessage> encryptionService; private final EncryptionService<MailboxMessage> encryptionService;
private final OfferBookService offerBookService; private final OfferBookService offerBookService;
@ -105,7 +107,8 @@ public class TradeManager {
@Inject @Inject
public TradeManager(User user, AccountSettings accountSettings, public TradeManager(User user, AccountSettings accountSettings,
MessageService messageService, MailboxService mailboxService, AddressService addressService, BlockChainService blockChainService, MessageService messageService, MailboxService mailboxService, AddressService addressService, BlockChainService blockChainService,
WalletService walletService, SignatureService signatureService, EncryptionService<MailboxMessage> encryptionService, WalletService walletService, TradeWalletService tradeWalletService, SignatureService signatureService,
EncryptionService<MailboxMessage> encryptionService,
OfferBookService offerBookService, ArbitrationRepository arbitrationRepository, @Named("storage.dir") File storageDir) { OfferBookService offerBookService, ArbitrationRepository arbitrationRepository, @Named("storage.dir") File storageDir) {
this.user = user; this.user = user;
this.accountSettings = accountSettings; this.accountSettings = accountSettings;
@ -114,6 +117,7 @@ public class TradeManager {
this.addressService = addressService; this.addressService = addressService;
this.blockChainService = blockChainService; this.blockChainService = blockChainService;
this.walletService = walletService; this.walletService = walletService;
this.tradeWalletService = tradeWalletService;
this.signatureService = signatureService; this.signatureService = signatureService;
this.encryptionService = encryptionService; this.encryptionService = encryptionService;
this.offerBookService = offerBookService; this.offerBookService = offerBookService;
@ -169,6 +173,7 @@ public class TradeManager {
OffererTrade offererTrade = (OffererTrade) trade; OffererTrade offererTrade = (OffererTrade) trade;
OffererAsBuyerProtocol protocol = createOffererAsBuyerProtocol(offererTrade); OffererAsBuyerProtocol protocol = createOffererAsBuyerProtocol(offererTrade);
offererTrade.setProtocol(protocol); offererTrade.setProtocol(protocol);
offererTrade.updateTxFromWallet(tradeWalletService);
} }
else if (trade instanceof TakerTrade) { else if (trade instanceof TakerTrade) {
TakerTrade takerTrade = (TakerTrade) trade; TakerTrade takerTrade = (TakerTrade) trade;

View file

@ -37,7 +37,7 @@ public class TakerCommitDepositTx extends Task<TakerAsSellerModel> {
protected void doRun() { protected void doRun() {
try { try {
// To access tx confidence we need to add that tx into our wallet. // To access tx confidence we need to add that tx into our wallet.
Transaction depositTx = model.tradeWalletService.takerCommitsDepositTx(model.trade.getDepositTx()); Transaction depositTx = model.tradeWalletService.commitsDepositTx(model.trade.getDepositTx());
model.trade.setDepositTx(depositTx); model.trade.setDepositTx(depositTx);