-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
119 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { getSchemaForEndpoint } from '@blockfrost/openapi'; | ||
import { isUnpaged } from '../../../utils/routes.js'; | ||
import { toJSONStream } from '../../../utils/string-utils.js'; | ||
import { FastifyInstance, FastifyRequest } from 'fastify'; | ||
import { SQLQuery } from '../../../sql/index.js'; | ||
import * as QueryTypes from '../../../types/queries/tx.js'; | ||
import { getDbSync } from '../../../utils/database.js'; | ||
|
||
async function route(fastify: FastifyInstance) { | ||
fastify.route({ | ||
url: '/txs/:hash/required_signers', | ||
method: 'GET', | ||
schema: getSchemaForEndpoint('/txs/:hash:/required_signers'), | ||
handler: async (request: FastifyRequest<QueryTypes.RequestParameters>, reply) => { | ||
const clientDbSync = await getDbSync(fastify); | ||
|
||
try { | ||
const { rows } = await clientDbSync.query<QueryTypes.TxWits>( | ||
SQLQuery.get('txs_hash_wits'), | ||
[request.params.hash], | ||
); | ||
|
||
clientDbSync.release(); | ||
|
||
if (rows.length === 0) { | ||
return reply.send([]); | ||
} | ||
|
||
const list: string[] = []; | ||
|
||
for (const row of rows) { | ||
list.push(row.hash); | ||
} | ||
|
||
const unpaged = isUnpaged(request); | ||
|
||
if (unpaged) { | ||
// Use of Reply.raw functions is at your own risk as you are skipping all the Fastify logic of handling the HTTP response | ||
// https://www.fastify.io/docs/latest/Reference/Reply/#raw | ||
reply.raw.writeHead(200, { 'Content-Type': 'application/json' }); | ||
await toJSONStream(list, reply.raw); | ||
return reply; | ||
} else { | ||
return reply.send(list); | ||
} | ||
} catch (error) { | ||
if (clientDbSync) { | ||
clientDbSync.release(); | ||
} | ||
throw error; | ||
} | ||
}, | ||
}); | ||
} | ||
|
||
export default route; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
SELECT encode(wit.hash, 'hex') AS "hash" | ||
FROM tx | ||
JOIN extra_key_witness wit ON (wit.tx_id = tx.id) | ||
WHERE encode(tx.hash, 'hex') = $1 | ||
ORDER BY wit.id |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters