Skip to content

Commit

Permalink
Fix enum parsing bug
Browse files Browse the repository at this point in the history
  • Loading branch information
0xabhinav committed Jan 4, 2024
1 parent 47ff77f commit 2fedba0
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions ts/packages/anchor/src/coder/borsh/instruction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,8 @@ class InstructionFormatter {
.map((d: IdlField) =>
this.formatIdlData(
{ name: "", type: (<IdlTypeVec>idlField.type).vec },
d
d,
types
)
)
.join(", ") +
Expand Down Expand Up @@ -303,11 +304,15 @@ class InstructionFormatter {
const variants = typeDef.type.variants;
const variant = Object.keys(data)[0];
const enumType = data[variant];
const camelCaseVariant = camelCase(variant);
const enumVariant = variants.find((v) => camelCase(v.name) === camelCaseVariant);
const relevantFields = enumVariant?.fields;
const namedFields = Object.keys(enumType)
.map((f) => {
const fieldData = enumType[f];
const idlField = variants[variant]?.find(
(v: IdlField) => v.name === f
const camelCaseField = camelCase(f);
const idlField = relevantFields?.find<IdlField>(
(v): v is IdlField => camelCase((v as IdlField).name) === camelCaseField
);
if (!idlField) {
throw new Error("Unable to find variant");
Expand Down

0 comments on commit 2fedba0

Please sign in to comment.