Skip to content

Commit 96f5acc

Browse files
authored
Merge pull request #285 from hirosystems/beta
release to master
2 parents ae4c71f + a652d6d commit 96f5acc

File tree

12 files changed

+186
-313
lines changed

12 files changed

+186
-313
lines changed

CHANGELOG.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1+
## [1.1.5-beta.3](https://github.com/hirosystems/token-metadata-api/compare/v1.1.5-beta.2...v1.1.5-beta.3) (2024-10-22)
2+
3+
4+
### Bug Fixes
5+
6+
* upgrade to new chainhook ts client ([#280](https://github.com/hirosystems/token-metadata-api/issues/280)) ([b67dc8c](https://github.com/hirosystems/token-metadata-api/commit/b67dc8cd4e21f91a50a1c0c85880d2f265ab1d51))
7+
8+
## [1.1.5-beta.2](https://github.com/hirosystems/token-metadata-api/compare/v1.1.5-beta.1...v1.1.5-beta.2) (2024-10-21)
9+
10+
11+
### Bug Fixes
12+
13+
* allow multiple sft mints for the same token per transaction ([#279](https://github.com/hirosystems/token-metadata-api/issues/279)) ([9b28880](https://github.com/hirosystems/token-metadata-api/commit/9b28880815a75f93f218fae69dc6e7147c908514))
14+
15+
## [1.1.5-beta.1](https://github.com/hirosystems/token-metadata-api/compare/v1.1.4...v1.1.5-beta.1) (2024-10-07)
16+
17+
18+
### Bug Fixes
19+
20+
* process nft and sft mints in batches ([#271](https://github.com/hirosystems/token-metadata-api/issues/271)) ([c98f0cd](https://github.com/hirosystems/token-metadata-api/commit/c98f0cd6a1001933764ab2fbb4026f8824127f35))
21+
122
## [1.1.4](https://github.com/hirosystems/token-metadata-api/compare/v1.1.3...v1.1.4) (2024-09-23)
223

324

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"@fastify/type-provider-typebox": "^3.2.0",
5757
"@google-cloud/storage": "^7.12.1",
5858
"@hirosystems/api-toolkit": "^1.7.1",
59-
"@hirosystems/chainhook-client": "^1.12.0",
59+
"@hirosystems/chainhook-client": "^2.0.0",
6060
"@sinclair/typebox": "^0.28.17",
6161
"@stacks/transactions": "^6.1.0",
6262
"@types/node": "^20.16.1",

src/chainhook/server.ts

Lines changed: 10 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,23 @@
1-
import * as fs from 'fs';
21
import {
32
ChainhookEventObserver,
43
ChainhookNodeOptions,
4+
EventObserverOptions,
5+
EventObserverPredicate,
56
Payload,
6-
ServerOptions,
7-
ServerPredicate,
87
StacksPayload,
98
} from '@hirosystems/chainhook-client';
109
import { PgStore } from '../pg/pg-store';
1110
import { ENV } from '../env';
1211
import { logger } from '@hirosystems/api-toolkit';
13-
import { randomUUID } from 'node:crypto';
14-
15-
export function getPersistedPredicateFromDisk(): ServerPredicate | undefined {
16-
const predicatePath = `${ENV.CHAINHOOK_PREDICATE_PATH}/predicate.json`;
17-
try {
18-
if (!fs.existsSync(predicatePath)) {
19-
return;
20-
}
21-
const fileData = fs.readFileSync(predicatePath, 'utf-8');
22-
return JSON.parse(fileData) as ServerPredicate;
23-
} catch (error) {
24-
logger.error(error, `ChainhookServer unable to get persisted predicate`);
25-
}
26-
}
27-
28-
export function persistPredicateToDisk(predicate: ServerPredicate) {
29-
const predicatePath = `${ENV.CHAINHOOK_PREDICATE_PATH}/predicate.json`;
30-
try {
31-
fs.mkdirSync(ENV.CHAINHOOK_PREDICATE_PATH, { recursive: true });
32-
fs.writeFileSync(predicatePath, JSON.stringify(predicate, null, 2));
33-
} catch (error) {
34-
logger.error(error, `ChainhookServer unable to persist predicate to disk`);
35-
}
36-
}
3712

3813
export async function startChainhookServer(args: { db: PgStore }): Promise<ChainhookEventObserver> {
3914
const blockHeight = await args.db.getChainTipBlockHeight();
4015
logger.info(`ChainhookServer is at block ${blockHeight}`);
4116

42-
const predicates: ServerPredicate[] = [];
17+
const predicates: EventObserverPredicate[] = [];
4318
if (ENV.CHAINHOOK_AUTO_PREDICATE_REGISTRATION) {
44-
const existingPredicate = getPersistedPredicateFromDisk();
45-
if (existingPredicate) {
46-
logger.info(
47-
`ChainhookServer will attempt to resume existing predicate ${existingPredicate.uuid}`
48-
);
49-
}
5019
const header = {
51-
uuid: existingPredicate?.uuid ?? randomUUID(),
52-
name: 'block',
20+
name: 'metadata-api-blocks',
5321
version: 1,
5422
chain: 'stacks',
5523
};
@@ -87,38 +55,33 @@ export async function startChainhookServer(args: { db: PgStore }): Promise<Chain
8755
}
8856
}
8957

90-
const opts: ServerOptions = {
58+
const observer: EventObserverOptions = {
9159
hostname: ENV.API_HOST,
9260
port: ENV.EVENT_PORT,
9361
auth_token: ENV.CHAINHOOK_NODE_AUTH_TOKEN,
9462
external_base_url: `http://${ENV.EXTERNAL_HOSTNAME}`,
9563
wait_for_chainhook_node: ENV.CHAINHOOK_AUTO_PREDICATE_REGISTRATION,
9664
validate_chainhook_payloads: false,
9765
body_limit: ENV.EVENT_SERVER_BODY_LIMIT,
66+
predicate_disk_file_path: ENV.CHAINHOOK_PREDICATE_PATH,
67+
predicate_health_check_interval_ms: 300_000,
9868
node_type: 'chainhook',
9969
};
10070
const chainhook: ChainhookNodeOptions = {
10171
base_url: `http://${ENV.CHAINHOOK_NODE_RPC_HOST}:${ENV.CHAINHOOK_NODE_RPC_PORT}`,
10272
};
103-
const server = new ChainhookEventObserver(opts, chainhook);
104-
await server.start(predicates, async (uuid: string, payload: Payload) => {
73+
const server = new ChainhookEventObserver(observer, chainhook);
74+
await server.start(predicates, async (payload: Payload) => {
10575
logger.info(
10676
`ChainhookServer received ${
10777
payload.chainhook.is_streaming_blocks ? 'streamed' : 'replay'
108-
} payload from predicate ${uuid}`
78+
} payload from predicate ${payload.chainhook.uuid}`
10979
);
11080
await args.db.chainhook.processPayload(payload as StacksPayload);
11181
});
112-
if (predicates.length) persistPredicateToDisk(predicates[0]);
11382
return server;
11483
}
11584

11685
export async function closeChainhookServer(server: ChainhookEventObserver) {
117-
try {
118-
const predicatePath = `${ENV.CHAINHOOK_PREDICATE_PATH}/predicate.json`;
119-
if (fs.existsSync(predicatePath)) fs.rmSync(predicatePath);
120-
} catch (error) {
121-
logger.error(error, `ChainhookServer unable to delete persisted predicate`);
122-
}
12386
await server.close();
12487
}

0 commit comments

Comments
 (0)