Skip to content

Commit

Permalink
fix issues scheduling offer with exact input amount (#934)
Browse files Browse the repository at this point in the history
  • Loading branch information
woodser authored May 19, 2024
1 parent 7885d95 commit 80db207
Showing 1 changed file with 10 additions and 22 deletions.
32 changes: 10 additions & 22 deletions core/src/main/java/haveno/core/offer/OpenOfferManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -892,34 +892,18 @@ private void processUnpostedOffer(List<OpenOffer> openOffers, OpenOffer openOffe

// find tx with exact input amount
MoneroTxWallet splitOutputTx = findSplitOutputFundingTx(openOffers, openOffer);
if (splitOutputTx != null && openOffer.getScheduledTxHashes() == null) {
openOffer.setScheduledTxHashes(Arrays.asList(splitOutputTx.getHash()));
openOffer.setScheduledAmount(amountNeeded.toString());
openOffer.setState(OpenOffer.State.SCHEDULED);
if (splitOutputTx != null && openOffer.getSplitOutputTxHash() == null) {
setSplitOutputTx(openOffer, splitOutputTx);
}

// if not found, create tx to split exact output
if (splitOutputTx == null) {
if (openOffer.getSplitOutputTxHash() != null) {
log.warn("Split output tx not found for offer {}", openOffer.getId());
}
if (openOffer.getSplitOutputTxHash() != null) log.warn("Split output tx not found for offer {}", openOffer.getId());
splitOrSchedule(openOffers, openOffer, amountNeeded);
} else if (!splitOutputTx.isLocked()) {

// otherwise sign and post offer if split output available
signAndPostOffer(openOffer, true, resultHandler, (errMsg) -> {

// on error, create split output tx if not already created
if (openOffer.getSplitOutputTxHash() == null) {
int offerSubaddress = xmrWalletService.getOrCreateAddressEntry(openOffer.getId(), XmrAddressEntry.Context.OFFER_FUNDING).getSubaddressIndex();
BigInteger balance = xmrWalletService.getBalanceForSubaddress(offerSubaddress);
log.warn("Splitting new output because spending scheduled output(s) failed, offerId={}, offerSubaddress={}, hasBalance={}", openOffer.getId(), offerSubaddress, balance.compareTo(BigInteger.ZERO) > 0);
splitOrSchedule(openOffers, openOffer, amountNeeded);
resultHandler.handleResult(null);
} else {
errorMessageHandler.handleErrorMessage(errMsg);
}
});
signAndPostOffer(openOffer, true, resultHandler, errorMessageHandler);
return;
}
} else {
Expand Down Expand Up @@ -1069,13 +1053,17 @@ private MoneroTxWallet splitAndSchedule(OpenOffer openOffer) {
log.info("Done creating split output tx to fund offer {} in {} ms", openOffer.getId(), System.currentTimeMillis() - startTime);
}

// schedule txs
// set split tx
setSplitOutputTx(openOffer, splitOutputTx);
return splitOutputTx;
}

private void setSplitOutputTx(OpenOffer openOffer, MoneroTxWallet splitOutputTx) {
openOffer.setSplitOutputTxHash(splitOutputTx.getHash());
openOffer.setSplitOutputTxFee(splitOutputTx.getFee().longValueExact());
openOffer.setScheduledTxHashes(Arrays.asList(splitOutputTx.getHash()));
openOffer.setScheduledAmount(openOffer.getOffer().getAmountNeeded().toString());
openOffer.setState(OpenOffer.State.SCHEDULED);
return splitOutputTx;
}

private void scheduleWithEarliestTxs(List<OpenOffer> openOffers, OpenOffer openOffer) {
Expand Down

0 comments on commit 80db207

Please sign in to comment.