Skip to content

Commit

Permalink
Merge pull request #118 from blockfrost/network
Browse files Browse the repository at this point in the history
feat: network endpoint
  • Loading branch information
1000101 committed Aug 31, 2021
2 parents 71459bf + 7e2496c commit 717c439
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.1.0]

### Added

- `network` endpoint

## [1.0.2]

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion docs/badge-coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions examples/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ async function run() {

try {
const latestBlock = await API.blocksLatest();
const networkInfo = await API.network();
const latestEpoch = await API.epochsLatest();
const health = await API.health();
const address = await API.addresses(
'addr1qxqs59lphg8g6qndelq8xwqn60ag3aeyfcp33c2kdp46a09re5df3pzwwmyq946axfcejy5n4x0y99wqpgtp2gd0k09qsgy6pz',
);

console.log('address', address);
console.log('networkInfo', networkInfo);
console.log('latestEpoch', latestEpoch);
console.log('latestBlock', latestBlock);
console.log('health', health);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@blockfrost/blockfrost-js",
"version": "1.0.2",
"version": "1.1.0",
"description": "A JavaScript/TypeScript SDK for interacting with the https://blockfrost.io API",
"keywords": [
"blockfrost",
Expand Down
10 changes: 10 additions & 0 deletions src/BlockFrostAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ import {
nutlinkTickersAll,
} from './endpoints/api/nutlink';

import { network } from './endpoints/api/network';

import { Options, ValidatedOptions } from './types';
import join from 'url-join';
import { validateOptions } from './utils';
Expand Down Expand Up @@ -868,6 +870,14 @@ class BlockFrostAPI {
*
*/
getAccount = getAccount;

/**
* network
*
* @returns Detailed network information.
*
*/
network = network;
}

export { BlockFrostAPI };
17 changes: 17 additions & 0 deletions src/endpoints/api/network/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { handleError } from '../../../utils';
import { BlockFrostAPI } from '../../../index';
import { components } from '../../../types/OpenApi';

export async function network(
this: BlockFrostAPI,
): Promise<components['schemas']['network']> {
return new Promise((resolve, reject) => {
this.axiosInstance(`${this.apiUrl}/network`)
.then(resp => {
resolve(resp.data);
})
.catch(err => {
reject(handleError(err));
});
});
}
18 changes: 18 additions & 0 deletions test/fixtures/endpoints/network.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { BlockFrostAPI } from '../../../src';

export default [
{
command: (SDK: BlockFrostAPI) => SDK.network(),
response: {
supply: {
max: expect.any(String),
total: expect.any(String),
circulating: expect.any(String),
},
stake: {
live: expect.any(String),
active: expect.any(String),
},
},
},
] as const;

0 comments on commit 717c439

Please sign in to comment.