getNewAddressEntry() recovers and gets new subaddress if offline

This commit is contained in:
woodser 2023-05-25 07:49:18 -04:00
parent 55edf10635
commit 4aa13bffff

View file

@ -844,9 +844,14 @@ public class XmrWalletService {
public synchronized XmrAddressEntry getNewAddressEntry(String offerId, XmrAddressEntry.Context context) {
// try to use available and not yet used entries
try {
List<MoneroTxWallet> incomingTxs = getIncomingTxs(); // prefetch all incoming txs to avoid query per subaddress
Optional<XmrAddressEntry> emptyAvailableAddressEntry = getAddressEntryListAsImmutableList().stream().filter(e -> XmrAddressEntry.Context.AVAILABLE == e.getContext()).filter(e -> isSubaddressUnused(e.getSubaddressIndex(), incomingTxs)).findAny();
if (emptyAvailableAddressEntry.isPresent()) return xmrAddressEntryList.swapAvailableToAddressEntryWithOfferId(emptyAvailableAddressEntry.get(), context, offerId);
} catch (Exception e) {
log.warn("Error getting new address entriy based on incoming transactions");
e.printStackTrace();
}
// create new subaddress and entry
MoneroSubaddress subaddress = wallet.createSubaddress(0);