/** * 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 { assertIsInstructionWithAccounts, containsBytes, extendClient, getU8Encoder, SOLANA_ERROR__PROGRAM_CLIENTS__FAILED_TO_IDENTIFY_ACCOUNT, SOLANA_ERROR__PROGRAM_CLIENTS__FAILED_TO_IDENTIFY_INSTRUCTION, SOLANA_ERROR__PROGRAM_CLIENTS__UNRECOGNIZED_INSTRUCTION_TYPE, SolanaError, type Address, type ClientWithRpc, type ClientWithTransactionPlanning, type ClientWithTransactionSending, type ExtendedClient, type GetAccountInfoApi, type GetMultipleAccountsApi, type HasAddress, type Instruction, type InstructionWithData, type ReadonlyUint8Array, } from '@solana/kit'; import { addSelfFetchFunctions, addSelfPlanAndSendFunctions, type SelfFetchFunctions, type SelfPlanAndSendFunctions, } from '@solana/kit/program-client-core'; import { getRecordDataCodec, type RecordData, type RecordDataArgs } from '../accounts'; import { getCloseAccountInstruction, getInitializeInstruction, getReallocateInstruction, getSetAuthorityInstruction, getWriteInstruction, parseCloseAccountInstruction, parseInitializeInstruction, parseReallocateInstruction, parseSetAuthorityInstruction, parseWriteInstruction, type CloseAccountInput, type InitializeInput, type ParsedCloseAccountInstruction, type ParsedInitializeInstruction, type ParsedReallocateInstruction, type ParsedSetAuthorityInstruction, type ParsedWriteInstruction, type ReallocateInput, type SetAuthorityInput, type WriteInput, } from '../instructions'; export const RECORD_PROGRAM_ADDRESS = 'recr1L3PCGKLbckBqMNcJhuuyU1zgo8nBhfLVsJNwr5' as Address<'recr1L3PCGKLbckBqMNcJhuuyU1zgo8nBhfLVsJNwr5'>; export enum RecordAccount { RecordData, } export function identifyRecordAccount(account: { data: ReadonlyUint8Array } | ReadonlyUint8Array): RecordAccount { const data = 'data' in account ? account.data : account; if (containsBytes(data, getU8Encoder().encode(1), 0)) { return RecordAccount.RecordData; } throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__FAILED_TO_IDENTIFY_ACCOUNT, { accountData: data, programName: 'record', }); } export enum RecordInstruction { Initialize, Write, SetAuthority, CloseAccount, Reallocate, } export function identifyRecordInstruction( instruction: { data: ReadonlyUint8Array } | ReadonlyUint8Array, ): RecordInstruction { const data = 'data' in instruction ? instruction.data : instruction; if (containsBytes(data, getU8Encoder().encode(0), 0)) { return RecordInstruction.Initialize; } if (containsBytes(data, getU8Encoder().encode(1), 0)) { return RecordInstruction.Write; } if (containsBytes(data, getU8Encoder().encode(2), 0)) { return RecordInstruction.SetAuthority; } if (containsBytes(data, getU8Encoder().encode(3), 0)) { return RecordInstruction.CloseAccount; } if (containsBytes(data, getU8Encoder().encode(4), 0)) { return RecordInstruction.Reallocate; } throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__FAILED_TO_IDENTIFY_INSTRUCTION, { instructionData: data, programName: 'record', }); } export type ParsedRecordInstruction = | ({ instructionType: RecordInstruction.Initialize } & ParsedInitializeInstruction) | ({ instructionType: RecordInstruction.Write } & ParsedWriteInstruction) | ({ instructionType: RecordInstruction.SetAuthority } & ParsedSetAuthorityInstruction) | ({ instructionType: RecordInstruction.CloseAccount } & ParsedCloseAccountInstruction) | ({ instructionType: RecordInstruction.Reallocate } & ParsedReallocateInstruction); export function parseRecordInstruction( instruction: Instruction & InstructionWithData, ): ParsedRecordInstruction { const instructionType = identifyRecordInstruction(instruction); switch (instructionType) { case RecordInstruction.Initialize: { assertIsInstructionWithAccounts(instruction); return { instructionType: RecordInstruction.Initialize, ...parseInitializeInstruction(instruction) }; } case RecordInstruction.Write: { assertIsInstructionWithAccounts(instruction); return { instructionType: RecordInstruction.Write, ...parseWriteInstruction(instruction) }; } case RecordInstruction.SetAuthority: { assertIsInstructionWithAccounts(instruction); return { instructionType: RecordInstruction.SetAuthority, ...parseSetAuthorityInstruction(instruction) }; } case RecordInstruction.CloseAccount: { assertIsInstructionWithAccounts(instruction); return { instructionType: RecordInstruction.CloseAccount, ...parseCloseAccountInstruction(instruction) }; } case RecordInstruction.Reallocate: { assertIsInstructionWithAccounts(instruction); return { instructionType: RecordInstruction.Reallocate, ...parseReallocateInstruction(instruction) }; } default: throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__UNRECOGNIZED_INSTRUCTION_TYPE, { instructionType: instructionType as string, programName: 'record', }); } } export type RecordPlugin = { accounts: RecordPluginAccounts; instructions: RecordPluginInstructions; identifyAccount: typeof identifyRecordAccount; identifyInstruction: typeof identifyRecordInstruction; parseInstruction: typeof parseRecordInstruction; }; export type RecordPluginAccounts = { recordData: ReturnType & SelfFetchFunctions; }; export type RecordPluginInstructions = { initialize: ( input: InitializeInput, config?: { programAddress?: Address | HasAddress }, ) => ReturnType & SelfPlanAndSendFunctions; write: ( input: WriteInput, config?: { programAddress?: Address | HasAddress }, ) => ReturnType & SelfPlanAndSendFunctions; setAuthority: ( input: SetAuthorityInput, config?: { programAddress?: Address | HasAddress }, ) => ReturnType & SelfPlanAndSendFunctions; closeAccount: ( input: CloseAccountInput, config?: { programAddress?: Address | HasAddress }, ) => ReturnType & SelfPlanAndSendFunctions; reallocate: ( input: ReallocateInput, config?: { programAddress?: Address | HasAddress }, ) => ReturnType & SelfPlanAndSendFunctions; }; export type RecordPluginRequirements = ClientWithRpc & ClientWithTransactionPlanning & ClientWithTransactionSending; export function recordProgram(config: { programAddress?: Address | HasAddress } = {}) { return (client: T): ExtendedClient => { return extendClient(client, { record: { accounts: { recordData: addSelfFetchFunctions(client, getRecordDataCodec()) }, instructions: { initialize: (input, instructionConfig) => addSelfPlanAndSendFunctions( client, getInitializeInstruction(input, { programAddress: instructionConfig?.programAddress ?? config.programAddress, }), ), write: (input, instructionConfig) => addSelfPlanAndSendFunctions( client, getWriteInstruction(input, { programAddress: instructionConfig?.programAddress ?? config.programAddress, }), ), setAuthority: (input, instructionConfig) => addSelfPlanAndSendFunctions( client, getSetAuthorityInstruction(input, { programAddress: instructionConfig?.programAddress ?? config.programAddress, }), ), closeAccount: (input, instructionConfig) => addSelfPlanAndSendFunctions( client, getCloseAccountInstruction(input, { programAddress: instructionConfig?.programAddress ?? config.programAddress, }), ), reallocate: (input, instructionConfig) => addSelfPlanAndSendFunctions( client, getReallocateInstruction(input, { programAddress: instructionConfig?.programAddress ?? config.programAddress, }), ), }, identifyAccount: identifyRecordAccount, identifyInstruction: identifyRecordInstruction, parseInstruction: parseRecordInstruction, }, }); }; }