UNPKG

@nosana/kit

Version:

Nosana KIT

85 lines (84 loc) 3.4 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, getI64Decoder, getI64Encoder, getStructDecoder, getStructEncoder, getU128Decoder, getU128Encoder, getU64Decoder, getU64Encoder, getU8Decoder, getU8Encoder, transformEncoder, } from '@solana/kit'; import { NOSANA_JOBS_PROGRAM_ADDRESS } from '../programs'; import { getAccountMetaFactory } from '../shared'; export const UPDATE_DISCRIMINATOR = new Uint8Array([ 219, 200, 88, 176, 158, 63, 253, 127, ]); export function getUpdateDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(UPDATE_DISCRIMINATOR); } export function getUpdateInstructionDataEncoder() { return transformEncoder(getStructEncoder([ ['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['jobExpiration', getI64Encoder()], ['jobPrice', getU64Encoder()], ['jobType', getU8Encoder()], ['nodeStakeMinimum', getU128Encoder()], ['jobTimeout', getI64Encoder()], ]), (value) => ({ ...value, discriminator: UPDATE_DISCRIMINATOR })); } export function getUpdateInstructionDataDecoder() { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['jobExpiration', getI64Decoder()], ['jobPrice', getU64Decoder()], ['jobType', getU8Decoder()], ['nodeStakeMinimum', getU128Decoder()], ['jobTimeout', getI64Decoder()], ]); } export function getUpdateInstructionDataCodec() { return combineCodec(getUpdateInstructionDataEncoder(), getUpdateInstructionDataDecoder()); } export function getUpdateInstruction(input, config) { // Program address. const programAddress = config?.programAddress ?? NOSANA_JOBS_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { market: { value: input.market ?? null, isWritable: true }, accessKey: { value: input.accessKey ?? null, isWritable: false }, authority: { value: input.authority ?? null, isWritable: false }, }; const accounts = originalAccounts; // Original args. const args = { ...input }; const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); const instruction = { accounts: [ getAccountMeta(accounts.market), getAccountMeta(accounts.accessKey), getAccountMeta(accounts.authority), ], programAddress, data: getUpdateInstructionDataEncoder().encode(args), }; return instruction; } export function parseUpdateInstruction(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(), accessKey: getNextAccount(), authority: getNextAccount(), }, data: getUpdateInstructionDataDecoder().decode(instruction.data), }; }