Update server/status.js
Add transaction lookup API
This commit is contained in:
@@ -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')
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user