export type GetApiPeersListArgs = {unreachable?: boolean | undefined, closedApi?: boolean | undefined, limit?: number | undefined}; export type GetApiPeersListOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Lists known peers sorted by block height * * GET /peers/list */ export const getApiPeersList = async (args: GetApiPeersListArgs, options?: GetApiPeersListOptions) => { const {baseUrl = "https://api.tokenjay.app", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "*/*") if (args.unreachable != null) query.append("unreachable", String(args.unreachable)) if (args.closedApi != null) query.append("closedApi", String(args.closedApi)) if (args.limit != null) query.append("limit", String(args.limit)) const url = `${baseUrl.replace(/\/+$/, '')}/peers/list${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 res.blob() };