Skip to content

Commit

Permalink
Merge pull request #181 from blockfrost/srk/txCBOR
Browse files Browse the repository at this point in the history
feat(txs): raw TX CBOR
  • Loading branch information
vladimirvolek authored Jul 2, 2024
2 parents 4d42279 + b5fb367 commit ed52208
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 7 deletions.
Binary file not shown.
Binary file not shown.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]

### Added

- `/txs/{hash}/cbor` endpoint
- Proxy for Mithril Aggregator API
- config options `mithril.enabled`, `mithril.aggregator`, `mithril.snapshotCDN` (optional) and `mithril.allowedEndpoints` (optional)
- ENV var options `BLOCKFROST_MITHRIL_ENABLED`, `BLOCKFROST_MITHRIL_AGGREGATOR` and `BLOCKFROST_MITHRIL_SNAPSHOT_CDN`

### Changed

- Upgraded Fastify dependencies
- Upgraded Typescript

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"dependencies": {
"@blockfrost/blockfrost-js": "5.4.0",
"@blockfrost/blockfrost-utils": "2.8.0",
"@blockfrost/openapi": "0.1.63",
"@blockfrost/openapi": "0.1.64",
"@emurgo/cardano-serialization-lib-nodejs": "11.5.0",
"@fastify/cors": "^9.0.1",
"@fastify/http-proxy": "^9.5.0",
Expand Down Expand Up @@ -78,4 +78,4 @@
"engines": {
"node": ">=16"
}
}
}
1 change: 1 addition & 0 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ const start = (options = {}): FastifyInstance => {
registerRoute(app, import('./routes/txs/hash/metadata/index.js'));
registerRoute(app, import('./routes/txs/hash/metadata/cbor.js'));
registerRoute(app, import('./routes/txs/hash/required-signers.js'));
registerRoute(app, import('./routes/txs/hash/cbor.js'));

// utils
registerRoute(app, import('./routes/utils/addresses/xpub/xpub/role/index.js'));
Expand Down
40 changes: 40 additions & 0 deletions src/routes/txs/hash/cbor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { getSchemaForEndpoint } from '@blockfrost/openapi';
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';
import { handle404 } from '@blockfrost/blockfrost-utils/lib/fastify.js';

async function route(fastify: FastifyInstance) {
fastify.route({
url: '/txs/:hash/cbor',
method: 'GET',
schema: getSchemaForEndpoint('/txs/{hash}/cbor'),
handler: async (request: FastifyRequest<QueryTypes.RequestParameters>, reply) => {
const clientDbSync = await getDbSync(fastify);

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

clientDbSync.release();

if (rows.length === 0) {
return handle404(reply);
}

return reply.send(rows[0]);
} catch (error) {
if (clientDbSync) {
clientDbSync.release();
}
throw error;
}
},
});
}

export default route;
1 change: 1 addition & 0 deletions src/sql/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ const QUERY_FILES = {
txs_hash_pool_updates: 'txs/txs_hash_pool_updates.sql',
txs_hash_metadata: 'txs/txs_hash_metadata.sql',
txs_hash_wits: 'txs/txs_hash_wits.sql',
txs_hash_cbor: 'txs/txs_hash_cbor.sql',
} as const;

type QueryKey = keyof typeof QUERY_FILES;
Expand Down
5 changes: 5 additions & 0 deletions src/sql/txs/txs_hash_cbor.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
SELECT encode(tx_cbor.bytes, 'hex') as "cbor"
FROM tx_cbor
JOIN tx ON tx_cbor.tx_id = tx.id
WHERE encode(tx.hash, 'hex') = $1

4 changes: 4 additions & 0 deletions src/types/queries/tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,7 @@ export interface TxRedeemers {
export interface TxWitnesses {
witness_hash: string;
}

export interface TxCbor {
cbor: string;
}
1 change: 1 addition & 0 deletions src/types/responses/tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ 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'];
export type TxCbor = OpenApiResponseTypes['tx_content_cbor'];
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,14 @@ __metadata:
languageName: node
linkType: hard

"@blockfrost/openapi@npm:0.1.63":
version: 0.1.63
resolution: "@blockfrost/openapi@npm:0.1.63"
"@blockfrost/openapi@npm:0.1.64":
version: 0.1.64
resolution: "@blockfrost/openapi@npm:0.1.64"
dependencies:
ajv: ^8.12.0
cbor: ^9.0.1
yaml: ^2.3.4
checksum: a743deeded6b709864fead7570a48676d0ee2a4f8cca56076ee6d3dc62f03cd0a803443bedbfeb26ed8aee8c713f778c6446b25816777d69731e835fdc559004
checksum: 520149d3037cd59b6a200a8ea4509b3e0f78b52a814993a819b597242403c9f0a8118d601f82735aa73053a293303daa2348ef1f480c96c2b10e3d2b311377b1
languageName: node
linkType: hard

Expand Down Expand Up @@ -2262,7 +2262,7 @@ __metadata:
"@blockfrost/blockfrost-js": 5.4.0
"@blockfrost/blockfrost-tests": 1.11.0
"@blockfrost/blockfrost-utils": 2.8.0
"@blockfrost/openapi": 0.1.63
"@blockfrost/openapi": 0.1.64
"@emurgo/cardano-serialization-lib-nodejs": 11.5.0
"@fastify/cors": ^9.0.1
"@fastify/http-proxy": ^9.5.0
Expand Down

0 comments on commit ed52208

Please sign in to comment.