Skip to content

Commit

Permalink
Merge pull request #92 from hirosystems/develop
Browse files Browse the repository at this point in the history
release to master
  • Loading branch information
rafaelcr committed Jun 8, 2023
2 parents 0968719 + fb93474 commit 464f24f
Show file tree
Hide file tree
Showing 14 changed files with 572 additions and 31 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/vercel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ jobs:
runs-on: ubuntu-latest

env:
VERCEL_ENV: ${{ contains(github.ref_name, "refs/tags") && 'production' || 'preview' }}
VERCEL_PROD: ${{ contains(github.ref_name, "refs/tags") && '--prod' || '' }}
VERCEL_ENV: ${{ contains(github.ref_name, 'refs/tags') && 'production' || 'preview' }}
VERCEL_PROD: ${{ contains(github.ref_name, 'refs/tags') && '--prod' || '' }}

environment:
name: ${{ contains(github.ref_name, "refs/tags") && 'Production' || 'Preview' }}
url: ${{ contains(github.ref_name, "refs/tags") && 'https://ordinals-api.vercel.app/' || 'https://ordinals-api-pbcblockstack-blockstack.vercel.app/' }}
name: ${{ contains(github.ref_name, 'refs/tags') && 'Production' || 'Preview' }}
url: ${{ contains(github.ref_name, 'refs/tags') && 'https://ordinals-api.vercel.app/' || 'https://ordinals-api-pbcblockstack-blockstack.vercel.app/' }}

steps:
- uses: actions/checkout@v2
Expand Down
16 changes: 16 additions & 0 deletions migrations/1685378650151_prev-location.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* eslint-disable @typescript-eslint/naming-convention */
import { MigrationBuilder, ColumnDefinitions } from 'node-pg-migrate';

export const shorthands: ColumnDefinitions | undefined = undefined;

export function up(pgm: MigrationBuilder): void {
pgm.addColumns('locations', {
prev_output: {
type: 'text',
},
prev_offset: {
type: 'numeric',
},
});
pgm.createIndex('locations', ['prev_output']);
}
12 changes: 12 additions & 0 deletions migrations/1686170300438_curse-type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/* eslint-disable @typescript-eslint/naming-convention */
import { MigrationBuilder, ColumnDefinitions } from 'node-pg-migrate';

export const shorthands: ColumnDefinitions | undefined = undefined;

export function up(pgm: MigrationBuilder): void {
pgm.addColumns('inscriptions', {
curse_type: {
type: 'text',
},
});
}
48 changes: 47 additions & 1 deletion src/api/routes/sats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,17 @@ import { TypeBoxTypeProvider } from '@fastify/type-provider-typebox';
import { Type } from '@sinclair/typebox';
import { FastifyPluginCallback } from 'fastify';
import { Server } from 'http';
import { NotFoundResponse, OrdinalParam, SatoshiResponse } from '../schemas';
import {
InscriptionResponse,
LimitParam,
NotFoundResponse,
OffsetParam,
OrdinalParam,
PaginatedResponse,
SatoshiResponse,
} from '../schemas';
import { OrdinalSatoshi } from '../util/ordinal-satoshi';
import { DEFAULT_API_LIMIT, parseDbInscriptions } from '../util/helpers';

export const SatRoutes: FastifyPluginCallback<Record<never, never>, Server, TypeBoxTypeProvider> = (
fastify,
Expand Down Expand Up @@ -49,5 +58,42 @@ export const SatRoutes: FastifyPluginCallback<Record<never, never>, Server, Type
}
);

fastify.get(
'/sats/:ordinal/inscriptions',
{
schema: {
operationId: 'getSatoshiInscriptions',
summary: 'Satoshi Inscriptions',
description: 'Retrieves all inscriptions associated with a single satoshi',
tags: ['Satoshis'],
params: Type.Object({
ordinal: OrdinalParam,
}),
querystring: Type.Object({
// Pagination
offset: Type.Optional(OffsetParam),
limit: Type.Optional(LimitParam),
}),
response: {
200: PaginatedResponse(InscriptionResponse, 'Paginated Satoshi Inscriptions Response'),
},
},
},
async (request, reply) => {
const limit = request.query.limit ?? DEFAULT_API_LIMIT;
const offset = request.query.offset ?? 0;
const inscriptions = await fastify.db.getInscriptions(
{ limit, offset },
{ sat_ordinal: BigInt(request.params.ordinal) }
);
await reply.send({
limit,
offset,
total: inscriptions.total,
results: parseDbInscriptions(inscriptions.results),
});
}
);

done();
};
2 changes: 2 additions & 0 deletions src/api/routes/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ export const StatusRoutes: FastifyPluginCallback<
const result = await fastify.db.sqlTransaction(async sql => {
const block_height = await fastify.db.getChainTipBlockHeight();
const max_inscription_number = await fastify.db.getMaxInscriptionNumber();
const max_cursed_inscription_number = await fastify.db.getMaxCursedInscriptionNumber();
return {
server_version: `ordinals-api ${SERVER_VERSION.tag} (${SERVER_VERSION.branch}:${SERVER_VERSION.commit})`,
status: 'ready',
block_height,
max_inscription_number,
max_cursed_inscription_number,
};
});
await reply.send(result);
Expand Down
3 changes: 2 additions & 1 deletion src/api/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ export const InscriptionIdsParam = Type.Array(InscriptionIdParam, {
});

export const InscriptionNumberParam = Type.Integer({
minimum: 0,
title: 'Inscription Number',
description: 'Inscription number',
examples: ['10500'],
Expand Down Expand Up @@ -250,6 +249,7 @@ export const InscriptionResponse = Type.Object(
content_type: Type.String({ examples: ['text/plain;charset=utf-8'] }),
content_length: Type.Integer({ examples: [59] }),
timestamp: Type.Integer({ examples: [1677733170000] }),
curse_type: Nullable(Type.String({ examples: ['p2wsh'] })),
},
{ title: 'Inscription Response' }
);
Expand Down Expand Up @@ -282,6 +282,7 @@ export const ApiStatusResponse = Type.Object(
status: Type.String(),
block_height: Type.Optional(Type.Integer()),
max_inscription_number: Type.Optional(Type.Integer()),
max_cursed_inscription_number: Type.Optional(Type.Integer()),
},
{ title: 'Api Status Response' }
);
Expand Down
1 change: 1 addition & 0 deletions src/api/util/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export function parseDbInscriptions(
content_type: i.content_type,
content_length: parseInt(i.content_length),
timestamp: i.timestamp.valueOf(),
curse_type: i.curse_type,
}));
}
export function parseDbInscription(item: DbFullyLocatedInscriptionResult): InscriptionResponseType {
Expand Down
18 changes: 18 additions & 0 deletions src/chainhook/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,23 @@ const InscriptionRevealedSchema = Type.Object({
});
export type InscriptionRevealed = Static<typeof InscriptionRevealedSchema>;

const CursedInscriptionRevealedSchema = Type.Object({
content_bytes: Type.String(),
content_type: Type.String(),
content_length: Type.Integer(),
inscription_number: Type.Integer(),
inscription_fee: Type.Integer(),
inscription_id: Type.String(),
inscription_output_value: Type.Integer(),
inscriber_address: Type.String(),
ordinal_number: Type.Integer(),
ordinal_block_height: Type.Integer(),
ordinal_offset: Type.Integer(),
satpoint_post_inscription: Type.String(),
curse_type: Type.String(),
});
export type CursedInscriptionRevealed = Static<typeof CursedInscriptionRevealedSchema>;

const InscriptionTransferredSchema = Type.Object({
inscription_number: Type.Integer(),
inscription_id: Type.String(),
Expand All @@ -36,6 +53,7 @@ const InscriptionTransferredSchema = Type.Object({
export type InscriptionTransferred = Static<typeof InscriptionTransferredSchema>;

const OrdinalOperation = Type.Object({
cursed_inscription_revealed: Type.Optional(CursedInscriptionRevealedSchema),
inscription_revealed: Type.Optional(InscriptionRevealedSchema),
inscription_transferred: Type.Optional(InscriptionTransferredSchema),
});
Expand Down
Loading

0 comments on commit 464f24f

Please sign in to comment.