Skip to content

Commit

Permalink
fix!: rename chainhook env vars to ordhook (#314)
Browse files Browse the repository at this point in the history
* fix: rename ordhook env vars

* fix: test setup

* fix: debug server
  • Loading branch information
rafaelcr committed Feb 21, 2024
1 parent f6d441d commit ae4ec01
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 19 deletions.
8 changes: 4 additions & 4 deletions src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,19 @@ const schema = Type.Object({
EXTERNAL_HOSTNAME: Type.String({ default: '127.0.0.1' }),

/** Hostname of the ordhook node we'll use to register predicates */
CHAINHOOK_NODE_RPC_HOST: Type.String({ default: '127.0.0.1' }),
ORDHOOK_NODE_RPC_HOST: Type.String({ default: '127.0.0.1' }),
/** Control port of the ordhook node */
CHAINHOOK_NODE_RPC_PORT: Type.Number({ default: 20456, minimum: 0, maximum: 65535 }),
ORDHOOK_NODE_RPC_PORT: Type.Number({ default: 20456, minimum: 0, maximum: 65535 }),
/**
* Authorization token that the ordhook node must send with every event to make sure it's
* coming from the valid instance
*/
CHAINHOOK_NODE_AUTH_TOKEN: Type.String(),
ORDHOOK_NODE_AUTH_TOKEN: Type.String(),
/**
* Register ordhook predicates automatically when the API is first launched. Set this to `false`
* if you're configuring your predicates manually for any reason.
*/
CHAINHOOK_AUTO_PREDICATE_REGISTRATION: Type.Boolean({ default: true }),
ORDHOOK_AUTO_PREDICATE_REGISTRATION: Type.Boolean({ default: true }),

PGHOST: Type.String(),
PGPORT: Type.Number({ default: 5432, minimum: 0, maximum: 65535 }),
Expand Down
8 changes: 4 additions & 4 deletions src/ordhook/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
} from '@hirosystems/chainhook-client';
import { logger } from '@hirosystems/api-toolkit';

export const ORDHOOK_BASE_PATH = `http://${ENV.CHAINHOOK_NODE_RPC_HOST}:${ENV.CHAINHOOK_NODE_RPC_PORT}`;
export const ORDHOOK_BASE_PATH = `http://${ENV.ORDHOOK_NODE_RPC_HOST}:${ENV.ORDHOOK_NODE_RPC_PORT}`;
export const PREDICATE_UUID = randomUUID();

/**
Expand All @@ -20,7 +20,7 @@ export const PREDICATE_UUID = randomUUID();
*/
export async function startOrdhookServer(args: { db: PgStore }): Promise<ChainhookEventObserver> {
const predicates: ServerPredicate[] = [];
if (ENV.CHAINHOOK_AUTO_PREDICATE_REGISTRATION) {
if (ENV.ORDHOOK_AUTO_PREDICATE_REGISTRATION) {
const blockHeight = await args.db.getChainTipBlockHeight();
logger.info(`Ordinals predicate starting from block ${blockHeight}...`);
predicates.push({
Expand All @@ -43,9 +43,9 @@ export async function startOrdhookServer(args: { db: PgStore }): Promise<Chainho
const serverOpts: ServerOptions = {
hostname: ENV.API_HOST,
port: ENV.EVENT_PORT,
auth_token: ENV.CHAINHOOK_NODE_AUTH_TOKEN,
auth_token: ENV.ORDHOOK_NODE_AUTH_TOKEN,
external_base_url: `http://${ENV.EXTERNAL_HOSTNAME}`,
wait_for_chainhook_node: ENV.CHAINHOOK_AUTO_PREDICATE_REGISTRATION,
wait_for_chainhook_node: ENV.ORDHOOK_AUTO_PREDICATE_REGISTRATION,
validate_chainhook_payloads: true,
body_limit: ENV.EVENT_SERVER_BODY_LIMIT,
node_type: 'ordhook',
Expand Down
16 changes: 8 additions & 8 deletions tests/ordhook/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('EventServer', () => {

beforeEach(async () => {
await runMigrations(MIGRATIONS_DIR, 'up');
ENV.CHAINHOOK_AUTO_PREDICATE_REGISTRATION = false;
ENV.ORDHOOK_AUTO_PREDICATE_REGISTRATION = false;
db = await PgStore.connect({ skipMigrations: true });
server = await startOrdhookServer({ db });
fastify = await buildApiServer({ db });
Expand Down Expand Up @@ -74,7 +74,7 @@ describe('EventServer', () => {
const response = await server['fastify'].inject({
method: 'POST',
url: `/payload`,
headers: { authorization: `Bearer ${ENV.CHAINHOOK_NODE_AUTH_TOKEN}` },
headers: { authorization: `Bearer ${ENV.ORDHOOK_NODE_AUTH_TOKEN}` },
payload: payload1,
});
expect(response.statusCode).toBe(200);
Expand Down Expand Up @@ -134,7 +134,7 @@ describe('EventServer', () => {
const response2 = await server['fastify'].inject({
method: 'POST',
url: `/payload`,
headers: { authorization: `Bearer ${ENV.CHAINHOOK_NODE_AUTH_TOKEN}` },
headers: { authorization: `Bearer ${ENV.ORDHOOK_NODE_AUTH_TOKEN}` },
payload: payload2,
});
expect(response2.statusCode).toBe(200);
Expand Down Expand Up @@ -214,7 +214,7 @@ describe('EventServer', () => {
const response = await server['fastify'].inject({
method: 'POST',
url: `/payload`,
headers: { authorization: `Bearer ${ENV.CHAINHOOK_NODE_AUTH_TOKEN}` },
headers: { authorization: `Bearer ${ENV.ORDHOOK_NODE_AUTH_TOKEN}` },
payload: payload1,
});
expect(response.statusCode).toBe(200);
Expand Down Expand Up @@ -274,7 +274,7 @@ describe('EventServer', () => {
const response2 = await server['fastify'].inject({
method: 'POST',
url: `/payload`,
headers: { authorization: `Bearer ${ENV.CHAINHOOK_NODE_AUTH_TOKEN}` },
headers: { authorization: `Bearer ${ENV.ORDHOOK_NODE_AUTH_TOKEN}` },
payload: payload2,
});
expect(response2.statusCode).toBe(200);
Expand Down Expand Up @@ -425,7 +425,7 @@ describe('EventServer', () => {
const response = await server['fastify'].inject({
method: 'POST',
url: `/payload`,
headers: { authorization: `Bearer ${ENV.CHAINHOOK_NODE_AUTH_TOKEN}` },
headers: { authorization: `Bearer ${ENV.ORDHOOK_NODE_AUTH_TOKEN}` },
payload: errorPayload,
});
expect(response.statusCode).toBe(400);
Expand Down Expand Up @@ -535,7 +535,7 @@ describe('EventServer', () => {
const response = await server['fastify'].inject({
method: 'POST',
url: `/payload`,
headers: { authorization: `Bearer ${ENV.CHAINHOOK_NODE_AUTH_TOKEN}` },
headers: { authorization: `Bearer ${ENV.ORDHOOK_NODE_AUTH_TOKEN}` },
payload: errorPayload,
});
expect(response.statusCode).toBe(400);
Expand Down Expand Up @@ -687,7 +687,7 @@ describe('EventServer', () => {
const response = await server['fastify'].inject({
method: 'POST',
url: `/payload`,
headers: { authorization: `Bearer ${ENV.CHAINHOOK_NODE_AUTH_TOKEN}` },
headers: { authorization: `Bearer ${ENV.ORDHOOK_NODE_AUTH_TOKEN}` },
payload: payload,
});
expect(response.statusCode).toBe(200);
Expand Down
5 changes: 3 additions & 2 deletions tests/setup.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// ts-unused-exports:disable-next-line
export default (): void => {
process.env.CHAINHOOK_NODE_AUTH_TOKEN = 'test';
process.env.CHAINHOOK_NODE_RPC_HOST = 'test.chainhooks.com';
process.env.ORDHOOK_NODE_AUTH_TOKEN = 'test';
process.env.ORDHOOK_NODE_RPC_HOST = 'test.chainhooks.com';
process.env.ORDHOOK_NODE_RPC_PORT = '13370';
process.env.PGDATABASE = 'postgres';
};
2 changes: 1 addition & 1 deletion util/debug-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import * as path from 'path';
const serverOpts: ServerOptions = {
hostname: ENV.API_HOST,
port: ENV.EVENT_PORT,
auth_token: ENV.CHAINHOOK_NODE_AUTH_TOKEN,
auth_token: ENV.ORDHOOK_NODE_AUTH_TOKEN,
external_base_url: `http://${ENV.EXTERNAL_HOSTNAME}`,
wait_for_chainhook_node: false,
validate_chainhook_payloads: false,
Expand Down

0 comments on commit ae4ec01

Please sign in to comment.