generated from codama-idl/renderers-demo
-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Description
The JavaScript renderer currently renders the following fields and types given a program:
export const PASS_PROGRAM_ADDRESS =
'nabZn3LTGJpknPtSDiqLXZq98VwfYVicy6zDfPu82Cs' as Address<'nabZn3LTGJpknPtSDiqLXZq98VwfYVicy6zDfPu82Cs'>;
export enum PassInstruction {
CreatePass,
UpdatePass,
MintPass,
MintPass2,
}
export function identifyPassInstruction(
instruction: { data: Uint8Array } | Uint8Array
): PassInstruction {
const data =
instruction instanceof Uint8Array ? instruction : instruction.data;
if (containsBytes(data, getU8Encoder().encode(0), 0)) {
return PassInstruction.CreatePass;
}
if (containsBytes(data, getU8Encoder().encode(1), 1)) {
return PassInstruction.UpdatePass;
}
if (containsBytes(data, getU8Encoder().encode(2), 2)) {
return PassInstruction.MintPass;
}
if (containsBytes(data, getU8Encoder().encode(3), 3)) {
return PassInstruction.MintPass2;
}
throw new Error(
'The provided instruction could not be identified as a pass instruction.'
);
}
export type ParsedPassInstruction<
TProgram extends string = 'nabZn3LTGJpknPtSDiqLXZq98VwfYVicy6zDfPu82Cs',
> =
| ({
instructionType: PassInstruction.CreatePass;
} & ParsedCreatePassInstruction<TProgram>)
| ({
instructionType: PassInstruction.UpdatePass;
} & ParsedUpdatePassInstruction<TProgram>)
| ({
instructionType: PassInstruction.MintPass;
} & ParsedMintPassInstruction<TProgram>)
| ({
instructionType: PassInstruction.MintPass2;
} & ParsedMintPass2Instruction<TProgram>);It would be useful to additionally generate a generic instruction codec to decode/encode any of the programs instructions which may work on top of identifyInstruction.
Metadata
Metadata
Assignees
Labels
No labels