Update server/status.js

Add transaction lookup API
This commit is contained in:
2026-08-29 11:54:17 +00:00
parent c9bd3adcb3
commit 2210a525ad
+51
View File
@@ -15,6 +15,9 @@ const {
scriptPubKeyToScripthash,
addressToScripthash,
} = require('./bitcoin-address')
const {
getTransaction,
} = require('./transactions')
const port = 8080
const fulcrumTimeoutMs = 3000
@@ -663,6 +666,54 @@ const server = http.createServer(async (req, res) => {
return
}
if (
req.method === 'GET' &&
req.url.startsWith('/api/transactions/')
) {
if (!isValidSession(req)) {
res.writeHead(401, {
'Content-Type': 'application/json',
})
res.end(
JSON.stringify({
error: 'Authentication required',
}),
)
return
}
const txid = decodeURIComponent(
req.url.slice('/api/transactions/'.length),
)
try {
const transaction = await getTransaction(txid)
res.writeHead(200, {
'Content-Type': 'application/json',
})
res.end(JSON.stringify(transaction))
} catch (error) {
res.writeHead(400, {
'Content-Type': 'application/json',
})
res.end(
JSON.stringify({
error:
error instanceof Error
? error.message
: 'Failed to get transaction',
}),
)
}
return
}
res.writeHead(404)
res.end('Not found')
})