Skip to content

Commit

Permalink
Add support for reorg events (#305)
Browse files Browse the repository at this point in the history
  • Loading branch information
moisses89 authored Oct 22, 2024
1 parent e6758e9 commit 8129ee0
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 2 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,16 @@ Some parameters are common to every event:
}
```

### Reorg detected

```json
{
"type": "REORG_DETECTED",
"blockNumber": "<int>",
"chainId": "<stringified-int>"
}
```

# FAQ

## Do you have a dashboard/status page?
Expand Down
15 changes: 15 additions & 0 deletions src/datasources/migrations/1729516032564-SendReorgs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class SendReorgs1729516032564 implements MigrationInterface {
name = 'SendReorgs1729516032564';

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "webhook" ADD "sendReorgs" boolean NOT NULL DEFAULT true`,
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "webhook" DROP COLUMN "sendReorgs"`);
}
}
3 changes: 2 additions & 1 deletion src/routes/events/event.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions src/routes/webhook/entities/webhook.entity.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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);
});
});
6 changes: 5 additions & 1 deletion src/routes/webhook/entities/webhook.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'))
);
}
}

0 comments on commit 8129ee0

Please sign in to comment.