-
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.
* Added aggregation endpoints * Added /uaw endpoint * Added supported chains as store (periodically updated) * Added chain parameter verification * Simplified queries and tests * Added /uaw/history endpoint * fixed endpoint name and unix date to seconds * enum time range filter and results split by chain --------- Co-authored-by: Pelotfr <polomeignan@hotmail.fr>
- Loading branch information
1 parent
66152da
commit 30990d7
Showing
14 changed files
with
570 additions
and
31 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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import client from "./createClient.js"; | ||
|
||
class ClickhouseStore { | ||
private ChainsPromise: Promise<string[]> | undefined = undefined; | ||
|
||
constructor() { | ||
// Fetch data initially | ||
this.fetchData(); | ||
|
||
// Set up a timer to fetch data periodically (e.g., every 1 hour) | ||
setInterval(() => { | ||
this.fetchData(); | ||
}, 10000); // 3600000 milliseconds = 1 hour | ||
} | ||
|
||
private fetchData() { | ||
this.ChainsPromise = client | ||
.query({ query: "SELECT DISTINCT chain FROM blocks", format: "JSONEachRow" }) | ||
.then((response) => response.json<Array<{ chain: string }>>()) | ||
.then((chains) => chains.map(({ chain }) => chain)) | ||
.catch(() => []); | ||
} | ||
|
||
public get chains() { | ||
return this.ChainsPromise; | ||
} | ||
} | ||
|
||
export const store = new ClickhouseStore(); |
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,24 @@ | ||
import { makeQuery } from "../clickhouse/makeQuery.js"; | ||
import { logger } from "../logger.js"; | ||
import { getAggregate } 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, pathname: string) { | ||
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 = getAggregate(searchParams, pathname.replace("/", "")); | ||
const response = await makeQuery<number>(query) | ||
return toJSON(response.data); | ||
} catch (e: any) { | ||
logger.error(e); | ||
prometheus.request_error.inc({pathname: pathname, status: 400}); | ||
return BadRequest | ||
} | ||
} |
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,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 | ||
} | ||
} |
Oops, something went wrong.