Skip to content
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

Merged
merged 4 commits into from
Mar 15, 2021

Conversation

mattsse
Copy link
Collaborator

@mattsse mattsse commented Mar 13, 2021

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:

  • elementary datatypes (ethabi::ParamType), like int25 _y;
  • struct references as String, like MyStruct m; and MostOuter.Outer.Inner m;
  • struct arrays, fixed and unbounded: MyStruct[] m; and MyStruct[10] m;
  • mappings and nested mappings like mapping(string => string) and mapping(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:

  • a struct becomes a tuple: struct S {int x; int y;} => tuple(int,int)
  • a struct array becomes an array: function(S[] _s) => tuple(int,int)[] and function(S[10] _s) => tuple(int,int)[10]
  • nested structs become nested tuples: struct X {S s; address a;} => `tuple(tuple(int,int),address)
  • mappings are disallowed and lead to errors in the AbiParser

The parse api remaines unchanged but its code is replaced AbiParser::default().parse(s)

@gakonst gakonst self-requested a review March 14, 2021 15:06
@mattsse mattsse marked this pull request as draft March 14, 2021 21:13
@mattsse mattsse marked this pull request as ready for review March 14, 2021 23:02
Copy link
Owner

@gakonst gakonst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great, thank you.

@gakonst gakonst merged commit cf8e239 into gakonst:master Mar 15, 2021
meetmangukiya pushed a commit to meetmangukiya/ethers-rs that referenced this pull request Mar 21, 2022
* fix bad state reset

* fmt

* clippy
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.

2 participants