/** * 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 { combineCodec, getStructDecoder, getStructEncoder, getU8Decoder, getU8Encoder, SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, SolanaError, transformEncoder, type AccountMeta, type Address, type FixedSizeCodec, type FixedSizeDecoder, type FixedSizeEncoder, type Instruction, type InstructionWithAccounts, type InstructionWithData, type ReadonlyUint8Array, type WritableAccount, } from '@solana/kit'; import { getAccountMetaFactory, type ResolvedInstructionAccount } from '@solana/program-client-core'; import { PAYMENT_CHANNELS_PROGRAM_ADDRESS } from '../programs/index.js'; export const SEAL_DISCRIMINATOR = 6; export function getSealDiscriminatorBytes(): ReadonlyUint8Array { return getU8Encoder().encode(SEAL_DISCRIMINATOR); } export type SealInstruction< TProgram extends string = typeof PAYMENT_CHANNELS_PROGRAM_ADDRESS, TAccountChannel extends string | AccountMeta = string, TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [TAccountChannel extends string ? WritableAccount : TAccountChannel, ...TRemainingAccounts] >; export type SealInstructionData = { discriminator: number }; export type SealInstructionDataArgs = {}; export function getSealInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder(getStructEncoder([['discriminator', getU8Encoder()]]), value => ({ ...value, discriminator: SEAL_DISCRIMINATOR, })); } export function getSealInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([['discriminator', getU8Decoder()]]); } export function getSealInstructionDataCodec(): FixedSizeCodec { return combineCodec(getSealInstructionDataEncoder(), getSealInstructionDataDecoder()); } export type SealInput = { channel: Address; }; export function getSealInstruction< TAccountChannel extends string, TProgramAddress extends Address = typeof PAYMENT_CHANNELS_PROGRAM_ADDRESS, >( input: SealInput, config?: { programAddress?: TProgramAddress }, ): SealInstruction { // Program address. const programAddress = config?.programAddress ?? PAYMENT_CHANNELS_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { channel: { value: input.channel ?? null, isWritable: true }, }; const accounts = originalAccounts as Record; const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); return Object.freeze({ accounts: [getAccountMeta('channel', accounts.channel)], data: getSealInstructionDataEncoder().encode({}), programAddress, } as SealInstruction); } export type ParsedSealInstruction< TProgram extends string = typeof PAYMENT_CHANNELS_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { channel: TAccountMetas[0]; }; data: SealInstructionData; }; export function parseSealInstruction( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedSealInstruction { if (instruction.accounts.length < 1) { throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 1, }); } let accountIndex = 0; const getNextAccount = () => { const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; accountIndex += 1; return accountMeta; }; return { programAddress: instruction.programAddress, accounts: { channel: getNextAccount() }, data: getSealInstructionDataDecoder().decode(instruction.data), }; }