Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Enhancement: Add enum objects to contract objects #3552

Merged
merged 2 commits into from
Nov 23, 2020
Merged

Conversation

haltman-at
Copy link
Contributor

This PR (suggested by @gnidan) adds enums to contract objects. Note that top-level enums are not covered; only enums defined in a contract.

So, let's say you define a contract C which defines enum E { e0, e1, e2 }.

Then now, the contract object for C will have a field C.E which is an object {e0: 0, e1: 1, e2: 2}. So, you could write C.E.e2 for 2. This allows one to pass in enums to functions that take them without needing to worry about their numerical value.

Also, all the enums will be under C.enums, so you could also do C.enums.E.e2 for 2. (I made it so that C.E will only be created if it doesn't overwrite anything, so C.enums.E exists as a fallback way to get at E.)

Note, I set all this up in bootstrap.js. This is... not really the right for place for this. The right place is probably constructorMethods.js. But, well, this was easier. Sorry. Truffle Contract is a gigantic mess of overly clever dynamic code, and finding the right place to put things is hard. Well, we'll redo all this in the rewrite.

Anyway, yeah, despite the ugliness, now there are enums!

Also, prettier made some changes.

Hm, maybe I should go back and add a test...

@haltman-at
Copy link
Contributor Author

OK, went back and added a test of this!

Copy link
Contributor

@gnidan gnidan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! This will be handy!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants