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

autoload: Add abiFillEmptyNames helper #150

Merged
merged 12 commits into from
Nov 8, 2024
Merged

Conversation

yohamta
Copy link
Contributor

@yohamta yohamta commented Nov 7, 2024

This PR addresses #148

Changes overview:

  • Added the abiFillEmptyNames helper function and necessary types
  • Added the abiHelpers option to the AutoloadConfig

Copy link
Owner

@shazow shazow left a comment

Choose a reason for hiding this comment

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

Overall looks good, just a couple nits/questions. The main thing is I think I'd prefer to put this in abi.ts rather than make a helpers.ts, let me know what you think!

src/helpers.ts Outdated Show resolved Hide resolved
src/helpers.ts Outdated Show resolved Hide resolved
src/helpers.ts Outdated
export function abiFillEmptyNames(abi: ABI): ABI {
function processComponents(components: ABIInOut[]): void {
components.forEach((component, index) => {
component.name ||= `field${index}`;
Copy link
Owner

Choose a reason for hiding this comment

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

Should probably refer to them as "parameter" rather than "field? per https://docs.soliditylang.org/en/latest/abi-spec.html

Is there a convention to hint that it's not an official name? Underscore-prefix or something?

I liked your original idea of just doing _{index} because it "looks" more generative, but I could be convinced for something else.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How about _p{index}? We initially tried _{index}, but geth requires at least one alphabetical character.

Copy link
Owner

Choose a reason for hiding this comment

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

Ah. How about _param{index} then?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I’ve updated it to _p{index} with commit add0386

Copy link
Contributor Author

@yohamta yohamta Nov 8, 2024

Choose a reason for hiding this comment

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

Oh sorry, I missed the comment. Updated it to _param{index}: 1b24265

Choose a reason for hiding this comment

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

@shazow @yohamta I think param is okay, but if we're going by the ABI spec that shazow shared above, wouldn't it be component for tuples and not parameter?

Copy link
Owner

@shazow shazow Nov 8, 2024

Choose a reason for hiding this comment

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

I'm just going by this:

name: the name of the parameter.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, you're right. Since we're dealing with components, using _comp{index} might make sense too, I think.

@yohamta yohamta requested a review from shazow November 8, 2024 01:13
src/auto.ts Outdated
* @group Settings
* @experimental
*/
abiHelpers?: Array<(abi: ABI) => ABI>;
Copy link
Owner

@shazow shazow Nov 8, 2024

Choose a reason for hiding this comment

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

This still doesn't feel great to me, because the code difference is...

const result = whatsabi.autoload(address, { provider, abiHelpers: [whatsabi.abi.abiFillEmptyNames] })
result.abi // use it

vs

const result = whatsabi.autoload(address, { provider })
whatsabi.abi.abiFillEmptyNames(result.abi) // use it

Which doesn't feel like it warrants putting it into autoload?

Also now I'm thinking maybe it should be whatsabi.abi.fillEmptyNames, but I can update that later.

By the way, are you using enableExperimentalMetadata?

Copy link
Contributor Author

@yohamta yohamta Nov 8, 2024

Choose a reason for hiding this comment

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

Sure, let's remove it from autoload for now: 32be43b

I also renamed the function: 2ba3e9e

We're using enableExperimentalMetadata, though we’re not entirely sure if it's necessary at this point.

Copy link
Owner

Choose a reason for hiding this comment

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

I'd feel more comfortable making it default under the enableExperimentalMetadata flag, since I don't think many people use it so it won't be very breaking (plus it is experimental).

Also I think WhatsABI would only generate types with empty names with that flag enabled? Or I might be mistaken.

Copy link
Owner

Choose a reason for hiding this comment

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

Appreciate the changes. No need to make further changes, just brainstorming at the moment. :)

@yohamta yohamta requested a review from shazow November 8, 2024 01:37
@yohamta
Copy link
Contributor Author

yohamta commented Nov 8, 2024

Thanks for the great review! I just pushed a small fix in the comment part: 6f618fc

@shazow
Copy link
Owner

shazow commented Nov 8, 2024

Thanks for the PR and rapid iterations. :)

I'll take a closer look tomorrow and merge this.

@shazow shazow merged commit 4f24657 into shazow:main Nov 8, 2024
0 of 3 checks passed
@yohamta yohamta deleted the disasm-helper branch November 10, 2024 12:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants