-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ae974c3
commit f598da1
Showing
11 changed files
with
113 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
"cdbsync", | ||
"dbsync", | ||
"delegators", | ||
"dreps", | ||
"elgohr", | ||
"emurgo", | ||
"esbuild", | ||
|
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,28 @@ | ||
import { FastifyInstance, FastifyRequest } from 'fastify'; | ||
import * as QueryTypes from '../../../../types/queries/blocks.js'; | ||
import * as ResponseTypes from '../../../../types/responses/blocks.js'; | ||
import { getDbSync } from '../../../../utils/database.js'; | ||
import { SQLQuery } from '../../../../sql/index.js'; | ||
|
||
async function route(fastify: FastifyInstance) { | ||
fastify.route({ | ||
url: '/governance/dreps/:hash/distribution', | ||
method: 'GET', | ||
// TODO: add schema when available | ||
// schema: getSchemaForEndpoint('/governance/dreps/{hash}/distribution'), | ||
handler: async (request: FastifyRequest<QueryTypes.RequestParameters>, reply) => { | ||
const clientDbSync = await getDbSync(fastify); | ||
|
||
const { rows }: { rows: ResponseTypes.Block[] } = await clientDbSync.query<QueryTypes.Block>( | ||
SQLQuery.get('governance_dreps_distribution'), | ||
[request.params.hash, request.query.order, request.query.count, request.query.page], | ||
); | ||
|
||
clientDbSync.release(); | ||
|
||
return reply.send(rows); | ||
}, | ||
}); | ||
} | ||
|
||
export default route; |
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,34 @@ | ||
import { FastifyInstance, FastifyRequest } from 'fastify'; | ||
import * as QueryTypes from '../../../../types/queries/blocks.js'; | ||
import * as ResponseTypes from '../../../../types/responses/blocks.js'; | ||
import { getDbSync } from '../../../../utils/database.js'; | ||
import { handle404 } from '../../../../utils/error-handler.js'; | ||
import { SQLQuery } from '../../../../sql/index.js'; | ||
|
||
async function route(fastify: FastifyInstance) { | ||
fastify.route({ | ||
url: '/governance/dreps/:hash', | ||
method: 'GET', | ||
// TODO: add schema when available | ||
// schema: getSchemaForEndpoint('/governance/dreps/{hash}'), | ||
handler: async (request: FastifyRequest<QueryTypes.RequestParameters>, reply) => { | ||
const clientDbSync = await getDbSync(fastify); | ||
|
||
const { rows }: { rows: ResponseTypes.Block[] } = await clientDbSync.query<QueryTypes.Block>( | ||
SQLQuery.get('governance_dreps_details'), | ||
[request.params.hash], | ||
); | ||
|
||
clientDbSync.release(); | ||
|
||
const row = rows[0]; | ||
|
||
if (!row) { | ||
return handle404(reply); | ||
} | ||
return reply.send(row); | ||
}, | ||
}); | ||
} | ||
|
||
export default route; |
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,37 @@ | ||
import { FastifyInstance, FastifyRequest } from 'fastify'; | ||
import { SQLQuery } from '../../../sql/index.js'; | ||
import * as QueryTypes from '../../../types/queries/epochs.js'; | ||
import * as ResponseTypes from '../../../types/responses/epochs.js'; | ||
import { getDbSync } from '../../../utils/database.js'; | ||
|
||
async function route(fastify: FastifyInstance) { | ||
fastify.route({ | ||
url: '/governance/dreps', | ||
method: 'GET', | ||
// TODO: add schema when available | ||
// schema: getSchemaForEndpoint('/epochs/latest'), | ||
handler: async (request: FastifyRequest<QueryTypes.RequestParameters>, reply) => { | ||
const clientDbSync = await getDbSync(fastify); | ||
|
||
try { | ||
const { rows }: { rows: ResponseTypes.Epoch[] } = | ||
await clientDbSync.query<QueryTypes.Epoch>(SQLQuery.get('governance_dreps'), [ | ||
request.query.order, | ||
request.query.count, | ||
request.query.page, | ||
]); | ||
|
||
clientDbSync.release(); | ||
|
||
return reply.send(rows); | ||
} catch (error) { | ||
if (clientDbSync) { | ||
clientDbSync.release(); | ||
} | ||
throw error; | ||
} | ||
}, | ||
}); | ||
} | ||
|
||
export default route; |
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 @@ | ||
governance_dreps |
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 @@ | ||
drep_details |
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 @@ | ||
dreps_dristribution |
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