/** * This code was AUTOGENERATED using the Codama library. * Please DO NOT EDIT THIS FILE, instead use visitors * to add features, then rerun Codama to update it. * * @see https://github.com/codama-idl/codama */ import { addDecoderSizePrefix, addEncoderSizePrefix, combineCodec, getBooleanDecoder, getBooleanEncoder, getDiscriminatedUnionDecoder, getDiscriminatedUnionEncoder, getOptionDecoder, getOptionEncoder, getStructDecoder, getStructEncoder, getU32Decoder, getU32Encoder, getU64Decoder, getU64Encoder, getUtf8Decoder, getUtf8Encoder, type Codec, type Decoder, type Encoder, type GetDiscriminatedUnionVariant, type GetDiscriminatedUnionVariantContent, type Option, type OptionOrNullable, } from "@solana/kit"; import { getPayloadDecoder, getPayloadEncoder, type Payload, type PayloadArgs, } from "./index.ts"; /** Versioned arguments for the `validate` instruction. */ export type ValidateArgs = { __kind: "V1"; /** The name of the operation being validated (e.g. `Transfer`). */ operation: string; /** The runtime values the operation's rules will evaluate. */ payload: Payload; /** Whether stateful rules (e.g. Frequency) should be advanced and persisted. */ updateRuleState: boolean; /** Optional revision to validate against; defaults to the latest. */ ruleSetRevision: Option; }; export type ValidateArgsArgs = { __kind: "V1"; /** The name of the operation being validated (e.g. `Transfer`). */ operation: string; /** The runtime values the operation's rules will evaluate. */ payload: PayloadArgs; /** Whether stateful rules (e.g. Frequency) should be advanced and persisted. */ updateRuleState: boolean; /** Optional revision to validate against; defaults to the latest. */ ruleSetRevision: OptionOrNullable; }; export function getValidateArgsEncoder(): Encoder { return getDiscriminatedUnionEncoder([ [ "V1", getStructEncoder([ ["operation", addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder())], ["payload", getPayloadEncoder()], ["updateRuleState", getBooleanEncoder()], ["ruleSetRevision", getOptionEncoder(getU64Encoder())], ]), ], ]); } export function getValidateArgsDecoder(): Decoder { return getDiscriminatedUnionDecoder([ [ "V1", getStructDecoder([ ["operation", addDecoderSizePrefix(getUtf8Decoder(), getU32Decoder())], ["payload", getPayloadDecoder()], ["updateRuleState", getBooleanDecoder()], ["ruleSetRevision", getOptionDecoder(getU64Decoder())], ]), ], ]); } export function getValidateArgsCodec(): Codec { return combineCodec(getValidateArgsEncoder(), getValidateArgsDecoder()); } // Data Enum Helpers. export function validateArgs( kind: "V1", data: GetDiscriminatedUnionVariantContent, ): GetDiscriminatedUnionVariant; export function validateArgs( kind: K, data?: Data, ) { return Array.isArray(data) ? { __kind: kind, fields: data } : { __kind: kind, ...(data ?? {}) }; } export function isValidateArgs( kind: K, value: ValidateArgs, ): value is ValidateArgs & { __kind: K } { return value.__kind === kind; }