From 8776fecef0be3ab69cfc9c07d7407acefde24a29 Mon Sep 17 00:00:00 2001 From: woodser Date: Thu, 25 Jan 2024 06:16:52 -0500 Subject: [PATCH] use wallet lock with xmr address entries --- .../core/xmr/wallet/XmrWalletService.java | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/core/src/main/java/haveno/core/xmr/wallet/XmrWalletService.java b/core/src/main/java/haveno/core/xmr/wallet/XmrWalletService.java index 516ef669..46b8d376 100644 --- a/core/src/main/java/haveno/core/xmr/wallet/XmrWalletService.java +++ b/core/src/main/java/haveno/core/xmr/wallet/XmrWalletService.java @@ -1206,8 +1206,10 @@ public class XmrWalletService { } public List getFundedAvailableAddressEntries() { - List subaddresses = wallet.getSubaddresses(0); - return getAvailableAddressEntries().stream().filter(addressEntry -> getBalanceForSubaddress(addressEntry.getSubaddressIndex(), subaddresses).compareTo(BigInteger.ZERO) > 0).collect(Collectors.toList()); + synchronized (walletLock) { + List subaddresses = wallet.getSubaddresses(0); + return getAvailableAddressEntries().stream().filter(addressEntry -> getBalanceForSubaddress(addressEntry.getSubaddressIndex(), subaddresses).compareTo(BigInteger.ZERO) > 0).collect(Collectors.toList()); + } } public List getAddressEntryListAsImmutableList() { @@ -1225,7 +1227,9 @@ public class XmrWalletService { } public List getUnusedAddressEntries() { - return getUnusedAddressEntries(getTxsWithIncomingOutputs(), wallet.getSubaddresses(0)); + synchronized (walletLock) { + return getUnusedAddressEntries(getTxsWithIncomingOutputs(), wallet.getSubaddresses(0)); + } } public List getUnusedAddressEntries(List cachedTxs, List cachedSubaddresses) { @@ -1338,12 +1342,14 @@ public class XmrWalletService { } public Stream getAddressEntriesForAvailableBalanceStream() { - Stream available = getFundedAvailableAddressEntries().stream(); - available = Stream.concat(available, getAddressEntries(XmrAddressEntry.Context.ARBITRATOR).stream()); - available = Stream.concat(available, getAddressEntries(XmrAddressEntry.Context.OFFER_FUNDING).stream().filter(entry -> !tradeManager.getOpenOfferManager().getOpenOfferById(entry.getOfferId()).isPresent())); - available = Stream.concat(available, getAddressEntries(XmrAddressEntry.Context.TRADE_PAYOUT).stream().filter(entry -> tradeManager.getTrade(entry.getOfferId()) == null || tradeManager.getTrade(entry.getOfferId()).isPayoutUnlocked())); - List subaddresses = wallet.getSubaddresses(0); - return available.filter(addressEntry -> getBalanceForSubaddress(addressEntry.getSubaddressIndex(), subaddresses).compareTo(BigInteger.ZERO) > 0); + synchronized (walletLock) { + Stream available = getFundedAvailableAddressEntries().stream(); + available = Stream.concat(available, getAddressEntries(XmrAddressEntry.Context.ARBITRATOR).stream()); + available = Stream.concat(available, getAddressEntries(XmrAddressEntry.Context.OFFER_FUNDING).stream().filter(entry -> !tradeManager.getOpenOfferManager().getOpenOfferById(entry.getOfferId()).isPresent())); + available = Stream.concat(available, getAddressEntries(XmrAddressEntry.Context.TRADE_PAYOUT).stream().filter(entry -> tradeManager.getTrade(entry.getOfferId()) == null || tradeManager.getTrade(entry.getOfferId()).isPayoutUnlocked())); + List subaddresses = wallet.getSubaddresses(0); + return available.filter(addressEntry -> getBalanceForSubaddress(addressEntry.getSubaddressIndex(), subaddresses).compareTo(BigInteger.ZERO) > 0); + } } public void addWalletListener(MoneroWalletListenerI listener) {