/** * 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, getArrayDecoder, getArrayEncoder, getBytesDecoder, getBytesEncoder, getMapDecoder, getMapEncoder, getStructDecoder, getStructEncoder, getU16Decoder, getU16Encoder, getU64Decoder, getU64Encoder, 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 { findShipDefinitionUploadPda, ShipDefinitionUploadSeeds, } from '../pdas'; import { getCargoIdDecoder, getCargoIdEncoder, getResearchTagDecoder, getResearchTagEncoder, getShipIdDecoder, getShipIdEncoder, getShipSizedDecoder, getShipSizedEncoder, getShipUploadModeDecoder, getShipUploadModeEncoder, type CargoId, type CargoIdArgs, type ResearchTag, type ResearchTagArgs, type ShipId, type ShipIdArgs, type ShipSized, type ShipSizedArgs, type ShipUploadMode, type ShipUploadModeArgs, } from '../types'; export const SHIP_DEFINITION_UPLOAD_DISCRIMINATOR = new Uint8Array([ 140, 185, 128, 12, 228, 208, 144, 176, ]); export function getShipDefinitionUploadDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( SHIP_DEFINITION_UPLOAD_DISCRIMINATOR, ); } /** * Ship-definition upload staging account. * * Used to upload a complete ship definition in chunks and apply it atomically * on commit. */ export type ShipDefinitionUpload = { discriminator: ReadonlyUint8Array; /** Data version. */ version: number; /** The game this upload belongs to. */ gameId: Address; /** The ship id being uploaded. */ shipId: ShipId; /** Whether this upload should create a new ship or update an existing one. */ mode: ShipUploadMode; /** The full sized ship data to apply on commit. */ ship: ShipSized; /** Expected total count of research requirements. */ expectedResearchLen: number; /** Expected total count of component requirements. */ expectedComponentLen: number; /** PDA bump. */ bump: number; /** Staged research requirements. */ researchRequirements: Array; /** Staged component requirements. */ componentRequirements: Map; }; export type ShipDefinitionUploadArgs = { /** Data version. */ version: number; /** The game this upload belongs to. */ gameId: Address; /** The ship id being uploaded. */ shipId: ShipIdArgs; /** Whether this upload should create a new ship or update an existing one. */ mode: ShipUploadModeArgs; /** The full sized ship data to apply on commit. */ ship: ShipSizedArgs; /** Expected total count of research requirements. */ expectedResearchLen: number; /** Expected total count of component requirements. */ expectedComponentLen: number; /** PDA bump. */ bump: number; /** Staged research requirements. */ researchRequirements: Array; /** Staged component requirements. */ componentRequirements: Map; }; /** Gets the encoder for {@link ShipDefinitionUploadArgs} account data. */ export function getShipDefinitionUploadEncoder(): Encoder { return transformEncoder( getStructEncoder([ ['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['version', getU8Encoder()], ['gameId', getAddressEncoder()], ['shipId', getShipIdEncoder()], ['mode', getShipUploadModeEncoder()], ['ship', getShipSizedEncoder()], ['expectedResearchLen', getU16Encoder()], ['expectedComponentLen', getU16Encoder()], ['bump', getU8Encoder()], ['researchRequirements', getArrayEncoder(getResearchTagEncoder())], [ 'componentRequirements', getMapEncoder(getCargoIdEncoder(), getU64Encoder()), ], ]), (value) => ({ ...value, discriminator: SHIP_DEFINITION_UPLOAD_DISCRIMINATOR, }), ); } /** Gets the decoder for {@link ShipDefinitionUpload} account data. */ export function getShipDefinitionUploadDecoder(): Decoder { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['version', getU8Decoder()], ['gameId', getAddressDecoder()], ['shipId', getShipIdDecoder()], ['mode', getShipUploadModeDecoder()], ['ship', getShipSizedDecoder()], ['expectedResearchLen', getU16Decoder()], ['expectedComponentLen', getU16Decoder()], ['bump', getU8Decoder()], ['researchRequirements', getArrayDecoder(getResearchTagDecoder())], [ 'componentRequirements', getMapDecoder(getCargoIdDecoder(), getU64Decoder()), ], ]); } /** Gets the codec for {@link ShipDefinitionUpload} account data. */ export function getShipDefinitionUploadCodec(): Codec< ShipDefinitionUploadArgs, ShipDefinitionUpload > { return combineCodec( getShipDefinitionUploadEncoder(), getShipDefinitionUploadDecoder(), ); } export function decodeShipDefinitionUpload( encodedAccount: EncodedAccount, ): Account; export function decodeShipDefinitionUpload( encodedAccount: MaybeEncodedAccount, ): MaybeAccount; export function decodeShipDefinitionUpload( encodedAccount: EncodedAccount | MaybeEncodedAccount, ): | Account | MaybeAccount { return decodeAccount( encodedAccount as MaybeEncodedAccount, getShipDefinitionUploadDecoder(), ); } export async function fetchShipDefinitionUpload< TAddress extends string = string, >( rpc: Parameters[0], address: Address, config?: FetchAccountConfig, ): Promise> { const maybeAccount = await fetchMaybeShipDefinitionUpload( rpc, address, config, ); assertAccountExists(maybeAccount); return maybeAccount; } export async function fetchMaybeShipDefinitionUpload< TAddress extends string = string, >( rpc: Parameters[0], address: Address, config?: FetchAccountConfig, ): Promise> { const maybeAccount = await fetchEncodedAccount(rpc, address, config); return decodeShipDefinitionUpload(maybeAccount); } export async function fetchAllShipDefinitionUpload( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig, ): Promise[]> { const maybeAccounts = await fetchAllMaybeShipDefinitionUpload( rpc, addresses, config, ); assertAccountsExist(maybeAccounts); return maybeAccounts; } export async function fetchAllMaybeShipDefinitionUpload( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig, ): Promise[]> { const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); return maybeAccounts.map((maybeAccount) => decodeShipDefinitionUpload(maybeAccount), ); } export async function fetchShipDefinitionUploadFromSeeds( rpc: Parameters[0], seeds: ShipDefinitionUploadSeeds, config: FetchAccountConfig & { programAddress?: Address } = {}, ): Promise> { const maybeAccount = await fetchMaybeShipDefinitionUploadFromSeeds( rpc, seeds, config, ); assertAccountExists(maybeAccount); return maybeAccount; } export async function fetchMaybeShipDefinitionUploadFromSeeds( rpc: Parameters[0], seeds: ShipDefinitionUploadSeeds, config: FetchAccountConfig & { programAddress?: Address } = {}, ): Promise> { const { programAddress, ...fetchConfig } = config; const [address] = await findShipDefinitionUploadPda(seeds, { programAddress, }); return await fetchMaybeShipDefinitionUpload(rpc, address, fetchConfig); }