/** * 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, getI64Decoder, getI64Encoder, getStructDecoder, getStructEncoder, getU32Decoder, getU32Encoder, 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 { getI8F56Decoder, getI8F56Encoder, type I8F56, type I8F56Args, } from '../../fixed/codecs'; import { getCombatRewardLegDecoder, getCombatRewardLegEncoder, getLootInfoDecoder, getLootInfoEncoder, type CombatRewardLeg, type CombatRewardLegArgs, type LootInfo, type LootInfoArgs, } from '../types'; export const LOOT_DISCRIMINATOR = new Uint8Array([ 151, 225, 207, 228, 115, 210, 64, 159, ]); export function getLootDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(LOOT_DISCRIMINATOR); } /** Represents the loot available at a location */ export type Loot = { discriminator: ReadonlyUint8Array; /** the data version of this account. */ version: number; /** the `Game` that this belongs to */ gameId: Address; /** the `Profile` that created this account */ profile: Address; /** The coordinates at which the loot is located */ coordinates: Array; /** Future-hash combat-reward commitment. Ordinary cargo-only Loot keeps status `NONE`. */ rewardStatus: number; rewardLegCount: number; rewardPad: Array; rewardConfigVersion: number; rewardCommitSlot: bigint; rewardCommittedAt: bigint; rewardLegs: Array; /** the actual lootable items */ items: { /** The total size of the unsized bytes in the list */ unsizedLen: number; /** The list of items containing offsets, and potentially extra metadata, for the start of each element in the unsized list */ offsetList: Array; /** The list of byte offsets for the start of each element in the unsized list */ unsizedList: Array; }; }; export type LootArgs = { /** the data version of this account. */ version: number; /** the `Game` that this belongs to */ gameId: Address; /** the `Profile` that created this account */ profile: Address; /** The coordinates at which the loot is located */ coordinates: Array; /** Future-hash combat-reward commitment. Ordinary cargo-only Loot keeps status `NONE`. */ rewardStatus: number; rewardLegCount: number; rewardPad: Array; rewardConfigVersion: number; rewardCommitSlot: number | bigint; rewardCommittedAt: number | bigint; rewardLegs: Array; /** the actual lootable items */ items: { /** The total size of the unsized bytes in the list */ unsizedLen: number; /** The list of items containing offsets, and potentially extra metadata, for the start of each element in the unsized list */ offsetList: Array; /** The list of byte offsets for the start of each element in the unsized list */ unsizedList: Array; }; }; /** Gets the encoder for {@link LootArgs} account data. */ export function getLootEncoder(): Encoder { return transformEncoder( getStructEncoder([ ['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['version', getU8Encoder()], ['gameId', getAddressEncoder()], ['profile', getAddressEncoder()], ['coordinates', getArrayEncoder(getI8F56Encoder(), { size: 2 })], ['rewardStatus', getU8Encoder()], ['rewardLegCount', getU8Encoder()], ['rewardPad', getArrayEncoder(getU8Encoder(), { size: 2 })], ['rewardConfigVersion', getU32Encoder()], ['rewardCommitSlot', getU64Encoder()], ['rewardCommittedAt', getI64Encoder()], ['rewardLegs', getArrayEncoder(getCombatRewardLegEncoder(), { size: 2 })], [ 'items', getStructEncoder([ ['unsizedLen', getU32Encoder()], ['offsetList', getArrayEncoder(getU32Encoder())], ['unsizedList', getArrayEncoder(getLootInfoEncoder())], ]), ], ]), (value) => ({ ...value, discriminator: LOOT_DISCRIMINATOR }), ); } /** Gets the decoder for {@link Loot} account data. */ export function getLootDecoder(): Decoder { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['version', getU8Decoder()], ['gameId', getAddressDecoder()], ['profile', getAddressDecoder()], ['coordinates', getArrayDecoder(getI8F56Decoder(), { size: 2 })], ['rewardStatus', getU8Decoder()], ['rewardLegCount', getU8Decoder()], ['rewardPad', getArrayDecoder(getU8Decoder(), { size: 2 })], ['rewardConfigVersion', getU32Decoder()], ['rewardCommitSlot', getU64Decoder()], ['rewardCommittedAt', getI64Decoder()], ['rewardLegs', getArrayDecoder(getCombatRewardLegDecoder(), { size: 2 })], [ 'items', getStructDecoder([ ['unsizedLen', getU32Decoder()], ['offsetList', getArrayDecoder(getU32Decoder())], ['unsizedList', getArrayDecoder(getLootInfoDecoder())], ]), ], ]); } /** Gets the codec for {@link Loot} account data. */ export function getLootCodec(): Codec { return combineCodec(getLootEncoder(), getLootDecoder()); } export function decodeLoot( encodedAccount: EncodedAccount, ): Account; export function decodeLoot( encodedAccount: MaybeEncodedAccount, ): MaybeAccount; export function decodeLoot( encodedAccount: EncodedAccount | MaybeEncodedAccount, ): Account | MaybeAccount { return decodeAccount( encodedAccount as MaybeEncodedAccount, getLootDecoder(), ); } export async function fetchLoot( rpc: Parameters[0], address: Address, config?: FetchAccountConfig, ): Promise> { const maybeAccount = await fetchMaybeLoot(rpc, address, config); assertAccountExists(maybeAccount); return maybeAccount; } export async function fetchMaybeLoot( rpc: Parameters[0], address: Address, config?: FetchAccountConfig, ): Promise> { const maybeAccount = await fetchEncodedAccount(rpc, address, config); return decodeLoot(maybeAccount); } export async function fetchAllLoot( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig, ): Promise[]> { const maybeAccounts = await fetchAllMaybeLoot(rpc, addresses, config); assertAccountsExist(maybeAccounts); return maybeAccounts; } export async function fetchAllMaybeLoot( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig, ): Promise[]> { const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); return maybeAccounts.map((maybeAccount) => decodeLoot(maybeAccount)); }