UNPKG

@blockfrost/blockfrost-js

Version:

A JavaScript/TypeScript SDK for interacting with the https://blockfrost.io API

267 lines (266 loc) 8.64 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.txSubmit = exports.txsCbor = exports.txsRequiredSigners = exports.txsRedeemers = exports.txsMetadataCbor = exports.txsMetadata = exports.txsPoolRetires = exports.txsPoolUpdates = exports.txsMirs = exports.txsWithdrawals = exports.txsDelegations = exports.txsStakes = exports.txsUtxos = exports.txs = void 0; const errors_1 = require("../../../utils/errors"); /** * Obtains a specific transaction * @see {@link https://docs.blockfrost.io/#tag/Cardano-Transactions/paths/~1txs~1%7Bhash%7D/get | API docs for Transaction} * * @param hash - Transaction hash * @returns Transaction * */ async function txs(hash) { try { const res = await this.instance(`txs/${hash}`); return res.body; } catch (error) { throw (0, errors_1.handleError)(error); } } exports.txs = txs; /** * Obtains the inputs and outputs of the specific transaction. * @see {@link https://docs.blockfrost.io/#tag/Cardano-Transactions/paths/~1txs~1%7Bhash%7D~1utxos/get | API docs for Transaction UTXOs} * * @param hash - Transaction hash * @returns Transaction inputs and outputs * */ async function txsUtxos(hash) { try { const res = await this.instance(`txs/${hash}/utxos`); return res.body; } catch (error) { throw (0, errors_1.handleError)(error); } } exports.txsUtxos = txsUtxos; /** * Obtains information about (de)registration of stake addresses within a transaction. * @see {@link https://docs.blockfrost.io/#tag/Cardano-Transactions/paths/~1txs~1%7Bhash%7D~1stakes/get | API docs for Transaction stake addresses certificates} * * @param hash - Transaction hash * @returns List of (de)registration certificates within the transaction * */ async function txsStakes(hash) { try { const res = await this.instance(`txs/${hash}/stakes`); return res.body; } catch (error) { throw (0, errors_1.handleError)(error); } } exports.txsStakes = txsStakes; /** * Obtains information about delegation certificates of a specific transaction. * @see {@link https://docs.blockfrost.io/#tag/Cardano-Transactions/paths/~1txs~1%7Bhash%7D~1delegations/get | API docs for Transaction stake addresses certificates} * * @param hash - Transaction hash * @returns List of delegation certificates within the transaction * */ async function txsDelegations(hash) { try { const res = await this.instance(`txs/${hash}/delegations`); return res.body; } catch (error) { throw (0, errors_1.handleError)(error); } } exports.txsDelegations = txsDelegations; /** * Obtains information about withdrawals within a specific transaction. * @see {@link https://docs.blockfrost.io/#tag/Cardano-Transactions/paths/~1txs~1%7Bhash%7D~1withdrawals/get | API docs for Transaction withdrawal} * * @param hash - Transaction hash * @returns List of withdrawals within the transaction * */ async function txsWithdrawals(hash) { try { const res = await this.instance(`txs/${hash}/withdrawals`); return res.body; } catch (error) { throw (0, errors_1.handleError)(error); } } exports.txsWithdrawals = txsWithdrawals; /** * Obtains information about Move Instantaneous Rewards (MIRs) of a specific transaction. * @see {@link https://docs.blockfrost.io/#tag/Cardano-Transactions/paths/~1txs~1%7Bhash%7D~1mirs/get | API docs for Transaction MIRs} * * @param hash - Transaction hash * @returns List of Move Instantaneous Rewards (MIRs) within the transaction * */ async function txsMirs(hash) { try { const res = await this.instance(`txs/${hash}/mirs`); return res.body; } catch (error) { throw (0, errors_1.handleError)(error); } } exports.txsMirs = txsMirs; /** * Obtains information about stake pool registration and update certificates of a specific transaction. * @see {@link https://docs.blockfrost.io/#tag/Cardano-Transactions/paths/~1txs~1%7Bhash%7D~1pool_updates/get | API docs for Transaction stake pool registration and update certificates} * * @param hash - Transaction hash * @returns List of stake pool registration and update certificates within a specific transaction * */ async function txsPoolUpdates(hash) { try { const res = await this.instance(`txs/${hash}/pool_updates`); return res.body; } catch (error) { throw (0, errors_1.handleError)(error); } } exports.txsPoolUpdates = txsPoolUpdates; /** * Obtains information about stake pool retirements within a specific transaction. * @see {@link https://docs.blockfrost.io/#tag/Cardano-Transactions/paths/~1txs~1%7Bhash%7D~1pool_retires/get | API docs for Transaction stake pool retirement certificates} * * @param hash - Transaction hash * @returns List of stake pool retirement certificates * */ async function txsPoolRetires(hash) { try { const res = await this.instance(`txs/${hash}/pool_retires`); return res.body; } catch (error) { throw (0, errors_1.handleError)(error); } } exports.txsPoolRetires = txsPoolRetires; /** * Obtains transaction metadata in JSON format. * @see {@link https://docs.blockfrost.io/#tag/Cardano-Transactions/paths/~1txs~1%7Bhash%7D~1metadata/get | API docs for Transaction metadata} * * @param hash - Transaction hash * @returns Transaction metadata in JSON * */ async function txsMetadata(hash) { try { const res = await this.instance(`txs/${hash}/metadata`); return res.body; } catch (error) { throw (0, errors_1.handleError)(error); } } exports.txsMetadata = txsMetadata; /** * Obtains transaction metadata in CBOR format. * @see {@link https://docs.blockfrost.io/#tag/Cardano-Transactions/paths/~1txs~1%7Bhash%7D~1metadata~1cbor/get | API docs for Transaction metadata in CBOR} * * @param hash - Transaction hash * @returns Transaction metadata in CBOR * */ async function txsMetadataCbor(hash) { try { const res = await this.instance(`txs/${hash}/metadata/cbor`); return res.body; } catch (error) { throw (0, errors_1.handleError)(error); } } exports.txsMetadataCbor = txsMetadataCbor; /** * Obtains transaction redeemers. * @see {@link https://docs.blockfrost.io/#tag/Cardano-Transactions/paths/~1txs~1%7Bhash%7D~1redeemers/get | API docs for Transaction redeemers} * * @param hash - Transaction hash * @returns Transaction redeemers * */ async function txsRedeemers(hash) { try { const res = await this.instance(`txs/${hash}/redeemers`); return res.body; } catch (error) { throw (0, errors_1.handleError)(error); } } exports.txsRedeemers = txsRedeemers; /** * Obtains extra transaction witnesses. * @see {@link https://docs.blockfrost.io/#tag/Cardano-Transactions/paths/~1txs~1%7Bhash%7D~required_signers/get | API docs for Transaction redeemers} * * @param hash - Transaction hash * @returns Extra transaction witnesses * */ async function txsRequiredSigners(hash) { try { const res = await this.instance(`txs/${hash}/required_signers`); return res.body; } catch (error) { throw (0, errors_1.handleError)(error); } } exports.txsRequiredSigners = txsRequiredSigners; /** * Obtains Obtain the CBOR serialized transaction. * @see {@link https://docs.blockfrost.io/#tag/Cardano-Transactions/paths/~1txs~1%7Bhash%7D~cbor/get | API docs for Transaction CBOR} * * @param hash - Transaction hash * @returns Transaction CBOR * */ async function txsCbor(hash) { try { const res = await this.instance(`txs/${hash}/cbor`); return res.body; } catch (error) { throw (0, errors_1.handleError)(error); } } exports.txsCbor = txsCbor; /** * Submits a transaction to the network. * @see {@link https://docs.blockfrost.io/#tag/Cardano-Transactions/paths/~1tx~1submit/post | API docs for Transaction submit} * * @param transaction - Transaction bytes as Uint8Array or hex-encoded string * @returns ID of the submitted transaction * */ async function txSubmit(transaction) { let tx; if (typeof transaction === 'string') { tx = Buffer.from(transaction, 'hex'); } else { tx = Buffer.from(transaction); } try { const res = await this.instance.post(`tx/submit`, { body: tx, headers: { 'Content-type': 'application/cbor' }, }); return res.body; } catch (error) { throw (0, errors_1.handleError)(error); } } exports.txSubmit = txSubmit;