@blockfrost/blockfrost-js
Version:
A JavaScript/TypeScript SDK for interacting with the https://blockfrost.io API
349 lines (348 loc) • 14 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.GovernanceAPI = void 0;
const utils_1 = require("../../../utils");
const errors_1 = require("../../../utils/errors");
class GovernanceAPI {
constructor(blockfrostAPI) {
this.blockfrostAPI = blockfrostAPI;
}
/**
* Obtains list of Delegate Representatives (DReps).
* @see {@link https://docs.blockfrost.io/#tag/cardano--governance/GET/governance/dreps | API docs for Delegate Representatives (DReps)}
*
* @param pagination - Optional, Pagination options
* @returns List of registered stake pools.
*
*/
async dreps(pagination) {
const paginationOptions = (0, utils_1.getPaginationOptions)(pagination);
try {
const res = await this.blockfrostAPI.instance(`governance/dreps`, {
searchParams: {
page: paginationOptions.page,
count: paginationOptions.count,
order: paginationOptions.order,
},
});
return res.body;
}
catch (error) {
throw (0, errors_1.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
*
*/
async drepsById(drepId) {
try {
const res = await this.blockfrostAPI.instance(`governance/dreps/${drepId}`);
return res.body;
}
catch (error) {
throw (0, errors_1.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
*
*/
async drepsByIdMetadata(drepId, pagination) {
const paginationOptions = (0, utils_1.getPaginationOptions)(pagination);
try {
const res = await this.blockfrostAPI.instance(`governance/dreps/${drepId}/metadata`, {
searchParams: {
page: paginationOptions.page,
count: paginationOptions.count,
order: paginationOptions.order,
},
});
return res.body;
}
catch (error) {
throw (0, errors_1.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
*
*/
async drepsByIdDelegators(drepId, pagination) {
const paginationOptions = (0, utils_1.getPaginationOptions)(pagination);
try {
const res = await this.blockfrostAPI.instance(`governance/dreps/${drepId}/delegators`, {
searchParams: {
page: paginationOptions.page,
count: paginationOptions.count,
order: paginationOptions.order,
},
});
return res.body;
}
catch (error) {
throw (0, errors_1.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
*
*/
async drepsByIdDelegatorsAll(drepId, allMethodOptions) {
return (0, utils_1.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
*
*/
async drepsByIdUpdates(drepId, pagination) {
const paginationOptions = (0, utils_1.getPaginationOptions)(pagination);
try {
const res = await this.blockfrostAPI.instance(`governance/dreps/${drepId}/updates`, {
searchParams: {
page: paginationOptions.page,
count: paginationOptions.count,
order: paginationOptions.order,
},
});
return res.body;
}
catch (error) {
throw (0, errors_1.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
*
*/
async drepsByIdUpdatesAll(drepId, allMethodOptions) {
return (0, utils_1.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
*
*/
async drepsByIdVotes(drepId, pagination) {
const paginationOptions = (0, utils_1.getPaginationOptions)(pagination);
try {
const res = await this.blockfrostAPI.instance(`governance/dreps/${drepId}/votes`, {
searchParams: {
page: paginationOptions.page,
count: paginationOptions.count,
order: paginationOptions.order,
},
});
return res.body;
}
catch (error) {
throw (0, errors_1.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
*
*/
async drepsByIdVotesAll(drepId, allMethodOptions) {
return (0, utils_1.paginateMethod)(pagination => this.drepsByIdVotes(drepId, pagination), allMethodOptions);
}
/**
* Obtains list of proposals.
* @see {@link https://docs.blockfrost.io/#tag/cardano--governance/GET/governance/proposals | API docs for Proposals}
*
* @param pagination - Optional, Pagination options
* @returns List of proposals
*
*/
async proposals(pagination) {
const paginationOptions = (0, utils_1.getPaginationOptions)(pagination);
try {
const res = await this.blockfrostAPI.instance(`governance/proposals`, {
searchParams: {
page: paginationOptions.page,
count: paginationOptions.count,
order: paginationOptions.order,
},
});
return res.body;
}
catch (error) {
throw (0, errors_1.handleError)(error);
}
}
/**
* Obtains a specific Proposal
* @see {@link https://docs.blockfrost.io/#tag/cardano--governance/GET/governance/proposals/%tx_hash%7D/%cert_index%7D | API docs for Specific Proposal}
*
* @param txHash - Transaction Hash
* @param cert_index - Index of the certificate within the proposal transaction.
* @returns Proposal information
*
*/
async proposal(txHash, certIndex) {
try {
const res = await this.blockfrostAPI.instance(`governance/proposals/${txHash}/${certIndex}`);
return res.body;
}
catch (error) {
throw (0, errors_1.handleError)(error);
}
}
/**
* Obtains a parameters of specific proposal
* @see {@link https://docs.blockfrost.io/#tag/cardano--governance/GET/governance/proposals/%tx_hash%7D/%cert_index%7D/parameters | API docs for Specific Proposal parameters}
*
* @param txHash - Transaction Hash
* @param cert_index - Index of the certificate within the proposal transaction.
* @returns Parameters proposal details.
*
*/
async proposalParameters(txHash, certIndex) {
try {
const res = await this.blockfrostAPI.instance(`governance/proposals/${txHash}/${certIndex}/parameters`);
return res.body;
}
catch (error) {
throw (0, errors_1.handleError)(error);
}
}
/**
* Obtains Specific withdrawals proposal
* @see {@link https://docs.blockfrost.io/#tag/cardano--governance/GET/governance/proposals/%tx_hash%7D/%cert_index%7D/withdrawals | API docs for Specific withdrawals proposal}
*
* @param txHash - Transaction Hash
* @param cert_index - Index of the certificate within the proposal transaction.
* @returns Parameters withdrawals details.
*
*/
async proposalWithdrawals(txHash, certIndex, pagination) {
const paginationOptions = (0, utils_1.getPaginationOptions)(pagination);
try {
const res = await this.blockfrostAPI.instance(`governance/proposals/${txHash}/${certIndex}/withdrawals`, {
searchParams: {
page: paginationOptions.page,
count: paginationOptions.count,
order: paginationOptions.order,
},
});
return res.body;
}
catch (error) {
throw (0, errors_1.handleError)(error);
}
}
/**
* Obtains Specific withdrawals proposal
* @see {@link https://docs.blockfrost.io/#tag/cardano--governance/GET/governance/proposals/%tx_hash%7D/%cert_index%7D/withdrawals | API docs for Specific withdrawals proposal}
* @remarks
* Variant of `proposalWithdrawals` method for fetching all pages with built-in requests batching
*
* @param txHash - Transaction Hash
* @param cert_index - Index of the certificate within the proposal transaction.
* @param allMethodOptions - Optional, Options for request batching
* @returns Parameters withdrawals details.
*
*/
async proposalWithdrawalsAll(txHash, certIndex, allMethodOptions) {
return (0, utils_1.paginateMethod)(pagination => this.proposalWithdrawals(txHash, certIndex, pagination), allMethodOptions);
}
/**
* Obtains History of Proposal votes.
* @see {@link https://docs.blockfrost.io/#tag/cardano--governance/GET/governance/proposals/%tx_hash%7D/%cert_index%7D/votes | API docs for Proposal votes}
*
* @param txHash - Transaction Hash
* @param cert_index - Index of the certificate within the proposal transaction.
* @returns History of Proposal votes.
*
*/
async proposalVotes(txHash, certIndex, pagination) {
const paginationOptions = (0, utils_1.getPaginationOptions)(pagination);
try {
const res = await this.blockfrostAPI.instance(`governance/proposals/${txHash}/${certIndex}/votes`, {
searchParams: {
page: paginationOptions.page,
count: paginationOptions.count,
order: paginationOptions.order,
},
});
return res.body;
}
catch (error) {
throw (0, errors_1.handleError)(error);
}
}
/**
* Obtains History of Proposal votes.
* @see {@link https://docs.blockfrost.io/#tag/cardano--governance/GET/governance/proposals/%tx_hash%7D/%cert_index%7D/votes | API docs for Proposal votes}
* @remarks
* Variant of `proposalVotes` method for fetching all pages with built-in requests batching
*
* @param txHash - Transaction Hash
* @param cert_index - Index of the certificate within the proposal transaction.
* @param allMethodOptions - Optional, Options for request batching
* @returns History of DRep votes
*
*/
async proposalVotesAll(txHash, certIndex, allMethodOptions) {
return (0, utils_1.paginateMethod)(pagination => this.proposalVotes(txHash, certIndex, pagination), allMethodOptions);
}
/**
* Obtains Proposal metadata information.
* @see {@link https://docs.blockfrost.io/#tag/cardano--governance/GET/governance/proposals/%tx_hash%7D/%cert_index%7D/metadata | API docs for Proposal metadata}
*
* @param txHash - Transaction Hash
* @param cert_index - Index of the certificate within the proposal transaction.
* @returns Proposal metadata information
*
*/
async proposalMetadata(txHash, certIndex) {
try {
const res = await this.blockfrostAPI.instance(`governance/proposals/${txHash}/${certIndex}/metadata`);
return res.body;
}
catch (error) {
throw (0, errors_1.handleError)(error);
}
}
}
exports.GovernanceAPI = GovernanceAPI;