diff --git a/plugins/sysio/abigen.hpp b/plugins/sysio/abigen.hpp index aca755ffc..d0ba12999 100644 --- a/plugins/sysio/abigen.hpp +++ b/plugins/sysio/abigen.hpp @@ -313,6 +313,9 @@ namespace sysio { namespace cdt { }else if (inside_type.getTypePtr()->isRecordType()) { add_struct(inside_type.getTypePtr()->getAsCXXRecordDecl()); inside_type_name = inside_type.getTypePtr()->getAsCXXRecordDecl()->getNameAsString(); + } else if (inside_type.getTypePtr()->isEnumeralType()) { + add_type(inside_type); + inside_type_name = get_base_type_name(inside_type); } else { std::string errstring = "adding_explicit_nested_dispatcher: this inside type "; errstring += inside_type.getAsString(); diff --git a/plugins/sysio/gen.hpp b/plugins/sysio/gen.hpp index b44c0510f..e4a51650c 100644 --- a/plugins/sysio/gen.hpp +++ b/plugins/sysio/gen.hpp @@ -544,6 +544,8 @@ struct generation_utils { inside_type_name = get_template_name(inside_type); }else if (inside_type.getTypePtr()->isRecordType()) { inside_type_name = inside_type.getTypePtr()->getAsCXXRecordDecl()->getNameAsString(); + } else if (inside_type.getTypePtr()->isEnumeralType()) { + inside_type_name = get_base_type_name(inside_type); } else { std::string errstring = "translating_explicit_nested_dispatcher: this inside type "; errstring += inside_type.getAsString(); diff --git a/tools/toolchain-tester/examples/abigen-pass/abigen_test_enum_table.cpp b/tools/toolchain-tester/examples/abigen-pass/abigen_test_enum_table.cpp new file mode 100644 index 000000000..6b3d2fb1d --- /dev/null +++ b/tools/toolchain-tester/examples/abigen-pass/abigen_test_enum_table.cpp @@ -0,0 +1,69 @@ +#include +using namespace sysio; + +enum test_chain_kind : uint8_t { + CHAIN_KIND_UNKNOWN = 0, + CHAIN_KIND_WIRE = 1, + CHAIN_KIND_ETHEREUM = 2, + CHAIN_KIND_SOLANA = 3 +}; + +enum class test_status : uint8_t { + WARMUP = 1, + ACTIVE = 2, + COOLDOWN = 3, + TERMINATED = 240 +}; + +CONTRACT abigen_test_enum_table : public contract { + public: + using contract::contract; + abigen_test_enum_table( name receiver, name code, datastream ds ) + : contract(receiver, code, ds), outposts(receiver, receiver.value), + operators(receiver, receiver.value) {} + + ACTION regoutpost( test_chain_kind chain_kind, uint32_t chain_id ); + ACTION regoperator( name account, test_status status ); + + // Simple enum field in table struct + TABLE outpost_info { + uint64_t id; + test_chain_kind chain_kind; + uint32_t chain_id; + uint64_t primary_key() const { return id; } + }; + + // Enum inside nested container (std::vector>) + TABLE operator_info { + name account; + test_status status; + std::vector> chain_addresses; + uint64_t primary_key() const { return account.value; } + }; + + using outposts_t = sysio::multi_index<"outposts"_n, outpost_info>; + using operators_t = sysio::multi_index<"operators"_n, operator_info>; + + using regoutpost_action = action_wrapper<"regoutpost"_n, &abigen_test_enum_table::regoutpost>; + using regoperator_action = action_wrapper<"regoperator"_n, &abigen_test_enum_table::regoperator>; + + outposts_t outposts; + operators_t operators; +}; + +ACTION abigen_test_enum_table::regoutpost( test_chain_kind chain_kind, uint32_t chain_id ) { + require_auth(get_self()); + outposts.emplace(get_self(), [&](auto& o) { + o.id = outposts.available_primary_key(); + o.chain_kind = chain_kind; + o.chain_id = chain_id; + }); +} + +ACTION abigen_test_enum_table::regoperator( name account, test_status status ) { + require_auth(get_self()); + operators.emplace(get_self(), [&](auto& o) { + o.account = account; + o.status = status; + }); +} diff --git a/tools/toolchain-tester/examples/abigen-pass/abigen_test_enum_table.json b/tools/toolchain-tester/examples/abigen-pass/abigen_test_enum_table.json new file mode 100644 index 000000000..4ed65cd00 --- /dev/null +++ b/tools/toolchain-tester/examples/abigen-pass/abigen_test_enum_table.json @@ -0,0 +1,9 @@ +{ + "tests": [ + { + "expected": { + "abi": "{\n \"____comment\": \"This file was generated with sysio-abigen. DO NOT EDIT \",\n \"version\": \"sysio::abi/1.2\",\n \"types\": [\n {\n \"new_type_name\": \"B_pair_test_chain_kind_checksum256_E\",\n \"type\": \"pair_test_chain_kind_checksum256\"\n }\n ],\n \"structs\": [\n {\n \"name\": \"operator_info\",\n \"base\": \"\",\n \"fields\": [\n {\n \"name\": \"account\",\n \"type\": \"name\"\n },\n {\n \"name\": \"status\",\n \"type\": \"test_status\"\n },\n {\n \"name\": \"chain_addresses\",\n \"type\": \"B_pair_test_chain_kind_checksum256_E[]\"\n }\n ]\n },\n {\n \"name\": \"outpost_info\",\n \"base\": \"\",\n \"fields\": [\n {\n \"name\": \"id\",\n \"type\": \"uint64\"\n },\n {\n \"name\": \"chain_kind\",\n \"type\": \"test_chain_kind\"\n },\n {\n \"name\": \"chain_id\",\n \"type\": \"uint32\"\n }\n ]\n },\n {\n \"name\": \"pair_test_chain_kind_checksum256\",\n \"base\": \"\",\n \"fields\": [\n {\n \"name\": \"first\",\n \"type\": \"test_chain_kind\"\n },\n {\n \"name\": \"second\",\n \"type\": \"checksum256\"\n }\n ]\n },\n {\n \"name\": \"regoperator\",\n \"base\": \"\",\n \"fields\": [\n {\n \"name\": \"account\",\n \"type\": \"name\"\n },\n {\n \"name\": \"status\",\n \"type\": \"test_status\"\n }\n ]\n },\n {\n \"name\": \"regoutpost\",\n \"base\": \"\",\n \"fields\": [\n {\n \"name\": \"chain_kind\",\n \"type\": \"test_chain_kind\"\n },\n {\n \"name\": \"chain_id\",\n \"type\": \"uint32\"\n }\n ]\n }\n ],\n \"actions\": [\n {\n \"name\": \"regoperator\",\n \"type\": \"regoperator\",\n \"ricardian_contract\": \"\"\n },\n {\n \"name\": \"regoutpost\",\n \"type\": \"regoutpost\",\n \"ricardian_contract\": \"\"\n }\n ],\n \"tables\": [\n {\n \"name\": \"operators\",\n \"type\": \"operator_info\",\n \"index_type\": \"i64\",\n \"key_names\": [],\n \"key_types\": []\n },\n {\n \"name\": \"outposts\",\n \"type\": \"outpost_info\",\n \"index_type\": \"i64\",\n \"key_names\": [],\n \"key_types\": []\n }\n ],\n \"ricardian_clauses\": [],\n \"variants\": [],\n \"action_results\": [],\n \"enums\": [\n {\n \"name\": \"test_chain_kind\",\n \"type\": \"uint8\",\n \"values\": [\n {\n \"name\": \"CHAIN_KIND_UNKNOWN\",\n \"value\": 0\n },\n {\n \"name\": \"CHAIN_KIND_WIRE\",\n \"value\": 1\n },\n {\n \"name\": \"CHAIN_KIND_ETHEREUM\",\n \"value\": 2\n },\n {\n \"name\": \"CHAIN_KIND_SOLANA\",\n \"value\": 3\n }\n ]\n },\n {\n \"name\": \"test_status\",\n \"type\": \"uint8\",\n \"values\": [\n {\n \"name\": \"WARMUP\",\n \"value\": 1\n },\n {\n \"name\": \"ACTIVE\",\n \"value\": 2\n },\n {\n \"name\": \"COOLDOWN\",\n \"value\": 3\n },\n {\n \"name\": \"TERMINATED\",\n \"value\": 240\n }\n ]\n }\n ]\n}" + } + } + ] +}