How to decode CandyMachine
instruction type?
I can decode Spl
instructions:
import * as spl from '@solana/spl-token';
import { TransactionInstruction } from '@solana/web3.js';
import { u8 } from '@solana/buffer-layout';
import { SplToken, SystemProgram as SystemProgramIdl } from '@project-serum/anchor';
import { ParsedInstruction, ParsedIdlInstruction } from './interfaces';
function decodeTokenInstruction(
instruction: TransactionInstruction,
): ParsedInstruction<SplToken> {
let parsed: ParsedIdlInstruction<SplToken> | null;
const decoded = u8().decode(instruction.data);
switch (decoded) {
case spl.TokenInstruction.InitializeMint: {
...
}
case spl.TokenInstruction.InitializeAccount: {
...
}
}
}
Also SystemInstruction
:
function decodeSystemInstruction(
instruction: TransactionInstruction,
): ParsedInstruction<SystemProgramIdl> {
const ixType = SystemInstruction.decodeInstructionType(instruction);
let parsed: ParsedIdlInstruction<SystemProgramIdl> | null;
switch (ixType) {
case 'AdvanceNonceAccount': {
...
}
}
}
But how I can decode type of CandyMachine
instructions?
EDIT
Each instruction in CandyMachine
has its own instructionDiscriminator
, for example:
export const updateCandyMachineInstructionDiscriminator = [243, 251, 124, 156, 211, 211, 118, 239];
I created the following structure:
export const instructionDiscriminatorStruct = new beet.FixableBeetArgsStruct<{
instructionDiscriminator: number[] /* size: 8 */;
}>([['instructionDiscriminator', beet.uniformFixedSizeArray(beet.u8, 8)]]);
And with it I can get instructionDiscriminator
:
const [{ instructionDiscriminator }] = instructionDiscriminatorStruct.deserialize(instruction.data);