Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Internal improvement: Move selector computation from codec into abi-utils #5465

Merged
merged 4 commits into from
Aug 24, 2022

Conversation

haltman-at
Copy link
Contributor

This PR moves code for computing signatures and selectors from codec into abi-utils. Note that we continue to re-export these functions from Codec, in order to avoid a breaking change. I also added a few tests of these functions in abi-utils -- not property-based, sorry, I couldn't figure out a good way to do that. On top of that, I expanded the abi-utils README to cover this new functionality.

Since this PR is mostly just moving code around and not changing it, there's not a lot to say here about the code itself. However, I wanted to record why I'm doing this.

Basically, it comes back to the abi-to-sol problem. I want to be able to make breakiing changes to Codec without a repeat of the problem that caused last time (see #5396 for an explanation). This is the only code from Codec that abi-to-sol uses. Moving it to abi-utils will of course not get rid of the problem, but it reduces it, since it means that the problem will only come up when we break abi-utils rather than when we break codec. Since we break abi-utils hardly ever, and break codec somewhat frequently, this acts as a stopgap to allow us to avoid problems until we figure out a better solution.

@cds-amal
Copy link
Member

Basically, it comes back to the abi-to-sol problem. I want to be able to make breakiing changes to Codec without a repeat of the problem that caused last time (see #5396 for an explanation). This is the only code from Codec that abi-to-sol uses. Moving it to abi-utils will of course not get rid of the problem, but it reduces it, since it means that the problem will only come up when we break abi-utils rather than when we break codec. Since we break abi-utils hardly ever, and break codec somewhat frequently, this acts as a stopgap to allow us to avoid problems until we figure out a better solution.

This makes sense! Good call.

@haltman-at
Copy link
Contributor Author

More specifically the reason it came up is because I'm planning a substantial Codec breakage to deal with this internal function pointers problem. :P

Btw, you may notice I added the new-feature: @truffle/abi-utils label and then removed it. I added it because, duh, it's a new feature for abi-utils! I removed it because, oh right, abi-utils is still in 0.x, so there's no distinction between a new feature and a breaking change... so if we increment the minor version number, we'll hit the exact problem I'm trying to avoid. >_> So much for semver...

Copy link
Contributor

@eggplantzzz eggplantzzz left a comment

Choose a reason for hiding this comment

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

I like it

Copy link
Member

@cds-amal cds-amal left a comment

Choose a reason for hiding this comment

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

I have a question about the regex type matching, but otherwise looks good!

Comment on lines 19 to 21
const tupleMatch = parameter.type.match(/tuple(.*)/);
if (tupleMatch === null) {
//does not start with "tuple"
Copy link
Member

Choose a reason for hiding this comment

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

The comment says does not start with tuple but the regex doesn't use ^. Is that correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops! Good catch. This code will work anyway, because there's no other place that tuple can occur, but I should change it to not rely on that, thanks.

@haltman-at haltman-at merged commit a6bb433 into develop Aug 24, 2022
@haltman-at haltman-at deleted the abi-to-abi branch August 24, 2022 19:56
@haltman-at
Copy link
Contributor Author

Putting the label back on at @gnidan's insistence.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants