mirror of
https://github.com/boldsuck/haveno.git
synced 2024-12-22 20:19:21 +00:00
use cached txs in xmr wallet service instead of querying wallet
This commit is contained in:
parent
a107acbdb4
commit
8097b0f499
8 changed files with 36 additions and 22 deletions
|
@ -158,7 +158,7 @@ class CoreWalletsService {
|
|||
|
||||
List<MoneroTxWallet> getXmrTxs() {
|
||||
accountService.checkAccountOpen();
|
||||
return xmrWalletService.getWallet().getTxs();
|
||||
return xmrWalletService.getTxs();
|
||||
}
|
||||
|
||||
MoneroTxWallet createXmrTx(List<MoneroDestination> destinations) {
|
||||
|
|
|
@ -947,14 +947,14 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe
|
|||
|
||||
// return split output tx if already assigned
|
||||
if (openOffer != null && openOffer.getSplitOutputTxHash() != null) {
|
||||
return xmrWalletService.getWallet().getTx(openOffer.getSplitOutputTxHash());
|
||||
return xmrWalletService.getTx(openOffer.getSplitOutputTxHash());
|
||||
}
|
||||
|
||||
// return earliest tx with exact amount to offer's subaddress if available
|
||||
if (preferredSubaddressIndex != null) {
|
||||
|
||||
// get txs with exact output amount
|
||||
fundingTxs = xmrWalletService.getWallet().getTxs(new MoneroTxQuery()
|
||||
fundingTxs = xmrWalletService.getTxs(new MoneroTxQuery()
|
||||
.setIsConfirmed(true)
|
||||
.setOutputQuery(new MoneroOutputQuery()
|
||||
.setAccountIndex(0)
|
||||
|
@ -972,7 +972,7 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe
|
|||
if (openOffer.getScheduledTxHashes() != null) return null;
|
||||
|
||||
// get all transactions including from pool
|
||||
List<MoneroTxWallet> allTxs = xmrWalletService.getTransactions(false);
|
||||
List<MoneroTxWallet> allTxs = xmrWalletService.getTxs(false);
|
||||
|
||||
if (preferredSubaddressIndex != null) {
|
||||
|
||||
|
@ -1067,7 +1067,7 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe
|
|||
}
|
||||
|
||||
// get locked txs
|
||||
List<MoneroTxWallet> lockedTxs = xmrWalletService.getWallet().getTxs(new MoneroTxQuery().setIsLocked(true));
|
||||
List<MoneroTxWallet> lockedTxs = xmrWalletService.getTxs(new MoneroTxQuery().setIsLocked(true));
|
||||
|
||||
// get earliest unscheduled txs with sufficient incoming amount
|
||||
List<String> scheduledTxHashes = new ArrayList<String>();
|
||||
|
|
|
@ -1215,7 +1215,7 @@ public abstract class Trade implements Tradable, Model {
|
|||
}
|
||||
|
||||
// then check daemon
|
||||
if (tx == null) tx = getXmrWalletService().getTxWithCache(txId);
|
||||
if (tx == null) tx = xmrWalletService.getDaemonTxWithCache(txId);
|
||||
return tx;
|
||||
}
|
||||
|
||||
|
@ -1541,7 +1541,7 @@ public abstract class Trade implements Tradable, Model {
|
|||
@Nullable
|
||||
public MoneroTx getPayoutTx() {
|
||||
if (payoutTx == null) {
|
||||
payoutTx = payoutTxId == null ? null : (this instanceof ArbitratorTrade) ? xmrWalletService.getTxWithCache(payoutTxId) : xmrWalletService.getWallet().getTx(payoutTxId);
|
||||
payoutTx = payoutTxId == null ? null : (this instanceof ArbitratorTrade) ? xmrWalletService.getDaemonTxWithCache(payoutTxId) : xmrWalletService.getTx(payoutTxId);
|
||||
}
|
||||
return payoutTx;
|
||||
}
|
||||
|
|
|
@ -779,12 +779,12 @@ public class XmrWalletService {
|
|||
return feeEstimate;
|
||||
}
|
||||
|
||||
public MoneroTx getTx(String txHash) {
|
||||
List<MoneroTx> txs = getTxs(Arrays.asList(txHash));
|
||||
public MoneroTx getDaemonTx(String txHash) {
|
||||
List<MoneroTx> txs = getDaemonTxs(Arrays.asList(txHash));
|
||||
return txs.isEmpty() ? null : txs.get(0);
|
||||
}
|
||||
|
||||
public List<MoneroTx> getTxs(List<String> txHashes) {
|
||||
public List<MoneroTx> getDaemonTxs(List<String> txHashes) {
|
||||
synchronized (txCache) {
|
||||
|
||||
// fetch txs
|
||||
|
@ -804,12 +804,12 @@ public class XmrWalletService {
|
|||
}
|
||||
}
|
||||
|
||||
public MoneroTx getTxWithCache(String txHash) {
|
||||
List<MoneroTx> cachedTxs = getTxsWithCache(Arrays.asList(txHash));
|
||||
public MoneroTx getDaemonTxWithCache(String txHash) {
|
||||
List<MoneroTx> cachedTxs = getDaemonTxsWithCache(Arrays.asList(txHash));
|
||||
return cachedTxs.isEmpty() ? null : cachedTxs.get(0);
|
||||
}
|
||||
|
||||
public List<MoneroTx> getTxsWithCache(List<String> txHashes) {
|
||||
public List<MoneroTx> getDaemonTxsWithCache(List<String> txHashes) {
|
||||
synchronized (txCache) {
|
||||
try {
|
||||
// get cached txs
|
||||
|
@ -821,7 +821,7 @@ public class XmrWalletService {
|
|||
}
|
||||
|
||||
// return txs from cache if available, otherwise fetch
|
||||
return uncachedTxHashes.isEmpty() ? cachedTxs : getTxs(txHashes);
|
||||
return uncachedTxHashes.isEmpty() ? cachedTxs : getDaemonTxs(txHashes);
|
||||
} catch (Exception e) {
|
||||
if (!isShutDownStarted) throw e;
|
||||
return null;
|
||||
|
@ -1136,13 +1136,27 @@ public class XmrWalletService {
|
|||
xmrAddressEntryList.requestPersistence();
|
||||
}
|
||||
|
||||
public List<MoneroTxWallet> getTransactions(boolean includeFailed) {
|
||||
public List<MoneroTxWallet> getTxs(boolean includeFailed) {
|
||||
List<MoneroTxWallet> txs = getTxs();
|
||||
if (includeFailed) return txs;
|
||||
return txs.stream().filter(tx -> !tx.isFailed()).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public List<MoneroTxWallet> getTxs() {
|
||||
return getTxs(new MoneroTxQuery());
|
||||
}
|
||||
|
||||
public List<MoneroTxWallet> getTxs(MoneroTxQuery query) {
|
||||
if (cachedTxs == null) {
|
||||
log.warn("Transactions not cached, fetching from wallet");
|
||||
cachedTxs = wallet.getTxs(new MoneroTxQuery().setIncludeOutputs(true)); // fetches from pool
|
||||
}
|
||||
if (includeFailed) return cachedTxs;
|
||||
return cachedTxs.stream().filter(tx -> !tx.isFailed()).collect(Collectors.toList());
|
||||
return cachedTxs.stream().filter(tx -> query.meetsCriteria(tx)).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public MoneroTxWallet getTx(String txId) {
|
||||
List<MoneroTxWallet> txs = getTxs(new MoneroTxQuery().setHash(txId));
|
||||
return txs.isEmpty() ? null : txs.get(0);
|
||||
}
|
||||
|
||||
public BigInteger getBalance() {
|
||||
|
|
|
@ -171,7 +171,7 @@ public class TxIdTextField extends AnchorPane {
|
|||
private synchronized void updateConfidence(String txId, boolean useCache, Long height) {
|
||||
MoneroTx tx = null;
|
||||
try {
|
||||
tx = useCache ? xmrWalletService.getTxWithCache(txId) : xmrWalletService.getTx(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
|
||||
} catch (Exception e) {
|
||||
// do nothing
|
||||
|
|
|
@ -50,7 +50,7 @@ class DisplayedTransactions extends ObservableListDecorator<TransactionsListItem
|
|||
}
|
||||
|
||||
private List<TransactionsListItem> getTransactionListItems() {
|
||||
List<MoneroTxWallet> transactions = xmrWalletService.getTransactions(false);
|
||||
List<MoneroTxWallet> transactions = xmrWalletService.getTxs(false);
|
||||
return transactions.stream()
|
||||
.map(this::convertTransactionToListItem)
|
||||
.collect(Collectors.toList());
|
||||
|
|
|
@ -171,7 +171,7 @@ public abstract class TradeStepView extends AnchorPane {
|
|||
List<String> txIds = new ArrayList<String>();
|
||||
if (!model.dataModel.makerTxId.isEmpty().get()) txIds.add(model.dataModel.makerTxId.get());
|
||||
if (!model.dataModel.takerTxId.isEmpty().get()) txIds.add(model.dataModel.takerTxId.get());
|
||||
new Thread(() -> trade.getXmrWalletService().getTxsWithCache(txIds)).start();
|
||||
new Thread(() -> trade.getXmrWalletService().getDaemonTxsWithCache(txIds)).start();
|
||||
}
|
||||
|
||||
public void activate() {
|
||||
|
|
|
@ -40,7 +40,7 @@ public class DisplayedTransactionsTest {
|
|||
List<MoneroTxWallet> transactions = Lists.newArrayList(mock(MoneroTxWallet.class), mock(MoneroTxWallet.class));
|
||||
|
||||
XmrWalletService walletService = mock(XmrWalletService.class);
|
||||
when(walletService.getTransactions(false)).thenReturn(transactions);
|
||||
when(walletService.getTxs(false)).thenReturn(transactions);
|
||||
|
||||
TransactionListItemFactory transactionListItemFactory = mock(TransactionListItemFactory.class,
|
||||
RETURNS_DEEP_STUBS);
|
||||
|
@ -60,7 +60,7 @@ public class DisplayedTransactionsTest {
|
|||
@Test
|
||||
public void testUpdateWhenRepositoryIsEmpty() {
|
||||
XmrWalletService walletService = mock(XmrWalletService.class);
|
||||
when(walletService.getTransactions(false))
|
||||
when(walletService.getTxs(false))
|
||||
.thenReturn(Collections.singletonList(mock(MoneroTxWallet.class)));
|
||||
|
||||
TradableRepository tradableRepository = mock(TradableRepository.class);
|
||||
|
|
Loading…
Reference in a new issue