/** * 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, getStructDecoder, getStructEncoder, getU32Decoder, getU32Encoder, getU64Decoder, getU64Encoder, getU8Decoder, getU8Encoder, transformEncoder, type Account, type Address, type EncodedAccount, type FetchAccountConfig, type FetchAccountsConfig, type FixedSizeCodec, type FixedSizeDecoder, type FixedSizeEncoder, type MaybeAccount, type MaybeEncodedAccount, type ReadonlyUint8Array, } from '@solana/kit'; import { findGarrisonReservationPda, GarrisonReservationSeeds } from '../pdas'; export const GARRISON_RESERVATION_DISCRIMINATOR = new Uint8Array([ 80, 237, 110, 51, 17, 63, 137, 44, ]); export function getGarrisonReservationDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( GARRISON_RESERVATION_DISCRIMINATOR, ); } export type GarrisonReservation = { discriminator: ReadonlyUint8Array; version: number; bump: number; starbasePlayer: Address; starbaseSeqId: bigint; committedCrew: number; }; export type GarrisonReservationArgs = { version: number; bump: number; starbasePlayer: Address; starbaseSeqId: number | bigint; committedCrew: number; }; /** Gets the encoder for {@link GarrisonReservationArgs} account data. */ export function getGarrisonReservationEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([ ['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['version', getU8Encoder()], ['bump', getU8Encoder()], ['starbasePlayer', getAddressEncoder()], ['starbaseSeqId', getU64Encoder()], ['committedCrew', getU32Encoder()], ]), (value) => ({ ...value, discriminator: GARRISON_RESERVATION_DISCRIMINATOR, }), ); } /** Gets the decoder for {@link GarrisonReservation} account data. */ export function getGarrisonReservationDecoder(): FixedSizeDecoder { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['version', getU8Decoder()], ['bump', getU8Decoder()], ['starbasePlayer', getAddressDecoder()], ['starbaseSeqId', getU64Decoder()], ['committedCrew', getU32Decoder()], ]); } /** Gets the codec for {@link GarrisonReservation} account data. */ export function getGarrisonReservationCodec(): FixedSizeCodec< GarrisonReservationArgs, GarrisonReservation > { return combineCodec( getGarrisonReservationEncoder(), getGarrisonReservationDecoder(), ); } export function decodeGarrisonReservation( encodedAccount: EncodedAccount, ): Account; export function decodeGarrisonReservation( encodedAccount: MaybeEncodedAccount, ): MaybeAccount; export function decodeGarrisonReservation( encodedAccount: EncodedAccount | MaybeEncodedAccount, ): | Account | MaybeAccount { return decodeAccount( encodedAccount as MaybeEncodedAccount, getGarrisonReservationDecoder(), ); } export async function fetchGarrisonReservation< TAddress extends string = string, >( rpc: Parameters[0], address: Address, config?: FetchAccountConfig, ): Promise> { const maybeAccount = await fetchMaybeGarrisonReservation( rpc, address, config, ); assertAccountExists(maybeAccount); return maybeAccount; } export async function fetchMaybeGarrisonReservation< TAddress extends string = string, >( rpc: Parameters[0], address: Address, config?: FetchAccountConfig, ): Promise> { const maybeAccount = await fetchEncodedAccount(rpc, address, config); return decodeGarrisonReservation(maybeAccount); } export async function fetchAllGarrisonReservation( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig, ): Promise[]> { const maybeAccounts = await fetchAllMaybeGarrisonReservation( rpc, addresses, config, ); assertAccountsExist(maybeAccounts); return maybeAccounts; } export async function fetchAllMaybeGarrisonReservation( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig, ): Promise[]> { const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); return maybeAccounts.map((maybeAccount) => decodeGarrisonReservation(maybeAccount), ); } export async function fetchGarrisonReservationFromSeeds( rpc: Parameters[0], seeds: GarrisonReservationSeeds, config: FetchAccountConfig & { programAddress?: Address } = {}, ): Promise> { const maybeAccount = await fetchMaybeGarrisonReservationFromSeeds( rpc, seeds, config, ); assertAccountExists(maybeAccount); return maybeAccount; } export async function fetchMaybeGarrisonReservationFromSeeds( rpc: Parameters[0], seeds: GarrisonReservationSeeds, config: FetchAccountConfig & { programAddress?: Address } = {}, ): Promise> { const { programAddress, ...fetchConfig } = config; const [address] = await findGarrisonReservationPda(seeds, { programAddress }); return await fetchMaybeGarrisonReservation(rpc, address, fetchConfig); }