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

Generate Solidity style full descriptions of functions/events/structs #71

Merged
merged 9 commits into from
Aug 12, 2024

Conversation

peterbroadhurst
Copy link
Contributor

@peterbroadhurst peterbroadhurst commented Aug 11, 2024

In PR chain with #70

solDef, childStructs, err := abi.Functions()["invoice"].SolidityDef()
assert.NoError(t, err)
assert.Equal(t, "function invoice(Invoice memory _invoice) external payable { }", solDef)
assert.Equal(t, []string{
"struct Customer { address owner; bytes32 locator; }",
"struct Widget { string description; uint256 price; string[] attributes; }",
"struct Invoice { Customer customer; Widget[] widgets; }",
}, childStructs)
solDef, childStructs, err = abi.Events()["Invoiced"].SolidityDef()
assert.NoError(t, err)
assert.Equal(t, "event Invoiced(Customer customer, Widget[] widgets)", solDef)
assert.Equal(t, []string{
"struct Customer { address owner; bytes32 locator; }",
"struct Widget { string description; uint256 price; string[] attributes; }",
}, childStructs)

There are cases where we need to build descriptors of functions/events (and their containing structures) that preserve the full information of how they will be parsed/serialized.

For example when determining if the list of event definitions, including containing type names, is identical to another list.

This PR provides that feature, and does it uses Solidity as the inspiration for the formatting, which makes it human readable.

The solidity strings have the characteristic that they uniquely identify each function, including where overrides are used.

Signed-off-by: Peter Broadhurst <peter.broadhurst@kaleido.io>
…nctions

Signed-off-by: Peter Broadhurst <peter.broadhurst@kaleido.io>
…s/structs

Signed-off-by: Peter Broadhurst <peter.broadhurst@kaleido.io>
Signed-off-by: Peter Broadhurst <peter.broadhurst@kaleido.io>
@peterbroadhurst peterbroadhurst changed the title Solidity defs Generate Solidity style full descriptions of functions/events/structs Aug 12, 2024
buff.WriteRune(')')

if isFunction {
buff.WriteString(" external")
Copy link
Contributor

Choose a reason for hiding this comment

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

Why include "external" in the descriptor if it's the same for all functions? Is it just to make it read more like a proper Solidity function definition?

Copy link
Contributor Author

@peterbroadhurst peterbroadhurst Aug 12, 2024

Choose a reason for hiding this comment

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

Exactly that.
It allows you to paste it into a code editor in an interface or actual .sol file and it work as-is

pkg/abi/abidecode_test.go Outdated Show resolved Hide resolved
Copy link
Contributor

@awrichar awrichar left a comment

Choose a reason for hiding this comment

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

I asked some questions inline, but I think this looks good.

Signed-off-by: Peter Broadhurst <peter.broadhurst@kaleido.io>
Signed-off-by: Peter Broadhurst <peter.broadhurst@kaleido.io>
Signed-off-by: Peter Broadhurst <peter.broadhurst@kaleido.io>
Signed-off-by: Peter Broadhurst <peter.broadhurst@kaleido.io>
@peterbroadhurst peterbroadhurst merged commit c2aa0ba into main Aug 12, 2024
2 checks passed
@peterbroadhurst peterbroadhurst mentioned this pull request Aug 20, 2024
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.

2 participants