import {z} from 'zod' export type GetApiApiSubnetNeuronRegistrationV1Args = {netuid?: number | undefined, uid?: number | undefined, hotkey?: string | undefined, coldkey?: string | undefined, block_number?: number | undefined, block_start?: number | undefined, block_end?: number | undefined, timestamp_start?: number | undefined, timestamp_end?: number | undefined, page?: number | undefined, limit?: number | undefined, order?: ('block_number_asc' | 'block_number_desc' | 'timestamp_asc' | 'timestamp_desc' | 'registration_cost_asc' | 'registration_cost_desc') | undefined}; export type GetApiApiSubnetNeuronRegistrationV1Options = {baseUrl?: string | undefined, sec0?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiSubnetNeuronRegistrationV1Response = z.object({pagination: z.object({current_page: z.number().int().optional(), per_page: z.number().int().optional(), total_items: z.number().int().optional(), total_pages: z.number().int().optional(), next_page: z.number().int().optional(), prev_page: z.unknown()}).optional(), data: z.array(z.object({block_number: z.number().int().optional(), timestamp: z.string().optional(), netuid: z.number().int().optional(), uid: z.number().int().optional(), hotkey: z.object({ss58: z.string().optional(), hex: z.string().optional()}).optional(), coldkey: z.object({ss58: z.string().optional(), hex: z.string().optional()}).optional(), registration_cost: 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 }; /** * Get Neuron Registrations * * GET /api/subnet/neuron/registration/v1 */ export const getApiApiSubnetNeuronRegistrationV1 = async (args: GetApiApiSubnetNeuronRegistrationV1Args, options?: GetApiApiSubnetNeuronRegistrationV1Options) => { const {baseUrl = "https://api.taostats.io", fetch: fetchFn = fetch, sec0} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.netuid != null) query.append("netuid", String(args.netuid)) if (args.uid != null) query.append("uid", String(args.uid)) if (args.hotkey != null) query.append("hotkey", String(args.hotkey)) if (args.coldkey != null) query.append("coldkey", String(args.coldkey)) if (args.block_number != null) query.append("block_number", String(args.block_number)) if (args.block_start != null) query.append("block_start", String(args.block_start)) if (args.block_end != null) query.append("block_end", String(args.block_end)) if (args.timestamp_start != null) query.append("timestamp_start", String(args.timestamp_start)) if (args.timestamp_end != null) query.append("timestamp_end", String(args.timestamp_end)) if (args.page != null) query.append("page", String(args.page)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.order != null) query.append("order", String(args.order)) if (sec0 !== undefined) headers.set("Authorization", sec0) const url = `${baseUrl.replace(/\/+$/, '')}/api/subnet/neuron/registration/v1${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(getApiApiSubnetNeuronRegistrationV1Response, await res.json()) };