Skip to content

Commit

Permalink
Merge pull request #241 from blockfrost/feat/mempool
Browse files Browse the repository at this point in the history
chore: add methods for mempool endpoint, refactor types with @blockfrost/openapi
  • Loading branch information
vladimirvolek authored Nov 21, 2022
2 parents e15125e + ca5f7a5 commit 742deb8
Show file tree
Hide file tree
Showing 57 changed files with 769 additions and 5,720 deletions.
425 changes: 364 additions & 61 deletions .pnp.cjs

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed .yarn/cache/mime-npm-3.0.0-8d911e4c06-f43f9b7bfa.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 2 additions & 0 deletions packages/blockfrost-js/CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

- `BlockfrostServerError` now includes `body` property in cases where the error was not formatted by Blockfrost Backend (eg. various nginx errors)
- `mempool`, `mempoolAll`, `mempoolTx` methods for [Blockfrost Mempool](https://docs.blockfrost.io/#tag/Cardano-Mempool)
- use `@blockfrost/openapi` for type definitions

## [5.0.0]

Expand Down
3 changes: 1 addition & 2 deletions packages/blockfrost-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"build": "yarn clean && tsc",
"type-check": "tsc --project ./tsconfig.types.json",
"clean": "rimraf lib",
"generate-types": "openapi-typescript https://raw.githubusercontent.com/blockfrost/openapi/master/openapi.yaml --output ./src/types/OpenApi.ts",
"lint": "eslint ./src/**/*.ts",
"prepublishOnly": "yarn build",
"test": "yarn run-s 'test:*'",
Expand All @@ -29,6 +28,7 @@
"docs": "yarn typedoc ./src/index.ts --theme ./node_modules/typedoc-github-wiki-theme/dist"
},
"dependencies": {
"@blockfrost/openapi": "^0.1.44",
"@emurgo/cardano-serialization-lib-nodejs": "^10.2.0",
"@emurgo/cip14-js": "3.0.1",
"bottleneck": "^2.19.5",
Expand All @@ -44,7 +44,6 @@
"jest-extended": "^3.0.2",
"make-coverage-badge": "^1.2.0",
"nock": "^13.2.9",
"openapi-typescript": "^5.4.1",
"prettier": "2.7.1",
"rimraf": "^3.0.2",
"serialize-error": "^11.0.0",
Expand Down
5 changes: 5 additions & 0 deletions packages/blockfrost-js/src/BlockFrostAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ import {
metadataTxsLabels,
} from './endpoints/api/metadata';

import { mempool, mempoolAll, mempoolTx } from './endpoints/api/mempool';

import { health, healthClock } from './endpoints/api/health';
import { metrics, metricsEndpoints } from './endpoints/api/metrics';
import {
Expand Down Expand Up @@ -703,6 +705,9 @@ class BlockFrostAPI {
*/
genesis = genesis;

mempool = mempool;
mempoolAll = mempoolAll;
mempoolTx = mempoolTx;
/**
* metadataTxsLabel
*
Expand Down
2 changes: 1 addition & 1 deletion packages/blockfrost-js/src/endpoints/api/accounts/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { components } from '@blockfrost/openapi';
import { BlockFrostAPI } from '../../../index';
import { AllMethodOptions, PaginationOptions } from '../../../types';
import { components } from '../../../types/OpenApi';
import { getPaginationOptions, paginateMethod } from '../../../utils';
import { handleError } from '../../../utils/errors';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
getPaginationOptions,
paginateMethod,
} from '../../../utils';
import { components } from '../../../types/OpenApi';
import { components } from '@blockfrost/openapi';
import { BlockFrostAPI } from '../../../index';
import { handleError } from '../../../utils/errors';
import {
Expand Down
2 changes: 1 addition & 1 deletion packages/blockfrost-js/src/endpoints/api/assets/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getPaginationOptions, paginateMethod } from '../../../utils';
import { handleError } from '../../../utils/errors';
import { components } from '../../../types/OpenApi';
import { components } from '@blockfrost/openapi';
import { AllMethodOptions, PaginationOptions } from '../../../types';
import { BlockFrostAPI } from '../../../index';

Expand Down
2 changes: 1 addition & 1 deletion packages/blockfrost-js/src/endpoints/api/blocks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
HashOrNumber,
PaginationOptions,
} from '../../../types';
import { components } from '../../../types/OpenApi';
import { components } from '@blockfrost/openapi';
import { BlockFrostAPI } from '../../../index';

export async function blocks(
Expand Down
2 changes: 1 addition & 1 deletion packages/blockfrost-js/src/endpoints/api/epochs/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getPaginationOptions, paginateMethod } from '../../../utils';
import { AllMethodOptions, PaginationOptions } from '../../../types';
import { components } from '../../../types/OpenApi';
import { components } from '@blockfrost/openapi';
import { BlockFrostAPI } from '../../../index';
import { handleError } from '../../../utils/errors';

Expand Down
2 changes: 1 addition & 1 deletion packages/blockfrost-js/src/endpoints/api/ledger/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { handleError } from '../../../utils/errors';
import { components } from '../../../types/OpenApi';
import { components } from '@blockfrost/openapi';
import { BlockFrostAPI } from '../../../index';

export function genesis(
Expand Down
55 changes: 55 additions & 0 deletions packages/blockfrost-js/src/endpoints/api/mempool/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { getPaginationOptions, paginateMethod } from '../../../utils';
import { components } from '@blockfrost/openapi';
import { BlockFrostAPI } from '../../../index';
import { AllMethodOptions, PaginationOptions } from '../../../types';
import { handleError } from '../../../utils/errors';

export async function mempool(
this: BlockFrostAPI,
pagination?: PaginationOptions,
): Promise<components['schemas']['mempool_content']> {
const paginationOptions = getPaginationOptions(pagination);

return new Promise((resolve, reject) => {
this.instance<components['schemas']['mempool_content']>(`mempool`, {
searchParams: {
page: paginationOptions.page,
count: paginationOptions.count,
order: paginationOptions.order,
},
})
.then(resp => {
resolve(resp.body);
})
.catch(err => {
reject(handleError(err));
});
});
}

export async function mempoolAll(
this: BlockFrostAPI,
allMethodOptions?: AllMethodOptions,
): Promise<components['schemas']['mempool_content']> {
return paginateMethod(
pagination => this.mempool(pagination),
allMethodOptions,
);
}

export async function mempoolTx(
this: BlockFrostAPI,
hash: string,
): Promise<components['schemas']['mempool_tx_content']> {
return new Promise((resolve, reject) => {
this.instance<components['schemas']['mempool_tx_content']>(
`mempool/${hash}`,
)
.then(resp => {
resolve(resp.body);
})
.catch(err => {
reject(handleError(err));
});
});
}
2 changes: 1 addition & 1 deletion packages/blockfrost-js/src/endpoints/api/metadata/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getPaginationOptions } from '../../../utils';
import { components } from '../../../types/OpenApi';
import { components } from '@blockfrost/openapi';
import { handleError } from '../../../utils/errors';
import { PaginationOptions } from '../../../types';
import { BlockFrostAPI } from '../../../index';
Expand Down
2 changes: 1 addition & 1 deletion packages/blockfrost-js/src/endpoints/api/metrics/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { handleError } from '../../../utils/errors';
import { components } from '../../../types/OpenApi';
import { components } from '@blockfrost/openapi';
import { BlockFrostAPI } from '../../../index';

export async function metrics(
Expand Down
2 changes: 1 addition & 1 deletion packages/blockfrost-js/src/endpoints/api/network/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { handleError } from '../../../utils/errors';
import { BlockFrostAPI } from '../../../index';
import { components } from '../../../types/OpenApi';
import { components } from '@blockfrost/openapi';

export async function network(
this: BlockFrostAPI,
Expand Down
2 changes: 1 addition & 1 deletion packages/blockfrost-js/src/endpoints/api/nutlink/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getPaginationOptions, paginateMethod } from '../../../utils';
import { handleError } from '../../../utils/errors';
import { components } from '../../../types/OpenApi';
import { components } from '@blockfrost/openapi';
import { AllMethodOptions, PaginationOptions } from '../../../types';
import { BlockFrostAPI } from '../../../index';

Expand Down
2 changes: 1 addition & 1 deletion packages/blockfrost-js/src/endpoints/api/pools/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getPaginationOptions, paginateMethod } from '../../../utils';
import { components } from '../../../types/OpenApi';
import { components } from '@blockfrost/openapi';
import { BlockFrostAPI } from '../../../index';
import { AllMethodOptions, PaginationOptions } from '../../../types';
import { handleError } from '../../../utils/errors';
Expand Down
2 changes: 1 addition & 1 deletion packages/blockfrost-js/src/endpoints/api/scripts/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getPaginationOptions } from '../../../utils';
import { components } from '../../../types/OpenApi';
import { components } from '@blockfrost/openapi';
import { handleError } from '../../../utils/errors';
import { PaginationOptions } from '../../../types';
import { BlockFrostAPI } from '../../../index';
Expand Down
2 changes: 1 addition & 1 deletion packages/blockfrost-js/src/endpoints/api/txs/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { handleError } from '../../../utils/errors';
import { components } from '../../../types/OpenApi';
import { components } from '@blockfrost/openapi';
import { BlockFrostAPI } from '../../../index';

export async function txs(
Expand Down
2 changes: 1 addition & 1 deletion packages/blockfrost-js/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { components } from './types/OpenApi';
import { components } from '@blockfrost/openapi';
import { BlockFrostAPI } from './BlockFrostAPI';
import { BlockFrostIPFS } from './BlockFrostIPFS';
import {
Expand Down
Loading

0 comments on commit 742deb8

Please sign in to comment.