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(() -> {
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();

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.
*
@ -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<Integer> 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<String> keyImages = new ArrayList<String>();
for (MoneroOutput input : tradeTx.getInputs()) keyImages.add(input.getKeyImage().getHex());
freezeOutputs(keyImages);
saveMainWallet();
return tradeTx;
}