import {z} from 'zod' export type GetApiApiV1CelestiaL2BatchMetadataArgs = {height?: unknown | undefined, namespace?: string | undefined, commitment?: string | undefined}; export type GetApiApiV1CelestiaL2BatchMetadataOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const v1CelestiaBlobId = z.object({height: z.string().optional(), namespace: z.string().optional(), commitment: z.string().optional()}); export const v1CelestiaL2BatchMetadata = z.object({l2ChainId: z.number().int().optional(), l2BatchId: z.string().optional(), l2StartBlock: z.string().optional(), l2EndBlock: z.string().optional(), l2BatchTxCount: z.number().int().optional(), l2BlockscoutUrl: z.string().optional(), l1TxHash: z.string().optional(), l1TxTimestamp: z.string().optional(), l1ChainId: z.number().int().optional(), relatedBlobs: z.array(v1CelestiaBlobId).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 }; /** * **Deprecation Notice:** Per instance endpoints will be deprecated soon in favor of PRO API endpoints. Please see the [PRO API reference page](https://docs.blockscout.com/devs/pro-api-responses-and-routes) for information. * * GET /api/v1/celestia/l2BatchMetadata * * Also accepts auth: apiKeyAuth */ export const getApiApiV1CelestiaL2BatchMetadata = async (args: GetApiApiV1CelestiaL2BatchMetadataArgs, options?: GetApiApiV1CelestiaL2BatchMetadataOptions) => { const {baseUrl = "https://api.blockscout.com", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.height != null) query.append("height", String(args.height)) if (args.namespace != null) query.append("namespace", String(args.namespace)) if (args.commitment != null) query.append("commitment", String(args.commitment)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/celestia/l2BatchMetadata${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(v1CelestiaL2BatchMetadata, await res.json()) };