-
Notifications
You must be signed in to change notification settings - Fork 20.9k
cmd/abigen, accounts/abi/bind: implement abigen version 2 #26782
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
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.
Looks pretty cool! I don't like the *2
naming, but I guess Felix likes it, so I won't argue to hard against it. I'm going to do some more tests and then approve
Something is broken here:
With this contract it produces invalid code:
Produced code:
(out is never used) I think the issue is that you generate Unpacking functions for solidity functions that have no return value. |
You should probably do with fmt the same thing as with the other imports: |
Aha, we don't need an unpack method when there are no return params. |
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.
Please add some tests, and more documentation.
@s1na are you still actively working on this PR? It is of interest to our project so we would be willing to devote some time to helping getting it over the line. Our use case is: we are building a state channel client in Go. Currently, it manages a private key, and acts as a signer. It uses the One suggestion I would have is to maintain backward compatibility with the current version of |
Hi @geoknee, great to see your interest in this PR. I'm not actively working on this, although I plan to finish it at some point. Your help is appreciated. I want to first address
We really want to get v2 out instead of packing more features into v1. I saw you have already generated v2 bindings for your contract. It'd be already great to hear if things are working and you've had any friction points. The biggest outstanding point is to add a test suite for v2. |
Fair enough, we can use both side by side in our project without too much pain.
I did spot a couple of problems:
statechannels/go-nitro@a1e9dd7 I pushed a fix here s1na#10.
|
c044348
to
008028e
Compare
accounts/abi/bind/v2/v2_test.go
Outdated
"context" | ||
"encoding/json" | ||
"github.com/ethereum/go-ethereum/accounts/abi/bind/backends" | ||
"github.com/ethereum/go-ethereum/accounts/abi/bind/testdata/v2_generated_testcase" |
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.
Build fails on this import atm
@MariusVanDerWijden I have a few things I am trying to wrap with this. It's in a bit of a messy state, and I'd ask to hold off on review until I can get this finished (couple of hours). |
The
Especially for fallback, it can support |
So in this case, the input to That being said, I'm fine with generating packing functions when fallback/receive are defined (and an unpack if |
I found out that if a Even if this could be fixed in solidity, we still have to deal with the current behavior. Accordingly, I think the best option for us will be to provide generic pack/unpack for fallback from |
…utputs should be gathered into a struct
…alizeArgs returns args with names that start lowercase.
Is this ready to be merged ? or will it be merged any time soon ? |
…pdate any bindings that were stale (all changed because I used a newer version of solc)
@wisehalvdan soon! |
… utilties. Better documentation indicating the intended use of DefaultDeployer and the deployment options available.
… be used with contract bindings generated with --v2. Simplify Transact impl
Before we merge this, I want to reopen so that I get main authorship of the PR. |
This PR adds a new version of abigen which will co-exist parallel to the existing version for a while. To generate v2 bindings provide the
--v2
flag toabigen
cmd.Summary
The main point of abigen v2 is having a lightweight generated binding which allows for more composability. This is possible now thanks to Go generics. "only" methods to pack and unpack call and return data are generated for a contract. As well as unpacking of logs.
To interact with the contract a library is available with functions such as
Call
,Transact
,FilterLogs
, etc. These take in the packed calldata, or a function pointer to unpack return data.Features
The new version is at feature-parity with v1 at a much lower generated binding size. The only missing feature as of now is sessions.
Example
V1 and v2 bindings for a sample contract are available here: https://gist.github.com/s1na/05f2d241b07372b41ba1747ce6e098b7. A sample script using v2 is available in
main.go
.