From b6783dc732c7eeed65ebccb7bb91560c7ba460ff Mon Sep 17 00:00:00 2001 From: woodser Date: Sat, 16 Jul 2022 20:47:04 -0400 Subject: [PATCH] thaw outputs not reserved for trade or offer on startup --- .../core/btc/wallet/XmrWalletService.java | 6 ++-- .../java/bisq/core/trade/TradeManager.java | 30 +++++++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/bisq/core/btc/wallet/XmrWalletService.java b/core/src/main/java/bisq/core/btc/wallet/XmrWalletService.java index 3aa02fb3..596db4b3 100644 --- a/core/src/main/java/bisq/core/btc/wallet/XmrWalletService.java +++ b/core/src/main/java/bisq/core/btc/wallet/XmrWalletService.java @@ -387,7 +387,7 @@ public class XmrWalletService { private void initialize() { // initialize main wallet if connected or previously created - tryInitMainWallet(); + maybeInitMainWallet(); // update wallet connections on change connectionsService.addListener(newConnection -> { @@ -400,7 +400,7 @@ public class XmrWalletService { return new File(path + ".keys").exists(); } - private void tryInitMainWallet() { + private void maybeInitMainWallet() { // open or create wallet MoneroWalletConfig walletConfig = new MoneroWalletConfig().setPath(MONERO_WALLET_NAME).setPassword(getWalletPassword()); @@ -517,7 +517,7 @@ public class XmrWalletService { private void setWalletDaemonConnections(MoneroRpcConnection connection) { log.info("Setting wallet daemon connection: " + (connection == null ? null : connection.getUri())); - if (wallet == null) tryInitMainWallet(); + if (wallet == null) maybeInitMainWallet(); if (wallet != null) { wallet.setDaemonConnection(connection); wallet.startSyncing(connectionsService.getDefaultRefreshPeriodMs()); diff --git a/core/src/main/java/bisq/core/trade/TradeManager.java b/core/src/main/java/bisq/core/trade/TradeManager.java index d668a30d..0be0e2df 100644 --- a/core/src/main/java/bisq/core/trade/TradeManager.java +++ b/core/src/main/java/bisq/core/trade/TradeManager.java @@ -118,6 +118,7 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import monero.daemon.model.MoneroTx; +import monero.wallet.model.MoneroOutputQuery; public class TradeManager implements PersistedDataHost, DecryptedDirectMessageListener { @@ -288,6 +289,35 @@ public class TradeManager implements PersistedDataHost, DecryptedDirectMessageLi log.warn("Swapping pending OFFER_FUNDING entries at startup. offerId={}", addressEntry.getOfferId()); xmrWalletService.swapTradeEntryToAvailableEntry(addressEntry.getOfferId(), XmrAddressEntry.Context.OFFER_FUNDING); }); + + // thaw unreserved outputs + thawUnreservedOutputs(); + } + + private void thawUnreservedOutputs() { + if (xmrWalletService.getWallet() == null) return; + + // collect reserved outputs + Set reservedKeyImages = new HashSet(); + for (Trade trade : getObservableList()) { + if (trade.getSelf().getReserveTxKeyImages() == null) continue; + reservedKeyImages.addAll(trade.getSelf().getReserveTxKeyImages()); + } + for (OpenOffer openOffer : openOfferManager.getObservableList()) { + reservedKeyImages.addAll(openOffer.getOffer().getOfferPayload().getReserveTxKeyImages()); + } + + // thaw unreserved outputs + Set frozenKeyImages = xmrWalletService.getWallet().getOutputs(new MoneroOutputQuery() + .setIsFrozen(true) + .setIsSpent(false)) + .stream().map(output -> output.getKeyImage().getHex()) + .collect(Collectors.toSet()); + frozenKeyImages.removeAll(reservedKeyImages); + for (String unreservedFrozenKeyImage : frozenKeyImages) { + log.info("Thawing output which is not reserved for offer or trade: " + unreservedFrozenKeyImage); + xmrWalletService.getWallet().thawOutput(unreservedFrozenKeyImage); + } } public TradeProtocol getTradeProtocol(Trade trade) {