Skip to content

Commit

Permalink
Add endpoint for provider status
Browse files Browse the repository at this point in the history
  • Loading branch information
danial303065 committed Aug 9, 2024
1 parent 7b9c271 commit fc52d32
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions packages/relay/src/routers/ProviderRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ export class ProviderRouter {
this.provider_balance.bind(this)
);

this.app.get(
"/v1/provider/status/:provider",
[param("provider").exists().trim().isEthereumAddress()],
this.provider_status.bind(this)
);

this.app.post(
"/v1/provider/send/account",
[
Expand Down Expand Up @@ -143,7 +149,7 @@ export class ProviderRouter {
}

private async provider_balance(req: express.Request, res: express.Response) {
logger.http(`GET /v1/provider/balance/:account ${req.ip}:${JSON.stringify(req.params)}`);
logger.http(`GET /v1/provider/balance/:provider ${req.ip}:${JSON.stringify(req.params)}`);

const errors = validationResult(req);
if (!errors.isEmpty()) {
Expand All @@ -166,7 +172,33 @@ export class ProviderRouter {
);
} catch (error: any) {
const msg = ResponseMessage.getEVMErrorMessage(error);
logger.error(`GET /v1/provider/balance/account/:account : ${msg.error.message}`);
logger.error(`GET /v1/provider/balance/:provider : ${msg.error.message}`);
this.metrics.add("failure", 1);
return res.status(200).json(this.makeResponseData(msg.code, undefined, msg.error));
}
}

private async provider_status(req: express.Request, res: express.Response) {
logger.http(`GET /v1/provider/status/:provider ${req.ip}:${JSON.stringify(req.params)}`);

const errors = validationResult(req);
if (!errors.isEmpty()) {
return res.status(200).json(ResponseMessage.getErrorMessage("2001", { validation: errors.array() }));
}

try {
const provider: string = String(req.params.provider).trim();
const isProvider = await this.contractManager.sideLedgerContract.isProvider(provider);
this.metrics.add("success", 1);
return res.status(200).json(
this.makeResponseData(0, {
provider,
enable: isProvider,
})
);
} catch (error: any) {
const msg = ResponseMessage.getEVMErrorMessage(error);
logger.error(`GET /v1/provider/status/:provider : ${msg.error.message}`);
this.metrics.add("failure", 1);
return res.status(200).json(this.makeResponseData(msg.code, undefined, msg.error));
}
Expand Down

0 comments on commit fc52d32

Please sign in to comment.