Skip to content

Commit

Permalink
Merge pull request #43 from blockfrost/block-txs-all
Browse files Browse the repository at this point in the history
Blocks txs all
  • Loading branch information
mmahut authored May 21, 2021
2 parents 6e78853 + ef3b0c5 commit 4cf29a0
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 1 deletion.
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).

## [0.3.0] - 2021-05-21

### Added

- blocksTxsAll endpoint

## [0.2.6] - 2021-05-20

### Fixed
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": "0.2.6",
"version": "0.3.0",
"description": "A JavaScript/TypeScript SDK for interacting with the https://blockfrost.io API",
"files": [
"lib/**/*.js",
Expand Down
41 changes: 41 additions & 0 deletions src/endpoints/blocks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,44 @@ export async function blocksTxs(
});
});
}

export async function blocksTxsAll(
this: BlockFrostAPI,
hashOrNumber: string | number,
order = DEFAULT_ORDER,
batchSize = 10,
): Promise<components['schemas']['block_content_txs']> {
let page = 1;
const res: components['schemas']['block_content_txs'] = [];
let shouldRun = true;
const promisesBundle: Promise<
components['schemas']['block_content_txs']
>[] = [];

while (shouldRun) {
for (let i = 0; i < batchSize; i++) {
const promise = this.blocksTxs(
hashOrNumber,
page,
DEFAULT_PAGINATION_PAGE_ITEMS_COUNT,
order,
);
promisesBundle.push(promise);
page++;
}

const result = await Promise.all(promisesBundle).then(values => {
values.map(batch => {
if (batch.length < DEFAULT_PAGINATION_PAGE_ITEMS_COUNT) {
shouldRun = false;
}
});

return values.flat();
});

if (!shouldRun) return result;
}

return res;
}
10 changes: 10 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
blocksNext,
blocksPrevious,
blocksTxs,
blocksTxsAll,
} from './endpoints/blocks';

import {
Expand Down Expand Up @@ -319,6 +320,15 @@ class BlockFrostAPI {
*/
blocksTxs = blocksTxs;

/**
* blocksTxsAll
*
* @param blocksTxsAll
* @returns xxx
*
*/
blocksTxsAll = blocksTxsAll;

/**
* epochs
*
Expand Down

0 comments on commit 4cf29a0

Please sign in to comment.