Skip to content

Commit

Permalink
feat: add ordhook debug server (#306)
Browse files Browse the repository at this point in the history
  • Loading branch information
g0drlc committed Feb 12, 2024
1 parent 3c46eb9 commit e8bd800
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"build": "rimraf ./dist && tsc --project tsconfig.build.json",
"start": "node dist/src/index.js",
"start-ts": "ts-node ./src/index.ts",
"start:debug-server": "node dist/util/debug-server.js",
"test": "jest --runInBand",
"test:brc-20": "npm run test -- ./tests/brc-20/",
"test:api": "npm run test -- ./tests/api/",
Expand Down
48 changes: 48 additions & 0 deletions util/debug-server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* Ordhook Debug Server
* ---
*
* This file provides a quick way to start an Ordhook event server that only saves received payloads
* to local text files instead of attempting to process them into the Ordinals API database.
*
* You can use this tool to debug an Ordhook payload that is not being processed correctly into the
* API.
*/
import {
ChainhookEventObserver,
ChainhookNodeOptions,
Payload,
ServerOptions,
} from '@hirosystems/chainhook-client';
import { ENV } from '../src/env';
import { ORDHOOK_BASE_PATH } from '../src/ordhook/server';
import { logger } from '@hirosystems/api-toolkit';
import * as fs from 'fs';
import * as path from 'path';

const serverOpts: ServerOptions = {
hostname: ENV.API_HOST,
port: ENV.EVENT_PORT,
auth_token: ENV.CHAINHOOK_NODE_AUTH_TOKEN,
external_base_url: `http://${ENV.EXTERNAL_HOSTNAME}`,
wait_for_chainhook_node: false,
validate_chainhook_payloads: false,
body_limit: ENV.EVENT_SERVER_BODY_LIMIT,
node_type: 'ordhook',
};
const ordhookOpts: ChainhookNodeOptions = {
base_url: ORDHOOK_BASE_PATH,
};
const dirPath = path.join(__dirname, '../../tmp/debug-server/');
fs.mkdirSync(dirPath, { recursive: true });
logger.info(`DebugServer saving outputs to ${dirPath}`);

const server = new ChainhookEventObserver(serverOpts, ordhookOpts);
server
.start([], async (uuid: string, payload: Payload) => {
logger.info(`DebugServer received payload from predicate ${uuid}`);
const filePath = path.join(dirPath, `${new Date().getTime()}.txt`);
fs.writeFileSync(filePath, JSON.stringify(payload, null, 2));
return Promise.resolve();
})
.catch(err => logger.error(err));

0 comments on commit e8bd800

Please sign in to comment.