AntelopeIO / abieos

Other
2 stars 12 forks source link

"Invalid nesting" error when trying to use an optional vector in ABI #26

Open michael-drygola opened 7 months ago

michael-drygola commented 7 months ago

I've got an EOS smart contract which uses std::optional<std::vector<eosio::name>> as a type of one of its fields. When compiled with AntelopeIO CDT v4.0.1, it produces an ABI which seems to be valid and works fine when deployed to blockchain. However, the abieos lib fails to parse the ABI and throws an "Invalid nesting" error.

Here is a minimum reproducible code to illustrate the problem:

#include <abieos.h>
#include <iostream>

int main( int argc, char** argv ) {
    const char *bad_abi = R"(
    {
      "version": "eosio::abi/1.2",
      "types": [{
          "new_type_name": "B_vector_name_E",
          "type": "name[]"
        }
      ],
      "structs": [{
          "name": "actionname",
          "base": "",
          "fields": [{
              "name": "opt_list",
              "type": "B_vector_name_E?"
            }
          ]
        }
      ],
      "actions": [{
          "name": "actionname",
          "type": "actionname",
          "ricardian_contract": ""
        }
      ],
      "ricardian_clauses": [],
      "error_messages": [],
      "abi_extensions": [],
      "variants": [],
      "action_results": []
    }
    )";

    auto context = abieos_create ();
    if (abieos_set_abi (context, 1, bad_abi)) {
        std::cout << "OK";
    } else {
        std::cout << abieos_get_error (context); // getting "Invalid nesting" here
    }

    return 0;
}

Considering this ABI is valid, would be nice to add support of such nested structures to the lib :)

igorls commented 1 week ago

I believe this might fall in the same case as https://github.com/AntelopeIO/abieos/pull/35 although for optional arrays further testing might be needed