Skip to content

Commit

Permalink
DistributorV2
Browse files Browse the repository at this point in the history
  • Loading branch information
youngkidwarrior committed Oct 10, 2024
1 parent d3340df commit 446e2fa
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 124 deletions.
25 changes: 25 additions & 0 deletions apps/distributor/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { DistributorV1Worker } from './distributor'
import { StandardMerkleTree } from '@openzeppelin/merkle-tree'
import { selectAll } from 'app/utils/supabase/selectAll'
import { supabaseAdmin } from './supabase'
import { DistributorV2Worker } from './distributorv2'

const logger = pino({
level: process.env.LOG_LEVEL || 'info',
Expand All @@ -12,6 +13,7 @@ const logger = pino({

// Initialize DistributorWorker
const distributorV1Worker = new DistributorV1Worker(logger)
const distributorV2Worker = new DistributorV2Worker(logger)

// Initialize Express app
const app = express()
Expand All @@ -32,6 +34,13 @@ distributorRouter.get('/v1', async (req: Request, res: Response) => {
})
})

distributorRouter.get('/v2', async (req: Request, res: Response) => {
res.json({
distributor: true,
...distributorV2Worker.toJSON(),
})
})

// Middleware for checking authorization
const checkAuthorization = (req: Request, res: Response, next: () => void) => {
if (!req.headers.authorization?.includes(process.env.SUPABASE_SERVICE_ROLE as string)) {
Expand Down Expand Up @@ -117,6 +126,22 @@ distributorRouter.post('/v1', checkAuthorization, async (req, res) => {
})
})

distributorRouter.post('/v2', checkAuthorization, async (req, res) => {
const { id } = req.body as { id: string }
logger.info({ id }, 'Received request to calculate distribution')
try {
await distributorV2Worker.calculateDistribution(id)
} catch (err) {
logger.error(err, 'Error while calculating distribution')
throw err
}

res.json({
distributor: true,
id: id,
})
})

app.use('/distributor', distributorRouter)

export default app
Expand Down
Loading

0 comments on commit 446e2fa

Please sign in to comment.