/** * 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, 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 { findOutlawFlagPda, OutlawFlagSeeds } from '../pdas'; export const OUTLAW_FLAG_DISCRIMINATOR = new Uint8Array([ 19, 104, 160, 23, 98, 218, 253, 173, ]); export function getOutlawFlagDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(OUTLAW_FLAG_DISCRIMINATOR); } export type OutlawFlag = { discriminator: ReadonlyUint8Array; version: number; /** The profile this flag belongs to (cross-checked by `AccountValidate`). */ profile: Address; /** * The faction this outlaw status is AGAINST — raw `Faction` repr as `u8` (Pod-safe; `Faction` is a * niche enum and is NOT `Pod`, so it cannot live on a `Pod` account; the PDA seed encodes it too). */ faction: number; /** 1 = currently outlaw against `faction`, 0 = cleared. */ outlaw: number; /** Unix ts the outlaw status was (last) declared. */ declaredAt: bigint; /** * ABSOLUTE unix ts the commitment window ends (`declared_at + OUTLAW_WINDOW_EPOCHS * epoch_len_secs`). * Stored absolute (not an epoch count) — there is no native on-chain epoch counter; the window check * is a single `now >= pvp_until` compare and survives any epoch-length retune. */ pvpUntil: bigint; bump: number; }; export type OutlawFlagArgs = { version: number; /** The profile this flag belongs to (cross-checked by `AccountValidate`). */ profile: Address; /** * The faction this outlaw status is AGAINST — raw `Faction` repr as `u8` (Pod-safe; `Faction` is a * niche enum and is NOT `Pod`, so it cannot live on a `Pod` account; the PDA seed encodes it too). */ faction: number; /** 1 = currently outlaw against `faction`, 0 = cleared. */ outlaw: number; /** Unix ts the outlaw status was (last) declared. */ declaredAt: number | bigint; /** * ABSOLUTE unix ts the commitment window ends (`declared_at + OUTLAW_WINDOW_EPOCHS * epoch_len_secs`). * Stored absolute (not an epoch count) — there is no native on-chain epoch counter; the window check * is a single `now >= pvp_until` compare and survives any epoch-length retune. */ pvpUntil: number | bigint; bump: number; }; /** Gets the encoder for {@link OutlawFlagArgs} account data. */ export function getOutlawFlagEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([ ['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['version', getU8Encoder()], ['profile', getAddressEncoder()], ['faction', getU8Encoder()], ['outlaw', getU8Encoder()], ['declaredAt', getI64Encoder()], ['pvpUntil', getI64Encoder()], ['bump', getU8Encoder()], ]), (value) => ({ ...value, discriminator: OUTLAW_FLAG_DISCRIMINATOR }), ); } /** Gets the decoder for {@link OutlawFlag} account data. */ export function getOutlawFlagDecoder(): FixedSizeDecoder { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['version', getU8Decoder()], ['profile', getAddressDecoder()], ['faction', getU8Decoder()], ['outlaw', getU8Decoder()], ['declaredAt', getI64Decoder()], ['pvpUntil', getI64Decoder()], ['bump', getU8Decoder()], ]); } /** Gets the codec for {@link OutlawFlag} account data. */ export function getOutlawFlagCodec(): FixedSizeCodec< OutlawFlagArgs, OutlawFlag > { return combineCodec(getOutlawFlagEncoder(), getOutlawFlagDecoder()); } export function decodeOutlawFlag( encodedAccount: EncodedAccount, ): Account; export function decodeOutlawFlag( encodedAccount: MaybeEncodedAccount, ): MaybeAccount; export function decodeOutlawFlag( encodedAccount: EncodedAccount | MaybeEncodedAccount, ): Account | MaybeAccount { return decodeAccount( encodedAccount as MaybeEncodedAccount, getOutlawFlagDecoder(), ); } export async function fetchOutlawFlag( rpc: Parameters[0], address: Address, config?: FetchAccountConfig, ): Promise> { const maybeAccount = await fetchMaybeOutlawFlag(rpc, address, config); assertAccountExists(maybeAccount); return maybeAccount; } export async function fetchMaybeOutlawFlag( rpc: Parameters[0], address: Address, config?: FetchAccountConfig, ): Promise> { const maybeAccount = await fetchEncodedAccount(rpc, address, config); return decodeOutlawFlag(maybeAccount); } export async function fetchAllOutlawFlag( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig, ): Promise[]> { const maybeAccounts = await fetchAllMaybeOutlawFlag(rpc, addresses, config); assertAccountsExist(maybeAccounts); return maybeAccounts; } export async function fetchAllMaybeOutlawFlag( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig, ): Promise[]> { const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); return maybeAccounts.map((maybeAccount) => decodeOutlawFlag(maybeAccount)); } export async function fetchOutlawFlagFromSeeds( rpc: Parameters[0], seeds: OutlawFlagSeeds, config: FetchAccountConfig & { programAddress?: Address } = {}, ): Promise> { const maybeAccount = await fetchMaybeOutlawFlagFromSeeds(rpc, seeds, config); assertAccountExists(maybeAccount); return maybeAccount; } export async function fetchMaybeOutlawFlagFromSeeds( rpc: Parameters[0], seeds: OutlawFlagSeeds, config: FetchAccountConfig & { programAddress?: Address } = {}, ): Promise> { const { programAddress, ...fetchConfig } = config; const [address] = await findOutlawFlagPda(seeds, { programAddress }); return await fetchMaybeOutlawFlag(rpc, address, fetchConfig); }