import {z} from 'zod' export type GetApiCosmosSlashingV1beta1SigningInfosConsAddressArgs = {cons_address: string}; export type GetApiCosmosSlashingV1beta1SigningInfosConsAddressOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const getApiCosmosSlashingV1beta1SigningInfosConsAddressResponse = z.object({val_signing_info: z.object({address: z.string().optional(), start_height: z.string().optional(), index_offset: z.string().optional(), jailed_until: z.string().optional(), tombstoned: z.boolean().optional(), missed_blocks_counter: z.string().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 }; /** * SigningInfo queries the signing info of given cons address * * GET /cosmos/slashing/v1beta1/signing_infos/{cons_address} */ export const getApiCosmosSlashingV1beta1SigningInfosConsAddress = async (args: GetApiCosmosSlashingV1beta1SigningInfosConsAddressArgs, options: GetApiCosmosSlashingV1beta1SigningInfosConsAddressOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/cosmos/slashing/v1beta1/signing_infos/${encodeURIComponent(String(args.cons_address))}${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(getApiCosmosSlashingV1beta1SigningInfosConsAddressResponse, await res.json()) };