Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AbiItem parsing from human readable ABI does not allow for state mutibility keywords #681

Closed
0xfourzerofour opened this issue Jun 24, 2024 · 2 comments · Fixed by #682
Closed
Labels
bug Something isn't working

Comments

@0xfourzerofour
Copy link

Component

dyn-abi, json-abi

What version of Alloy are you on?

0.1.0

Operating System

macOS (Apple Silicon)

Describe the bug

I am trying to parse the following human readable ABI into an AbitItem (AbitItem::Function to be specific) however when I pass it into the parse function I get the following error.

function balanceOf(address owner) view returns (uint256 balance)
Error: parser error:
balanceOf(address owner) view returns (uint256 balance)

When I remove the state mutability keyword "view" it will not give me the error

@0xfourzerofour 0xfourzerofour added the bug Something isn't working label Jun 24, 2024
@0xfourzerofour
Copy link
Author

0xfourzerofour commented Jun 24, 2024

I have tried using both the following setups but end up with the same result

        let item: AbiItem = data.function_signature.parse()?;
        println!("item {:?}", item);
        let function: Function = data.function_signature.parse()?;
        println!("function {:?}", function);

@0xfourzerofour
Copy link
Author

Looking at the implementation of the parser this may be a little harder to do than I thought to make it work for ParseSigTuple<Param>

/// Returns `(name, inputs, outputs, anonymous)`.
#[doc(hidden)]
pub fn parse_signature<'a, const OUT: bool, F: Fn(ParameterSpecifier<'a>) -> T, T>(
    s: &'a str,
    f: F,
) -> Result<(String, Vec<T>, Vec<T>, bool)> {
    trace(
        "signature",
        (
            RootType::parser.map(|x| x.span().into()),
            preceded(space0, tuple_parser(ParameterSpecifier::parser.map(&f))),
            |i: &mut _| {
                if OUT {
                    preceded(
                        (space0, opt(":"), opt("returns"), space0),
                        opt(tuple_parser(ParameterSpecifier::parser.map(&f))),
                    )
                    .parse_next(i)
                    .map(Option::unwrap_or_default)
                } else {
                    Ok(vec![])
                }
            },
            preceded(space0, opt("anonymous").map(|x| x.is_some())),
        ),
    )
    .parse(s)
    .map_err(Error::parser)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant