/*
* 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";
/**
* The operation_identifier uniquely identifies an operation within a transaction.
*/
export type OperationIdentifier = {
/**
* The operation index is used to ensure each operation has a unique identifier within a transaction. This index is only relative to the transaction and NOT GLOBAL. The operations in each transaction should start from index 0. To clarify, there may not be any notion of an operation index in the blockchain being described.
*/
index: number;
/**
* Some blockchains specify an operation index that is essential for client use. For example, Bitcoin uses a network_index to identify which UTXO was used in a transaction. network_index should not be populated if there is no notion of an operation index in a blockchain (typically most account-based blockchains).
*/
networkIndex?: number | undefined;
};
/** @internal */
export const OperationIdentifier$inboundSchema: z.ZodType<
OperationIdentifier,
z.ZodTypeDef,
unknown
> = z.object({
index: z.number().int(),
network_index: z.number().int().optional(),
}).transform((v) => {
return remap$(v, {
"network_index": "networkIndex",
});
});
/** @internal */
export type OperationIdentifier$Outbound = {
index: number;
network_index?: number | undefined;
};
/** @internal */
export const OperationIdentifier$outboundSchema: z.ZodType<
OperationIdentifier$Outbound,
z.ZodTypeDef,
OperationIdentifier
> = z.object({
index: z.number().int(),
networkIndex: z.number().int().optional(),
}).transform((v) => {
return remap$(v, {
networkIndex: "network_index",
});
});
/**
* @internal
* @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
*/
export namespace OperationIdentifier$ {
/** @deprecated use `OperationIdentifier$inboundSchema` instead. */
export const inboundSchema = OperationIdentifier$inboundSchema;
/** @deprecated use `OperationIdentifier$outboundSchema` instead. */
export const outboundSchema = OperationIdentifier$outboundSchema;
/** @deprecated use `OperationIdentifier$Outbound` instead. */
export type Outbound = OperationIdentifier$Outbound;
}
export function operationIdentifierToJSON(
operationIdentifier: OperationIdentifier,
): string {
return JSON.stringify(
OperationIdentifier$outboundSchema.parse(operationIdentifier),
);
}
export function operationIdentifierFromJSON(
jsonString: string,
): SafeParseResult<OperationIdentifier, SDKValidationError> {
return safeParse(
jsonString,
(x) => OperationIdentifier$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'OperationIdentifier' from JSON`,
);
}