0

I have a simple enum (or enum class, neither one is working )

enum vote_option {
  upvote = 0,
  downvote

and a table which will store a value of that enum type.

struct [[eosio::table]] poll
{
  uint64_t key;
  vote_option opt;

  uint64_t primary_key() const { return key; }
};

And the problem is the build is fine, but when I even get table I've got

Error 3015004: The type defined in the ABI is invalid
Error Details:
vote_option

Has anyone experienced this kind of problem ?

I use eosio.cdt v 1.6.2 and eosio v1.8.4 .

1 Answer 1

3

If you use a custom type you must also define the type to a built in type. A list of accepted types by EOSIO can be found here, https://eosio.stackexchange.com/a/1932/3333.

For instance, your custom enum is actually a uint8_t type.

You'll need something like ..

## header file

enum e_vote_option {
  upvote = 0,
  downvote
}

typedef uint8_t vote_option;

struct [[eosio::table]] poll
{
  uint64_t key;
  vote_option opt;

  uint64_t primary_key() const { return key; }
};
### source file

vote_table.emplace(_self, [&](auto& o) {
    o.key = vote_table.available_primary_key();
    o.opt = e_vote_option::downvote;
});

With this format, your ABI file will correctly set vote_option as uint8_t.

6
  • So, you agree that we can't use enum typed members in tables. The same goes for enum classes with underlying type specified. Commented Oct 10, 2019 at 9:04
  • I have personally used the suggestion I gave and it worked fine. I just had to declare the enum and then specify it's type to be picked up by the ABI. Commented Oct 10, 2019 at 9:08
  • What I can't understand is how do you declare the enum and then typedef the same name. You can't have enum and typdefed type at the same time. Commented Oct 10, 2019 at 10:51
  • Right so you have a name for the enum type. Then you typedef the uint8_t, and use the typedef name in place of the enum type. In the end, the enum is a declaration of a certain type of objects, in this case I used the uint8_t example. github.com/eostitan/delphioracle/blob/write-hash/include/… this example might give you more clarification Commented Oct 10, 2019 at 13:54
  • 1
    Thank you, fully understood ;) Before marking your answer as accepted, could you please edit it to make it clearer. Commented Oct 10, 2019 at 18:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.