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

Feature/subtivity #52

Merged
merged 20 commits into from
Nov 22, 2023
Merged
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
11026ef
Added aggregation endpoints
Pelotfr Nov 13, 2023
1354a17
Added /uaw endpoint
Pelotfr Nov 14, 2023
9e7ba1d
Added supported chains as store (periodically updated)
Pelotfr Nov 15, 2023
ba4a2a0
Added chain parameter verification
Pelotfr Nov 15, 2023
c428f7b
Simplified queries and tests
Pelotfr Nov 15, 2023
df69f33
Added /uaw/history endpoint
Pelotfr Nov 15, 2023
98aef4f
fixed endpoint name and unix date to seconds
Pelotfr Nov 15, 2023
faccf5d
enum time range filter and results split by chain
Pelotfr Nov 16, 2023
23403f1
Renamed /uaw/history into /uaw and removed previous /uaw endpoint
Pelotfr Nov 17, 2023
332b0d3
Refactored parameter verification and defaults
Pelotfr Nov 17, 2023
b56f3d9
Added multi select + history logic to agg endpoints
Pelotfr Nov 21, 2023
e7aa833
added normalized data format and grouped similar queries in one
Pelotfr Nov 21, 2023
bba20f9
Removed multi-select for aggregate functions, defined new standard re…
Pelotfr Nov 21, 2023
6be9bd7
Updated docs and endpoints to use new standard response and simpler q…
Pelotfr Nov 21, 2023
6441d18
Changed from blocks to module_hashes for faster result
Pelotfr Nov 22, 2023
a3277f2
Default agg to sum and simplified checks
Pelotfr Nov 22, 2023
f2443cc
moved uaw request handling into aggregate, added some comments
Pelotfr Nov 22, 2023
5eab96a
Fixed description
Pelotfr Nov 22, 2023
e18d74e
Merge branch 'main' into feature/subtivity
Pelotfr Nov 22, 2023
0f0f201
Revert "Merge branch 'main' into feature/subtivity"
Pelotfr Nov 22, 2023
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
Prev Previous commit
Next Next commit
moved uaw request handling into aggregate, added some comments
  • Loading branch information
Pelotfr committed Nov 22, 2023

Verified

This commit was signed with the committer’s verified signature.
zackkatz Zack Katz
commit f2443cc973188ca91f434d2fed5db57ba1f18c90
3 changes: 1 addition & 2 deletions src/fetch/GET.ts
Original file line number Diff line number Diff line change
@@ -4,7 +4,6 @@ import health from "./health.js";
import chains from "./chains.js";
import block from "./block.js";
import aggregate from "./aggregate.js";
import uaw from "./uaw.js";
import * as prometheus from "../prometheus.js";
import { logger } from "../logger.js";
import swaggerHtml from "../../swagger/index.html"
@@ -23,7 +22,7 @@ export default async function (req: Request) {
if ( pathname === "/block" ) return block(req);
if ( pathname === "/trace_calls" ) return aggregate(req, pathname);
if ( pathname === "/transaction_traces" ) return aggregate(req, pathname);
if ( pathname === "/uaw" ) return uaw(req);
if ( pathname === "/uaw" ) return aggregate(req, pathname);
logger.warn(`Not found: ${pathname}`);
prometheus.request_error.inc({pathname, status: 404});
return NotFound;
4 changes: 4 additions & 0 deletions src/fetch/aggregate.ts
Original file line number Diff line number Diff line change
@@ -5,16 +5,20 @@ import * as prometheus from "../prometheus.js";
import { BadRequest, toJSON } from "./cors.js";
import { parseNormalized, verifyParameters } from "../utils.js";

// endpoint for aggregates (trace_calls, transaction_traces, uaw)
export default async function (req: Request, pathname: string) {
// verify some crucial parameters beforehand
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))});
// creates the query for requested aggregate column based on pathname
const query = getAggregate(searchParams, pathname.replace("/", ""));
const response = await makeQuery<NormalizedHistoryData>(query)
// formats the response into daily intervals
const formatted = parseNormalized(response.data, 86400);
return toJSON(formatted);
} catch (e: any) {
25 changes: 0 additions & 25 deletions src/fetch/uaw.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/queries.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, jest, mock, test } from "bun:test";
import { createBlockQuery, getBlock, getAggregate, /*getUAWHistory*/ } from "./queries.js";
import { createBlockQuery, getBlock, getAggregate } from "./queries.js";
import { store } from "./clickhouse/stores.js";

// Mock supported chains data to prevent DB query
3 changes: 3 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -89,6 +89,7 @@ export function parseAggregateFunction(aggregate_function?: string|null) {
return aggregate_function;
}

// same logic from above
export function parseHistoryRange(range?: string|null) {
if (!range) return "24h";
if (!z.enum(["24h", "7d", "30d", "90d", "1y", "all"]).safeParse(range).success) {
@@ -98,6 +99,7 @@ export function parseHistoryRange(range?: string|null) {
return range;
}

// used before running the query to gain time
export async function verifyParameters(req: Request) {
const url = new URL(req.url);
// chain
@@ -120,6 +122,7 @@ export async function verifyParameters(req: Request) {
}
}

// parses the db response into normalized format for easier further handling
export function parseNormalized(data: NormalizedHistoryData[], interval: number): NormalizedHistoryFormat[] {
const parsedData: Record<string, NormalizedHistoryFormat> = {};