-
Notifications
You must be signed in to change notification settings - Fork 104
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: add abigen!
macro
#475
Conversation
Just seen that Maybe we want two ways of initialize the contract: // For calls only.
let contract = MyContract::new(address, provider);
// For invoke and calls.
let contract = MyContract::new_with_account(address, account); And internally, we use the provider if present in case 1, or the one from the account in case 2. *** EDIT *** |
As we need the type match for deserialization, the item path is expecting , which fails if we pass a slice
interfaces define some functions that are exposed by the contract. Can it be interesting to split them?
@xJonathanLEI let me know when you would have time for a first review, in order to keep going forward with this feature. 👍 I am exploring a new version where every interface in the ABI is implemented in a trait, this IMO can be helpful to easily switch targeted contracts without changing the actual code using them. |
Other idea that may be interesting, we can add some option for the code generation. For instance, it can be useful sometimes to get access to the |
Hey:)! At Kakarot, we're super interested in such a feature, any ETA or reason why it shouldn't more forward for now? |
Hey! Currently re-working the code to enhance the proposal in this PR using Syn crate to parse types and enhancing devX following alloy nomenclature. This will allow more flexibility on configuration for the calls and invokes. |
Here is the first draft for
abigen!
macro.Issues
fixes #286
fixes #445
Usage
This macro aims at being used like:
Code organization
The code is separated in 3 parts:
cairo_types
which contains the mapping of Cairo native types into rust types.parser
contains all the logic to parse ABI as a JSON, where types are strings, and totally flatten. This is where the generic types are detected and applied to each member/variant or struct/enum.abigen
contains the code logic related to macro expansion and code generation.Examples
Two examples were added:
abigen.rs
contains the very basic usage working on testnet with user addresses.abigen_event.rs
shows howabigen!
facilitate the deserialization of events.