@blockfrost/blockfrost-js
Version:
A JavaScript/TypeScript SDK for interacting with the https://blockfrost.io API
294 lines (293 loc) • 11.4 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.epochsLatestParameters = exports.epochsParameters = exports.epochsBlocksByPoolIdAll = exports.epochsBlocksByPoolId = exports.epochsBlocksAll = exports.epochsBlocks = exports.epochsStakesByPoolIdAll = exports.epochsStakesByPoolId = exports.epochsStakesAll = exports.epochsStakes = exports.epochsPrevious = exports.epochsNext = exports.epochsLatest = exports.epochs = void 0;
const utils_1 = require("../../../utils");
const errors_1 = require("../../../utils/errors");
/**
* Obtains information about a specific epoch.
* @see {@link https://docs.blockfrost.io/#tag/Cardano-Epochs/paths/~1epochs~1%7Bnumber%7D/get | API docs for Specific epoch}
*
* @param number - Number of the epoch
* @returns Information about a specific epoch.
*
*/
async function epochs(number) {
try {
const res = await this.instance(`epochs/${number}`);
return res.body;
}
catch (error) {
throw (0, errors_1.handleError)(error);
}
}
exports.epochs = epochs;
/**
* Obtains the information about the latest, therefore current, epoch.
* @see {@link https://docs.blockfrost.io/#tag/Cardano-Epochs/paths/~1epochs~1latest/get | API docs for Latest epoch}
*
* @returns Information about the current epoch.
*
*/
async function epochsLatest() {
try {
const res = await this.instance(`epochs/latest`);
return res.body;
}
catch (error) {
throw (0, errors_1.handleError)(error);
}
}
exports.epochsLatest = epochsLatest;
/**
* Obtains a list of epochs following a specific epoch.
* @see {@link https://docs.blockfrost.io/#tag/Cardano-Epochs/paths/~1epochs~1%7Bnumber%7D~1next/get | API docs for Listing of next epochs}
*
* @param number - Number of the epoch
* @param pagination - Optional, Pagination options
* @returns List of epochs following a specific epoch.
*
*/
async function epochsNext(number, pagination) {
const paginationOptions = (0, utils_1.getPaginationOptions)(pagination);
try {
const res = await this.instance(`epochs/${number}/next`, {
searchParams: {
page: paginationOptions.page,
count: paginationOptions.count,
},
});
return res.body;
}
catch (error) {
throw (0, errors_1.handleError)(error);
}
}
exports.epochsNext = epochsNext;
/**
* Obtains a list of epochs preceding a specific epoch.
* @see {@link https://docs.blockfrost.io/#tag/Cardano-Epochs/paths/~1epochs~1%7Bnumber%7D~1previous/get | API docs for Listing of next epochs}
*
* @param number - Number of the epoch
* @param pagination - Optional, Pagination options
* @returns List of epochs preceding a specific epoch.
*
*/
async function epochsPrevious(number, pagination) {
const paginationOptions = (0, utils_1.getPaginationOptions)(pagination);
try {
const res = await this.instance(`epochs/${number}/previous`, {
searchParams: {
page: paginationOptions.page,
count: paginationOptions.count,
},
});
return res.body;
}
catch (error) {
throw (0, errors_1.handleError)(error);
}
}
exports.epochsPrevious = epochsPrevious;
/**
* Obtains the active stake distribution for the specified epoch.
* @see {@link https://docs.blockfrost.io/#tag/Cardano-Epochs/paths/~1epochs~1%7Bnumber%7D~1stakes/get | API docs for Stake distribution}
*
* @param number - Number of the epoch
* @param pagination - Optional, Pagination options
* @returns Active stake distribution for the specified epoch
*
*/
async function epochsStakes(number, pagination) {
const paginationOptions = (0, utils_1.getPaginationOptions)(pagination);
try {
const res = await this.instance(`epochs/${number}/stakes`, {
searchParams: {
page: paginationOptions.page,
count: paginationOptions.count,
order: paginationOptions.order,
},
});
return res.body;
}
catch (error) {
throw (0, errors_1.handleError)(error);
}
}
exports.epochsStakes = epochsStakes;
/**
* Obtains the whole active stake distribution for the specified epoch.
* @see {@link https://docs.blockfrost.io/#tag/Cardano-Epochs/paths/~1epochs~1%7Bnumber%7D~1stakes/get | API docs for Stake distribution}
* @remarks
* Variant of `epochsStakes` method for fetching all pages with built-in requests batching
*
* @param number - Number of the epoch
* @param allMethodOptions - Optional, Options for request batching
* @returns Active stake distribution for the specified epoch
*
*/
async function epochsStakesAll(number, allMethodOptions) {
return (0, utils_1.paginateMethod)(pagination => this.epochsStakes(number, pagination), allMethodOptions);
}
exports.epochsStakesAll = epochsStakesAll;
/**
* Obtains the active stake distribution for the epoch specified by stake pool.
* @see {@link https://docs.blockfrost.io/#tag/Cardano-Epochs/paths/~1epochs~1%7Bnumber%7D~1stakes/get | API docs for Stake distribution}
*
* @param number - Number of the epoch
* @param poolId - Stake pool ID to filter
* @param pagination - Optional, Pagination options
* @returns Active stake distribution for the epoch specified by stake pool
*
*/
async function epochsStakesByPoolId(number, poolId, pagination) {
const paginationOptions = (0, utils_1.getPaginationOptions)(pagination);
try {
const res = await this.instance(`epochs/${number}/stakes/${poolId}`, {
searchParams: {
page: paginationOptions.page,
count: paginationOptions.count,
order: paginationOptions.order,
},
});
return res.body;
}
catch (error) {
throw (0, errors_1.handleError)(error);
}
}
exports.epochsStakesByPoolId = epochsStakesByPoolId;
/**
* Obtains the whole active stake distribution for the epoch specified by stake pool.
* @see {@link https://docs.blockfrost.io/#tag/Cardano-Epochs/paths/~1epochs~1%7Bnumber%7D~1stakes/get | API docs for Stake distribution}
* @remarks
* Variant of `epochsStakesByPoolId` method for fetching all pages with built-in requests batching
*
* @param number - Number of the epoch
* @param poolId - Stake pool ID to filter
* @param allMethodOptions - Optional, Options for request batching
* @returns Active stake distribution for the epoch specified by stake pool
*
*/
async function epochsStakesByPoolIdAll(number, poolId, allMethodOptions) {
return (0, utils_1.paginateMethod)(pagination => this.epochsStakesByPoolId(number, poolId, pagination), allMethodOptions);
}
exports.epochsStakesByPoolIdAll = epochsStakesByPoolIdAll;
/**
* Obtains the blocks minted for the epoch specified.
* @see {@link https://docs.blockfrost.io/#tag/Cardano-Epochs/paths/~1epochs~1%7Bnumber%7D~1blocks/get | API docs for Block distribution}
*
* @param number - Number of the epoch
* @param pagination - Optional, Pagination options
* @returns Blocks minted for the epoch specified
*
*/
async function epochsBlocks(number, pagination) {
const paginationOptions = (0, utils_1.getPaginationOptions)(pagination);
try {
const res = await this.instance(`epochs/${number}/blocks`, {
searchParams: {
page: paginationOptions.page,
count: paginationOptions.count,
order: paginationOptions.order,
},
});
return res.body;
}
catch (error) {
throw (0, errors_1.handleError)(error);
}
}
exports.epochsBlocks = epochsBlocks;
/**
* Obtains the blocks minted for the epoch specified.
* @see {@link https://docs.blockfrost.io/#tag/Cardano-Epochs/paths/~1epochs~1%7Bnumber%7D~1blocks/get | API docs for Block distribution}
* @remarks
* Variant of `epochsBlocks` method for fetching all pages with built-in requests batching
*
* @param number - Number of the epoch
* @param allMethodOptions - Optional, Options for request batching
* @returns Blocks minted for the epoch specified
*
*/
async function epochsBlocksAll(number, allMethodOptions) {
return (0, utils_1.paginateMethod)(pagination => this.epochsBlocks(number, pagination), allMethodOptions);
}
exports.epochsBlocksAll = epochsBlocksAll;
/**
* Obtains the blocks minted for the epoch specified by stake pool.
* @see {@link https://docs.blockfrost.io/#tag/Cardano-Epochs/paths/~1epochs~1%7Bnumber%7D~1blocks~1%7Bpool_id%7D/get | API docs for Block distribution by pool}
*
* @param number - Number of the epoch
* @param poolId - Stake pool ID to filter
* @param pagination - Optional, Pagination options
* @returns Blocks minted for the epoch specified by stake pool
*
*/
async function epochsBlocksByPoolId(number, poolId, pagination) {
const paginationOptions = (0, utils_1.getPaginationOptions)(pagination);
try {
const res = await this.instance(`epochs/${number}/blocks/${poolId}`, {
searchParams: {
page: paginationOptions.page,
count: paginationOptions.count,
order: paginationOptions.order,
},
});
return res.body;
}
catch (error) {
throw (0, errors_1.handleError)(error);
}
}
exports.epochsBlocksByPoolId = epochsBlocksByPoolId;
/**
* Obtains the blocks minted for the epoch specified by stake pool.
* @see {@link https://docs.blockfrost.io/#tag/Cardano-Epochs/paths/~1epochs~1%7Bnumber%7D~1blocks~1%7Bpool_id%7D/get | API docs for Block distribution by pool}
* @remarks
* Variant of `epochsBlocksByPoolId` method for fetching all pages with built-in requests batching
*
* @param number - Number of the epoch
* @param poolId - Stake pool ID to filter
* @param allMethodOptions - Optional, Options for request batching
* @returns Blocks minted for the epoch specified by stake pool
*
*/
async function epochsBlocksByPoolIdAll(number, poolId, allMethodOptions) {
return (0, utils_1.paginateMethod)(pagination => this.epochsBlocksByPoolId(number, poolId, pagination), allMethodOptions);
}
exports.epochsBlocksByPoolIdAll = epochsBlocksByPoolIdAll;
/**
* Obtains the protocol parameters for the epoch specified.
* @see {@link https://docs.blockfrost.io/#tag/Cardano-Epochs/paths/~1epochs~1%7Bnumber%7D~1parameters/get | API docs for Protocol Parameters}
*
* @param number - Number of the epoch
* @returns Protocol parameters for the epoch specified
*
*/
async function epochsParameters(number) {
try {
const res = await this.instance(`epochs/${number}/parameters`);
return res.body;
}
catch (error) {
throw (0, errors_1.handleError)(error);
}
}
exports.epochsParameters = epochsParameters;
/**
* Obtains the protocol parameters for the latest epoch.
* @see {@link https://docs.blockfrost.io/#tag/Cardano-Epochs/paths/~1epochs~1latest~1parameters/get | API docs for Latest epoch protocol parameters}
*
* @returns Protocol parameters for the latest epoch
*
*/
async function epochsLatestParameters() {
try {
const res = await this.instance(`epochs/latest/parameters`);
return res.body;
}
catch (error) {
throw (0, errors_1.handleError)(error);
}
}
exports.epochsLatestParameters = epochsLatestParameters;