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.Getter;
import lombok.Setter; import lombok.Setter;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import monero.common.MoneroError;
import monero.common.MoneroRpcConnection; import monero.common.MoneroRpcConnection;
import monero.common.TaskLooper; import monero.common.TaskLooper;
import monero.daemon.MoneroDaemon; import monero.daemon.MoneroDaemon;
@ -1181,43 +1180,12 @@ public abstract class Trade implements Tradable, Model {
@Nullable @Nullable
public MoneroTx getTakerDepositTx() { public MoneroTx getTakerDepositTx() {
return getDepositTx(getTaker()); return getTaker().getDepositTx();
} }
@Nullable @Nullable
public MoneroTx getMakerDepositTx() { public MoneroTx getMakerDepositTx() {
return getDepositTx(getMaker()); return getMaker().getDepositTx();
}
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;
} }
public void addAndPersistChatMessage(ChatMessage chatMessage) { 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(getMaker().getDepositTxHash())) getMaker().setDepositTx(tx);
if (tx.getHash().equals(getTaker().getDepositTxHash())) getTaker().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() { private void forceRestartTradeWallet() {

View file

@ -199,18 +199,18 @@ public class TxIdTextField extends AnchorPane {
tx = useCache ? xmrWalletService.getDaemonTxWithCache(txId) : xmrWalletService.getDaemonTx(txId); 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 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 { } else {
if (txId.equals(trade.getMaker().getDepositTxHash())) tx = trade.getMaker().getDepositTx(); if (txId.equals(trade.getMaker().getDepositTxHash())) tx = trade.getMakerDepositTx();
else if (txId.equals(trade.getTaker().getDepositTxHash())) tx = trade.getTaker().getDepositTx(); else if (txId.equals(trade.getTaker().getDepositTxHash())) tx = trade.getTakerDepositTx();
} }
} catch (Exception e) { } catch (Exception e) {
// do nothing // do nothing
} }
updateConfidence(tx); updateConfidence(tx, trade);
} }
private void updateConfidence(MoneroTx tx) { private void updateConfidence(MoneroTx tx, Trade trade) {
UserThread.execute(() -> { UserThread.execute(() -> {
GUIUtil.updateConfidence(tx, progressIndicatorTooltip, txConfidenceIndicator); GUIUtil.updateConfidence(tx, trade, progressIndicatorTooltip, txConfidenceIndicator);
if (txConfidenceIndicator.getProgress() != 0) { if (txConfidenceIndicator.getProgress() != 0) {
AnchorPane.setRightAnchor(txConfidenceIndicator, 0.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.PaymentAccountList;
import haveno.core.payment.payload.PaymentMethod; import haveno.core.payment.payload.PaymentMethod;
import haveno.core.trade.HavenoUtils; import haveno.core.trade.HavenoUtils;
import haveno.core.trade.Trade;
import haveno.core.user.DontShowAgainLookup; import haveno.core.user.DontShowAgainLookup;
import haveno.core.user.Preferences; import haveno.core.user.Preferences;
import haveno.core.user.User; import haveno.core.user.User;
@ -528,9 +529,21 @@ public class GUIUtil {
public static void updateConfidence(MoneroTx tx, public static void updateConfidence(MoneroTx tx,
Tooltip tooltip, Tooltip tooltip,
TxConfidenceIndicator txConfidenceIndicator) { 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 (tx == null || tx.getNumConfirmations() == null || !tx.isRelayed()) {
tooltip.setText(Res.get("confidence.unknown")); if (trade != null && trade.isDepositsUnlocked()) {
txConfidenceIndicator.setProgress(-1); tooltip.setText(Res.get("confidence.confirmed", ">=10"));
txConfidenceIndicator.setProgress(1.0);
} else {
tooltip.setText(Res.get("confidence.unknown"));
txConfidenceIndicator.setProgress(-1);
}
} else { } else {
if (tx.isFailed()) { if (tx.isFailed()) {
tooltip.setText(Res.get("confidence.invalid")); tooltip.setText(Res.get("confidence.invalid"));