Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
strategy:
fail-fast: false
matrix:
suite: [admin, api, chainhook, token-queue]
suite: [admin, api, stacks-core, token-queue]
runs-on: ubuntu-latest
env:
API_HOST: 127.0.0.1
Expand Down
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,13 @@
{
"type": "node",
"request": "launch",
"name": "Jest: Chainhook",
"name": "Jest: Stacks Core",
"program": "${workspaceFolder}/node_modules/jest/bin/jest",
"args": [
"--testTimeout=3600000",
"--runInBand",
"--no-cache",
"${workspaceFolder}/tests/chainhook/",
"${workspaceFolder}/tests/stacks-core/",
],
"outputCapture": "std",
"console": "integratedTerminal",
Expand Down
21 changes: 21 additions & 0 deletions migrations/1661125881755_blocks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* 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('blocks', {
index_block_hash: {
type: 'text',
primaryKey: true,
},
parent_index_block_hash: {
type: 'text',
notNull: true,
},
block_height: {
type: 'int',
notNull: true,
},
});
}
3 changes: 3 additions & 0 deletions migrations/1670264425574_smart-contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ export function up(pgm: MigrationBuilder): void {
index_block_hash: {
type: 'text',
notNull: true,
references: 'blocks',
onDelete: 'CASCADE',
},
tx_id: {
type: 'text',
Expand All @@ -54,4 +56,5 @@ export function up(pgm: MigrationBuilder): void {
},
});
pgm.createIndex('smart_contracts', [{ name: 'block_height', sort: 'DESC' }]);
pgm.createIndex('smart_contracts', ['index_block_hash']);
}
4 changes: 3 additions & 1 deletion migrations/1670265062169_tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ export function up(pgm: MigrationBuilder): void {
index_block_hash: {
type: 'text',
notNull: true,
references: 'blocks',
onDelete: 'CASCADE',
},
tx_id: {
type: 'text',
Expand Down Expand Up @@ -76,5 +78,5 @@ export function up(pgm: MigrationBuilder): void {
pgm.createIndex('tokens', ['symbol']);
pgm.createIndex('tokens', ['type', 'LOWER(name)'], { where: "type = 'ft'" });
pgm.createIndex('tokens', ['type', 'LOWER(symbol)'], { where: "type = 'ft'" });
pgm.createIndex('tokens', ['type']);
pgm.createIndex('tokens', ['index_block_hash']);
}
27 changes: 0 additions & 27 deletions migrations/1671125881755_chain-tip.ts

This file was deleted.

2 changes: 2 additions & 0 deletions migrations/1721103820876_update-notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export function up(pgm: MigrationBuilder): void {
index_block_hash: {
type: 'text',
notNull: true,
references: 'blocks',
onDelete: 'CASCADE',
},
tx_id: {
type: 'text',
Expand Down
28 changes: 28 additions & 0 deletions migrations/1767813638023_ft-supply-deltas.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* 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('ft_supply_deltas', {
token_id: {
type: 'int',
references: 'tokens',
onDelete: 'CASCADE',
},
block_height: {
type: 'int',
notNull: true,
},
index_block_hash: {
type: 'text',
notNull: true,
references: 'blocks',
onDelete: 'CASCADE',
},
delta: {
type: 'numeric',
notNull: true,
},
});
}
111 changes: 102 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"test": "jest --runInBand",
"test:admin": "npm run test -- ./tests/admin/",
"test:api": "npm run test -- ./tests/api/",
"test:chainhook": "npm run test -- ./tests/chainhook/",
"test:stacks-core": "npm run test -- ./tests/stacks-core/",
"test:token-queue": "npm run test -- ./tests/token-queue/",
"testenv:run": "docker compose -f docker/docker-compose.dev.postgres.yml up",
"testenv:stop": "docker compose -f docker/docker-compose.dev.postgres.yml down -v -t 0",
Expand Down Expand Up @@ -66,7 +66,7 @@
"@fastify/type-provider-typebox": "^3.2.0",
"@google-cloud/storage": "^7.12.1",
"@hirosystems/api-toolkit": "^1.12.0",
"@hirosystems/chainhook-client": "^2.4.0",
"@hirosystems/salt-n-pepper-client": "^1.2.0",
"@hirosystems/stacks-encoding-native-js": "^1.2.0",
"@sinclair/typebox": "^0.28.17",
"@stacks/blockchain-api-client": "^8.13.6",
Expand Down
2 changes: 1 addition & 1 deletion src/admin-rpc/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ export const AdminApi: FastifyPluginCallback<Record<never, never>, Server, TypeB

// Enqueue contract for processing.
await fastify.db.sqlWriteTransaction(async sql => {
await fastify.db.chainhook.enqueueContract(sql, {
await fastify.db.core.enqueueContract(sql, {
block_height: contract.block_height,
index_block_hash: block.index_block_hash,
principal: contract.contract_id,
Expand Down
35 changes: 9 additions & 26 deletions src/api/routes/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const StatusRoutes: FastifyPluginCallback<
schema: {
operationId: 'getApiStatus',
summary: 'API Status',
description: 'Displays the status of the API and its current workload',
description: 'Displays the status of the API',
tags: ['Status'],
response: {
200: ApiStatusResponse,
Expand All @@ -26,35 +26,18 @@ export const StatusRoutes: FastifyPluginCallback<
},
async (request, reply) => {
const result = await fastify.db.sqlTransaction(async sql => {
const block_height = await fastify.db.getChainTipBlockHeight();

const smartContracts: Record<string, number> = {};
const contractCounts = await fastify.db.getSmartContractCounts();
for (const row of contractCounts) {
smartContracts[row.sip] = row.count;
}

const tokens: Record<string, number> = {};
const tokenCounts = await fastify.db.getTokenCounts();
for (const row of tokenCounts) {
tokens[row.type] = row.count;
let chain_tip = null;
const chainTipResult = await fastify.db.core.getChainTip(sql);
if (chainTipResult) {
chain_tip = {
block_height: chainTipResult.block_height,
index_block_hash: chainTipResult.index_block_hash,
};
}

const queue: Record<string, number> = {};
const jobCounts = await fastify.db.getJobStatusCounts();
for (const row of jobCounts) {
queue[row.status] = row.count;
}

return {
server_version: `token-metadata-api ${SERVER_VERSION.tag} (${SERVER_VERSION.branch}:${SERVER_VERSION.commit})`,
status: 'ready',
chain_tip: {
block_height,
},
tokens: tokenCounts.length ? tokens : undefined,
token_contracts: contractCounts.length ? smartContracts : undefined,
job_queue: jobCounts.length ? queue : undefined,
chain_tip: chain_tip,
};
});
await reply.send(result);
Expand Down
Loading