diff --git a/CHANGELOG.MD b/CHANGELOG.MD index dad4de0e..3c1a58c5 100644 --- a/CHANGELOG.MD +++ b/CHANGELOG.MD @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - added the `gotOptions` property to the `BlockFrostAPI` class. This property can be passed during the initialization of the `BlockFrostAPI` object. For more details, refer to the [Got Options documentation](https://github.com/sindresorhus/got/blob/main/documentation/2-options.md). - `txsRequiredSigners` for retrieving required signers (extra transaction witnesses) +- `networkEras` method for querying [blockchain eras](https://docs.blockfrost.io/#tag/Cardano-Network/paths/~1network~1eras/get) ## [5.5.0] - 2023-12-20 diff --git a/src/BlockFrostAPI.ts b/src/BlockFrostAPI.ts index 55cbd45d..846784ea 100644 --- a/src/BlockFrostAPI.ts +++ b/src/BlockFrostAPI.ts @@ -145,7 +145,7 @@ import { nutlinkTickersAll, } from './endpoints/api/nutlink'; -import { network } from './endpoints/api/network'; +import { network, networkEras } from './endpoints/api/network'; import { utilsTxsEvaluate, utilsTxsEvaluateUtxos, @@ -334,6 +334,7 @@ class BlockFrostAPI { txSubmit = txSubmit; network = network; + networkEras = networkEras; utilsTxsEvaluate = utilsTxsEvaluate; utilsTxsEvaluateUtxos = utilsTxsEvaluateUtxos; diff --git a/src/endpoints/api/network/index.ts b/src/endpoints/api/network/index.ts index 5e8d2749..829be09f 100644 --- a/src/endpoints/api/network/index.ts +++ b/src/endpoints/api/network/index.ts @@ -20,3 +20,24 @@ export async function network( throw handleError(error); } } + +/** + * Returns start and end of each era along with parameters that can vary between hard forks. + * @see {@link https://docs.blockfrost.io/#tag/Cardano-Network/paths/~1network~1eras/get | API docs for Network information} + * + * @returns List of blockchain eras. + * + */ +export async function networkEras( + this: BlockFrostAPI, +): Promise { + try { + const res = + await this.instance( + `network/eras`, + ); + return res.body; + } catch (error) { + throw handleError(error); + } +} diff --git a/test/fixtures/blockfrost.ts b/test/fixtures/blockfrost.ts index c3bcdfb7..7cc7b21a 100644 --- a/test/fixtures/blockfrost.ts +++ b/test/fixtures/blockfrost.ts @@ -23,6 +23,42 @@ export default { active: '25197315592272395', }, }, + networkEras: [ + { + start: { + time: 0, + slot: 0, + epoch: 0, + }, + end: { + time: 0, + slot: 0, + epoch: 0, + }, + parameters: { + epoch_length: 4320, + slot_length: 20, + safe_zone: 864, + }, + }, + { + start: { + time: 0, + slot: 0, + epoch: 0, + }, + end: { + time: 0, + slot: 0, + epoch: 0, + }, + parameters: { + epoch_length: 86400, + slot_length: 1, + safe_zone: 25920, + }, + }, + ], metrics: [{ a: 'a' }], metricsEndpoints: [{ a: 'a' }], ledger: { diff --git a/test/fixtures/endpoints.ts b/test/fixtures/endpoints.ts index 37b7e832..cfbbc565 100644 --- a/test/fixtures/endpoints.ts +++ b/test/fixtures/endpoints.ts @@ -27,6 +27,12 @@ export default [ endpointMock: mocks.network, response: mocks.network, }, + { + command: (SDK: BlockFrostAPI) => SDK.networkEras(), + path: mainnetUrl('/network/eras'), + endpointMock: mocks.networkEras, + response: mocks.networkEras, + }, { command: (SDK: BlockFrostAPI) => SDK.metrics(), path: mainnetUrl('/metrics'),