Skip to content

Commit

Permalink
feat: add DReps endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
slowbackspace committed Oct 31, 2024
1 parent 3fb352c commit c8cf018
Show file tree
Hide file tree
Showing 5 changed files with 576 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
"commitlint",
"delegators",
"deregistrations",
"drep",
"dreps",
"emurgo",
"id",
"io",
Expand Down Expand Up @@ -41,5 +43,4 @@
"**/.pnp.*": true
},
"eslint.nodePath": ".yarn/sdks",
"prettier.prettierPath": ".yarn/sdks/prettier/index.js"
}
4 changes: 4 additions & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- methods for querying governance DReps endpoints - `dreps`, `drepsById`, `drepsByIdDelegators`, `drepsByIdDelegatorsAll`, `drepsByIdMetadata`, `drepsByIdUpdates`, `drepsByIdUpdatesAll`, `drepsByIdVotes`, `drepsByIdVotesAll`

## [5.6.0] - 2024-10-03

### Added
Expand Down
21 changes: 21 additions & 0 deletions src/BlockFrostAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,17 @@ import {
blocksAddressesAll,
} from './endpoints/api/blocks';

import {
dreps,
drepsById,
drepsByIdDelegators,
drepsByIdDelegatorsAll,
drepsByIdMetadata,
drepsByIdUpdates,
drepsByIdUpdatesAll,
drepsByIdVotes,
drepsByIdVotesAll,
} from './endpoints/api/governance/dreps';
import {
epochs,
epochsBlocks,
Expand Down Expand Up @@ -257,6 +268,16 @@ class BlockFrostAPI {
blocksAddresses = blocksAddresses;
blocksAddressesAll = blocksAddressesAll;

dreps = dreps;
drepsById = drepsById;
drepsByIdDelegators = drepsByIdDelegators;
drepsByIdDelegatorsAll = drepsByIdDelegatorsAll;
drepsByIdMetadata = drepsByIdMetadata;
drepsByIdUpdates = drepsByIdUpdates;
drepsByIdUpdatesAll = drepsByIdUpdatesAll;
drepsByIdVotes = drepsByIdVotes;
drepsByIdVotesAll = drepsByIdVotesAll;

epochs = epochs;
epochsBlocks = epochsBlocks;
epochsBlocksAll = epochsBlocksAll;
Expand Down
252 changes: 252 additions & 0 deletions src/endpoints/api/governance/dreps/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,252 @@
import { getPaginationOptions, paginateMethod } from '../../../../utils';
import { components } from '@blockfrost/openapi';
import { BlockFrostAPI } from '../../../../index';
import { AllMethodOptions, PaginationOptions } from '../../../../types';
import { handleError } from '../../../../utils/errors';

/**
* Obtains list of Delegate Representatives (DReps).
* @see {@link https://docs.blockfrost.io/#tag/cardano--governance/GET/governance/dreps | API docs for of Delegate Representatives (DReps)}
*
* @param pagination - Optional, Pagination options
* @returns List of registered stake pools.
*
*/
export async function dreps(
this: BlockFrostAPI,
pagination?: PaginationOptions,
): Promise<components['schemas']['dreps']> {
const paginationOptions = getPaginationOptions(pagination);

try {
const res = await this.instance<components['schemas']['dreps']>(
`governance/dreps`,
{
searchParams: {
page: paginationOptions.page,
count: paginationOptions.count,
order: paginationOptions.order,
},
},
);
return res.body;
} catch (error) {
throw handleError(error);
}
}

/**
* Obtains information of a specific DRep.
* @see {@link https://docs.blockfrost.io/#tag/cardano--governance/GET/governance/dreps/%7Bdrep_id%7D | API docs for Stake Pool}
*
* @param drepId - DRep ID
* @returns Information of a specific DRep
*
*/
export async function drepsById(
this: BlockFrostAPI,
drepId: string,
): Promise<components['schemas']['drep']> {
try {
const res = await this.instance<components['schemas']['drep']>(
`governance/dreps/${drepId}`,
);
return res.body;
} catch (error) {
throw handleError(error);
}
}

/**
* Obtains DRep metadata.
* @see {@link https://docs.blockfrost.io/#tag/cardano--governance/GET/governance/dreps/%7Bdrep_id%7D/metadata | API docs for DRep Metadata}
*
* @param drepId - DRep ID
* @returns DRep Metadata
*
*/
export async function drepsByIdMetadata(
this: BlockFrostAPI,
drepId: string,
pagination?: PaginationOptions,
): Promise<components['schemas']['drep_metadata']> {
const paginationOptions = getPaginationOptions(pagination);

try {
const res = await this.instance<components['schemas']['drep_metadata']>(
`governance/dreps/${drepId}/metadata`,
{
searchParams: {
page: paginationOptions.page,
count: paginationOptions.count,
order: paginationOptions.order,
},
},
);
return res.body;
} catch (error) {
throw handleError(error);
}
}

/**
* Obtains current DRep delegators.
* @see {@link https://docs.blockfrost.io/#tag/cardano--governance/GET/governance/dreps/%7Bdrep_id%7D/delegators | API docs for DRep Delegators}
*
* @param drepId - DRep ID
* @returns Current DRep delegators
*
*/
export async function drepsByIdDelegators(
this: BlockFrostAPI,
drepId: string,
pagination?: PaginationOptions,
): Promise<components['schemas']['drep_delegators']> {
const paginationOptions = getPaginationOptions(pagination);

try {
const res = await this.instance<components['schemas']['drep_delegators']>(
`governance/dreps/${drepId}/delegators`,
{
searchParams: {
page: paginationOptions.page,
count: paginationOptions.count,
order: paginationOptions.order,
},
},
);
return res.body;
} catch (error) {
throw handleError(error);
}
}

/**
* Obtains current DRep delegators.
* @see {@link https://docs.blockfrost.io/#tag/cardano--governance/GET/governance/dreps/%7Bdrep_id%7D/delegators | API docs for DRep Delegators}
* @remarks
* Variant of `drepsByIdDelegators` method for fetching all pages with built-in requests batching
*
* @param drepId - DRep ID
* @param allMethodOptions - Optional, Options for request batching
* @returns Current DRep delegators
*
*/
export async function drepsByIdDelegatorsAll(
this: BlockFrostAPI,
drepId: string,
allMethodOptions?: AllMethodOptions,
): Promise<components['schemas']['drep_delegators']> {
return paginateMethod(
pagination => this.drepsByIdDelegators(drepId, pagination),
allMethodOptions,
);
}

/**
* Obtains List of certificate updates to the DRep.
* @see {@link https://docs.blockfrost.io/#tag/cardano--governance/GET/governance/dreps/%7Bdrep_id%7D/updates | API docs for DRep Updates}
*
* @param drepId - DRep ID
* @returns List of certificate updates to the DRep
*
*/
export async function drepsByIdUpdates(
this: BlockFrostAPI,
drepId: string,
pagination?: PaginationOptions,
): Promise<components['schemas']['drep_updates']> {
const paginationOptions = getPaginationOptions(pagination);

try {
const res = await this.instance<components['schemas']['drep_updates']>(
`governance/dreps/${drepId}/updates`,
{
searchParams: {
page: paginationOptions.page,
count: paginationOptions.count,
order: paginationOptions.order,
},
},
);
return res.body;
} catch (error) {
throw handleError(error);
}
}

/**
* Obtains List of certificate updates to the DRep.
* @see {@link https://docs.blockfrost.io/#tag/cardano--governance/GET/governance/dreps/%7Bdrep_id%7D/updates | API docs for History of DRep updates}
* @remarks
* Variant of `drepsByIdUpdates` method for fetching all pages with built-in requests batching
*
* @param drepId - DRep ID
* @param allMethodOptions - Optional, Options for request batching
* @returns List of certificate updates to the DRep
*
*/
export async function drepsByIdUpdatesAll(
this: BlockFrostAPI,
drepId: string,
allMethodOptions?: AllMethodOptions,
): Promise<components['schemas']['drep_updates']> {
return paginateMethod(
pagination => this.drepsByIdUpdates(drepId, pagination),
allMethodOptions,
);
}

/**
* Obtains History of DRep votes.
* @see {@link https://docs.blockfrost.io/#tag/cardano--governance/GET/governance/dreps/%7Bdrep_id%7D/votes | API docs for History of DRep votes}
*
* @param drepId - DRep ID
* @returns History of DRep votes
*
*/
export async function drepsByIdVotes(
this: BlockFrostAPI,
drepId: string,
pagination?: PaginationOptions,
): Promise<components['schemas']['drep_votes']> {
const paginationOptions = getPaginationOptions(pagination);

try {
const res = await this.instance<components['schemas']['drep_votes']>(
`governance/dreps/${drepId}/votes`,
{
searchParams: {
page: paginationOptions.page,
count: paginationOptions.count,
order: paginationOptions.order,
},
},
);
return res.body;
} catch (error) {
throw handleError(error);
}
}

/**
* Obtains History of DRep votes.
* @see {@link https://docs.blockfrost.io/#tag/cardano--governance/GET/governance/dreps/%7Bdrep_id%7D/votes | API docs for History of DRep votes}
* @remarks
* Variant of `drepsByIdVotes` method for fetching all pages with built-in requests batching
*
* @param drepId - DRep ID
* @param allMethodOptions - Optional, Options for request batching
* @returns History of DRep votes
*
*/
export async function drepsByIdVotesAll(
this: BlockFrostAPI,
drepId: string,
allMethodOptions?: AllMethodOptions,
): Promise<components['schemas']['drep_votes']> {
return paginateMethod(
pagination => this.drepsByIdVotes(drepId, pagination),
allMethodOptions,
);
}
Loading

0 comments on commit c8cf018

Please sign in to comment.