Skip to content

Commit

Permalink
fix: upgrade chainhook client to v1.4.2 (#277)
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelcr committed Nov 29, 2023
1 parent 0692f02 commit 67ba3d4
Show file tree
Hide file tree
Showing 12 changed files with 142 additions and 85 deletions.
43 changes: 36 additions & 7 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"@fastify/swagger": "^8.3.1",
"@fastify/type-provider-typebox": "^3.2.0",
"@hirosystems/api-toolkit": "^1.3.1",
"@hirosystems/chainhook-client": "^1.4.1",
"@hirosystems/chainhook-client": "^1.4.2",
"@semantic-release/changelog": "^6.0.3",
"@semantic-release/commit-analyzer": "^10.0.4",
"@semantic-release/git": "^10.0.1",
Expand Down
9 changes: 5 additions & 4 deletions src/chainhook/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 CHAINHOOK_BASE_PATH = `http://${ENV.CHAINHOOK_NODE_RPC_HOST}:${ENV.CHAINHOOK_NODE_RPC_PORT}`;
export const ORDHOOK_BASE_PATH = `http://${ENV.CHAINHOOK_NODE_RPC_HOST}:${ENV.CHAINHOOK_NODE_RPC_PORT}`;
export const PREDICATE_UUID = randomUUID();

/**
Expand Down Expand Up @@ -48,11 +48,12 @@ export async function startChainhookServer(args: { db: PgStore }): Promise<Chain
wait_for_chainhook_node: ENV.CHAINHOOK_AUTO_PREDICATE_REGISTRATION,
validate_chainhook_payloads: true,
body_limit: ENV.EVENT_SERVER_BODY_LIMIT,
node_type: 'ordhook',
};
const chainhookOpts: ChainhookNodeOptions = {
base_url: CHAINHOOK_BASE_PATH,
const ordhookOpts: ChainhookNodeOptions = {
base_url: ORDHOOK_BASE_PATH,
};
const server = new ChainhookEventObserver(serverOpts, chainhookOpts);
const server = new ChainhookEventObserver(serverOpts, ordhookOpts);
await server.start(predicates, async (_uuid: string, payload: Payload) => {
await args.db.updateInscriptions(payload);
});
Expand Down
16 changes: 8 additions & 8 deletions src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ const schema = Type.Object({
/**
* Run mode for this service. Allows you to control how the API runs, typically in an auto-scaled
* environment. Available values are:
* * `default`: Runs the chainhook server and the REST API server (this is the default)
* * `writeonly`: Runs only the chainhook server
* * `default`: Runs the ordhook server and the REST API server (this is the default)
* * `writeonly`: Runs only the ordhook server
* * `readonly`: Runs only the REST API server
*/
RUN_MODE: Type.Enum(
Expand All @@ -20,24 +20,24 @@ const schema = Type.Object({
API_PORT: Type.Number({ default: 3000, minimum: 0, maximum: 65535 }),
/** Port in which to serve the Admin RPC interface */
ADMIN_RPC_PORT: Type.Number({ default: 3001, minimum: 0, maximum: 65535 }),
/** Port in which to receive chainhook events */
/** Port in which to receive ordhook events */
EVENT_PORT: Type.Number({ default: 3099, minimum: 0, maximum: 65535 }),
/** Event server body limit (bytes) */
EVENT_SERVER_BODY_LIMIT: Type.Integer({ default: 20971520 }),
/** Hostname that will be reported to the chainhook node so it can call us back with events */
/** Hostname that will be reported to the ordhook node so it can call us back with events */
EXTERNAL_HOSTNAME: Type.String({ default: '127.0.0.1' }),

/** Hostname of the chainhook node we'll use to register predicates */
/** Hostname of the ordhook node we'll use to register predicates */
CHAINHOOK_NODE_RPC_HOST: Type.String({ default: '127.0.0.1' }),
/** Control port of the chainhook node */
/** Control port of the ordhook node */
CHAINHOOK_NODE_RPC_PORT: Type.Number({ default: 20456, minimum: 0, maximum: 65535 }),
/**
* Authorization token that the chainhook node must send with every event to make sure it's
* 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(),
/**
* Register chainhook predicates automatically when the API is first launched. Set this to `false`
* 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 }),
Expand Down
47 changes: 1 addition & 46 deletions src/pg/pg-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,6 @@ export class PgStore extends BasePgStore {
const genesis_id = operation.inscription_revealed.inscription_id;
await this.rollBackInscription({ genesis_id, number, block_height });
}
if (operation.cursed_inscription_revealed) {
const number = operation.cursed_inscription_revealed.inscription_number;
const genesis_id = operation.cursed_inscription_revealed.inscription_id;
await this.rollBackInscription({ genesis_id, number, block_height });
}
if (operation.inscription_transferred) {
const genesis_id = operation.inscription_transferred.inscription_id;
const satpoint = parseSatPoint(
Expand Down Expand Up @@ -160,47 +155,7 @@ export class PgStore extends BasePgStore {
number: reveal.inscription_number,
content: removeNullBytes(reveal.content_bytes),
fee: reveal.inscription_fee.toString(),
curse_type: null,
sat_ordinal: reveal.ordinal_number.toString(),
sat_rarity: satoshi.rarity,
sat_coinbase_height: satoshi.blockHeight,
recursive: recursive_refs.length > 0,
},
location: {
block_hash,
block_height,
tx_id,
tx_index: reveal.tx_index,
block_transfer_index: null,
genesis_id: reveal.inscription_id,
address: reveal.inscriber_address,
output: `${satpoint.tx_id}:${satpoint.vout}`,
offset: satpoint.offset ?? null,
prev_output: null,
prev_offset: null,
value: reveal.inscription_output_value.toString(),
timestamp: event.timestamp,
transfer_type: DbLocationTransferType.transferred,
},
recursive_refs,
});
}
if (operation.cursed_inscription_revealed) {
const reveal = operation.cursed_inscription_revealed;
const satoshi = new OrdinalSatoshi(reveal.ordinal_number);
const satpoint = parseSatPoint(reveal.satpoint_post_inscription);
const recursive_refs = getInscriptionRecursion(reveal.content_bytes);
const contentType = removeNullBytes(reveal.content_type);
writes.push({
inscription: {
genesis_id: reveal.inscription_id,
mime_type: contentType.split(';')[0],
content_type: contentType,
content_length: reveal.content_length,
number: reveal.inscription_number,
content: removeNullBytes(reveal.content_bytes),
fee: reveal.inscription_fee.toString(),
curse_type: JSON.stringify(reveal.curse_type),
curse_type: reveal.curse_type ? JSON.stringify(reveal.curse_type) : null,
sat_ordinal: reveal.ordinal_number.toString(),
sat_rarity: satoshi.rarity,
sat_coinbase_height: satoshi.blockHeight,
Expand Down
7 changes: 7 additions & 0 deletions tests/cache.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ describe('ETag cache', () => {
inscription_input_index: 0,
transfers_pre_inscription: 0,
tx_index: 0,
curse_type: null,
})
.build();
await db.updateInscriptions(block);
Expand Down Expand Up @@ -172,6 +173,7 @@ describe('ETag cache', () => {
inscription_input_index: 0,
transfers_pre_inscription: 0,
tx_index: 0,
curse_type: null,
})
.build();
await db.updateInscriptions(block1);
Expand All @@ -196,6 +198,7 @@ describe('ETag cache', () => {
inscription_input_index: 0,
transfers_pre_inscription: 0,
tx_index: 0,
curse_type: null,
})
.build();
await db.updateInscriptions(block2);
Expand Down Expand Up @@ -267,6 +270,7 @@ describe('ETag cache', () => {
inscription_input_index: 0,
transfers_pre_inscription: 0,
tx_index: 0,
curse_type: null,
})
.build();
await db.updateInscriptions(block1);
Expand Down Expand Up @@ -310,6 +314,7 @@ describe('ETag cache', () => {
inscription_input_index: 0,
transfers_pre_inscription: 0,
tx_index: 0,
curse_type: null,
})
.build();
await db.updateInscriptions(block2);
Expand Down Expand Up @@ -345,6 +350,7 @@ describe('ETag cache', () => {
inscription_input_index: 0,
transfers_pre_inscription: 0,
tx_index: 0,
curse_type: null,
})
.build();
await db.updateInscriptions(block1);
Expand Down Expand Up @@ -388,6 +394,7 @@ describe('ETag cache', () => {
inscription_input_index: 0,
transfers_pre_inscription: 0,
tx_index: 0,
curse_type: null,
})
.build();
await db.updateInscriptions(block2);
Expand Down
7 changes: 1 addition & 6 deletions tests/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { TypeBoxTypeProvider } from '@fastify/type-provider-typebox';
import {
BitcoinCursedInscriptionRevealed,
BitcoinEvent,
BitcoinInscriptionRevealed,
BitcoinInscriptionTransferred,
Expand Down Expand Up @@ -91,11 +90,6 @@ export class TestChainhookPayloadBuilder {
return this;
}

cursedInscriptionRevealed(args: BitcoinCursedInscriptionRevealed): this {
this.lastBlockTx.metadata.ordinal_operations.push({ cursed_inscription_revealed: args });
return this;
}

inscriptionTransferred(args: BitcoinInscriptionTransferred): this {
this.lastBlockTx.metadata.ordinal_operations.push({ inscription_transferred: args });
return this;
Expand Down Expand Up @@ -137,6 +131,7 @@ export function brc20Reveal(args: {
inscription_input_index: 0,
transfers_pre_inscription: 0,
tx_index: 0,
curse_type: null,
};
return reveal;
}
Expand Down
Loading

0 comments on commit 67ba3d4

Please sign in to comment.