/*
* 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 {
BalanceExemption,
BalanceExemption$inboundSchema,
BalanceExemption$Outbound,
BalanceExemption$outboundSchema,
} from "./balanceexemption.js";
import { Case, Case$inboundSchema, Case$outboundSchema } from "./case.js";
import {
ErrorT,
ErrorT$inboundSchema,
ErrorT$Outbound,
ErrorT$outboundSchema,
} from "./error.js";
import { SDKValidationError } from "./errors/sdkvalidationerror.js";
import {
OperationStatus,
OperationStatus$inboundSchema,
OperationStatus$Outbound,
OperationStatus$outboundSchema,
} from "./operationstatus.js";
/**
* Allow specifies supported Operation status, Operation types, and all possible error statuses. This Allow object is used by clients to validate the correctness of a Rosetta Server implementation. It is expected that these clients will error if they receive some response that contains any of the above information that is not specified here.
*/
export type Allow = {
/**
* All Operation.Status this implementation supports. Any status that is returned during parsing that is not listed here will cause client validation to error.
*/
operationStatuses: Array<OperationStatus>;
/**
* All Operation.Type this implementation supports. Any type that is returned during parsing that is not listed here will cause client validation to error.
*/
operationTypes: Array<string>;
/**
* All Errors that this implementation could return. Any error that is returned during parsing that is not listed here will cause client validation to error.
*/
errors: Array<ErrorT>;
/**
* Any Rosetta implementation that supports querying the balance of an account at any height in the past should set this to true.
*/
historicalBalanceLookup: boolean;
/**
* If populated, `timestamp_start_index` indicates the first block index where block timestamps are considered valid (i.e. all blocks less than `timestamp_start_index` could have invalid timestamps). This is useful when the genesis block (or blocks) of a network have timestamp 0. If not populated, block timestamps are assumed to be valid for all available blocks.
*/
timestampStartIndex?: number | undefined;
/**
* All methods that are supported by the /call endpoint. Communicating which parameters should be provided to /call is the responsibility of the implementer (this is en lieu of defining an entire type system and requiring the implementer to define that in Allow).
*/
callMethods: Array<string>;
/**
* BalanceExemptions is an array of BalanceExemption indicating which account balances could change without a corresponding Operation. BalanceExemptions should be used sparingly as they may introduce significant complexity for integrators that attempt to reconcile all account balance changes. If your implementation relies on any BalanceExemptions, you MUST implement historical balance lookup (the ability to query an account balance at any BlockIdentifier).
*/
balanceExemptions: Array<BalanceExemption>;
/**
* Any Rosetta implementation that can update an AccountIdentifier's unspent coins based on the contents of the mempool should populate this field as true. If false, requests to `/account/coins` that set `include_mempool` as true will be automatically rejected.
*/
mempoolCoins: boolean;
/**
* Case specifies the expected case for strings and hashes.
*/
blockHashCase?: Case | null | undefined;
/**
* Case specifies the expected case for strings and hashes.
*/
transactionHashCase?: Case | null | undefined;
};
/** @internal */
export const Allow$inboundSchema: z.ZodType<Allow, z.ZodTypeDef, unknown> = z
.object({
operation_statuses: z.array(OperationStatus$inboundSchema),
operation_types: z.array(z.string()),
errors: z.array(ErrorT$inboundSchema),
historical_balance_lookup: z.boolean(),
timestamp_start_index: z.number().int().optional(),
call_methods: z.array(z.string()),
balance_exemptions: z.array(BalanceExemption$inboundSchema),
mempool_coins: z.boolean(),
block_hash_case: z.nullable(Case$inboundSchema.default("case_sensitive")),
transaction_hash_case: z.nullable(
Case$inboundSchema.default("case_sensitive"),
),
}).transform((v) => {
return remap$(v, {
"operation_statuses": "operationStatuses",
"operation_types": "operationTypes",
"historical_balance_lookup": "historicalBalanceLookup",
"timestamp_start_index": "timestampStartIndex",
"call_methods": "callMethods",
"balance_exemptions": "balanceExemptions",
"mempool_coins": "mempoolCoins",
"block_hash_case": "blockHashCase",
"transaction_hash_case": "transactionHashCase",
});
});
/** @internal */
export type Allow$Outbound = {
operation_statuses: Array<OperationStatus$Outbound>;
operation_types: Array<string>;
errors: Array<ErrorT$Outbound>;
historical_balance_lookup: boolean;
timestamp_start_index?: number | undefined;
call_methods: Array<string>;
balance_exemptions: Array<BalanceExemption$Outbound>;
mempool_coins: boolean;
block_hash_case: string | null;
transaction_hash_case: string | null;
};
/** @internal */
export const Allow$outboundSchema: z.ZodType<
Allow$Outbound,
z.ZodTypeDef,
Allow
> = z.object({
operationStatuses: z.array(OperationStatus$outboundSchema),
operationTypes: z.array(z.string()),
errors: z.array(ErrorT$outboundSchema),
historicalBalanceLookup: z.boolean(),
timestampStartIndex: z.number().int().optional(),
callMethods: z.array(z.string()),
balanceExemptions: z.array(BalanceExemption$outboundSchema),
mempoolCoins: z.boolean(),
blockHashCase: z.nullable(Case$outboundSchema.default("case_sensitive")),
transactionHashCase: z.nullable(
Case$outboundSchema.default("case_sensitive"),
),
}).transform((v) => {
return remap$(v, {
operationStatuses: "operation_statuses",
operationTypes: "operation_types",
historicalBalanceLookup: "historical_balance_lookup",
timestampStartIndex: "timestamp_start_index",
callMethods: "call_methods",
balanceExemptions: "balance_exemptions",
mempoolCoins: "mempool_coins",
blockHashCase: "block_hash_case",
transactionHashCase: "transaction_hash_case",
});
});
/**
* @internal
* @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
*/
export namespace Allow$ {
/** @deprecated use `Allow$inboundSchema` instead. */
export const inboundSchema = Allow$inboundSchema;
/** @deprecated use `Allow$outboundSchema` instead. */
export const outboundSchema = Allow$outboundSchema;
/** @deprecated use `Allow$Outbound` instead. */
export type Outbound = Allow$Outbound;
}
export function allowToJSON(allow: Allow): string {
return JSON.stringify(Allow$outboundSchema.parse(allow));
}
export function allowFromJSON(
jsonString: string,
): SafeParseResult<Allow, SDKValidationError> {
return safeParse(
jsonString,
(x) => Allow$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'Allow' from JSON`,
);
}