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

Reuse same type parsing for defaultAbiCoder.encode as in utils.Interface #360

Closed
snario opened this issue Dec 4, 2018 · 4 comments
Closed
Assignees
Labels
enhancement New feature or improvement.

Comments

@snario
Copy link

snario commented Dec 4, 2018

If I have

const ENCODING = `
  tuple(
    address foo,
    bytes4 bar
  )`;

Then the following will work:

new ethers.utils.Interface([ENCODING]).encode({ foo, bar });

However the following will error:

ethers.utils.defaultAbiCoder.encode([ENCODING], [{ foo, bar }]);

Like so:

    unexpected character "a" at position 22 in "
      tuple(
        address foo,
        bytes4 bar
      )"

I think it is because different parsing logic is used? @ricmoo

@ricmoo
Copy link
Member

ricmoo commented Dec 4, 2018

I think this is because I don’t handle newline as whitespace... I can look into it. I can probably just replace \n with space...

@ricmoo
Copy link
Member

ricmoo commented Dec 4, 2018

Oh. Looking at the above code again, you are using Interface, which expects a function of sent signature, not a type.

In the first example it works in the first case because you are constructing a function named tuple, which takes in an address and a bytes4. It has nothing to do with an actual tuple.

I have confirmed the issue you are experiencing is the newlines. For now, if you use ENCODING.replace(/\n/g, '') it will work fine. I will look into treating those as normal whitespace for the aBI coder.

@ricmoo ricmoo self-assigned this Dec 4, 2018
@ricmoo ricmoo added enhancement New feature or improvement. on-deck This Enhancement or Bug is currently being worked on. labels Dec 4, 2018
@snario
Copy link
Author

snario commented Dec 4, 2018

Ah, makes sense, thanks @ricmoo. It remains to be the case that it works for this, too:

new ethers.utils.Interface([`foobar(${ENCODING})`]).encode({ foo, bar });

@ricmoo
Copy link
Member

ricmoo commented Dec 4, 2018

You should be able to safely use newline (or any other whitespace) now in the human-readable ABI, in version4.0.16. Let me know if there are still problems, and feel free to re-open this issue.

Thanks! :)

@ricmoo ricmoo closed this as completed Dec 4, 2018
@ricmoo ricmoo removed the on-deck This Enhancement or Bug is currently being worked on. label Dec 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or improvement.
Projects
None yet
Development

No branches or pull requests

2 participants