import {z} from 'zod' export type AddressHash = string; export type GetApiChainIdApiV2AddressesAddressHashParamTabsCountersArgs = {address_hash_param: AddressHash, chain_id: string}; export type GetApiChainIdApiV2AddressesAddressHashParamTabsCountersOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const addressTabsCounters = z.object({internal_transactions_count: z.number().int().optional(), logs_count: z.number().int().optional(), token_balances_count: z.number().int().optional(), token_transfers_count: z.number().int().optional(), transactions_count: z.number().int().optional(), validations_count: z.number().int().optional(), withdrawals_count: z.number().int().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 counters for address tabs * * GET /{chain_id}/api/v2/addresses/{address_hash_param}/tabs-counters * * Also accepts auth: apiKeyAuth */ export const getApiChainIdApiV2AddressesAddressHashParamTabsCounters = async (args: GetApiChainIdApiV2AddressesAddressHashParamTabsCountersArgs, options?: GetApiChainIdApiV2AddressesAddressHashParamTabsCountersOptions) => { 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 (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/${encodeURIComponent(String(args.chain_id))}/api/v2/addresses/${encodeURIComponent(String(args.address_hash_param))}/tabs-counters${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(addressTabsCounters, await res.json()) };