UNPKG

@nosana/kit

Version:

Nosana KIT

74 lines (73 loc) 2.87 kB
/** * 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, fixDecoderSize, fixEncoderSize, getBytesDecoder, getBytesEncoder, getStructDecoder, getStructEncoder, transformEncoder, } from '@solana/kit'; import { NOSANA_JOBS_PROGRAM_ADDRESS } from '../programs'; import { getAccountMetaFactory } from '../shared'; export const QUIT_DISCRIMINATOR = new Uint8Array([ 191, 103, 141, 240, 80, 129, 103, 153, ]); export function getQuitDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(QUIT_DISCRIMINATOR); } export function getQuitInstructionDataEncoder() { return transformEncoder(getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)]]), (value) => ({ ...value, discriminator: QUIT_DISCRIMINATOR })); } export function getQuitInstructionDataDecoder() { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ]); } export function getQuitInstructionDataCodec() { return combineCodec(getQuitInstructionDataEncoder(), getQuitInstructionDataDecoder()); } export function getQuitInstruction(input, config) { // Program address. const programAddress = config?.programAddress ?? NOSANA_JOBS_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { job: { value: input.job ?? null, isWritable: true }, run: { value: input.run ?? null, isWritable: true }, payer: { value: input.payer ?? null, isWritable: true }, authority: { value: input.authority ?? null, isWritable: false }, }; const accounts = originalAccounts; const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); const instruction = { accounts: [ getAccountMeta(accounts.job), getAccountMeta(accounts.run), getAccountMeta(accounts.payer), getAccountMeta(accounts.authority), ], programAddress, data: getQuitInstructionDataEncoder().encode({}), }; return instruction; } export function parseQuitInstruction(instruction) { if (instruction.accounts.length < 4) { // TODO: Coded error. throw new Error('Not enough accounts'); } let accountIndex = 0; const getNextAccount = () => { const accountMeta = instruction.accounts[accountIndex]; accountIndex += 1; return accountMeta; }; return { programAddress: instruction.programAddress, accounts: { job: getNextAccount(), run: getNextAccount(), payer: getNextAccount(), authority: getNextAccount(), }, data: getQuitInstructionDataDecoder().decode(instruction.data), }; }