Skip to content

Commit

Permalink
Enable {chain}/final route query (#34)
Browse files Browse the repository at this point in the history
Similar to `{chain}/current` except it only takes into account the
blocks marked final in the chain. Returns the highest block number present.
  • Loading branch information
0237h authored Oct 20, 2023
1 parent 1a0b42f commit dfd8657
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,11 @@ export function generateApp() {
return JSONAPIResponseWrapper<SingleBlocknumQueryResponseSchema>(c, await currentBlocknumQuery(chain));
});

/*app.openapi(routes.finalBlocknumQueryRoute, async (c) => {
app.openapi(routes.finalBlocknumQueryRoute, async (c) => {
const { chain } = c.req.valid('param') as BlockchainSchema;

return JSONAPIResponseWrapper<SingleBlocknumQueryResponseSchema>(c, await finalBlocknumQuery(chain));
});*/
});

return app;
}
Expand Down
5 changes: 2 additions & 3 deletions src/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,13 @@ export async function currentBlocknumQuery(chain: string) {
}

export async function finalBlocknumQuery(chain: string) {
/*const query = `SELECT MAX(block_number) as final FROM ${config.table} GROUP BY chain HAVING (chain == '${chain}')`;
const query = `SELECT MAX(block_number) as final FROM ${config.table} GROUP BY chain HAVING (chain == '${chain}') AND (final_block == true)`;
const json = await makeQuery(query);

return SingleBlocknumQueryResponseSchema.parse({
chain
chain,
block_number: Object.values(json as JSONObjectEachRow)[0].final,
});
*/
}

export async function supportedChainsQuery() {
Expand Down
2 changes: 1 addition & 1 deletion src/tests/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ describe('Blocknum query page (/{chain}/blocknum?timestamp=<timestamp>)', () =>
});
});

describe.each(['current'/*, 'final'*/])('Single blocknum query page (/{chain}/%s)', (query_type: string) => {
describe.each(['current', 'final'])('Single blocknum query page (/{chain}/%s)', (query_type: string) => {
it('Should fail on non-valid chains', async () => {
const res = await app.request(`/dummy/${query_type}`);
expect(res.status).toBe(422);
Expand Down

0 comments on commit dfd8657

Please sign in to comment.