Skip to content

Commit

Permalink
fix supply
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathieu Lefebvre committed Aug 6, 2024
1 parent 6529b71 commit e9eaa89
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 26 deletions.
15 changes: 11 additions & 4 deletions src/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down Expand Up @@ -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 };
}
Expand Down
2 changes: 1 addition & 1 deletion src/types/zod.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export type UsageHoldersQueryResponseSchema = z.infer<typeof usageHoldersQueryRe
export const usageSupplyPathParamsSchema = z.object({ "chain": z.lazy(() => supportedChainsSchema) });
export type UsageSupplyPathParamsSchema = z.infer<typeof usageSupplyPathParamsSchema>;

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<typeof usageSupplyQueryParamsSchema>;
/**
* @description Array of supplies.
Expand Down
1 change: 0 additions & 1 deletion src/typespec/openapi3.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ interface Usage {
@path chain: SupportedChains,
@query contract: Supply.contract,
...BlockFilter,
...PaginationQueryParams,
): APIResponse<UsageResponse<Supply[]>>;

/**
Expand Down
20 changes: 0 additions & 20 deletions tsp-output/@typespec/openapi3/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down

0 comments on commit e9eaa89

Please sign in to comment.