UNPKG

@yoroi/api

Version:
47 lines (46 loc) 1.5 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.parseUtxoDataResponse = exports.isUtxosDataResponse = exports.getUtxoData = void 0; var _common = require("@yoroi/common"); var _zod = require("zod"); const getUtxoData = (baseUrl, request = _common.fetcher) => async ({ txHash, txIndex }) => { return request({ url: `${baseUrl}/api/txs/io/${txHash}/o/${txIndex}`, data: undefined, method: 'GET', headers: { 'Content-Type': 'application/json' } }).then(response => { const parsedResponse = parseUtxoDataResponse(response); if (!parsedResponse) return Promise.reject(new Error('Invalid utxo data response')); return Promise.resolve(parsedResponse); }); }; exports.getUtxoData = getUtxoData; const parseUtxoDataResponse = data => { return isUtxosDataResponse(data) ? data : undefined; }; exports.parseUtxoDataResponse = parseUtxoDataResponse; const AssetSchema = _zod.z.object({ assetId: _zod.z.string(), policyId: _zod.z.string(), name: _zod.z.string(), amount: _zod.z.string() }); const UtxoDataSchema = _zod.z.object({ output: _zod.z.object({ address: _zod.z.string(), amount: _zod.z.string(), dataHash: _zod.z.string().nullable(), assets: _zod.z.array(AssetSchema) }), spendingTxHash: _zod.z.string().nullable().optional() }); const isUtxosDataResponse = exports.isUtxosDataResponse = (0, _common.createTypeGuardFromSchema)(UtxoDataSchema); //# sourceMappingURL=utxo-data.js.map