/** * 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, decodeAccount, fetchEncodedAccount, fetchEncodedAccounts, type Account, type EncodedAccount, type FetchAccountConfig, type FetchAccountsConfig, type MaybeAccount, type MaybeEncodedAccount, } from '@solana/accounts'; import { getAddressDecoder, getAddressEncoder, type Address, } from '@solana/addresses'; import { addDecoderSizePrefix, addEncoderSizePrefix, combineCodec, fixDecoderSize, fixEncoderSize, getBooleanDecoder, getBooleanEncoder, getBytesDecoder, getBytesEncoder, getI64Decoder, getI64Encoder, getStructDecoder, getStructEncoder, getU32Decoder, getU32Encoder, getU64Decoder, getU64Encoder, getU8Decoder, getU8Encoder, getUtf8Decoder, getUtf8Encoder, transformEncoder, type Codec, type Decoder, type Encoder, type ReadonlyUint8Array, } from '@solana/codecs'; export const CHANNEL_ACCOUNT_DISCRIMINATOR = new Uint8Array([ 89, 117, 191, 67, 201, 23, 89, 155, ]); export function getChannelAccountDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( CHANNEL_ACCOUNT_DISCRIMINATOR ); } export type ChannelAccount = { discriminator: ReadonlyUint8Array; creator: Address; channelId: string; name: string; description: string; visibility: number; maxParticipants: number; participantCount: number; feePerMessage: bigint; createdAt: bigint; isActive: boolean; bump: number; }; export type ChannelAccountArgs = { creator: Address; channelId: string; name: string; description: string; visibility: number; maxParticipants: number; participantCount: number; feePerMessage: number | bigint; createdAt: number | bigint; isActive: boolean; bump: number; }; export function getChannelAccountEncoder(): Encoder { return transformEncoder( getStructEncoder([ ['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['creator', getAddressEncoder()], ['channelId', addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder())], ['name', addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder())], ['description', addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder())], ['visibility', getU8Encoder()], ['maxParticipants', getU32Encoder()], ['participantCount', getU32Encoder()], ['feePerMessage', getU64Encoder()], ['createdAt', getI64Encoder()], ['isActive', getBooleanEncoder()], ['bump', getU8Encoder()], ]), (value) => ({ ...value, discriminator: CHANNEL_ACCOUNT_DISCRIMINATOR }) ); } export function getChannelAccountDecoder(): Decoder { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['creator', getAddressDecoder()], ['channelId', addDecoderSizePrefix(getUtf8Decoder(), getU32Decoder())], ['name', addDecoderSizePrefix(getUtf8Decoder(), getU32Decoder())], ['description', addDecoderSizePrefix(getUtf8Decoder(), getU32Decoder())], ['visibility', getU8Decoder()], ['maxParticipants', getU32Decoder()], ['participantCount', getU32Decoder()], ['feePerMessage', getU64Decoder()], ['createdAt', getI64Decoder()], ['isActive', getBooleanDecoder()], ['bump', getU8Decoder()], ]); } export function getChannelAccountCodec(): Codec< ChannelAccountArgs, ChannelAccount > { return combineCodec(getChannelAccountEncoder(), getChannelAccountDecoder()); } export function decodeChannelAccount( encodedAccount: EncodedAccount ): Account; export function decodeChannelAccount( encodedAccount: MaybeEncodedAccount ): MaybeAccount; export function decodeChannelAccount( encodedAccount: EncodedAccount | MaybeEncodedAccount ): Account | MaybeAccount { return decodeAccount( encodedAccount as MaybeEncodedAccount, getChannelAccountDecoder() ); } export async function fetchChannelAccount( rpc: Parameters[0], address: Address, config?: FetchAccountConfig ): Promise> { const maybeAccount = await fetchMaybeChannelAccount(rpc, address, config); assertAccountExists(maybeAccount); return maybeAccount; } export async function fetchMaybeChannelAccount< TAddress extends string = string, >( rpc: Parameters[0], address: Address, config?: FetchAccountConfig ): Promise> { const maybeAccount = await fetchEncodedAccount(rpc, address, config); return decodeChannelAccount(maybeAccount); } export async function fetchAllChannelAccount( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig ): Promise[]> { const maybeAccounts = await fetchAllMaybeChannelAccount( rpc, addresses, config ); assertAccountsExist(maybeAccounts); return maybeAccounts; } export async function fetchAllMaybeChannelAccount( rpc: Parameters[0], addresses: Array
, config?: FetchAccountsConfig ): Promise[]> { const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); return maybeAccounts.map((maybeAccount) => decodeChannelAccount(maybeAccount) ); }