-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(indexer-api): expose hubpool balance endpoint (#81)
Signed-off-by: david <[email protected]>
- Loading branch information
Showing
11 changed files
with
109 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,32 @@ | ||
import { Request, Response, NextFunction } from "express"; | ||
import * as s from "superstruct"; | ||
import { DepositsService } from "../services/deposits"; | ||
import { BalancesService } from "../services/balances"; | ||
import { | ||
HubPoolBalanceParams, | ||
HubPoolBalanceQueryParams, | ||
SpokePoolBalanceParams, | ||
} from "../dtos/balances.dto"; | ||
|
||
export class BalancesController { | ||
constructor(private service: DepositsService) {} | ||
constructor(private service: BalancesService) {} | ||
|
||
public getHubPoolBalance = async ( | ||
public getHubPoolBalance = ( | ||
req: Request, | ||
res: Response, | ||
next: NextFunction, | ||
) => { | ||
s.assert(req.query, HubPoolBalanceParams); | ||
return 0; | ||
req.query && s.assert(req.query, HubPoolBalanceQueryParams); | ||
this.service | ||
.hubPoolBalance(req.query) | ||
.then((result) => res.json(result)) | ||
.catch((err) => next(err)); | ||
}; | ||
|
||
public getSpokePoolBalance = async ( | ||
public getSpokePoolBalance = ( | ||
req: Request, | ||
res: Response, | ||
next: NextFunction, | ||
) => { | ||
s.assert(req.query, SpokePoolBalanceParams); | ||
|
||
return 0; | ||
req.query && s.assert(req.query, SpokePoolBalanceParams); | ||
res.json([]); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Router } from "express"; | ||
import Redis from "ioredis"; | ||
import { BalancesController } from "../controllers/balances"; | ||
import { BalancesService } from "../services/balances"; | ||
|
||
export function getRouter(redis: Redis): Router { | ||
const router = Router(); | ||
const service = new BalancesService(redis); | ||
const controller = new BalancesController(service); | ||
router.get("/hubpool-balance", controller.getHubPoolBalance); | ||
router.get("/spokepool-balance", controller.getSpokePoolBalance); | ||
return router; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * as deposits from "./deposits"; | ||
export * as balances from "./balances"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import assert from "assert"; | ||
import Redis from "ioredis"; | ||
import * as Indexer from "@repo/indexer"; | ||
|
||
export class BalancesService { | ||
hubBalancesCache: Indexer.redis.hubBalancesCache.HubPoolBalanceCache; | ||
constructor(private redis: Redis) { | ||
this.hubBalancesCache = | ||
new Indexer.redis.hubBalancesCache.HubPoolBalanceCache({ | ||
redis, | ||
prefix: "hubBalanceCache", | ||
}); | ||
} | ||
async hubPoolBalance(params?: { | ||
l1Token?: string; | ||
}): Promise<Indexer.redis.hubBalancesCache.HubPoolBalances> { | ||
if (params?.l1Token) { | ||
const balance = await this.hubBalancesCache.get(params.l1Token); | ||
assert(balance, `No hubpoolBalance found for ${params.l1Token}`); | ||
return [balance]; | ||
} else { | ||
return this.hubBalancesCache.getAllL1Tokens(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from "./main"; | ||
export * from "./parseEnv"; | ||
export * as redis from "./redis"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export * as bundleLeavesCache from "./bundleLeavesCache"; | ||
export * as hubBalancesCache from "./hubBalancesCache"; | ||
export * as rangeQueryStore from "./rangeQueryStore"; | ||
export * as redisCache from "./redisCache"; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.