@apexfusionfoundation/blockfrost-js
Version:
A JavaScript/TypeScript SDK for interacting with the https://blockfrost.io API
116 lines (115 loc) • 4.62 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.mempoolByAddressAll = exports.mempoolByAddress = exports.mempoolTx = exports.mempoolAll = exports.mempool = void 0;
const utils_1 = require("../../../utils");
const errors_1 = require("../../../utils/errors");
/**
* Obtains transactions that are currently stored in Blockfrost mempool, waiting to be included in a newly minted block.
* @remarks
* Returns only transactions submitted via Blockfrost.io.
* @see {@link https://docs.blockfrost.io/#tag/Cardano-Mempool/paths/~1mempool/get | API docs for Mempool}
*
* @param pagination - Optional, Pagination options
* @returns List of transactions in Blockfrost Mempool
*
*/
async function mempool(pagination) {
const paginationOptions = (0, utils_1.getPaginationOptions)(pagination);
return new Promise((resolve, reject) => {
this.instance(`mempool`, {
searchParams: {
page: paginationOptions.page,
count: paginationOptions.count,
order: paginationOptions.order,
},
})
.then(resp => {
resolve(resp.body);
})
.catch(err => {
reject((0, errors_1.handleError)(err));
});
});
}
exports.mempool = mempool;
/**
* Obtains all transactions that are currently stored in Blockfrost mempool, waiting to be included in a newly minted block.
* @remarks
* Returns only transactions submitted via Blockfrost.io.
* @see {@link https://docs.blockfrost.io/#tag/Cardano-Mempool/paths/~1mempool/get | API docs for Mempool}
* @remarks
* Variant of `mempool` method for fetching all pages with built-in requests batching
*
* @param allMethodOptions - Optional, Options for request batching
* @returns List of transactions in Blockfrost Mempool
*
*/
async function mempoolAll(allMethodOptions) {
return (0, utils_1.paginateMethod)(pagination => this.mempool(pagination), allMethodOptions);
}
exports.mempoolAll = mempoolAll;
/**
* Obtains mempool transaction
* @see {@link https://docs.blockfrost.io/#tag/Cardano-Mempool/paths/~1mempool~1%7Bhash%7D/get | API docs for Mempool transaction}
*
* @param hash - Hash of the requested transaction
* @returns Specific mempool transaction
*
*/
async function mempoolTx(hash) {
return new Promise((resolve, reject) => {
this.instance(`mempool/${hash}`)
.then(resp => {
resolve(resp.body);
})
.catch(err => {
reject((0, errors_1.handleError)(err));
});
});
}
exports.mempoolTx = mempoolTx;
/**
* Obtains list of mempool transactions where at least one of the transaction inputs or outputs belongs to the address (paginated).
* @remarks Shows only transactions submitted via Blockfrost.io.
* @see {@link https://docs.blockfrost.io/#tag/Cardano-Mempool/paths/~1mempool~1addresses~1%7Baddress%7D/get | API docs for Mempool by address}
*
* @param address - bech32 address
* @param pagination - Optional, Pagination options
* @returns List of mempool transactions affecting the address
*
*/
async function mempoolByAddress(address, pagination) {
const paginationOptions = (0, utils_1.getPaginationOptions)(pagination);
return new Promise((resolve, reject) => {
this.instance(`mempool/addresses/${address}`, {
searchParams: {
page: paginationOptions.page,
count: paginationOptions.count,
order: paginationOptions.order,
},
})
.then(resp => {
resolve(resp.body);
})
.catch(err => {
reject((0, errors_1.handleError)(err));
});
});
}
exports.mempoolByAddress = mempoolByAddress;
/**
* Obtains list of all mempool transactions where at least one of the transaction inputs or outputs belongs to the address.
* @remarks Shows only transactions submitted via Blockfrost.io.
* @remarks
* Variant of `mempoolByAddress` method for fetching all pages with built-in requests batching
* @see {@link https://docs.blockfrost.io/#tag/Cardano-Mempool/paths/~1mempool~1addresses~1%7Baddress%7D/get | API docs for Mempool by address}
*
* @param address - bech32 address
* @param allMethodOptions - Optional, Options for request batching
* @returns List of mempool transactions affecting the address
*
*/
async function mempoolByAddressAll(address, allMethodOptions) {
return (0, utils_1.paginateMethod)(pagination => this.mempoolByAddress(address, pagination), allMethodOptions);
}
exports.mempoolByAddressAll = mempoolByAddressAll;