@apexfusionfoundation/blockfrost-js
Version:
A JavaScript/TypeScript SDK for interacting with the https://blockfrost.io API
153 lines (152 loc) • 5.08 kB
JavaScript
;
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) {
return new Promise((resolve, reject) => {
this.instance(`scripts/${scriptHash}`)
.then(resp => {
resolve(resp.body);
})
.catch(err => {
reject((0, errors_1.handleError)(err));
});
});
}
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);
return new Promise((resolve, reject) => {
this.instance(`scripts`, {
searchParams: {
page: paginationOptions.page,
count: paginationOptions.count,
order: paginationOptions.order,
},
})
.then(resp => {
resolve(resp.body);
})
.catch(err => {
reject((0, errors_1.handleError)(err));
});
});
}
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) {
return new Promise((resolve, reject) => {
this.instance(`scripts/${scriptHash}/json`)
.then(resp => {
resolve(resp.body);
})
.catch(err => {
reject((0, errors_1.handleError)(err));
});
});
}
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) {
return new Promise((resolve, reject) => {
this.instance(`scripts/${scriptHash}/cbor`)
.then(resp => {
resolve(resp.body);
})
.catch(err => {
reject((0, errors_1.handleError)(err));
});
});
}
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) {
return new Promise((resolve, reject) => {
this.instance(`scripts/datum/${datumHash}`)
.then(resp => {
resolve(resp.body);
})
.catch(err => {
reject((0, errors_1.handleError)(err));
});
});
}
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) {
return new Promise((resolve, reject) => {
this.instance(`scripts/datum/${datumHash}/cbor`)
.then(resp => {
resolve(resp.body);
})
.catch(err => {
reject((0, errors_1.handleError)(err));
});
});
}
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) {
return new Promise((resolve, reject) => {
this.instance(`scripts/${scriptHash}/redeemers`)
.then(resp => {
resolve(resp.body);
})
.catch(err => {
reject((0, errors_1.handleError)(err));
});
});
}
exports.scriptsRedeemers = scriptsRedeemers;