do not fetch trade txs directly from daemon

This commit is contained in:
woodser 2024-04-22 07:16:06 -04:00
parent 2e672260d3
commit 895acc9d7c
3 changed files with 23 additions and 42 deletions

View file

@ -88,7 +88,6 @@ import javafx.collections.ObservableList;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import monero.common.MoneroError;
import monero.common.MoneroRpcConnection;
import monero.common.TaskLooper;
import monero.daemon.MoneroDaemon;
@ -1181,43 +1180,12 @@ public abstract class Trade implements Tradable, Model {
@Nullable
public MoneroTx getTakerDepositTx() {
return getDepositTx(getTaker());
return getTaker().getDepositTx();
}
@Nullable
public MoneroTx getMakerDepositTx() {
return getDepositTx(getMaker());
}
private MoneroTx getDepositTx(TradePeer trader) {
String depositId = trader.getDepositTxHash();
if (depositId == null) return null;
try {
if (trader.getDepositTx() == null || !trader.getDepositTx().isConfirmed()) {
MoneroTx depositTx = getDepositTxFromWalletOrDaemon(depositId);
if (depositTx != null) trader.setDepositTx(depositTx);
}
return trader.getDepositTx();
} catch (MoneroError e) {
log.error("Error getting {} deposit tx {}: {}", getPeerRole(trader), depositId, e.getMessage()); // TODO: peer.getRole()
throw e;
}
}
private MoneroTx getDepositTxFromWalletOrDaemon(String txId) {
MoneroTx tx = null;
// first check wallet
if (getWallet() != null) {
List<MoneroTxWallet> filteredTxs = getWallet().getTxs(new MoneroTxQuery()
.setHash(txId)
.setIsConfirmed(isDepositsConfirmed() ? true : null)); // avoid checking pool if confirmed
if (filteredTxs.size() == 1) tx = filteredTxs.get(0);
}
// then check daemon
if (tx == null) tx = xmrWalletService.getDaemonTxWithCache(txId);
return tx;
return getMaker().getDepositTx();
}
public void addAndPersistChatMessage(ChatMessage chatMessage) {
@ -2231,7 +2199,7 @@ public abstract class Trade implements Tradable, Model {
if (tx.getHash().equals(getMaker().getDepositTxHash())) getMaker().setDepositTx(tx);
if (tx.getHash().equals(getTaker().getDepositTxHash())) getTaker().setDepositTx(tx);
}
if (!txs.isEmpty()) depositTxsUpdateCounter.set(depositTxsUpdateCounter.get() + 1);
depositTxsUpdateCounter.set(depositTxsUpdateCounter.get() + 1);
}
private void forceRestartTradeWallet() {

View file

@ -199,18 +199,18 @@ public class TxIdTextField extends AnchorPane {
tx = useCache ? xmrWalletService.getDaemonTxWithCache(txId) : xmrWalletService.getDaemonTx(txId);
tx.setNumConfirmations(tx.isConfirmed() ? (height == null ? xmrWalletService.getConnectionService().getLastInfo().getHeight() : height) - tx.getHeight(): 0l); // TODO: don't set if tx.getNumConfirmations() works reliably on non-local testnet
} else {
if (txId.equals(trade.getMaker().getDepositTxHash())) tx = trade.getMaker().getDepositTx();
else if (txId.equals(trade.getTaker().getDepositTxHash())) tx = trade.getTaker().getDepositTx();
if (txId.equals(trade.getMaker().getDepositTxHash())) tx = trade.getMakerDepositTx();
else if (txId.equals(trade.getTaker().getDepositTxHash())) tx = trade.getTakerDepositTx();
}
} catch (Exception e) {
// do nothing
}
updateConfidence(tx);
updateConfidence(tx, trade);
}
private void updateConfidence(MoneroTx tx) {
private void updateConfidence(MoneroTx tx, Trade trade) {
UserThread.execute(() -> {
GUIUtil.updateConfidence(tx, progressIndicatorTooltip, txConfidenceIndicator);
GUIUtil.updateConfidence(tx, trade, progressIndicatorTooltip, txConfidenceIndicator);
if (txConfidenceIndicator.getProgress() != 0) {
AnchorPane.setRightAnchor(txConfidenceIndicator, 0.0);
}

View file

@ -48,6 +48,7 @@ import haveno.core.payment.PaymentAccount;
import haveno.core.payment.PaymentAccountList;
import haveno.core.payment.payload.PaymentMethod;
import haveno.core.trade.HavenoUtils;
import haveno.core.trade.Trade;
import haveno.core.user.DontShowAgainLookup;
import haveno.core.user.Preferences;
import haveno.core.user.User;
@ -528,9 +529,21 @@ public class GUIUtil {
public static void updateConfidence(MoneroTx tx,
Tooltip tooltip,
TxConfidenceIndicator txConfidenceIndicator) {
updateConfidence(tx, null, tooltip, txConfidenceIndicator);
}
public static void updateConfidence(MoneroTx tx,
Trade trade,
Tooltip tooltip,
TxConfidenceIndicator txConfidenceIndicator) {
if (tx == null || tx.getNumConfirmations() == null || !tx.isRelayed()) {
if (trade != null && trade.isDepositsUnlocked()) {
tooltip.setText(Res.get("confidence.confirmed", ">=10"));
txConfidenceIndicator.setProgress(1.0);
} else {
tooltip.setText(Res.get("confidence.unknown"));
txConfidenceIndicator.setProgress(-1);
}
} else {
if (tx.isFailed()) {
tooltip.setText(Res.get("confidence.invalid"));