mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-04-20 23:56:30 -04:00
Add confidence listener as task
This commit is contained in:
parent
02c9035af5
commit
6099f36b53
@ -20,7 +20,6 @@ package io.bitsquare.gui.main.portfolio.pending;
|
||||
import io.bitsquare.btc.AddressEntry;
|
||||
import io.bitsquare.btc.FeePolicy;
|
||||
import io.bitsquare.btc.WalletService;
|
||||
import io.bitsquare.btc.listeners.TxConfidenceListener;
|
||||
import io.bitsquare.common.viewfx.model.Activatable;
|
||||
import io.bitsquare.common.viewfx.model.DataModel;
|
||||
import io.bitsquare.offer.Direction;
|
||||
@ -33,7 +32,6 @@ import org.bitcoinj.core.AddressFormatException;
|
||||
import org.bitcoinj.core.Coin;
|
||||
import org.bitcoinj.core.InsufficientMoneyException;
|
||||
import org.bitcoinj.core.Transaction;
|
||||
import org.bitcoinj.core.TransactionConfidence;
|
||||
|
||||
import com.google.common.util.concurrent.FutureCallback;
|
||||
|
||||
@ -68,7 +66,6 @@ class PendingTradesDataModel implements Activatable, DataModel {
|
||||
private boolean isOfferer;
|
||||
private Trade closedTrade;
|
||||
|
||||
private TxConfidenceListener txConfidenceListener;
|
||||
private final ChangeListener<Trade.State> tradeStateChangeListener;
|
||||
private final MapChangeListener<String, Trade> mapChangeListener;
|
||||
|
||||
@ -155,15 +152,6 @@ class PendingTradesDataModel implements Activatable, DataModel {
|
||||
|
||||
if (trade.getDepositTx() != null)
|
||||
txId.set(trade.getDepositTx().getHashAsString());
|
||||
|
||||
txConfidenceListener = new TxConfidenceListener(txId.get()) {
|
||||
@Override
|
||||
public void onTransactionConfidenceChanged(TransactionConfidence confidence) {
|
||||
updateConfidence(confidence);
|
||||
}
|
||||
};
|
||||
walletService.addTxConfidenceListener(txConfidenceListener);
|
||||
updateConfidence(walletService.getConfidenceForTxId(txId.get()));
|
||||
}
|
||||
else {
|
||||
txId.set(null);
|
||||
@ -176,7 +164,6 @@ class PendingTradesDataModel implements Activatable, DataModel {
|
||||
}
|
||||
|
||||
void fiatPaymentReceived() {
|
||||
getTrade().setState(Trade.State.FIAT_PAYMENT_RECEIVED);
|
||||
tradeManager.onFiatPaymentReceived(getTrade().getId());
|
||||
}
|
||||
|
||||
@ -287,26 +274,11 @@ class PendingTradesDataModel implements Activatable, DataModel {
|
||||
return getTrade().getSecurityDeposit();
|
||||
}
|
||||
|
||||
private void updateConfidence(TransactionConfidence confidence) {
|
||||
log.trace("updateConfidence confidence " + confidence);
|
||||
log.trace("updateConfidence getTrade().getState() " + getTrade().getState());
|
||||
if (confidence != null &&
|
||||
confidence.getConfidenceType() == TransactionConfidence.ConfidenceType.BUILDING
|
||||
&& getTrade().getState() == Trade.State.DEPOSIT_PUBLISHED) {
|
||||
// only set it once when actual state is DEPOSIT_PUBLISHED, and remove listener afterwards
|
||||
getTrade().setState(Trade.State.DEPOSIT_CONFIRMED);
|
||||
walletService.removeTxConfidenceListener(txConfidenceListener);
|
||||
txConfidenceListener = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void cleanUpSelectedTrade() {
|
||||
if (selectedItem != null) {
|
||||
selectedItem.getTrade().stateProperty().removeListener(tradeStateChangeListener);
|
||||
}
|
||||
|
||||
if (txConfidenceListener != null)
|
||||
walletService.removeTxConfidenceListener(txConfidenceListener);
|
||||
}
|
||||
|
||||
private void sortList() {
|
||||
|
@ -356,6 +356,7 @@ public class PendingTradesView extends ActivatableViewAndModel<AnchorPane, Pendi
|
||||
setSummaryControlsVisible(false);
|
||||
|
||||
processBar.reset();
|
||||
log.debug("applyTakerState "+state);
|
||||
|
||||
if (state != null) {
|
||||
switch (state) {
|
||||
|
@ -127,6 +127,12 @@ public class OfferBookView extends ActivatableViewAndModel<GridPane, OfferBookVi
|
||||
// for irc demo
|
||||
showAdvancedSettingsButton.setVisible(false);
|
||||
showAdvancedSettingsButton.setManaged(false);
|
||||
|
||||
//TODO temp for testing
|
||||
|
||||
amountTextField.setText("1");
|
||||
priceTextField.setText("1");
|
||||
volumeTextField.setText("1");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -94,7 +94,7 @@ public class TomP2PDHTService extends TomP2PService implements DHTService {
|
||||
* @return
|
||||
*/
|
||||
public FutureGet getData(Number160 locationKey) {
|
||||
log.trace("getData");
|
||||
//log.trace("getData");
|
||||
return peerDHT.get(locationKey).start();
|
||||
}
|
||||
|
||||
|
@ -241,7 +241,6 @@ public class TradeManager {
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public void checkOfferAvailability(Offer offer) {
|
||||
offer.setState(Offer.State.UNKNOWN);
|
||||
if (!checkOfferAvailabilityProtocolMap.containsKey(offer.getId())) {
|
||||
CheckOfferAvailabilityModel model = new CheckOfferAvailabilityModel(
|
||||
offer,
|
||||
@ -471,9 +470,10 @@ public class TradeManager {
|
||||
TakerAsSellerProtocol protocol = new TakerAsSellerProtocol(model);
|
||||
takerAsSellerProtocolMap.put(trade.getId(), protocol);
|
||||
|
||||
if (mailboxMessages.containsKey(trade.getId()))
|
||||
if (mailboxMessages.containsKey(trade.getId())) {
|
||||
log.debug("TakerAsSellerProtocol setMailboxMessage " + trade.getId());
|
||||
protocol.setMailboxMessage(mailboxMessages.get(trade.getId()));
|
||||
|
||||
}
|
||||
return protocol;
|
||||
}
|
||||
|
||||
@ -541,9 +541,10 @@ public class TradeManager {
|
||||
|
||||
OffererAsBuyerProtocol protocol = new OffererAsBuyerProtocol(model);
|
||||
offererAsBuyerProtocolMap.put(offer.getId(), protocol);
|
||||
if (mailboxMessages.containsKey(trade.getId()))
|
||||
if (mailboxMessages.containsKey(trade.getId())) {
|
||||
log.debug("OffererAsBuyerProtocol setMailboxMessage " + trade.getId());
|
||||
protocol.setMailboxMessage(mailboxMessages.get(trade.getId()));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void closeTrade(Trade trade) {
|
||||
@ -581,14 +582,14 @@ public class TradeManager {
|
||||
if (mailboxMessage instanceof TradeMessage) {
|
||||
String tradeId = ((TradeMessage) mailboxMessage).tradeId;
|
||||
mailboxMessages.put(tradeId, mailboxMessage);
|
||||
log.trace("mailboxMessage with tradeID " + tradeId);
|
||||
log.trace("added mailboxMessage with tradeID " + tradeId);
|
||||
if (takerAsSellerProtocolMap.containsKey(tradeId)) {
|
||||
takerAsSellerProtocolMap.get(tradeId).setMailboxMessage(mailboxMessage);
|
||||
log.trace("sellerAsTakerProtocolMap exist with tradeID " + tradeId);
|
||||
log.trace("sellerAsTakerProtocol exist with tradeID " + tradeId);
|
||||
}
|
||||
if (offererAsBuyerProtocolMap.containsKey(tradeId)) {
|
||||
offererAsBuyerProtocolMap.get(tradeId).setMailboxMessage(mailboxMessage);
|
||||
log.trace("buyerAcceptsOfferProtocolMap exist with tradeID " + tradeId);
|
||||
log.trace("buyerAcceptsOfferProtocol exist with tradeID " + tradeId);
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
@ -596,6 +597,7 @@ public class TradeManager {
|
||||
log.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
log.trace("mailboxMessages.size=" + mailboxMessages.size());
|
||||
}
|
||||
|
||||
private void emptyMailbox() {
|
||||
@ -610,7 +612,6 @@ public class TradeManager {
|
||||
}
|
||||
|
||||
boolean isOfferOpen(String offerId) {
|
||||
// Don't use openOffers as the offer gets removed async from DHT, but is added sync to pendingTrades
|
||||
return openOffers.containsKey(offerId)
|
||||
&& (openOffers.get(offerId).getState() == Offer.State.UNKNOWN
|
||||
|| openOffers.get(offerId).getState() == Offer.State.AVAILABLE);
|
||||
|
@ -20,6 +20,7 @@ package io.bitsquare.trade.protocol.availability;
|
||||
import io.bitsquare.common.handlers.ErrorMessageHandler;
|
||||
import io.bitsquare.common.handlers.ResultHandler;
|
||||
import io.bitsquare.common.taskrunner.TaskRunner;
|
||||
import io.bitsquare.offer.Offer;
|
||||
import io.bitsquare.p2p.Message;
|
||||
import io.bitsquare.p2p.MessageHandler;
|
||||
import io.bitsquare.p2p.Peer;
|
||||
@ -64,6 +65,9 @@ public class CheckOfferAvailabilityProtocol {
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public void checkOfferAvailability() {
|
||||
// reset
|
||||
model.offer.setState(Offer.State.UNKNOWN);
|
||||
|
||||
model.messageService.addMessageHandler(messageHandler);
|
||||
|
||||
taskRunner = new TaskRunner<>(model,
|
||||
|
@ -22,10 +22,12 @@ import io.bitsquare.p2p.MailboxMessage;
|
||||
import io.bitsquare.p2p.Message;
|
||||
import io.bitsquare.p2p.MessageHandler;
|
||||
import io.bitsquare.p2p.Peer;
|
||||
import io.bitsquare.trade.Trade;
|
||||
import io.bitsquare.trade.protocol.trade.messages.DepositTxPublishedMessage;
|
||||
import io.bitsquare.trade.protocol.trade.messages.FiatTransferStartedMessage;
|
||||
import io.bitsquare.trade.protocol.trade.messages.RequestTakerDepositPaymentMessage;
|
||||
import io.bitsquare.trade.protocol.trade.messages.TradeMessage;
|
||||
import io.bitsquare.trade.protocol.trade.offerer.tasks.SetupListenerForBlockChainConfirmation;
|
||||
import io.bitsquare.trade.protocol.trade.taker.models.TakerAsSellerModel;
|
||||
import io.bitsquare.trade.protocol.trade.taker.tasks.BroadcastTakeOfferFeeTx;
|
||||
import io.bitsquare.trade.protocol.trade.taker.tasks.CreateAndSignContract;
|
||||
@ -154,7 +156,8 @@ public class TakerAsSellerProtocol {
|
||||
);
|
||||
taskRunner.addTasks(
|
||||
ProcessDepositTxPublishedMessage.class,
|
||||
TakerCommitDepositTx.class
|
||||
TakerCommitDepositTx.class,
|
||||
SetupListenerForBlockChainConfirmation.class
|
||||
);
|
||||
taskRunner.run();
|
||||
}
|
||||
@ -181,6 +184,8 @@ public class TakerAsSellerProtocol {
|
||||
|
||||
// User clicked the "bank transfer received" button, so we release the funds for pay out
|
||||
public void onFiatPaymentReceived() {
|
||||
model.trade.setState(Trade.State.FIAT_PAYMENT_RECEIVED);
|
||||
|
||||
TaskRunner<TakerAsSellerModel> taskRunner = new TaskRunner<>(model,
|
||||
() -> {
|
||||
log.debug("taskRunner at handleFiatReceivedUIEvent completed");
|
||||
|
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* 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.trade.taker.tasks;
|
||||
|
||||
import io.bitsquare.common.taskrunner.Task;
|
||||
import io.bitsquare.common.taskrunner.TaskRunner;
|
||||
import io.bitsquare.trade.Trade;
|
||||
import io.bitsquare.trade.protocol.trade.offerer.models.OffererAsBuyerModel;
|
||||
|
||||
import org.bitcoinj.core.Transaction;
|
||||
import org.bitcoinj.core.TransactionConfidence;
|
||||
|
||||
import javafx.application.Platform;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class SetupListenerForBlockChainConfirmation extends Task<OffererAsBuyerModel> {
|
||||
private static final Logger log = LoggerFactory.getLogger(SetupListenerForBlockChainConfirmation.class);
|
||||
|
||||
private TransactionConfidence.Listener transactionConfidenceListener;
|
||||
private TransactionConfidence transactionConfidence;
|
||||
|
||||
public SetupListenerForBlockChainConfirmation(TaskRunner taskHandler, OffererAsBuyerModel model) {
|
||||
super(taskHandler, model);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doRun() {
|
||||
transactionConfidence = model.trade.getDepositTx().getConfidence();
|
||||
transactionConfidenceListener = new TransactionConfidence.Listener() {
|
||||
@Override
|
||||
public void onConfidenceChanged(Transaction tx, ChangeReason reason) {
|
||||
log.trace("onConfidenceChanged " + tx.getConfidence());
|
||||
if (reason == ChangeReason.TYPE && tx.getConfidence().getConfidenceType() == TransactionConfidence.ConfidenceType.BUILDING) {
|
||||
model.trade.setState(Trade.State.DEPOSIT_CONFIRMED);
|
||||
|
||||
// transactionConfidence use CopyOnWriteArrayList as listeners, but be safe and delay remove a bit.
|
||||
Platform.runLater(() -> removeEventListener());
|
||||
}
|
||||
}
|
||||
};
|
||||
transactionConfidence.addEventListener(transactionConfidenceListener);
|
||||
|
||||
complete();
|
||||
}
|
||||
|
||||
private void removeEventListener() {
|
||||
if (!transactionConfidence.removeEventListener(transactionConfidenceListener))
|
||||
throw new RuntimeException("Remove transactionConfidenceListener failed at SetupListenerForBlockChainConfirmation.");
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user