import {z} from 'zod' export type GetApiBabylonCheckpointingV1RawCheckpointEpochNumArgs = {epoch_num: unknown}; export type GetApiBabylonCheckpointingV1RawCheckpointEpochNumOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const getApiBabylonCheckpointingV1RawCheckpointEpochNumResponse = z.object({raw_checkpoint: z.object({ckpt: z.object({epoch_num: z.string().optional(), block_hash_hex: z.string().optional(), bitmap: z.string().optional(), bls_multi_sig: z.string().optional()}).optional(), status: z.enum(["CKPT_STATUS_ACCUMULATING", "CKPT_STATUS_SEALED", "CKPT_STATUS_SUBMITTED", "CKPT_STATUS_CONFIRMED", "CKPT_STATUS_FINALIZED"]).optional(), status_desc: z.string().optional(), bls_aggr_pk: z.string().optional(), power_sum: z.string().optional(), lifecycle: z.array(z.object({state: z.enum(["CKPT_STATUS_ACCUMULATING", "CKPT_STATUS_SEALED", "CKPT_STATUS_SUBMITTED", "CKPT_STATUS_CONFIRMED", "CKPT_STATUS_FINALIZED"]).optional(), status_desc: z.string().optional(), block_height: z.string().optional(), block_time: z.string().optional()})).optional()}).optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * RawCheckpoint queries a checkpoints at a given epoch number. * * GET /babylon/checkpointing/v1/raw_checkpoint/{epoch_num} */ export const getApiBabylonCheckpointingV1RawCheckpointEpochNum = async (args: GetApiBabylonCheckpointingV1RawCheckpointEpochNumArgs, options: GetApiBabylonCheckpointingV1RawCheckpointEpochNumOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/babylon/checkpointing/v1/raw_checkpoint/${encodeURIComponent(String(args.epoch_num))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiBabylonCheckpointingV1RawCheckpointEpochNumResponse, await res.json()) };