/*
* 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 { SDKValidationError } from "./errors/sdkvalidationerror.js";
/**
* SyncStatus is used to provide additional context about an implementation's sync status. This object is often used by implementations to indicate healthiness when block data cannot be queried until some sync phase completes or cannot be determined by comparing the timestamp of the most recent block with the current time.
*/
export type SyncStatus = {
/**
* CurrentIndex is the index of the last synced block in the current stage. This is a separate field from current_block_identifier in NetworkStatusResponse because blocks with indices up to and including the current_index may not yet be queryable by the caller. To reiterate, all indices up to and including current_block_identifier in NetworkStatusResponse must be queryable via the /block endpoint (excluding indices less than oldest_block_identifier).
*/
currentIndex?: number | undefined;
/**
* TargetIndex is the index of the block that the implementation is attempting to sync to in the current stage.
*/
targetIndex?: number | undefined;
/**
* Stage is the phase of the sync process.
*/
stage?: string | undefined;
/**
* synced is a boolean that indicates if an implementation has synced up to the most recent block. If this field is not populated, the caller should rely on a traditional tip timestamp comparison to determine if an implementation is synced. This field is particularly useful for quiescent blockchains (blocks only produced when there are pending transactions). In these blockchains, the most recent block could have a timestamp far behind the current time but the node could be healthy and at tip.
*/
synced?: boolean | undefined;
};
/** @internal */
export const SyncStatus$inboundSchema: z.ZodType<
SyncStatus,
z.ZodTypeDef,
unknown
> = z.object({
current_index: z.number().int().optional(),
target_index: z.number().int().optional(),
stage: z.string().optional(),
synced: z.boolean().optional(),
}).transform((v) => {
return remap$(v, {
"current_index": "currentIndex",
"target_index": "targetIndex",
});
});
/** @internal */
export type SyncStatus$Outbound = {
current_index?: number | undefined;
target_index?: number | undefined;
stage?: string | undefined;
synced?: boolean | undefined;
};
/** @internal */
export const SyncStatus$outboundSchema: z.ZodType<
SyncStatus$Outbound,
z.ZodTypeDef,
SyncStatus
> = z.object({
currentIndex: z.number().int().optional(),
targetIndex: z.number().int().optional(),
stage: z.string().optional(),
synced: z.boolean().optional(),
}).transform((v) => {
return remap$(v, {
currentIndex: "current_index",
targetIndex: "target_index",
});
});
/**
* @internal
* @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
*/
export namespace SyncStatus$ {
/** @deprecated use `SyncStatus$inboundSchema` instead. */
export const inboundSchema = SyncStatus$inboundSchema;
/** @deprecated use `SyncStatus$outboundSchema` instead. */
export const outboundSchema = SyncStatus$outboundSchema;
/** @deprecated use `SyncStatus$Outbound` instead. */
export type Outbound = SyncStatus$Outbound;
}
export function syncStatusToJSON(syncStatus: SyncStatus): string {
return JSON.stringify(SyncStatus$outboundSchema.parse(syncStatus));
}
export function syncStatusFromJSON(
jsonString: string,
): SafeParseResult<SyncStatus, SDKValidationError> {
return safeParse(
jsonString,
(x) => SyncStatus$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'SyncStatus' from JSON`,
);
}