thaw outputs not reserved for trade or offer on startup
This commit is contained in:
parent
a80a7eec5f
commit
b6783dc732
@ -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());
|
||||
|
@ -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<String> reservedKeyImages = new HashSet<String>();
|
||||
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<String> 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) {
|
||||
|
Loading…
Reference in New Issue
Block a user