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 --- coinosv3 | 2 +- migrator/e2e-test.js | 7 +++++-- migrator/server.js | 19 ++++++++++++++++--- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/coinosv3 b/coinosv3 index 5bf43a1..d431c76 160000 --- a/coinosv3 +++ b/coinosv3 @@ -1 +1 @@ -Subproject commit 5bf43a1aed6b1490c7325a17f7e1a9dccc3c4093 +Subproject commit d431c76002ecd0ac4bce23498353ef0e70b229f5 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() }); } -- cgit v1.2.3