Skip to content

Commit

Permalink
Merge branch 'main' into feature/subtivity
Browse files Browse the repository at this point in the history
  • Loading branch information
Pelotfr authored Nov 22, 2023
2 parents 5eab96a + ac5cebe commit e18d74e
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/fetch/history.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { makeQuery } from "../clickhouse/makeQuery.js";
import { logger } from "../logger.js";
import { UAWHistory, getUAWHistory } from "../queries.js";
import * as prometheus from "../prometheus.js";
import { BadRequest, toJSON } from "./cors.js";
import { parseUAWResponse, verifyParameters } from "../utils.js";

export default async function (req: Request) {
const parametersResult = await verifyParameters(req);
if(parametersResult instanceof Response) {
return parametersResult;
}
try {
const { searchParams } = new URL(req.url);
logger.info({searchParams: Object.fromEntries(Array.from(searchParams))});
const query = getUAWHistory(searchParams);
const response = await makeQuery<UAWHistory>(query)
const formatted = parseUAWResponse(response.data);
return toJSON(formatted);
} catch (e: any) {
logger.error(e);
prometheus.request_error.inc({pathname: "/uaw/history", status: 400});
return BadRequest
}
}
24 changes: 24 additions & 0 deletions src/fetch/uaw.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { makeQuery } from "../clickhouse/makeQuery.js";
import { logger } from "../logger.js";
import { getUAWFromDate } from "../queries.js";
import * as prometheus from "../prometheus.js";
import { BadRequest, toJSON } from "./cors.js";
import { verifyParameters } from "../utils.js";

export default async function (req: Request) {
const parametersResult = await verifyParameters(req);
if(parametersResult instanceof Response) {
return parametersResult;
}
try {
const { searchParams } = new URL(req.url);
logger.info({searchParams: Object.fromEntries(Array.from(searchParams))});
const query = getUAWFromDate(searchParams);
const response = await makeQuery<number>(query)
return toJSON(response.data);
} catch (e: any) {
logger.error(e);
prometheus.request_error.inc({pathname: "/uaw", status: 400});
return BadRequest
}
}
1 change: 1 addition & 0 deletions src/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { expect, test } from "bun:test";
import { parseBlockId, parseBlockNumber, parseChain, parseLimit, parseSortBy,
parseTimestamp, parseAggregateFunction, parseHistoryRange } from "./utils.js";
import { DEFAULT_MAX_LIMIT, DEFAULT_SORT_BY } from "./config.js";
import { parse } from "querystring";

test("parseBlockId", () => {
expect(parseBlockId()).toBeUndefined();
Expand Down

0 comments on commit e18d74e

Please sign in to comment.