Skip to content

Commit

Permalink
Merge pull request #296 from blockfrost/feat/network-eras
Browse files Browse the repository at this point in the history
feat: network eras
  • Loading branch information
vladimirvolek authored Aug 21, 2024
2 parents ab8f8dd + 146b5d9 commit e8a15d0
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion src/BlockFrostAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -334,6 +334,7 @@ class BlockFrostAPI {
txSubmit = txSubmit;

network = network;
networkEras = networkEras;

utilsTxsEvaluate = utilsTxsEvaluate;
utilsTxsEvaluateUtxos = utilsTxsEvaluateUtxos;
Expand Down
21 changes: 21 additions & 0 deletions src/endpoints/api/network/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<components['schemas']['network-eras']> {
try {
const res =
await this.instance<components['schemas']['network-eras']>(
`network/eras`,
);
return res.body;
} catch (error) {
throw handleError(error);
}
}
36 changes: 36 additions & 0 deletions test/fixtures/blockfrost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
6 changes: 6 additions & 0 deletions test/fixtures/endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down

0 comments on commit e8a15d0

Please sign in to comment.