@nosana/kit
Version:
Nosana KIT
74 lines (73 loc) • 2.83 kB
JavaScript
/**
* 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 COMPLETE_DISCRIMINATOR = new Uint8Array([
0, 77, 224, 147, 136, 25, 88, 76,
]);
export function getCompleteDiscriminatorBytes() {
return fixEncoderSize(getBytesEncoder(), 8).encode(COMPLETE_DISCRIMINATOR);
}
export function getCompleteInstructionDataEncoder() {
return transformEncoder(getStructEncoder([
['discriminator', fixEncoderSize(getBytesEncoder(), 8)],
['ipfsResult', fixEncoderSize(getBytesEncoder(), 32)],
]), (value) => ({ ...value, discriminator: COMPLETE_DISCRIMINATOR }));
}
export function getCompleteInstructionDataDecoder() {
return getStructDecoder([
['discriminator', fixDecoderSize(getBytesDecoder(), 8)],
['ipfsResult', fixDecoderSize(getBytesDecoder(), 32)],
]);
}
export function getCompleteInstructionDataCodec() {
return combineCodec(getCompleteInstructionDataEncoder(), getCompleteInstructionDataDecoder());
}
export function getCompleteInstruction(input, config) {
// Program address.
const programAddress = config?.programAddress ?? NOSANA_JOBS_PROGRAM_ADDRESS;
// Original accounts.
const originalAccounts = {
job: { value: input.job ?? null, isWritable: true },
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.job),
getAccountMeta(accounts.authority),
],
programAddress,
data: getCompleteInstructionDataEncoder().encode(args),
};
return instruction;
}
export function parseCompleteInstruction(instruction) {
if (instruction.accounts.length < 2) {
// 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(),
authority: getNextAccount(),
},
data: getCompleteInstructionDataDecoder().decode(instruction.data),
};
}