Skip to content

Commit

Permalink
chore: array of objects
Browse files Browse the repository at this point in the history
  • Loading branch information
slowbackspace committed Feb 5, 2024
1 parent c358249 commit e150bed
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 18 deletions.
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"dependencies": {
"@blockfrost/blockfrost-js": "5.4.0",
"@blockfrost/blockfrost-utils": "2.8.0",
"@blockfrost/openapi": "0.1.61-beta.6",
"@blockfrost/openapi": "0.1.61-beta.24",
"@emurgo/cardano-serialization-lib-nodejs": "11.5.0",
"@emurgo/cip14-js": "^3.0.1",
"@fastify/cors": "^8.3.0",
Expand Down
15 changes: 7 additions & 8 deletions src/routes/txs/hash/required-signers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ 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 * as ResponseTypes from '../../../types/responses/tx.js';
import { getDbSync } from '../../../utils/database.js';

async function route(fastify: FastifyInstance) {
Expand All @@ -15,29 +16,27 @@ async function route(fastify: FastifyInstance) {
const clientDbSync = await getDbSync(fastify);

try {
const { rows } = await clientDbSync.query<QueryTypes.TxWits>(
SQLQuery.get('txs_hash_wits'),
[request.params.hash],
);
const { rows }: { rows: ResponseTypes.TxWitnesses } =
await clientDbSync.query<QueryTypes.TxWitnesses>(SQLQuery.get('txs_hash_wits'), [
request.params.hash,
]);

clientDbSync.release();

if (rows.length === 0) {
return reply.send([]);
}

const list = rows.map(row => 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);
await toJSONStream(rows, reply.raw);
return reply;
} else {
return reply.send(list);
return reply.send(rows);
}
} catch (error) {
if (clientDbSync) {
Expand Down
2 changes: 1 addition & 1 deletion src/sql/txs/txs_hash_wits.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SELECT encode(wit.hash, 'hex') AS "hash"
SELECT encode(wit.hash, 'hex') AS "witness_hash"
FROM tx
JOIN extra_key_witness wit ON (wit.tx_id = tx.id)
WHERE encode(tx.hash, 'hex') = $1
Expand Down
4 changes: 2 additions & 2 deletions src/types/queries/tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,6 @@ export interface TxRedeemers {
redeemer_data_hash: string;
}

export interface TxWits {
hash: string;
export interface TxWitnesses {
witness_hash: string;
}
1 change: 1 addition & 0 deletions src/types/responses/tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ export type Relay = OpenApiResponseTypes['pool_relays'];
export type TxRedeemers = OpenApiResponseTypes['tx_content_redeemers'];
export type TxMetadataCbor = OpenApiResponseTypes['tx_content_metadata_cbor'];
export type TxMetadata = OpenApiResponseTypes['tx_content_metadata'];
export type TxWitnesses = OpenApiResponseTypes['tx_content_required_signers'];
2 changes: 1 addition & 1 deletion yarn-project.nix
Original file line number Diff line number Diff line change
Expand Up @@ -1085,7 +1085,7 @@ cacheEntries = {
"word-wrap@npm:1.2.3" = { filename = "word-wrap-npm-1.2.3-7fb15ab002-30b48f91fc.zip"; sha512 = "30b48f91fcf12106ed3186ae4fa86a6a1842416df425be7b60485de14bec665a54a68e4b5156647dec3a70f25e84d270ca8bc8cd23182ed095f5c7206a938c1f"; };
"type-check@npm:0.3.2" = { filename = "type-check-npm-0.3.2-a4a38bb0b6-dd3b149564.zip"; sha512 = "dd3b1495642731bc0e1fc40abe5e977e0263005551ac83342ecb6f4f89551d106b368ec32ad3fb2da19b3bd7b2d1f64330da2ea9176d8ddbfe389fb286eb5124"; };
"levn@npm:0.3.0" = { filename = "levn-npm-0.3.0-48d774b1c2-0d084a5242.zip"; sha512 = "0d084a524231a8246bb10fec48cdbb35282099f6954838604f3c7fc66f2e16fa66fd9cc2f3f20a541a113c4dafdf181e822c887c8a319c9195444e6c64ac395e"; };
"@blockfrost/openapi@npm:0.1.61-beta.6" = { filename = "@blockfrost-openapi-npm-0.1.61-beta.6-900b59ba71-096f73aea1.zip"; sha512 = "096f73aea158e6b466c61195372188ba19e3d68f6b711c216dcf1ef5bfed08297c99ca9a3bd6021cfce2de892b57c44bc42a6da7c226ea4205e1629e60820196"; };
"@blockfrost/openapi@npm:0.1.61-beta.24" = { filename = "@blockfrost-openapi-npm-0.1.61-beta.24-88bebce6dc-bb39376e42.zip"; sha512 = "bb39376e420298d8d50d58b142336799e9e49d151cc5f9a43bada255d496c0bcc11bae3b6143b6be66466a7aaee55b63eb02dfa8e1e38a3a2aeeecb92fe2308d"; };
"yaml@npm:2.3.4" = { filename = "yaml-npm-2.3.4-8bb6dc2c0d-e6d1dae1c6.zip"; sha512 = "e6d1dae1c6383bcc8ba11796eef3b8c02d5082911c6723efeeb5ba50fc8e881df18d645e64de68e421b577296000bea9c75d6d9097c2f6699da3ae0406c030d8"; };
"cbor@npm:9.0.1" = { filename = "cbor-npm-9.0.1-3a5a6b7751-42333ac3d4.zip"; sha512 = "42333ac3d42cc3f6fcc7a529e68417a2dd8099eda43ca4be1304cdc5bc7494efe058e2db8a3d3b46ae60d69c7331ea813c22dbd019c4ac592d23e599d72bbcc9"; };
};
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,14 @@ __metadata:
languageName: node
linkType: hard

"@blockfrost/openapi@npm:0.1.61-beta.6":
version: 0.1.61-beta.6
resolution: "@blockfrost/openapi@npm:0.1.61-beta.6"
"@blockfrost/openapi@npm:0.1.61-beta.24":
version: 0.1.61-beta.24
resolution: "@blockfrost/openapi@npm:0.1.61-beta.24"
dependencies:
ajv: ^8.12.0
cbor: ^9.0.1
yaml: ^2.3.4
checksum: 096f73aea158e6b466c61195372188ba19e3d68f6b711c216dcf1ef5bfed08297c99ca9a3bd6021cfce2de892b57c44bc42a6da7c226ea4205e1629e60820196
checksum: bb39376e420298d8d50d58b142336799e9e49d151cc5f9a43bada255d496c0bcc11bae3b6143b6be66466a7aaee55b63eb02dfa8e1e38a3a2aeeecb92fe2308d
languageName: node
linkType: hard

Expand Down Expand Up @@ -1956,7 +1956,7 @@ __metadata:
"@blockfrost/blockfrost-js": 5.4.0
"@blockfrost/blockfrost-tests": 1.10.0
"@blockfrost/blockfrost-utils": 2.8.0
"@blockfrost/openapi": 0.1.61-beta.6
"@blockfrost/openapi": 0.1.61-beta.24
"@emurgo/cardano-serialization-lib-nodejs": 11.5.0
"@emurgo/cip14-js": ^3.0.1
"@esbuild/darwin-x64": "npm:0.16.17"
Expand Down

0 comments on commit e150bed

Please sign in to comment.