| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- /**
- * 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 {
- type AccountMeta,
- type Address,
- type Instruction,
- type InstructionWithAccounts,
- type WritableAccount,
- } from '@solana/kit';
- import { DUMMY_PROGRAM_ADDRESS } from '../programs';
- import { getAccountMetaFactory, type ResolvedAccount } from '../shared';
- export type Instruction7Instruction<
- TProgram extends string = typeof DUMMY_PROGRAM_ADDRESS,
- TAccountMyAccount extends string | AccountMeta<string> = string,
- TRemainingAccounts extends readonly AccountMeta<string>[] = [],
- > = Instruction<TProgram> &
- InstructionWithAccounts<
- [
- TAccountMyAccount extends string
- ? WritableAccount<TAccountMyAccount>
- : TAccountMyAccount,
- ...TRemainingAccounts,
- ]
- >;
- export type Instruction7Input<TAccountMyAccount extends string = string> = {
- myAccount?: Address<TAccountMyAccount>;
- };
- export function getInstruction7Instruction<
- TAccountMyAccount extends string,
- TProgramAddress extends Address = typeof DUMMY_PROGRAM_ADDRESS,
- >(
- input: Instruction7Input<TAccountMyAccount>,
- config?: { programAddress?: TProgramAddress }
- ): Instruction7Instruction<TProgramAddress, TAccountMyAccount> {
- // Program address.
- const programAddress = config?.programAddress ?? DUMMY_PROGRAM_ADDRESS;
- // Original accounts.
- const originalAccounts = {
- myAccount: { value: input.myAccount ?? null, isWritable: true },
- };
- const accounts = originalAccounts as Record<
- keyof typeof originalAccounts,
- ResolvedAccount
- >;
- const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
- return Object.freeze({
- accounts: [getAccountMeta(accounts.myAccount)],
- programAddress,
- } as Instruction7Instruction<TProgramAddress, TAccountMyAccount>);
- }
- export type ParsedInstruction7Instruction<
- TProgram extends string = typeof DUMMY_PROGRAM_ADDRESS,
- TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
- > = {
- programAddress: Address<TProgram>;
- accounts: {
- myAccount?: TAccountMetas[0] | undefined;
- };
- };
- export function parseInstruction7Instruction<
- TProgram extends string,
- TAccountMetas extends readonly AccountMeta[],
- >(
- instruction: Instruction<TProgram> & InstructionWithAccounts<TAccountMetas>
- ): ParsedInstruction7Instruction<TProgram, TAccountMetas> {
- if (instruction.accounts.length < 1) {
- // TODO: Coded error.
- throw new Error('Not enough accounts');
- }
- let accountIndex = 0;
- const getNextAccount = () => {
- const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
- accountIndex += 1;
- return accountMeta;
- };
- const getNextOptionalAccount = () => {
- const accountMeta = getNextAccount();
- return accountMeta.address === DUMMY_PROGRAM_ADDRESS
- ? undefined
- : accountMeta;
- };
- return {
- programAddress: instruction.programAddress,
- accounts: { myAccount: getNextOptionalAccount() },
- };
- }
|