-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add stats endpoint for inscription counts
- Loading branch information
Showing
4 changed files
with
95 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* 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.createTable('inscriptions_per_block', { | ||
block_height: { | ||
type: 'int', | ||
primaryKey: true, | ||
}, | ||
inscriptions: { | ||
type: 'int', | ||
notNull: true, | ||
}, | ||
inscriptions_total: { | ||
type: 'int', | ||
notNull: true, | ||
}, | ||
}); | ||
} | ||
|
||
export function down(pgm: MigrationBuilder): void { | ||
pgm.dropTable('inscriptions_per_block'); | ||
} |
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,25 @@ | ||
import { TypeBoxTypeProvider } from '@fastify/type-provider-typebox'; | ||
import { FastifyPluginAsync, FastifyPluginCallback } from 'fastify'; | ||
import { Server } from 'http'; | ||
|
||
const IndexRoutes: FastifyPluginCallback<Record<never, never>, Server, TypeBoxTypeProvider> = ( | ||
fastify, | ||
options, | ||
done | ||
) => { | ||
fastify.get('/stats/inscriptions', async (request, reply) => { | ||
const inscriptions = await fastify.db.getInscriptionCountPerBlock(); | ||
await reply.send({ | ||
results: inscriptions, | ||
}); | ||
}); | ||
done(); | ||
}; | ||
|
||
export const StatsRoutes: FastifyPluginAsync< | ||
Record<never, never>, | ||
Server, | ||
TypeBoxTypeProvider | ||
> = async fastify => { | ||
await fastify.register(IndexRoutes); | ||
}; |
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