-
-
Notifications
You must be signed in to change notification settings - Fork 77
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
Conversation
There was a problem hiding this 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
export function abiFillEmptyNames(abi: ABI): ABI { | ||
function processComponents(components: ABIInOut[]): void { | ||
components.forEach((component, index) => { | ||
component.name ||= `field${index}`; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
src/auto.ts
Outdated
* @group Settings | ||
* @experimental | ||
*/ | ||
abiHelpers?: Array<(abi: ABI) => ABI>; |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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. :)
Thanks for the great review! I just pushed a small fix in the comment part: 6f618fc |
Thanks for the PR and rapid iterations. :) I'll take a closer look tomorrow and merge this. |
This PR addresses #148
Changes overview:
abiFillEmptyNames
helper function and necessary typesabiHelpers
option to theAutoloadConfig