wait for split output tx to unlock before taking offer

This commit is contained in:
woodser 2024-01-13 08:39:27 -05:00
parent d739cc56e9
commit da79f15a5a

View File

@ -2276,8 +2276,12 @@ async function executeTrade(ctxP: Partial<TradeContext>): Promise<string> {
// wait for split output tx to unlock // wait for split output tx to unlock
if (ctx.isStopped) return ctx.offerId!; if (ctx.isStopped) return ctx.offerId!;
if (ctx.reserveExactAmount) { if (ctx.reserveExactAmount) {
await mineToHeight(await monerod.getHeight() + 10); // TODO: wait for offer to be available (dandilion) const splitOutputTxId = ctx.offer?.getSplitOutputTxHash();
await wait(TestConfig.daemonPollPeriodMs * 2); HavenoUtils.log(1, "Waiting for split output tx " + splitOutputTxId + " to unlock");
if (splitOutputTxId) {
await mineToUnlock(splitOutputTxId);
await wait(TestConfig.trade.walletSyncPeriodMs + TestConfig.trade.maxTimePeerNoticeMs);
}
} }
// take offer or get existing trade // take offer or get existing trade
@ -3454,6 +3458,17 @@ async function mineToHeight(height: number) {
if (miningStarted) await stopMining(); if (miningStarted) await stopMining();
} }
async function mineToUnlock(txHash: string) {
let tx = await monerod.getTx(txHash);
if (tx && tx.getNumConfirmations() >= 10) return; // TODO: tx.getIsLocked()
const miningStarted = await startMining();
while (!tx || tx.getNumConfirmations() < 10) {
await moneroTs.GenUtils.waitFor(TestConfig.trade.walletSyncPeriodMs);
tx = await monerod.getTx(txHash);
}
if (miningStarted) await stopMining();
}
/** /**
* Wait for unlocked balance in wallet or Haveno daemon. * Wait for unlocked balance in wallet or Haveno daemon.
*/ */