Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Fixed Bug Ignoring Action Name in ABI Generation #5459

Merged
merged 1 commit into from
Aug 28, 2018

Conversation

xJonathanLEI
Copy link
Contributor

Problem

There is currently a bug in ABI generation with the program eosio-abigen. For a comment like:

@abi action hi

The action name hi is ignored for good. The tool simple takes the method name and put it in the name field of the action.

This is NOT an intended behavior as shown by the RegEx found in the file abi_generator.cpp:

(@abi (action)((?: [a-z0-9]+)*))

Obviously, there is supposed to be an optional trailing action name.

The Need to Fix it

Sometimes we may want to use action names that are not allowed to be method names (e.g. C++ keywords like register). In this case, we would manually wire the request to a method with a different name as the action.

Cause

The problem is two-fold:

Incorrect RegEx

The third match of the following comment under the current RegEx would be <space>hi:

@abi action hi

If the name is used directly, an error would be thrown due to invalid format.

Name was Set to method_name Directly

The following line is found in the file abi_generator.cpp:

output->actions.push_back({method_name, method_name, rc[method_name]});

The program puts method_name for both the name and type fields unconditionally, without respecting the action name specified in the comment.

Solution

Fix the RegEx

The original RegEx:

(@abi (action)((?: [a-z0-9]+)*))

was changed to:

(@abi (action) ?((?:[a-z0-9]+)*))

so that the action name can be captured properly.

Capture the Optional Name if Present

A new variable action_name_from_comment is defined to capture the action name when raw_comment_is_action is true, and use it over method_name when it's not empty.

Result

After the fix, the following action:

/// @abi action hi
void hey(account_name user)
{
  print("Hello ", name{user});
}

can be correctly transformed to:

{
  "name": "hi",
  "type": "hey",
  "ricardian_contract": ""
}

@heifner heifner added this to the Version 1.2.3 milestone Aug 28, 2018
@heifner heifner merged commit a4096cb into EOSIO:release/1.2.x Aug 28, 2018
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.

3 participants