UNPKG

@yoroi/api

Version:
37 lines (36 loc) 1.19 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.parseBestBlock = exports.isBestBlock = exports.getBestBlock = void 0; var _common = require("@yoroi/common"); var _zod = require("zod"); const getBestBlock = (baseUrl, request = _common.fetcher) => async () => { return request({ url: `${baseUrl}/bestblock`, data: undefined, method: 'GET', headers: { 'Content-Type': 'application/json', 'Response-Type': 'application/json' } }).then(response => { const parsedResponse = parseBestBlock(response); if (!parsedResponse) return Promise.reject(new Error('Invalid best block response')); return Promise.resolve(parsedResponse); }); }; exports.getBestBlock = getBestBlock; const parseBestBlock = data => { return isBestBlock(data) ? data : undefined; }; exports.parseBestBlock = parseBestBlock; const BestBlockSchema = _zod.z.object({ epoch: _zod.z.number(), slot: _zod.z.number(), globalSlot: _zod.z.number(), hash: _zod.z.string(), height: _zod.z.number() }); const isBestBlock = exports.isBestBlock = (0, _common.createTypeGuardFromSchema)(BestBlockSchema); //# sourceMappingURL=best-block.js.map