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

feat(json-abi): add full_signature #480

Merged
merged 4 commits into from
Jan 9, 2024
Merged

feat(json-abi): add full_signature #480

merged 4 commits into from
Jan 9, 2024

Conversation

BrennerSpear
Copy link
Contributor

@BrennerSpear BrennerSpear commented Jan 8, 2024

Motivation

I’m working on a ABI fragments database so we can fill in function and event data for contracts that haven’t been verified, but we having a matching ABI fragment for from another contract.

We’re going to have each row be unique based on the full_signature, which includes the name of each param, for events, whether the param is indexed or not, and for functions, the state mutability

In ethers.js, there is a fragment FormatTypes.full that can generate the full signature for you.

https://docs.ethers.org/v5/api/utils/abi/fragments/#fragments--output-formats

some maximally illustrative examples:
function batchSwapExactIn(tuple(address pool, uint256 tokenInParam, uint256 tokenOutParam, uint256 maxPrice)[] swaps, address tokenIn, address tokenOut, uint256 totalAmountIn, uint256 minTotalAmountOut) payable returns (uint256 totalAmountOut)

event SetupDirectDebit(address indexed debtor, address indexed receiver, tuple(uint256 amount, uint256 startTime, uint256 interval) info)

Solution

I've added a .full_signature() function to the Function and Event structs

PR Checklist

  • Added Tests
  • Added Documentation
  • No Breaking changes

Notes

Functions already have signature_full that includes the output types. This is pretty close to full_signature as a name. Are we fine with that or do we need to think of a different name for full_signature?

I thought about trying to overload some of the functions instead of making additional functions prepended with full_, but I don’t think it’d make it any cleaner.

* WIP probably working

* add tests

* nits

add more comment

clean up
Copy link
Member

@DaniPopes DaniPopes left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks!

crates/json-abi/src/param.rs Outdated Show resolved Hide resolved
crates/json-abi/src/param.rs Outdated Show resolved Hide resolved
crates/json-abi/src/item.rs Show resolved Hide resolved
crates/json-abi/src/item.rs Outdated Show resolved Hide resolved
crates/json-abi/src/item.rs Outdated Show resolved Hide resolved
BrennerSpear and others added 2 commits January 9, 2024 15:11
Co-authored-by: DaniPopes <57450786+DaniPopes@users.noreply.github.com>
@DaniPopes DaniPopes merged commit 49e347b into alloy-rs:main Jan 9, 2024
21 checks passed
@yorhodes
Copy link

is this relevant? https://www.4byte.directory/

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