UNPKG

@nosana/kit

Version:

Nosana KIT

71 lines (70 loc) 2.74 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 STOP_DISCRIMINATOR = new Uint8Array([ 42, 133, 32, 60, 171, 253, 184, 155, ]); export function getStopDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(STOP_DISCRIMINATOR); } export function getStopInstructionDataEncoder() { return transformEncoder(getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)]]), (value) => ({ ...value, discriminator: STOP_DISCRIMINATOR })); } export function getStopInstructionDataDecoder() { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ]); } export function getStopInstructionDataCodec() { return combineCodec(getStopInstructionDataEncoder(), getStopInstructionDataDecoder()); } export function getStopInstruction(input, config) { // Program address. const programAddress = config?.programAddress ?? NOSANA_JOBS_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { market: { value: input.market ?? null, isWritable: true }, node: { value: input.node ?? null, isWritable: false }, authority: { value: input.authority ?? null, isWritable: false }, }; const accounts = originalAccounts; const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); const instruction = { accounts: [ getAccountMeta(accounts.market), getAccountMeta(accounts.node), getAccountMeta(accounts.authority), ], programAddress, data: getStopInstructionDataEncoder().encode({}), }; return instruction; } export function parseStopInstruction(instruction) { if (instruction.accounts.length < 3) { // 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: { market: getNextAccount(), node: getNextAccount(), authority: getNextAccount(), }, data: getStopInstructionDataDecoder().decode(instruction.data), }; }