From 2966f8461c7e495559086b83dfbdfce4c47ba1e9 Mon Sep 17 00:00:00 2001 From: woodser Date: Fri, 12 Jan 2024 21:39:41 -0500 Subject: [PATCH] update balances on freeze/thaw, register open offer before processing --- .../haveno/core/offer/OpenOfferManager.java | 4 ++-- .../core/xmr/wallet/XmrWalletService.java | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/haveno/core/offer/OpenOfferManager.java b/core/src/main/java/haveno/core/offer/OpenOfferManager.java index 1de7fbcd4c..9cc4098339 100644 --- a/core/src/main/java/haveno/core/offer/OpenOfferManager.java +++ b/core/src/main/java/haveno/core/offer/OpenOfferManager.java @@ -513,8 +513,8 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe ThreadUtils.execute(() -> { synchronized (processOffersLock) { CountDownLatch latch = new CountDownLatch(1); + addOpenOffer(openOffer); processUnpostedOffer(getOpenOffers(), openOffer, (transaction) -> { - addOpenOffer(openOffer); requestPersistence(); latch.countDown(); resultHandler.handleResult(transaction); @@ -1660,8 +1660,8 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe // repost offer synchronized (processOffersLock) { CountDownLatch latch = new CountDownLatch(1); + addOpenOffer(updatedOpenOffer); processUnpostedOffer(getOpenOffers(), updatedOpenOffer, (transaction) -> { - addOpenOffer(updatedOpenOffer); requestPersistence(); latch.countDown(); if (completeHandler != null) completeHandler.run(); 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 4da9bee70a..d8ea75e524 100644 --- a/core/src/main/java/haveno/core/xmr/wallet/XmrWalletService.java +++ b/core/src/main/java/haveno/core/xmr/wallet/XmrWalletService.java @@ -407,6 +407,18 @@ public class XmrWalletService { } } + /** + * Freeze the given outputs with a lock on the wallet. + * + * @param keyImages the key images to freeze + */ + public void freezeOutputs(Collection keyImages) { + synchronized (walletLock) { + for (String keyImage : keyImages) wallet.freezeOutput(keyImage); + } + updateBalanceListeners(); // TODO (monero-java): balance listeners not notified on freeze/thaw output + } + /** * Thaw the given outputs with a lock on the wallet. * @@ -416,6 +428,7 @@ public class XmrWalletService { synchronized (walletLock) { for (String keyImage : keyImages) wallet.thawOutput(keyImage); } + updateBalanceListeners(); // TODO (monero-java): balance listeners not notified on freeze/thaw output } private List getSubaddressesWithExactInput(BigInteger amount) { @@ -530,7 +543,9 @@ public class XmrWalletService { .setPriority(XmrWalletService.PROTOCOL_FEE_PRIORITY)); // pay fee from security deposit // freeze inputs - for (MoneroOutput input : tradeTx.getInputs()) wallet.freezeOutput(input.getKeyImage().getHex()); + List keyImages = new ArrayList(); + for (MoneroOutput input : tradeTx.getInputs()) keyImages.add(input.getKeyImage().getHex()); + freezeOutputs(keyImages); saveMainWallet(); return tradeTx; }