/** * 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 { assertAccountExists, assertAccountsExist, combineCodec, decodeAccount, fetchEncodedAccount, fetchEncodedAccounts, fixDecoderSize, fixEncoderSize, getAddressDecoder, getAddressEncoder, getBytesDecoder, getBytesEncoder, getMapDecoder, getMapEncoder, getStructDecoder, getStructEncoder, getU8Decoder, getU8Encoder, transformEncoder, type Account, type Address, type Codec, type Decoder, type EncodedAccount, type Encoder, type FetchAccountConfig, type FetchAccountsConfig, type MaybeAccount, type MaybeEncodedAccount, type ReadonlyUint8Array, } from '@solana/kit'; import { CargoDefinitionsCacheSeeds, findCargoDefinitionsCachePda, } from '../pdas'; import { getCargoIdDecoder, getCargoIdEncoder, getCargoTypeCacheDecoder, getCargoTypeCacheEncoder, type CargoId, type CargoIdArgs, type CargoTypeCache, type CargoTypeCacheArgs, } from '../types'; export const CARGO_DEFINITIONS_CACHE_DISCRIMINATOR = new Uint8Array([ 248, 247, 117, 9, 203, 30, 31, 146, ]); export function getCargoDefinitionsCacheDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( CARGO_DEFINITIONS_CACHE_DISCRIMINATOR, ); } export type CargoDefinitionsCache = { discriminator: ReadonlyUint8Array; /** The data version of this `CargoDefinitionsCache` account. */ version: number; /** The game_id that this `CargoDefinitionsCache` belongs to */ gameId: Address; /** Bump of Account PDA */ bump: number; /** A map of cargo types to their caches */ cargoTypeCache: Map; }; export type CargoDefinitionsCacheArgs = { /** The data version of this `CargoDefinitionsCache` account. */ version: number; /** The game_id that this `CargoDefinitionsCache` belongs to */ gameId: Address; /** Bump of Account PDA */ bump: number; /** A map of cargo types to their caches */ cargoTypeCache: Map; }; /** Gets the encoder for {@link CargoDefinitionsCacheArgs} account data. */ export function getCargoDefinitionsCacheEncoder(): Encoder { return transformEncoder( getStructEncoder([ ['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['version', getU8Encoder()], ['gameId', getAddressEncoder()], ['bump', getU8Encoder()], [ 'cargoTypeCache', getMapEncoder(getCargoIdEncoder(), getCargoTypeCacheEncoder()), ], ]), (value) => ({ ...value, discriminator: CARGO_DEFINITIONS_CACHE_DISCRIMINATOR, }), ); } /** Gets the decoder for {@link CargoDefinitionsCache} account data. */ export function getCargoDefinitionsCacheDecoder(): Decoder { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['version', getU8Decoder()], ['gameId', getAddressDecoder()], ['bump', getU8Decoder()], [ 'cargoTypeCache', getMapDecoder(getCargoIdDecoder(), getCargoTypeCacheDecoder()), ], ]); } /** Gets the codec for {@link CargoDefinitionsCache} account data. */ export function getCargoDefinitionsCacheCodec(): Codec< CargoDefinitionsCacheArgs, CargoDefinitionsCache > { return combineCodec( getCargoDefinitionsCacheEncoder(), getCargoDefinitionsCacheDecoder(), ); } export function decodeCargoDefinitionsCache( encodedAccount: EncodedAccount, ): Account; export function decodeCargoDefinitionsCache( encodedAccount: MaybeEncodedAccount, ): MaybeAccount; export function decodeCargoDefinitionsCache( encodedAccount: EncodedAccount | MaybeEncodedAccount, ): | Account | MaybeAccount { return decodeAccount( encodedAccount as MaybeEncodedAccount, getCargoDefinitionsCacheDecoder(), ); } export async function fetchCargoDefinitionsCache< TAddress extends string = string, >( rpc: Parameters[0], address: Address, config?: FetchAccountConfig, ): Promise> { const maybeAccount = await fetchMaybeCargoDefinitionsCache( rpc, address, config, ); assertAccountExists(maybeAccount); return maybeAccount; } export async function fetchMaybeCargoDefinitionsCache< TAddress extends string = string, >( rpc: Parameters[0], address: Address, config?: FetchAccountConfig, ): Promise> { const maybeAccount = await fetchEncodedAccount(rpc, address, config); return decodeCargoDefinitionsCache(maybeAccount); } export async function fetchAllCargoDefinitionsCache( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig, ): Promise[]> { const maybeAccounts = await fetchAllMaybeCargoDefinitionsCache( rpc, addresses, config, ); assertAccountsExist(maybeAccounts); return maybeAccounts; } export async function fetchAllMaybeCargoDefinitionsCache( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig, ): Promise[]> { const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); return maybeAccounts.map((maybeAccount) => decodeCargoDefinitionsCache(maybeAccount), ); } export async function fetchCargoDefinitionsCacheFromSeeds( rpc: Parameters[0], seeds: CargoDefinitionsCacheSeeds, config: FetchAccountConfig & { programAddress?: Address } = {}, ): Promise> { const maybeAccount = await fetchMaybeCargoDefinitionsCacheFromSeeds( rpc, seeds, config, ); assertAccountExists(maybeAccount); return maybeAccount; } export async function fetchMaybeCargoDefinitionsCacheFromSeeds( rpc: Parameters[0], seeds: CargoDefinitionsCacheSeeds, config: FetchAccountConfig & { programAddress?: Address } = {}, ): Promise> { const { programAddress, ...fetchConfig } = config; const [address] = await findCargoDefinitionsCachePda(seeds, { programAddress, }); return await fetchMaybeCargoDefinitionsCache(rpc, address, fetchConfig); }