diff --git a/src/queries.ts b/src/queries.ts index 23162ee..eab166a 100644 --- a/src/queries.ts +++ b/src/queries.ts @@ -16,6 +16,8 @@ export function addBlockFilter(q: any, additional_query_params: any, where: any[ } + + export function addBlockRangeFilter(q: any, additional_query_params: any, where: any[]) { if (q.block_range && q.block_range != '0') { @@ -87,20 +89,25 @@ export function getTotalSupply(endpoint: UsageEndpoints, query_param: any, examp if (contract) where.push(`${table}.contract = {contract : String}`); // timestamp and block filter - additional_query_params = addBlockFilter(q, additional_query_params, where); + + if (q.block_num) { + const max_block = q.block_num; + where.push(`block_num >= {max_block : int}`); + additional_query_params = { ...additional_query_params, max_block } + + } // Join WHERE statements with AND if (where.length) query += ` WHERE(${where.join(' AND ')})`; // Sort and Limit // const sort_by = searchParams.get("sort_by"); - query += ` ORDER BY block_num ${DEFAULT_SORT_BY} ` + query += ` ORDER BY block_num` } - query += ` LIMIT {limit: int} ` + query += ` LIMIT 1 ` - if (q.page) query += ` OFFSET {offset : int} ` return { query, additional_query_params }; } diff --git a/src/types/zod.gen.ts b/src/types/zod.gen.ts index 4eb3ee9..98fff6d 100644 --- a/src/types/zod.gen.ts +++ b/src/types/zod.gen.ts @@ -176,7 +176,7 @@ export type UsageHoldersQueryResponseSchema = z.infer supportedChainsSchema) }); export type UsageSupplyPathParamsSchema = z.infer; - export const usageSupplyQueryParamsSchema = z.object({ "contract": z.coerce.string(), "block_num": z.coerce.number().optional(), "limit": z.coerce.number().optional(), "page": z.coerce.number().optional() }); + export const usageSupplyQueryParamsSchema = z.object({ "contract": z.coerce.string(), "block_num": z.coerce.number().optional() }); export type UsageSupplyQueryParamsSchema = z.infer; /** * @description Array of supplies. diff --git a/src/typespec/openapi3.tsp b/src/typespec/openapi3.tsp index a3d4daa..7198885 100644 --- a/src/typespec/openapi3.tsp +++ b/src/typespec/openapi3.tsp @@ -158,7 +158,6 @@ interface Usage { @path chain: SupportedChains, @query contract: Supply.contract, ...BlockFilter, - ...PaginationQueryParams, ): APIResponse>; /** diff --git a/tsp-output/@typespec/openapi3/openapi.json b/tsp-output/@typespec/openapi3/openapi.json index 1ff20b9..2f3be4c 100644 --- a/tsp-output/@typespec/openapi3/openapi.json +++ b/tsp-output/@typespec/openapi3/openapi.json @@ -455,26 +455,6 @@ "type": "integer", "format": "uint64" } - }, - { - "name": "limit", - "in": "query", - "required": false, - "schema": { - "type": "integer", - "format": "uint64", - "default": 100 - } - }, - { - "name": "page", - "in": "query", - "required": false, - "schema": { - "type": "integer", - "format": "uint64", - "default": 1 - } } ], "responses": {