Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add ordhook debug server #306

Merged
merged 1 commit into from
Feb 12, 2024
Merged
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
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));
Loading