aboutsummaryrefslogtreecommitdiffstats
path: root/migrator/server.js
diff options
context:
space:
mode:
Diffstat (limited to 'migrator/server.js')
-rw-r--r--migrator/server.js19
1 files changed, 16 insertions, 3 deletions
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() });
}