From 8129ee06c65f862ac45dd3564018222b1bed3da1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mois=C3=A9s?= <7888669+moisses89@users.noreply.github.com> Date: Tue, 22 Oct 2024 11:03:22 +0200 Subject: [PATCH] Add support for reorg events (#305) --- README.md | 10 ++++++++++ .../migrations/1729516032564-SendReorgs.ts | 15 +++++++++++++++ src/routes/events/event.dto.ts | 3 ++- .../webhook/entities/webhook.entity.spec.ts | 8 ++++++++ src/routes/webhook/entities/webhook.entity.ts | 6 +++++- 5 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 src/datasources/migrations/1729516032564-SendReorgs.ts diff --git a/README.md b/README.md index 5211cbf..27ed280 100644 --- a/README.md +++ b/README.md @@ -139,6 +139,16 @@ Some parameters are common to every event: } ``` +### Reorg detected + +```json +{ +"type": "REORG_DETECTED", +"blockNumber": "", +"chainId": "" +} +``` + # FAQ ## Do you have a dashboard/status page? diff --git a/src/datasources/migrations/1729516032564-SendReorgs.ts b/src/datasources/migrations/1729516032564-SendReorgs.ts new file mode 100644 index 0000000..d3e193f --- /dev/null +++ b/src/datasources/migrations/1729516032564-SendReorgs.ts @@ -0,0 +1,15 @@ +import { MigrationInterface, QueryRunner } from 'typeorm'; + +export class SendReorgs1729516032564 implements MigrationInterface { + name = 'SendReorgs1729516032564'; + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query( + `ALTER TABLE "webhook" ADD "sendReorgs" boolean NOT NULL DEFAULT true`, + ); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE "webhook" DROP COLUMN "sendReorgs"`); + } +} diff --git a/src/routes/events/event.dto.ts b/src/routes/events/event.dto.ts index 3f1a40f..62d15b8 100644 --- a/src/routes/events/event.dto.ts +++ b/src/routes/events/event.dto.ts @@ -11,7 +11,8 @@ export type TxServiceEventType = | 'OUTGOING_TOKEN' | 'MESSAGE_CREATED' | 'MESSAGE_CONFIRMATION' - | 'DELETED_MULTISIG_TRANSACTION'; + | 'DELETED_MULTISIG_TRANSACTION' + | 'REORG_DETECTED'; export interface TxServiceEvent { chainId: string; diff --git a/src/routes/webhook/entities/webhook.entity.spec.ts b/src/routes/webhook/entities/webhook.entity.spec.ts index 9bb1608..d2fc236 100644 --- a/src/routes/webhook/entities/webhook.entity.spec.ts +++ b/src/routes/webhook/entities/webhook.entity.spec.ts @@ -21,6 +21,7 @@ describe('Webhook entity', () => { webhook.sendModuleTransactions = true; webhook.sendSafeCreations = true; webhook.sendMessages = true; + webhook.sendReorgs = true; }); it('If chain is set, only those chain messages will be sent', async () => { @@ -127,4 +128,11 @@ describe('Webhook entity', () => { webhook.sendMessages = false; expect(webhook.isEventRelevant(txServiceEvent)).toBe(false); }); + + it('REORG_DETECTED should not be relevant if sendReorgs is disabled', async () => { + txServiceEvent.type = 'REORG_DETECTED' as TxServiceEventType; + expect(webhook.isEventRelevant(txServiceEvent)).toBe(true); + webhook.sendReorgs = false; + expect(webhook.isEventRelevant(txServiceEvent)).toBe(false); + }); }); diff --git a/src/routes/webhook/entities/webhook.entity.ts b/src/routes/webhook/entities/webhook.entity.ts index 05978d4..a2a589b 100644 --- a/src/routes/webhook/entities/webhook.entity.ts +++ b/src/routes/webhook/entities/webhook.entity.ts @@ -42,6 +42,9 @@ export class Webhook extends BaseEntity { @Column({ default: true }) sendMessages: boolean; + @Column({ default: true }) + sendReorgs: boolean; + /** * Check if event chainId matches the one of the webhook (everything will match if webhook chains are empty). Check if event * type matches the flags enabled for the webhook @@ -71,7 +74,8 @@ export class Webhook extends BaseEntity { (this.sendMessages && (message.type === 'MESSAGE_CREATED' || message.type === 'MESSAGE_CONFIRMATION')) || - (this.sendSafeCreations && message.type === 'SAFE_CREATED')) + (this.sendSafeCreations && message.type === 'SAFE_CREATED') || + (this.sendReorgs && message.type === 'REORG_DETECTED')) ); } }