diff --git a/CHANGELOG.MD b/CHANGELOG.MD index 3c1a58c..369822d 100644 --- a/CHANGELOG.MD +++ b/CHANGELOG.MD @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - added the `gotOptions` property to the `BlockFrostAPI` class. This property can be passed during the initialization of the `BlockFrostAPI` object. For more details, refer to the [Got Options documentation](https://github.com/sindresorhus/got/blob/main/documentation/2-options.md). - `txsRequiredSigners` for retrieving required signers (extra transaction witnesses) - `networkEras` method for querying [blockchain eras](https://docs.blockfrost.io/#tag/Cardano-Network/paths/~1network~1eras/get) +- `txsCbor` for retrieving transaction CBOR ## [5.5.0] - 2023-12-20 diff --git a/src/BlockFrostAPI.ts b/src/BlockFrostAPI.ts index 846784e..7c57c61 100644 --- a/src/BlockFrostAPI.ts +++ b/src/BlockFrostAPI.ts @@ -124,6 +124,7 @@ import { txsMetadata, txsRedeemers, txsRequiredSigners, + txsCbor, txSubmit, } from './endpoints/api/txs'; import { @@ -331,6 +332,7 @@ class BlockFrostAPI { txsMetadata = txsMetadata; txsRedeemers = txsRedeemers; txsRequiredSigners = txsRequiredSigners; + txsCbor = txsCbor; txSubmit = txSubmit; network = network; diff --git a/src/endpoints/api/txs/index.ts b/src/endpoints/api/txs/index.ts index 72ec837..4c5fb1b 100644 --- a/src/endpoints/api/txs/index.ts +++ b/src/endpoints/api/txs/index.ts @@ -266,6 +266,28 @@ export async function 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 + * + */ +export async function txsCbor( + this: BlockFrostAPI, + hash: string, +): Promise { + try { + const res = await this.instance( + `txs/${hash}/cbor`, + ); + return res.body; + } catch (error) { + throw handleError(error); + } +} + /** * Submits a transaction to the network. * @see {@link https://docs.blockfrost.io/#tag/Cardano-Transactions/paths/~1tx~1submit/post | API docs for Transaction submit} diff --git a/test/fixtures/endpoints.ts b/test/fixtures/endpoints.ts index cfbbc56..07ff9d3 100644 --- a/test/fixtures/endpoints.ts +++ b/test/fixtures/endpoints.ts @@ -555,6 +555,17 @@ export default [ endpointMock: [], response: [], }, + { + command: (SDK: BlockFrostAPI) => + SDK.txsCbor( + 'e641005803337a553a03cf3c11a1819491a629bd7d0a3c39e4866a01b5dac36d', + ), + path: mainnetUrl( + '/txs/e641005803337a553a03cf3c11a1819491a629bd7d0a3c39e4866a01b5dac36d/cbor', + ), + endpointMock: { cbor: 'deadbeef' }, + response: { cbor: 'deadbeef' }, + }, { command: (SDK: BlockFrostAPI) => SDK.scripts(), path: mainnetUrl('/scripts'),