/*
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
*/
import * as z from "zod";
import { remap as remap$ } from "../lib/primitives.js";
import { safeParse } from "../lib/schemas.js";
import { Result as SafeParseResult } from "../types/fp.js";
import {
BlockEvent,
BlockEvent$inboundSchema,
BlockEvent$Outbound,
BlockEvent$outboundSchema,
} from "./blockevent.js";
import { SDKValidationError } from "./errors/sdkvalidationerror.js";
/**
* EventsBlocksResponse contains an ordered collection of BlockEvents and the max retrievable sequence.
*/
export type EventsBlocksResponse = {
/**
* max_sequence is the maximum available sequence number to fetch.
*/
maxSequence: number;
/**
* events is an array of BlockEvents indicating the order to add and remove blocks to maintain a canonical view of blockchain state. Lightweight clients can use this event stream to update state without implementing their own block syncing logic.
*/
events: Array<BlockEvent>;
};
/** @internal */
export const EventsBlocksResponse$inboundSchema: z.ZodType<
EventsBlocksResponse,
z.ZodTypeDef,
unknown
> = z.object({
max_sequence: z.number().int(),
events: z.array(BlockEvent$inboundSchema),
}).transform((v) => {
return remap$(v, {
"max_sequence": "maxSequence",
});
});
/** @internal */
export type EventsBlocksResponse$Outbound = {
max_sequence: number;
events: Array<BlockEvent$Outbound>;
};
/** @internal */
export const EventsBlocksResponse$outboundSchema: z.ZodType<
EventsBlocksResponse$Outbound,
z.ZodTypeDef,
EventsBlocksResponse
> = z.object({
maxSequence: z.number().int(),
events: z.array(BlockEvent$outboundSchema),
}).transform((v) => {
return remap$(v, {
maxSequence: "max_sequence",
});
});
/**
* @internal
* @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
*/
export namespace EventsBlocksResponse$ {
/** @deprecated use `EventsBlocksResponse$inboundSchema` instead. */
export const inboundSchema = EventsBlocksResponse$inboundSchema;
/** @deprecated use `EventsBlocksResponse$outboundSchema` instead. */
export const outboundSchema = EventsBlocksResponse$outboundSchema;
/** @deprecated use `EventsBlocksResponse$Outbound` instead. */
export type Outbound = EventsBlocksResponse$Outbound;
}
export function eventsBlocksResponseToJSON(
eventsBlocksResponse: EventsBlocksResponse,
): string {
return JSON.stringify(
EventsBlocksResponse$outboundSchema.parse(eventsBlocksResponse),
);
}
export function eventsBlocksResponseFromJSON(
jsonString: string,
): SafeParseResult<EventsBlocksResponse, SDKValidationError> {
return safeParse(
jsonString,
(x) => EventsBlocksResponse$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'EventsBlocksResponse' from JSON`,
);
}