mirror of
https://github.com/boldsuck/haveno.git
synced 2024-12-23 04:29:22 +00:00
fix issues scheduling offer with exact input amount (#934)
This commit is contained in:
parent
7885d95a4c
commit
80db207a98
1 changed files with 10 additions and 22 deletions
|
@ -892,34 +892,18 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe
|
||||||
|
|
||||||
// find tx with exact input amount
|
// find tx with exact input amount
|
||||||
MoneroTxWallet splitOutputTx = findSplitOutputFundingTx(openOffers, openOffer);
|
MoneroTxWallet splitOutputTx = findSplitOutputFundingTx(openOffers, openOffer);
|
||||||
if (splitOutputTx != null && openOffer.getScheduledTxHashes() == null) {
|
if (splitOutputTx != null && openOffer.getSplitOutputTxHash() == null) {
|
||||||
openOffer.setScheduledTxHashes(Arrays.asList(splitOutputTx.getHash()));
|
setSplitOutputTx(openOffer, splitOutputTx);
|
||||||
openOffer.setScheduledAmount(amountNeeded.toString());
|
|
||||||
openOffer.setState(OpenOffer.State.SCHEDULED);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// if not found, create tx to split exact output
|
// if not found, create tx to split exact output
|
||||||
if (splitOutputTx == null) {
|
if (splitOutputTx == null) {
|
||||||
if (openOffer.getSplitOutputTxHash() != null) {
|
if (openOffer.getSplitOutputTxHash() != null) log.warn("Split output tx not found for offer {}", openOffer.getId());
|
||||||
log.warn("Split output tx not found for offer {}", openOffer.getId());
|
|
||||||
}
|
|
||||||
splitOrSchedule(openOffers, openOffer, amountNeeded);
|
splitOrSchedule(openOffers, openOffer, amountNeeded);
|
||||||
} else if (!splitOutputTx.isLocked()) {
|
} else if (!splitOutputTx.isLocked()) {
|
||||||
|
|
||||||
// otherwise sign and post offer if split output available
|
// otherwise sign and post offer if split output available
|
||||||
signAndPostOffer(openOffer, true, resultHandler, (errMsg) -> {
|
signAndPostOffer(openOffer, true, resultHandler, errorMessageHandler);
|
||||||
|
|
||||||
// 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);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -1069,13 +1053,17 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe
|
||||||
log.info("Done creating split output tx to fund offer {} in {} ms", openOffer.getId(), System.currentTimeMillis() - startTime);
|
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.setSplitOutputTxHash(splitOutputTx.getHash());
|
||||||
openOffer.setSplitOutputTxFee(splitOutputTx.getFee().longValueExact());
|
openOffer.setSplitOutputTxFee(splitOutputTx.getFee().longValueExact());
|
||||||
openOffer.setScheduledTxHashes(Arrays.asList(splitOutputTx.getHash()));
|
openOffer.setScheduledTxHashes(Arrays.asList(splitOutputTx.getHash()));
|
||||||
openOffer.setScheduledAmount(openOffer.getOffer().getAmountNeeded().toString());
|
openOffer.setScheduledAmount(openOffer.getOffer().getAmountNeeded().toString());
|
||||||
openOffer.setState(OpenOffer.State.SCHEDULED);
|
openOffer.setState(OpenOffer.State.SCHEDULED);
|
||||||
return splitOutputTx;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void scheduleWithEarliestTxs(List<OpenOffer> openOffers, OpenOffer openOffer) {
|
private void scheduleWithEarliestTxs(List<OpenOffer> openOffers, OpenOffer openOffer) {
|
||||||
|
|
Loading…
Reference in a new issue