-
Notifications
You must be signed in to change notification settings - Fork 37
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
Add explicit enums implementation #529
Conversation
danielailie
commented
Nov 12, 2024
- Fix handling of explicit-enums #519
|
||
const typedValues = NativeSerializer.nativeToTypedValues([p1], endpoint); | ||
|
||
console.log(typedValues[0].valueOf()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Logging artifact.
|
||
// Simple enum by name | ||
const p1 = "completed"; | ||
// Enum with a single field |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment / code alignment.
} else if (typeDefinition.type == "enum") { | ||
customTypes.push(EnumType.fromJSON({ name: customTypeName, variants: typeDefinition.variants })); | ||
} else if (typeDefinition.type == "explicit-enum") { | ||
customTypes.push( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
import { StringBinaryCodec } from "./string"; | ||
|
||
export class ExplicitEnumBinaryCodec { | ||
private readonly stringCodec: StringBinaryCodec; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀
@@ -107,6 +112,12 @@ export class AbiRegistry { | |||
return <EnumType>result!; | |||
} | |||
|
|||
getExplicitEnum(name: string): ExplicitEnumType { | |||
const result = this.customTypes.find((e) => e.getName() == name && e.hasExactClass(ExplicitEnumType.ClassName)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps it does not help in this case, but I think it would be a good practice to use ===
wherever possible.