/*
* 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 {
Block,
Block$inboundSchema,
Block$Outbound,
Block$outboundSchema,
} from "./block.js";
import { SDKValidationError } from "./errors/sdkvalidationerror.js";
import {
TransactionIdentifier,
TransactionIdentifier$inboundSchema,
TransactionIdentifier$Outbound,
TransactionIdentifier$outboundSchema,
} from "./transactionidentifier.js";
/**
* A BlockResponse includes a fully-populated block or a partially-populated block with a list of other transactions to fetch (other_transactions). As a result of the consensus algorithm of some blockchains, blocks can be omitted (i.e. certain block indices can be skipped). If a query for one of these omitted indices is made, the response should not include a `Block` object. It is VERY important to note that blocks MUST still form a canonical, connected chain of blocks where each block has a unique index. In other words, the `PartialBlockIdentifier` of a block after an omitted block should reference the last non-omitted block.
*/
export type BlockResponse = {
/**
* 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.
*/
block?: Block | undefined;
/**
* Some blockchains may require additional transactions to be fetched that weren't returned in the block response (ex: block only returns transaction hashes). For blockchains with a lot of transactions in each block, this can be very useful as consumers can concurrently fetch all transactions returned.
*/
otherTransactions?: Array<TransactionIdentifier> | undefined;
};
/** @internal */
export const BlockResponse$inboundSchema: z.ZodType<
BlockResponse,
z.ZodTypeDef,
unknown
> = z.object({
block: Block$inboundSchema.optional(),
other_transactions: z.array(TransactionIdentifier$inboundSchema).optional(),
}).transform((v) => {
return remap$(v, {
"other_transactions": "otherTransactions",
});
});
/** @internal */
export type BlockResponse$Outbound = {
block?: Block$Outbound | undefined;
other_transactions?: Array<TransactionIdentifier$Outbound> | undefined;
};
/** @internal */
export const BlockResponse$outboundSchema: z.ZodType<
BlockResponse$Outbound,
z.ZodTypeDef,
BlockResponse
> = z.object({
block: Block$outboundSchema.optional(),
otherTransactions: z.array(TransactionIdentifier$outboundSchema).optional(),
}).transform((v) => {
return remap$(v, {
otherTransactions: "other_transactions",
});
});
/**
* @internal
* @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
*/
export namespace BlockResponse$ {
/** @deprecated use `BlockResponse$inboundSchema` instead. */
export const inboundSchema = BlockResponse$inboundSchema;
/** @deprecated use `BlockResponse$outboundSchema` instead. */
export const outboundSchema = BlockResponse$outboundSchema;
/** @deprecated use `BlockResponse$Outbound` instead. */
export type Outbound = BlockResponse$Outbound;
}
export function blockResponseToJSON(blockResponse: BlockResponse): string {
return JSON.stringify(BlockResponse$outboundSchema.parse(blockResponse));
}
export function blockResponseFromJSON(
jsonString: string,
): SafeParseResult<BlockResponse, SDKValidationError> {
return safeParse(
jsonString,
(x) => BlockResponse$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'BlockResponse' from JSON`,
);
}