-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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(forge-bind): add_derives
for serde in contract bindings
#5836
feat(forge-bind): add_derives
for serde in contract bindings
#5836
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.
this looks fine, however, I think we're missing support for configuring additional Cargo.toml dependencies in Abigen.
ideally serde would be added to the generated Cargo.toml as well.
currently we're only setting ethers:
so we need a way to also configure additional deps.
I think this should go here:
something like dependencies: Vec<String>
I don't want to add this as an additional arg to write_to_crate
since this would break.
Okay got it. Let me work on this. |
Would it instead be a simpler change to do this: In this pub use serde::{Serialize, Deserialize} And then replace the add_derive("serde::Serialize") with add_derive("::ethers::contract::Serialize") and of course the respective change for Trying this on my end worked fine in both crate/module bindings. |
public re-exports for third-party crates are hacky, really don't like this solution for this |
another fix would be to append the serde dependency manually in forge bind, but ideal solution would be support in abigen |
I was working on this for a while today inside From what I can gather, there is a process like:
where finally the I considered adding a: add_dependency() for Do you have more thoughts on this? I want to do it the right way here! |
hmm, I think we only need this here: -> MultiBindings -> MultiBindingsInner this is where it's written: foundry/crates/forge/bin/cmd/bind.rs Lines 171 to 176 in 8c1a569
so similar to |
140b90a
to
6c350e7
Compare
I made a fix here that pushes the relevant dependency into the bindings when generated via a crate. It will have to come after the change in |
Once we get ethers-rs issue 2606 in, can we revisit this as well? |
This has been fixed in Ethers |
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.
ty for this!
sorry for the delay
Motivation
The change was made to close #5835 which would allow users to get more functionality out of enums/structs in contract bindings, e.g., parse contract events from a chain into a file format such as CSV.
Solution
This is a basic solution where we just add in the
serde::Serialize
andserde:Deserialize
traits via theadd_derives
method onAbigen
. This does not give the end user any option in deriving these traits and, perhaps they may not want them.I am happy to provide flags as such described in #5835. Please let me know what you prefer.