aboutsummaryrefslogtreecommitdiffstats
path: root/migrator
diff options
context:
space:
mode:
Diffstat (limited to 'migrator')
-rw-r--r--migrator/e2e-test.js7
-rw-r--r--migrator/server.js19
2 files changed, 21 insertions, 5 deletions
diff --git a/migrator/e2e-test.js b/migrator/e2e-test.js
index 714e7a4..244b106 100644
--- a/migrator/e2e-test.js
+++ b/migrator/e2e-test.js
@@ -66,11 +66,14 @@ check('info names both servers', info.oldServerPubkey && info.newServerPubkey &&
console.log('\n[1] fund the migrator float on the new server');
const fb = await api('/admin/board', { amountSat: 500000 }, true);
check('admin board returns a funding address', !!fb.fundingAddress, fb.error || '');
+// change FIRST: the board output lands at vout 1, as an ordinary wallet might send it
const raw = sh(`${BCLI} createrawtransaction '[]' '[{"${fb.fundingAddress}":0.00500000}]'`);
-const funded = JSON.parse(sh(`${BCLI} fundrawtransaction ${raw} '{"changePosition":1}'`));
+const funded = JSON.parse(sh(`${BCLI} fundrawtransaction ${raw} '{"changePosition":0}'`));
const signed = JSON.parse(sh(`${BCLI} signrawtransactionwithwallet ${funded.hex}`));
const ftx = sh(`${BCLI} sendrawtransaction ${signed.hex}`);
-await api('/admin/board/complete', { actionId: fb.actionId, txid: ftx }, true);
+let bc1;
+for (let i = 0; i < 15; i++) { bc1 = await api('/admin/board/complete', { actionId: fb.actionId, txid: ftx }, true); if (bc1.status !== 409) break; await sleep(1000); }
+check('board output found at vout 1', bc1.vout === 1, JSON.stringify(bc1));
mine(3);
let sum;
for (let i = 0; i < 30; i++) { await sleep(2000); await api('/admin/board/complete', { actionId: fb.actionId, txid: ftx }, true); sum = await api('/admin/summary', null, true); if (sum.float.spendableSat > 0) break; }
diff --git a/migrator/server.js b/migrator/server.js
index 8b1f8fe..cf654ef 100644
--- a/migrator/server.js
+++ b/migrator/server.js
@@ -196,12 +196,25 @@ Bun.serve({
// float liquidity on the new server: board on-chain coins into it
if (req.method === 'POST' && p === '/admin/board') {
const { amountSat } = await req.json();
- return json(await newW.startBoard(Number(amountSat)));
+ const b = await newW.startBoard(Number(amountSat));
+ (state.boards ||= {})[b.actionId] = { fundingAddress: b.fundingAddress, amountSat: Number(amountSat) };
+ persist();
+ return json(b);
}
+ // { actionId, txid }: the funding tx may come from any wallet, so find
+ // the output paying the board address (exact amount) rather than
+ // assuming it's the first.
if (req.method === 'POST' && p === '/admin/board/complete') {
const { actionId, txid } = await req.json();
- const a = await newW.completeBoard(actionId, txid);
- return json({ step: a.step, error: a.lastError || null });
+ const b = state.boards?.[actionId];
+ if (!b) return json({ error: 'unknown board' }, 404);
+ const r = await fetch(`${CFG.new.esplora}/tx/${txid}`);
+ if (!r.ok) return json({ error: `funding tx ${txid} not seen by ${CFG.new.esplora} yet — try again shortly` }, 409);
+ const tx = await r.json();
+ const vout = tx.vout.findIndex((o) => o.scriptpubkey_address === b.fundingAddress && o.value === b.amountSat);
+ if (vout < 0) return json({ error: `no output of exactly ${b.amountSat} sat to ${b.fundingAddress} in ${txid}` }, 400);
+ const a = await newW.completeBoard(actionId, txid, vout);
+ return json({ step: a.step, vout, confs: a.confs ?? null, error: a.lastError || null });
}
if (req.method === 'GET' && p === '/admin/float-address') return json({ address: newW.address() });
}