/** * 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, getI64Decoder, getI64Encoder, getStructDecoder, getStructEncoder, 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 { CelestialBodySeeds, findCelestialBodyPda } from '../pdas'; import { getCelestialBodyIdDecoder, getCelestialBodyIdEncoder, getCelestialBodyTypeDecoder, getCelestialBodyTypeEncoder, getNameDecoder, getNameEncoder, type CelestialBodyId, type CelestialBodyIdArgs, type CelestialBodyType, type CelestialBodyTypeArgs, type Name, type NameArgs, } from '../types'; export const CELESTIAL_BODY_DISCRIMINATOR = new Uint8Array([ 185, 37, 29, 122, 14, 216, 142, 109, ]); export function getCelestialBodyDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( CELESTIAL_BODY_DISCRIMINATOR, ); } /** * CelestialBody * TODO: add new fields needed for research tree */ export type CelestialBody = { discriminator: ReadonlyUint8Array; /** The data version of this account. */ version: number; id: CelestialBodyId; /** The name of this `CelestialBody` */ name: Name; game: Address; /** the StarSystem that this belongs to */ system: Address; /** The sequence id of the system in which the celestial body is placed */ systemSeqId: bigint; /** * The timestamp of the starbase this `CelestialBody` was last synced with. * Set to slot time when registered if no starbase, or the starbases's build_destroyed_timestamp if there is a starbase */ lastSyncTimestamp: bigint; celestialBodyType: CelestialBodyType; }; export type CelestialBodyArgs = { /** The data version of this account. */ version: number; id: CelestialBodyIdArgs; /** The name of this `CelestialBody` */ name: NameArgs; game: Address; /** the StarSystem that this belongs to */ system: Address; /** The sequence id of the system in which the celestial body is placed */ systemSeqId: number | bigint; /** * The timestamp of the starbase this `CelestialBody` was last synced with. * Set to slot time when registered if no starbase, or the starbases's build_destroyed_timestamp if there is a starbase */ lastSyncTimestamp: number | bigint; celestialBodyType: CelestialBodyTypeArgs; }; /** Gets the encoder for {@link CelestialBodyArgs} account data. */ export function getCelestialBodyEncoder(): Encoder { return transformEncoder( getStructEncoder([ ['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['version', getU8Encoder()], ['id', getCelestialBodyIdEncoder()], ['name', getNameEncoder()], ['game', getAddressEncoder()], ['system', getAddressEncoder()], ['systemSeqId', getU64Encoder()], ['lastSyncTimestamp', getI64Encoder()], ['celestialBodyType', getCelestialBodyTypeEncoder()], ]), (value) => ({ ...value, discriminator: CELESTIAL_BODY_DISCRIMINATOR }), ); } /** Gets the decoder for {@link CelestialBody} account data. */ export function getCelestialBodyDecoder(): Decoder { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['version', getU8Decoder()], ['id', getCelestialBodyIdDecoder()], ['name', getNameDecoder()], ['game', getAddressDecoder()], ['system', getAddressDecoder()], ['systemSeqId', getU64Decoder()], ['lastSyncTimestamp', getI64Decoder()], ['celestialBodyType', getCelestialBodyTypeDecoder()], ]); } /** Gets the codec for {@link CelestialBody} account data. */ export function getCelestialBodyCodec(): Codec< CelestialBodyArgs, CelestialBody > { return combineCodec(getCelestialBodyEncoder(), getCelestialBodyDecoder()); } export function decodeCelestialBody( encodedAccount: EncodedAccount, ): Account; export function decodeCelestialBody( encodedAccount: MaybeEncodedAccount, ): MaybeAccount; export function decodeCelestialBody( encodedAccount: EncodedAccount | MaybeEncodedAccount, ): Account | MaybeAccount { return decodeAccount( encodedAccount as MaybeEncodedAccount, getCelestialBodyDecoder(), ); } export async function fetchCelestialBody( rpc: Parameters[0], address: Address, config?: FetchAccountConfig, ): Promise> { const maybeAccount = await fetchMaybeCelestialBody(rpc, address, config); assertAccountExists(maybeAccount); return maybeAccount; } export async function fetchMaybeCelestialBody( rpc: Parameters[0], address: Address, config?: FetchAccountConfig, ): Promise> { const maybeAccount = await fetchEncodedAccount(rpc, address, config); return decodeCelestialBody(maybeAccount); } export async function fetchAllCelestialBody( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig, ): Promise[]> { const maybeAccounts = await fetchAllMaybeCelestialBody( rpc, addresses, config, ); assertAccountsExist(maybeAccounts); return maybeAccounts; } export async function fetchAllMaybeCelestialBody( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig, ): Promise[]> { const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); return maybeAccounts.map((maybeAccount) => decodeCelestialBody(maybeAccount)); } export async function fetchCelestialBodyFromSeeds( rpc: Parameters[0], seeds: CelestialBodySeeds, config: FetchAccountConfig & { programAddress?: Address } = {}, ): Promise> { const maybeAccount = await fetchMaybeCelestialBodyFromSeeds( rpc, seeds, config, ); assertAccountExists(maybeAccount); return maybeAccount; } export async function fetchMaybeCelestialBodyFromSeeds( rpc: Parameters[0], seeds: CelestialBodySeeds, config: FetchAccountConfig & { programAddress?: Address } = {}, ): Promise> { const { programAddress, ...fetchConfig } = config; const [address] = await findCelestialBodyPda(seeds, { programAddress }); return await fetchMaybeCelestialBody(rpc, address, fetchConfig); }