import {z} from 'zod' export type GetApiCosmosUpgradeV1beta1UpgradedConsensusStateLastHeightArgs = {last_height: unknown}; export type GetApiCosmosUpgradeV1beta1UpgradedConsensusStateLastHeightOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const getApiCosmosUpgradeV1beta1UpgradedConsensusStateLastHeightResponse = z.object({upgraded_consensus_state: z.string().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 }; /** * UpgradedConsensusState queries the consensus state that will serve * as a trusted kernel for the next version of this chain. It will only be * stored at the last height of this chain. * UpgradedConsensusState RPC not supported with legacy querier * This rpc is deprecated now that IBC has its own replacement * (https://github.com/cosmos/ibc-go/blob/2c880a22e9f9cc75f62b527ca94aa75ce1106001/proto/ibc/core/client/v1/query.proto#L54) * * GET /cosmos/upgrade/v1beta1/upgraded_consensus_state/{last_height} */ export const getApiCosmosUpgradeV1beta1UpgradedConsensusStateLastHeight = async (args: GetApiCosmosUpgradeV1beta1UpgradedConsensusStateLastHeightArgs, options: GetApiCosmosUpgradeV1beta1UpgradedConsensusStateLastHeightOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/cosmos/upgrade/v1beta1/upgraded_consensus_state/${encodeURIComponent(String(args.last_height))}${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(getApiCosmosUpgradeV1beta1UpgradedConsensusStateLastHeightResponse, await res.json()) };