-
Notifications
You must be signed in to change notification settings - Fork 139
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
Support for Enum Types as Direct Transaction Parameters #3484
Labels
Comments
6 tasks
Enums are already supported as transaction parameters (and has been there for while). Hence we'll be closing the issue. @justinrandom Was there any particular issue / any specific error you ran into? If so, please feel free to re-open with the error details. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Issue to be solved
Issue to be Solved
Currently, enums cannot be used directly as transaction parameters in the Cadence language. This limitation requires developers to use integer values to represent enum cases, which reduces code readability and increases the risk of errors due to incorrect mappings between integers and their corresponding enum cases. This issue affects the security and usability of smart contracts, as users must be aware of the specific integer values representing each enum case, leading to potential mistakes and confusion.
In-scope:
Allowing enum types to be directly used as transaction parameters.
Improving the security and usability of smart contracts by enabling intuitive use of enums.
Out-of-scope:
Changing existing enum functionalities or how enums are defined within contracts.
Modifying how integer values are currently used in other parts of the language.
Suggested Solution
Details of the Technical Implementation:
Update the Cadence language to support enum types as valid transaction parameters.
Allow developers to define enums within contracts and use them directly in transaction arguments.
Ensure that the Cadence runtime can correctly interpret and validate enum values during transaction execution.
Tradeoffs Made in Design Decisions:
Pro: Enhanced readability and reduced risk of errors by using enums directly.
Pro: Improved developer experience and code maintainability.
Con: Requires updates to the Cadence language and runtime, which may involve significant development resources and testing.
Caveats and Considerations for the Future:
Ensure backward compatibility with existing contracts that use integers to represent enums.
Provide thorough documentation and examples to help developers transition to using enums as transaction parameters.
Consider potential performance implications of supporting enums in transaction parameters and optimize as necessary.
Example of Preferred Solution:
Currently, a transaction script might require the user to input an integer value to represent an enum case, such as:
In this script, the user must provide an integer representing the enum value. With the proposed enhancement, the script could be simplified to:
The text was updated successfully, but these errors were encountered: