Skip to content

Commit

Permalink
Merge pull request #457 from hirosystems/feat/transfer-destination
Browse files Browse the repository at this point in the history
feat: add inscription transfer destination schema
  • Loading branch information
Ludo Galabru authored Nov 8, 2023
2 parents d729c7a + ee4b25e commit b30c843
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
4 changes: 2 additions & 2 deletions components/client/typescript/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 components/client/typescript/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hirosystems/chainhook-client",
"version": "1.3.4",
"version": "1.4.1",
"description": "Chainhook TypeScript client",
"main": "./dist/index.js",
"typings": "./dist/index.d.ts",
Expand Down
9 changes: 8 additions & 1 deletion components/client/typescript/src/schemas/bitcoin/payload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,15 @@ export const BitcoinInscriptionRevealedSchema = Type.Object({
export type BitcoinInscriptionRevealed = Static<typeof BitcoinInscriptionRevealedSchema>;

export const BitcoinInscriptionTransferredSchema = Type.Object({
destination: Type.Object({
type: Type.Union([
Type.Literal('transferred'),
Type.Literal('spent_in_fees'),
Type.Literal('burnt'),
]),
value: Type.Optional(Type.String()),
}),
inscription_id: Type.String(),
updated_address: Nullable(Type.String()),
satpoint_pre_transfer: Type.String(),
satpoint_post_transfer: Type.String(),
post_transfer_output_value: Nullable(Type.Integer()),
Expand Down
20 changes: 18 additions & 2 deletions components/client/typescript/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ const ChainhookNodeOptionsSchema = Type.Object({
/** Chainhook node connection options */
export type ChainhookNodeOptions = Static<typeof ChainhookNodeOptionsSchema>;

/**
* Throw this error when processing a Chainhook Payload if you believe it is a bad request. This
* will cause the server to return a `400` status code.
*/
export class BadPayloadRequestError extends Error {
constructor(message: string) {
super(message);
this.name = this.constructor.name;
}
}

const IfThisThenNothingSchema = Type.Union([
Type.Composite([
BitcoinIfThisOptionsSchema,
Expand Down Expand Up @@ -209,8 +220,13 @@ export async function buildServer(
await callback(request.params.uuid, request.body);
await reply.code(200).send();
} catch (error) {
logger.error(error, `ChainhookEventObserver error processing payload`);
await reply.code(500).send();
if (error instanceof BadPayloadRequestError) {
logger.error(error, `ChainhookEventObserver bad payload`);
await reply.code(400).send();
} else {
logger.error(error, `ChainhookEventObserver error processing payload`);
await reply.code(500).send();
}
}
}
);
Expand Down

0 comments on commit b30c843

Please sign in to comment.