UNPKG

@yoroi/api

Version:
31 lines (30 loc) 945 B
"use strict"; import { createTypeGuardFromSchema, fetcher } from '@yoroi/common'; import { z } from 'zod'; export const getBestBlock = (baseUrl, request = 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); }); }; export const parseBestBlock = data => { return isBestBlock(data) ? data : undefined; }; const BestBlockSchema = z.object({ epoch: z.number(), slot: z.number(), globalSlot: z.number(), hash: z.string(), height: z.number() }); export const isBestBlock = createTypeGuardFromSchema(BestBlockSchema); //# sourceMappingURL=best-block.js.map