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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
There is currently a bug in ABI generation with the program
eosio-abigen
. For a comment like:The action name
hi
is ignored for good. The tool simple takes the method name and put it in thename
field of the action.This is NOT an intended behavior as shown by the RegEx found in the file
abi_generator.cpp
: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
:If the name is used directly, an error would be thrown due to invalid format.
Name was Set to
method_name
DirectlyThe following line is found in the file
abi_generator.cpp
:The program puts
method_name
for both thename
andtype
fields unconditionally, without respecting the action name specified in the comment.Solution
Fix the RegEx
The original RegEx:
was changed to:
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 whenraw_comment_is_action
is true, and use it overmethod_name
when it's not empty.Result
After the fix, the following action:
can be correctly transformed to: