UNPKG

@blockfrost/blockfrost-js

Version:

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

139 lines (138 loc) 4.5 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.scriptsRedeemers = exports.scriptsDatumCbor = exports.scriptsDatum = exports.scriptsCbor = exports.scriptsJson = exports.scripts = exports.scriptsByHash = void 0; const utils_1 = require("../../../utils"); const errors_1 = require("../../../utils/errors"); /** * Obtains information about a specific script. * @see {@link https://docs.blockfrost.io/#tag/Cardano-Scripts/paths/~1scripts~1%7Bscript_hash%7D/get | API docs for Script} * * @param scriptHash - Hash of the script * @returns Information about a specific script * */ async function scriptsByHash(scriptHash) { try { const res = await this.instance(`scripts/${scriptHash}`); return res.body; } catch (error) { throw (0, errors_1.handleError)(error); } } exports.scriptsByHash = scriptsByHash; /** * Obtains list of scripts (paginated). * @see {@link https://docs.blockfrost.io/#tag/Cardano-Scripts/paths/~1scripts/get | API docs for Scripts} * * @param pagination - Optional, Pagination options * @returns List of scripts * */ async function scripts(pagination) { const paginationOptions = (0, utils_1.getPaginationOptions)(pagination); try { const res = await this.instance(`scripts`, { searchParams: { page: paginationOptions.page, count: paginationOptions.count, order: paginationOptions.order, }, }); return res.body; } catch (error) { throw (0, errors_1.handleError)(error); } } exports.scripts = scripts; /** * Obtains JSON representation of a timelock script. * @see {@link https://docs.blockfrost.io/#tag/Cardano-Scripts/paths/~1scripts~1%7Bscript_hash%7D~1json/get | API docs for Script JSON} * * @param scriptHash - Hash of the script * @returns JSON representation of a timelock script * */ async function scriptsJson(scriptHash) { try { const res = await this.instance(`scripts/${scriptHash}/json`); return res.body; } catch (error) { throw (0, errors_1.handleError)(error); } } exports.scriptsJson = scriptsJson; /** * Obtains CBOR representation of a plutus script. * @see {@link https://docs.blockfrost.io/#tag/Cardano-Scripts/paths/~1scripts~1%7Bscript_hash%7D~1cbor/get | API docs for Script CBOR} * * @param scriptHash - Hash of the script * @returns CBOR representation of a plutus script * */ async function scriptsCbor(scriptHash) { try { const res = await this.instance(`scripts/${scriptHash}/cbor`); return res.body; } catch (error) { throw (0, errors_1.handleError)(error); } } exports.scriptsCbor = scriptsCbor; /** * Obtains JSON value of a datum by its hash. * @see {@link https://docs.blockfrost.io/#tag/Cardano-Scripts/paths/~1scripts~1datum~1%7Bdatum_hash%7D/get | API docs for Datum value} * * @param datumHash - Hash of the datum * @returns JSON value of a datum specified by its hash * */ async function scriptsDatum(datumHash) { try { const res = await this.instance(`scripts/datum/${datumHash}`); return res.body; } catch (error) { throw (0, errors_1.handleError)(error); } } exports.scriptsDatum = scriptsDatum; /** * Obtains CBOR serialized datum by its hash. * @see {@link https://docs.blockfrost.io/#tag/Cardano-Scripts/paths/~1scripts~1datum~1%7Bdatum_hash%7D~1cbor/get | API docs for Datum CBOR value} * * @param datumHash - Hash of the datum * @returns JSON value of a datum specified by its hash * */ async function scriptsDatumCbor(datumHash) { try { const res = await this.instance(`scripts/datum/${datumHash}/cbor`); return res.body; } catch (error) { throw (0, errors_1.handleError)(error); } } exports.scriptsDatumCbor = scriptsDatumCbor; /** * Obtains list of redeemers of a specific script * @see {@link https://docs.blockfrost.io/#tag/Cardano-Scripts/paths/~1scripts~1%7Bscript_hash%7D~1redeemers/get | API docs for Redeemers of a specific script} * * @param scriptHash - Hash of the script * @returns List of redeemers of a specific script * */ async function scriptsRedeemers(scriptHash) { try { const res = await this.instance(`scripts/${scriptHash}/redeemers`); return res.body; } catch (error) { throw (0, errors_1.handleError)(error); } } exports.scriptsRedeemers = scriptsRedeemers;