/** * 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, getArrayDecoder, getArrayEncoder, getBytesDecoder, getBytesEncoder, getStructDecoder, getStructEncoder, 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 { CrewRosterSeeds, findCrewRosterPda } from '../pdas'; import { getCrewRecordDecoder, getCrewRecordEncoder, getRosterSummaryDecoder, getRosterSummaryEncoder, type CrewRecord, type CrewRecordArgs, type RosterSummary, type RosterSummaryArgs, } from '../types'; export const CREW_ROSTER_DISCRIMINATOR = new Uint8Array([ 55, 198, 43, 4, 105, 28, 241, 90, ]); export function getCrewRosterDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(CREW_ROSTER_DISCRIMINATOR); } /** * The bulk crew container for one `(Character, page_index)`: a `RosterSummary` cache * header + an append-only `List`. * * `#[unsized_type(program_account, seeds = CrewRosterSeeds)]` — same form as the * marketplace `Market` (marketplace/src/state_rs:384-398) and SAGE `Character` * (character_rs:17-29). `summary` is the sized packed header (315 B); `crew` is the * unsized tail. */ export type CrewRoster = { discriminator: ReadonlyUint8Array; /** * The cached O(1) aggregate (the resurrected `total_crew` lives in * `summary.normalized_crew_total`). Packed 315-byte header. */ summary: RosterSummary; /** The crew records on this page, byte-packed (`CrewRecord: Align1` ⇒ List-able). */ crew: Array; }; export type CrewRosterArgs = { /** * The cached O(1) aggregate (the resurrected `total_crew` lives in * `summary.normalized_crew_total`). Packed 315-byte header. */ summary: RosterSummaryArgs; /** The crew records on this page, byte-packed (`CrewRecord: Align1` ⇒ List-able). */ crew: Array; }; /** Gets the encoder for {@link CrewRosterArgs} account data. */ export function getCrewRosterEncoder(): Encoder { return transformEncoder( getStructEncoder([ ['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['summary', getRosterSummaryEncoder()], ['crew', getArrayEncoder(getCrewRecordEncoder())], ]), (value) => ({ ...value, discriminator: CREW_ROSTER_DISCRIMINATOR }), ); } /** Gets the decoder for {@link CrewRoster} account data. */ export function getCrewRosterDecoder(): Decoder { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['summary', getRosterSummaryDecoder()], ['crew', getArrayDecoder(getCrewRecordDecoder())], ]); } /** Gets the codec for {@link CrewRoster} account data. */ export function getCrewRosterCodec(): Codec { return combineCodec(getCrewRosterEncoder(), getCrewRosterDecoder()); } export function decodeCrewRoster( encodedAccount: EncodedAccount, ): Account; export function decodeCrewRoster( encodedAccount: MaybeEncodedAccount, ): MaybeAccount; export function decodeCrewRoster( encodedAccount: EncodedAccount | MaybeEncodedAccount, ): Account | MaybeAccount { return decodeAccount( encodedAccount as MaybeEncodedAccount, getCrewRosterDecoder(), ); } export async function fetchCrewRoster( rpc: Parameters[0], address: Address, config?: FetchAccountConfig, ): Promise> { const maybeAccount = await fetchMaybeCrewRoster(rpc, address, config); assertAccountExists(maybeAccount); return maybeAccount; } export async function fetchMaybeCrewRoster( rpc: Parameters[0], address: Address, config?: FetchAccountConfig, ): Promise> { const maybeAccount = await fetchEncodedAccount(rpc, address, config); return decodeCrewRoster(maybeAccount); } export async function fetchAllCrewRoster( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig, ): Promise[]> { const maybeAccounts = await fetchAllMaybeCrewRoster(rpc, addresses, config); assertAccountsExist(maybeAccounts); return maybeAccounts; } export async function fetchAllMaybeCrewRoster( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig, ): Promise[]> { const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); return maybeAccounts.map((maybeAccount) => decodeCrewRoster(maybeAccount)); } export async function fetchCrewRosterFromSeeds( rpc: Parameters[0], seeds: CrewRosterSeeds, config: FetchAccountConfig & { programAddress?: Address } = {}, ): Promise> { const maybeAccount = await fetchMaybeCrewRosterFromSeeds(rpc, seeds, config); assertAccountExists(maybeAccount); return maybeAccount; } export async function fetchMaybeCrewRosterFromSeeds( rpc: Parameters[0], seeds: CrewRosterSeeds, config: FetchAccountConfig & { programAddress?: Address } = {}, ): Promise> { const { programAddress, ...fetchConfig } = config; const [address] = await findCrewRosterPda(seeds, { programAddress }); return await fetchMaybeCrewRoster(rpc, address, fetchConfig); }