Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: network eras #296

Merged
merged 1 commit into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading