import {z} from 'zod' export type DateTimeSeconds = string; export type CreateApiGetScheduledTransactionsArgs = {body: {lower_bound?: DateTimeSeconds | undefined, limit?: number | undefined, json?: boolean | undefined}}; export type CreateApiGetScheduledTransactionsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const dateTime = z.string(); export const wholeNumber = z.union([z.string(), z.number().int()]); export const namePrivileged = z.string(); export const nameBasic = z.string(); export const nameBid = z.string(); export const nameCatchAll = z.string(); export const name = z.union([namePrivileged, nameBasic, nameBid, nameCatchAll]); export const authority = z.object({actor: name, permission: name}); export const action = z.object({account: name, name: name, authorization: z.array(authority), data: z.record(z.string(), z.unknown()), hex_data: z.string()}); export const extension = z.array(z.union([z.number().int(), z.string()])); export const transaction = z.object({expiration: dateTime, ref_block_num: z.number().int(), ref_block_prefix: z.number().int(), max_net_usage_words: wholeNumber, max_cpu_usage_ms: wholeNumber, delay_sec: z.number().int(), context_free_actions: z.array(action), actions: z.array(action), transaction_extensions: z.array(extension).optional()}); export const createApiGetScheduledTransactionsResponse = z.object({transactions: z.array(transaction).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 }; /** * Retrieves scheduled transactions * * POST /get_scheduled_transactions */ export const createApiGetScheduledTransactions = async (args: CreateApiGetScheduledTransactionsArgs, options?: CreateApiGetScheduledTransactionsOptions) => { const {baseUrl = "https://wax.greymass.com/v1/chain", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/get_scheduled_transactions${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(createApiGetScheduledTransactionsResponse, await res.json()) };