@apexfusionfoundation/blockfrost-js
Version:
A JavaScript/TypeScript SDK for interacting with the https://blockfrost.io API
256 lines (255 loc) • 8.54 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.txSubmit = 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) {
return new Promise((resolve, reject) => {
this.instance(`txs/${hash}`)
.then(resp => {
resolve(resp.body);
})
.catch(err => {
reject((0, errors_1.handleError)(err));
});
});
}
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) {
return new Promise((resolve, reject) => {
this.instance(`txs/${hash}/utxos`)
.then(resp => {
resolve(resp.body);
})
.catch(err => {
reject((0, errors_1.handleError)(err));
});
});
}
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) {
return new Promise((resolve, reject) => {
this.instance(`txs/${hash}/stakes`)
.then(resp => {
resolve(resp.body);
})
.catch(err => {
reject((0, errors_1.handleError)(err));
});
});
}
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) {
return new Promise((resolve, reject) => {
this.instance(`txs/${hash}/delegations`)
.then(resp => {
resolve(resp.body);
})
.catch(err => {
reject((0, errors_1.handleError)(err));
});
});
}
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) {
return new Promise((resolve, reject) => {
this.instance(`txs/${hash}/withdrawals`)
.then(resp => {
resolve(resp.body);
})
.catch(err => {
reject((0, errors_1.handleError)(err));
});
});
}
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) {
return new Promise((resolve, reject) => {
this.instance(`txs/${hash}/mirs`)
.then(resp => {
resolve(resp.body);
})
.catch(err => {
reject((0, errors_1.handleError)(err));
});
});
}
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) {
return new Promise((resolve, reject) => {
this.instance(`txs/${hash}/pool_updates`)
.then(resp => {
resolve(resp.body);
})
.catch(err => {
reject((0, errors_1.handleError)(err));
});
});
}
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) {
return new Promise((resolve, reject) => {
this.instance(`txs/${hash}/pool_retires`)
.then(resp => {
resolve(resp.body);
})
.catch(err => {
reject((0, errors_1.handleError)(err));
});
});
}
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) {
return new Promise((resolve, reject) => {
this.instance(`txs/${hash}/metadata`)
.then(resp => {
resolve(resp.body);
})
.catch(err => {
reject((0, errors_1.handleError)(err));
});
});
}
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) {
return new Promise((resolve, reject) => {
this.instance(`txs/${hash}/metadata/cbor`)
.then(resp => {
resolve(resp.body);
})
.catch(err => {
reject((0, errors_1.handleError)(err));
});
});
}
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) {
return new Promise((resolve, reject) => {
this.instance(`txs/${hash}/redeemers`)
.then(resp => {
resolve(resp.body);
})
.catch(err => {
reject((0, errors_1.handleError)(err));
});
});
}
exports.txsRedeemers = txsRedeemers;
/**
* 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);
}
return new Promise((resolve, reject) => {
this.instance
.post(`tx/submit`, {
body: tx,
headers: { 'Content-type': 'application/cbor' },
})
.then(resp => {
resolve(resp.body);
})
.catch(err => {
reject((0, errors_1.handleError)(err));
});
});
}
exports.txSubmit = txSubmit;