Skip to content

Commit f80e983

Browse files
committed
feat: update inscription transfer schemas
1 parent 98d1a0a commit f80e983

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

components/client/typescript/src/schemas/bitcoin/payload.ts

-2
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ export const BitcoinInscriptionRevealedSchema = Type.Object({
2323
export type BitcoinInscriptionRevealed = Static<typeof BitcoinInscriptionRevealedSchema>;
2424

2525
export const BitcoinInscriptionTransferredSchema = Type.Object({
26-
inscription_number: Type.Integer(),
2726
inscription_id: Type.String(),
28-
ordinal_number: Type.Integer(),
2927
updated_address: Nullable(Type.String()),
3028
satpoint_pre_transfer: Type.String(),
3129
satpoint_post_transfer: Type.String(),

components/client/typescript/src/server.ts

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Static, Type, TypeBoxTypeProvider } from '@fastify/type-provider-typebox';
2+
import { TypeCompiler } from '@sinclair/typebox/compiler';
23
import Fastify, {
34
FastifyInstance,
45
FastifyPluginCallback,
@@ -22,7 +23,13 @@ const ServerOptionsSchema = Type.Object({
2223
port: Type.Integer(),
2324
auth_token: Type.String(),
2425
external_base_url: Type.String(),
26+
27+
/** Wait for the chainhook node to be available before submitting predicates */
2528
wait_for_chainhook_node: Type.Boolean({ default: true }),
29+
/** Validate the JSON schema of received chainhook payloads and report errors when invalid */
30+
validate_chainhook_payloads: Type.Boolean({ default: false }),
31+
/** Size limit for received chainhook payloads (default 40MB) */
32+
body_limit: Type.Number({ default: 41943040 }),
2633
});
2734
/** Local event server connection and authentication options */
2835
export type ServerOptions = Static<typeof ServerOptionsSchema>;
@@ -174,6 +181,7 @@ export async function buildServer(
174181
Server,
175182
TypeBoxTypeProvider
176183
> = (fastify, options, done) => {
184+
const compiledSchema = TypeCompiler.Compile(PayloadSchema);
177185
fastify.addHook('preHandler', isEventAuthorized);
178186
fastify.post(
179187
'/chainhook/:uuid',
@@ -186,6 +194,14 @@ export async function buildServer(
186194
},
187195
},
188196
async (request, reply) => {
197+
if (serverOpts.validate_chainhook_payloads && !compiledSchema.Check(request.body)) {
198+
logger.error(
199+
[...compiledSchema.Errors(request.body)],
200+
`ChainhookEventObserver received an invalid payload`
201+
);
202+
await reply.code(422).send();
203+
return;
204+
}
189205
try {
190206
await callback(request.params.uuid, request.body);
191207
await reply.code(200).send();
@@ -202,7 +218,7 @@ export async function buildServer(
202218
trustProxy: true,
203219
logger: PINO_CONFIG,
204220
pluginTimeout: 0, // Disable so ping can retry indefinitely
205-
bodyLimit: 41943040, // 40 MB
221+
bodyLimit: serverOpts.body_limit,
206222
}).withTypeProvider<TypeBoxTypeProvider>();
207223

208224
if (serverOpts.wait_for_chainhook_node) {

0 commit comments

Comments
 (0)