republish offers awaits prices and runs off UserThread

This commit is contained in:
woodser 2023-12-15 16:18:00 -05:00
parent dbd8db0e88
commit 26ea53883c
2 changed files with 18 additions and 2 deletions

View file

@ -863,7 +863,7 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe
// on error, create split output tx if not already created // on error, create split output tx if not already created
if (openOffer.getSplitOutputTxHash() == null) { if (openOffer.getSplitOutputTxHash() == null) {
int offerSubaddress = xmrWalletService.getOrCreateAddressEntry(openOffer.getId(), XmrAddressEntry.Context.OFFER_FUNDING).getSubaddressIndex(); int offerSubaddress = xmrWalletService.getOrCreateAddressEntry(openOffer.getId(), XmrAddressEntry.Context.OFFER_FUNDING).getSubaddressIndex();
log.warn("Splitting new output because spending scheduled output(s) failed for offer {}. Split output tx subaddresses={}. Offer funding subadress={}", openOffer.getId(), splitOutputTx.getOutgoingTransfer().getSubaddressIndices(), offerSubaddress); log.warn("Splitting new output because spending scheduled output(s) failed for offer {}. Offer funding subadress={}", openOffer.getId(), offerSubaddress);
splitOrSchedule(openOffers, openOffer, offerReserveAmount); splitOrSchedule(openOffers, openOffer, offerReserveAmount);
resultHandler.handleResult(null); resultHandler.handleResult(null);
} else { } else {
@ -1569,7 +1569,11 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe
stopPeriodicRefreshOffersTimer(); stopPeriodicRefreshOffersTimer();
priceFeedService.awaitPrices();
new Thread(() -> {
processListForRepublishOffers(getOpenOffers()); processListForRepublishOffers(getOpenOffers());
}).start();
} }
private void processListForRepublishOffers(List<OpenOffer> list) { private void processListForRepublishOffers(List<OpenOffer> list) {

View file

@ -137,6 +137,18 @@ public class PriceFeedService {
request(false); request(false);
} }
/**
* Awaits prices to be available, but does not request them.
*/
public void awaitPrices() {
if (hasPrices()) return;
CountDownLatch latch = new CountDownLatch(1);
ChangeListener<? super Number> listener = (observable, oldValue, newValue) -> { latch.countDown(); };
updateCounter.addListener(listener);
HavenoUtils.awaitLatch(latch);
updateCounter.removeListener(listener);
}
public boolean hasPrices() { public boolean hasPrices() {
return !cache.isEmpty(); return !cache.isEmpty();
} }