Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix enum parsing bug #2763

Merged
merged 7 commits into from
Jan 9, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 as IdlField[] | undefined;
0xabhinav marked this conversation as resolved.
Show resolved Hide resolved
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(
v => camelCase(v.name) === camelCaseField
);
if (!idlField) {
throw new Error("Unable to find variant");
Expand Down
Loading