Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(indexer): trigger address activity job #316

Merged
merged 1 commit into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions apps/indexer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@
"dependencies": {
"@dfuse/client": "^0.3.21",
"@repo/supabase": "workspace:*",
"@repo/trigger": "workspace:*",
"@sentry/integrations": "^7.114.0",
"@sentry/node": "^8.19.0",
"@sentry/profiling-node": "^8.26.0",
"@supabase/supabase-js": "^2.44.4",
"@trigger.dev/sdk": "^2.3.19",
"@types/pino-http": "^5.8.4",
"app-contracts": "workspace:*",
"app-env": "workspace:*",
Expand Down
23 changes: 15 additions & 8 deletions apps/indexer/src/routes/alchemy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,26 @@ import { Request, Response } from 'express'
import crypto from 'crypto'
import { appConfig } from '../config'
import { logger } from '~/lib/logger'
import {addressActivityTask} from '@repo/trigger';

function validateAlchemySignature(req: Request): boolean {
const alchemySignature = req.headers['x-alchemy-signature'] as string
const payload = JSON.stringify(req.body)
const hmac = crypto.createHmac('sha256', appConfig.evm.alchemySecretKey)
hmac.update(payload)
return alchemySignature === hmac.digest('hex')
}

export function alchemyWebhook(req: Request, res: Response) {
if (!validateAlchemySignature(req)) return res.status(401).send('Unauthorized')

logger.info(req.body)

// TODO: validate user is whitelisted
gaboesquivel marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reminder: Implement user whitelisting.

The TODO comment suggests future implementation of user whitelisting. Ensure this is tracked and implemented as needed.

Do you want me to open a GitHub issue to track this task?


addressActivityTask.trigger(req.body)

res.status(200).send('Webhook processed')
}
}


function validateAlchemySignature(req: Request): boolean {
const alchemySignature = req.headers['x-alchemy-signature'] as string
const payload = JSON.stringify(req.body)
const hmac = crypto.createHmac('sha256', appConfig.evm.alchemySecretKey)
hmac.update(payload)
return alchemySignature === hmac.digest('hex')
}
9 changes: 5 additions & 4 deletions apps/trigger/package.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
{
"name": "smartsale-jobs",
"name": "@repo/trigger",
"version": "0.0.1",
"private": true,
"main": "src/index.ts",
"scripts": {
"dev": "bunx trigger.dev@beta dev",
"deploy:test": "bunx trigger.dev@beta deploy --env test",
"deploy:prod": "bunx trigger.dev@beta deploy --env prod"
},
"dependencies": {
"@trigger.dev/sdk": "3.0.0-beta.54",
"viem": "latest",
"@trigger.dev/sdk": "^2.3.19",
"app-contracts": "workspace:*",
"app-env": "workspace:*",
"app-lib": "workspace:*"
"app-lib": "workspace:*",
"viem": "latest"
}
}
1 change: 1 addition & 0 deletions apps/trigger/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './trigger/activity'
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { logger, task } from "@trigger.dev/sdk/v3";
import { getErrorMessage } from "app-lib";

export const addressActivityTask = task({
id: "address-activity",
Expand All @@ -9,7 +10,7 @@ export const addressActivityTask = task({


} catch (error) {
logger.error("Error processing address activity", { error: (error as Error).message });
logger.error("Error processing address activity", { error: getErrorMessage(error) });
throw error;
}
},
Expand Down
Binary file modified bun.lockb
Binary file not shown.
Loading