UNPKG

@blockfrost/blockfrost-js

Version:

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

66 lines (65 loc) 2.82 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.utilsTxsEvaluateUtxos = exports.utilsTxsEvaluate = void 0; const errors_1 = require("../../../utils/errors"); const json_bigint_1 = __importDefault(require("json-bigint")); const betterJSON = (0, json_bigint_1.default)({ useNativeBigInt: true }); /** * Submits a transaction to evaluate how much execution units it requires. * @see {@link https://docs.blockfrost.io/#tag/Cardano-Utilities/paths/~1utils~1txs~1evaluate/post | API docs for Submit a transaction for execution units evaluation} * * @param transaction - Transaction bytes as Uint8Array or hex-encoded string * @returns result of Ogmios EvaluateTx @see {@link https://ogmios.dev/mini-protocols/local-tx-submission/#evaluatetx} * */ async function utilsTxsEvaluate(transaction) { let tx; if (typeof transaction === 'string') { tx = transaction; } else { tx = Buffer.from(transaction).toString('hex'); } try { const res = await this.instance.post(`utils/txs/evaluate`, { body: tx, headers: { 'Content-type': 'application/cbor' }, }); return res.body; } catch (error) { throw (0, errors_1.handleError)(error); } } exports.utilsTxsEvaluate = utilsTxsEvaluate; /** * Submits a transaction CBOR and additional utxo set to evaluate how much execution units it requires. * @see {@link https://docs.blockfrost.io//#tag/Cardano-Utilities/paths/~1utils~1txs~1evaluate~1utxos/post | API docs for Submit a transaction for execution units evaluation (additional UTXO set)} * * @param transaction - Transaction bytes as Uint8Array or hex-encoded string * @param additionalUtxoSet - Additional UTXO as an array of tuples [TxIn, TxOut]. See https://ogmios.dev/mini-protocols/local-tx-submission/#additional-utxo-set. * @returns result of Ogmios EvaluateTx @see {@link https://ogmios.dev/mini-protocols/local-tx-submission/#evaluatetx} * */ async function utilsTxsEvaluateUtxos(transaction, // base16 or base64 // Exported types aren't strict enough // additionalUtxoSet: paths['/utils/txs/evaluate/utxos']['post']['requestBody']['content']['application/json'], additionalUtxoSet) { try { const res = await this.instance.post(`utils/txs/evaluate/utxos`, { body: betterJSON.stringify({ cbor: transaction, additionalUtxoSet, }), headers: { 'Content-type': 'application/json' }, }); return res.body; } catch (error) { throw (0, errors_1.handleError)(error); } } exports.utilsTxsEvaluateUtxos = utilsTxsEvaluateUtxos;