update balances on freeze/thaw, register open offer before processing

This commit is contained in:
woodser 2024-01-12 21:39:41 -05:00
parent 036ddef52c
commit 2966f8461c
2 changed files with 18 additions and 3 deletions

View File

@ -513,8 +513,8 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe
ThreadUtils.execute(() -> { ThreadUtils.execute(() -> {
synchronized (processOffersLock) { synchronized (processOffersLock) {
CountDownLatch latch = new CountDownLatch(1); CountDownLatch latch = new CountDownLatch(1);
processUnpostedOffer(getOpenOffers(), openOffer, (transaction) -> {
addOpenOffer(openOffer); addOpenOffer(openOffer);
processUnpostedOffer(getOpenOffers(), openOffer, (transaction) -> {
requestPersistence(); requestPersistence();
latch.countDown(); latch.countDown();
resultHandler.handleResult(transaction); resultHandler.handleResult(transaction);
@ -1660,8 +1660,8 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe
// repost offer // repost offer
synchronized (processOffersLock) { synchronized (processOffersLock) {
CountDownLatch latch = new CountDownLatch(1); CountDownLatch latch = new CountDownLatch(1);
processUnpostedOffer(getOpenOffers(), updatedOpenOffer, (transaction) -> {
addOpenOffer(updatedOpenOffer); addOpenOffer(updatedOpenOffer);
processUnpostedOffer(getOpenOffers(), updatedOpenOffer, (transaction) -> {
requestPersistence(); requestPersistence();
latch.countDown(); latch.countDown();
if (completeHandler != null) completeHandler.run(); if (completeHandler != null) completeHandler.run();

View File

@ -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<String> 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. * Thaw the given outputs with a lock on the wallet.
* *
@ -416,6 +428,7 @@ public class XmrWalletService {
synchronized (walletLock) { synchronized (walletLock) {
for (String keyImage : keyImages) wallet.thawOutput(keyImage); for (String keyImage : keyImages) wallet.thawOutput(keyImage);
} }
updateBalanceListeners(); // TODO (monero-java): balance listeners not notified on freeze/thaw output
} }
private List<Integer> getSubaddressesWithExactInput(BigInteger amount) { private List<Integer> getSubaddressesWithExactInput(BigInteger amount) {
@ -530,7 +543,9 @@ public class XmrWalletService {
.setPriority(XmrWalletService.PROTOCOL_FEE_PRIORITY)); // pay fee from security deposit .setPriority(XmrWalletService.PROTOCOL_FEE_PRIORITY)); // pay fee from security deposit
// freeze inputs // freeze inputs
for (MoneroOutput input : tradeTx.getInputs()) wallet.freezeOutput(input.getKeyImage().getHex()); List<String> keyImages = new ArrayList<String>();
for (MoneroOutput input : tradeTx.getInputs()) keyImages.add(input.getKeyImage().getHex());
freezeOutputs(keyImages);
saveMainWallet(); saveMainWallet();
return tradeTx; return tradeTx;
} }