/*
* 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 {
BlockIdentifier,
BlockIdentifier$inboundSchema,
BlockIdentifier$Outbound,
BlockIdentifier$outboundSchema,
} from "./blockidentifier.js";
import { SDKValidationError } from "./errors/sdkvalidationerror.js";
import {
Transaction,
Transaction$inboundSchema,
Transaction$Outbound,
Transaction$outboundSchema,
} from "./transaction.js";
export type BlockMetadata = {};
/**
* Blocks contain an array of Transactions that occurred at a particular BlockIdentifier. A hard requirement for blocks returned by Rosetta implementations is that they MUST be _inalterable_: once a client has requested and received a block identified by a specific BlockIndentifier, all future calls for that same BlockIdentifier must return the same block contents.
*/
export type Block = {
/**
* The block_identifier uniquely identifies a block in a particular network.
*/
blockIdentifier: BlockIdentifier;
/**
* The block_identifier uniquely identifies a block in a particular network.
*/
parentBlockIdentifier: BlockIdentifier;
/**
* The timestamp of the block in milliseconds since the Unix Epoch. The timestamp is stored in milliseconds because some blockchains produce blocks more often than once a second.
*/
timestamp: number;
transactions: Array<Transaction>;
metadata?: BlockMetadata | undefined;
};
/** @internal */
export const BlockMetadata$inboundSchema: z.ZodType<
BlockMetadata,
z.ZodTypeDef,
unknown
> = z.object({});
/** @internal */
export type BlockMetadata$Outbound = {};
/** @internal */
export const BlockMetadata$outboundSchema: z.ZodType<
BlockMetadata$Outbound,
z.ZodTypeDef,
BlockMetadata
> = z.object({});
/**
* @internal
* @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
*/
export namespace BlockMetadata$ {
/** @deprecated use `BlockMetadata$inboundSchema` instead. */
export const inboundSchema = BlockMetadata$inboundSchema;
/** @deprecated use `BlockMetadata$outboundSchema` instead. */
export const outboundSchema = BlockMetadata$outboundSchema;
/** @deprecated use `BlockMetadata$Outbound` instead. */
export type Outbound = BlockMetadata$Outbound;
}
export function blockMetadataToJSON(blockMetadata: BlockMetadata): string {
return JSON.stringify(BlockMetadata$outboundSchema.parse(blockMetadata));
}
export function blockMetadataFromJSON(
jsonString: string,
): SafeParseResult<BlockMetadata, SDKValidationError> {
return safeParse(
jsonString,
(x) => BlockMetadata$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'BlockMetadata' from JSON`,
);
}
/** @internal */
export const Block$inboundSchema: z.ZodType<Block, z.ZodTypeDef, unknown> = z
.object({
block_identifier: BlockIdentifier$inboundSchema,
parent_block_identifier: BlockIdentifier$inboundSchema,
timestamp: z.number().int(),
transactions: z.array(Transaction$inboundSchema),
metadata: z.lazy(() => BlockMetadata$inboundSchema).optional(),
}).transform((v) => {
return remap$(v, {
"block_identifier": "blockIdentifier",
"parent_block_identifier": "parentBlockIdentifier",
});
});
/** @internal */
export type Block$Outbound = {
block_identifier: BlockIdentifier$Outbound;
parent_block_identifier: BlockIdentifier$Outbound;
timestamp: number;
transactions: Array<Transaction$Outbound>;
metadata?: BlockMetadata$Outbound | undefined;
};
/** @internal */
export const Block$outboundSchema: z.ZodType<
Block$Outbound,
z.ZodTypeDef,
Block
> = z.object({
blockIdentifier: BlockIdentifier$outboundSchema,
parentBlockIdentifier: BlockIdentifier$outboundSchema,
timestamp: z.number().int(),
transactions: z.array(Transaction$outboundSchema),
metadata: z.lazy(() => BlockMetadata$outboundSchema).optional(),
}).transform((v) => {
return remap$(v, {
blockIdentifier: "block_identifier",
parentBlockIdentifier: "parent_block_identifier",
});
});
/**
* @internal
* @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
*/
export namespace Block$ {
/** @deprecated use `Block$inboundSchema` instead. */
export const inboundSchema = Block$inboundSchema;
/** @deprecated use `Block$outboundSchema` instead. */
export const outboundSchema = Block$outboundSchema;
/** @deprecated use `Block$Outbound` instead. */
export type Outbound = Block$Outbound;
}
export function blockToJSON(block: Block): string {
return JSON.stringify(Block$outboundSchema.parse(block));
}
export function blockFromJSON(
jsonString: string,
): SafeParseResult<Block, SDKValidationError> {
return safeParse(
jsonString,
(x) => Block$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'Block' from JSON`,
);
}