This repository has been archived by the owner on Oct 19, 2024. It is now read-only.
feat: add struct parsing support for human readable ABI #226
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.
This adds support for parsing solidity structs in the humand readable ABI.
A new
AbiParser
can parse structs, turn them into tuples and substitute their references in events and functions.Also this improves the error handling with textual feedback about the error that occurred.
Additional tests are tests are added as well.
Motivation
Support for structs in the human readable ABI makes it easier to copy definitions from your solidity contract without further modifications.
Solution
The
SolStruct
can parse solidity structs, supported features are:ethabi::ParamType
), likeint25 _y;
String
, likeMyStruct m;
andMostOuter.Outer.Inner m;
MyStruct[] m;
andMyStruct[10] m;
mapping(string => string)
andmapping(string => mapping(string => string))
A new
AbiParser
is introduced that handles struct parsing and replacing them as tuples, either within structs or in event and function arguments.Substitution is based on the following rules:
struct S {int x; int y;}
=>tuple(int,int)
function(S[] _s)
=>tuple(int,int)[]
andfunction(S[10] _s)
=>tuple(int,int)[10]
struct X {S s; address a;}
=> `tuple(tuple(int,int),address)AbiParser
The
parse
api remaines unchanged but its code is replacedAbiParser::default().parse(s)