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

Add endpoint for provider status #34

Merged
merged 1 commit into from
Aug 9, 2024
Merged
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
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
Loading