Skip to content

Commit

Permalink
feat: integrate webhooks in the indexer (#114)
Browse files Browse the repository at this point in the history
Signed-off-by: david <[email protected]>
Co-authored-by: david <[email protected]>
  • Loading branch information
amateima and daywiss committed Nov 26, 2024
1 parent 969a6a9 commit 22ddb90
Show file tree
Hide file tree
Showing 27 changed files with 452 additions and 557 deletions.
4 changes: 2 additions & 2 deletions packages/indexer-api/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ export async function Main(
const redis = await initializeRedis(redisConfig, logger);
const webhooks = Webhooks.WebhookFactory(
{
requireApiKey: false,
enabledWebhooks: [Webhooks.WebhookTypes.DepositStatus],
enabledWebhookRequestWorkers: false,
},
{ postgres, logger },
{ postgres, logger, redis },
);

const allRouters: Record<string, Router> = {
Expand Down
11 changes: 6 additions & 5 deletions packages/indexer-database/src/entities/WebhookClient.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { Entity, PrimaryColumn, Column, PrimaryGeneratedColumn } from "typeorm";
import { Entity, Column, PrimaryGeneratedColumn, Unique } from "typeorm";

@Entity()
@Unique("UK_webhook_client_api_key", ["apiKey"])
export class WebhookClient {
@PrimaryGeneratedColumn()
id: number;

@Column()
name: string;

@PrimaryGeneratedColumn()
id: string;

@Column({ unique: true })
@Column()
apiKey: string;

@Column("jsonb")
Expand Down
18 changes: 15 additions & 3 deletions packages/indexer-database/src/entities/WebhookRequest.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
import { Entity, PrimaryColumn, Column } from "typeorm";
import {
Entity,
PrimaryColumn,
Column,
Unique,
CreateDateColumn,
Index,
} from "typeorm";

@Entity()
@Unique("UK_webhook_request_clientId_filter", ["clientId", "filter"])
@Index("IX_webhook_request_filter", ["filter"])
export class WebhookRequest {
@PrimaryColumn()
id: string;

@Column({ type: "integer" })
clientId: number;

@Column()
url: string;

@Column()
filter: string;

@Column({ type: "text", nullable: true, default: undefined })
clientId?: string | undefined;
@CreateDateColumn()
createdAt: Date;
}
3 changes: 3 additions & 0 deletions packages/indexer-database/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ export const createDataSource = (config: DatabaseConfig): DataSource => {
entities.RootBundleExecutedJoinTable,
// Others
entities.RelayHashInfo,
// Webhooks
entities.WebhookRequest,
entities.WebhookClient,
],
migrationsTableName: "_migrations",
migrations: ["migrations/*.ts"],
Expand Down
97 changes: 0 additions & 97 deletions packages/indexer-database/src/migrations/1732198003042-Webhook.ts

This file was deleted.

Loading

0 comments on commit 22ddb90

Please sign in to comment.