From 6ed67f1c8d9f552cbcbe5c149f25470da4916f05 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Fri, 4 Dec 2026 13:24:16 -0700 Subject: migrator: board the float from any wallet (finds the board output in the funding tx). MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The funding tx for the float's board comes from an ordinary wallet, which may put change first. /admin/board remembers each board's address and amount; /admin/board/complete looks the tx up on esplora, finds the output paying exactly that to that address, and boards from that vout (409 until esplora has seen the tx). e2e: the float board is funded with change first (vout 1) — 20/20 pass. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01VMan6WoqaQDYdpWkatPCar --- migrator/server.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'migrator/server.js') 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() }); } -- cgit v1.2.3