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(abigen): add provided derives for call and event enums #721

Merged
merged 2 commits into from Dec 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -23,6 +23,8 @@

## ethers-contract-abigen

- Add provided `event_derives` to call and event enums as well
[#721](https://github.com/gakonst/ethers-rs/pull/721).
- Implement snowtrace and polygonscan on par with the etherscan integration
[#666](https://github.com/gakonst/ethers-rs/pull/666).

Expand Down
8 changes: 5 additions & 3 deletions ethers-contract/ethers-contract-abigen/src/contract/events.rs
Expand Up @@ -61,13 +61,15 @@ impl Context {
.map(|e| expand_struct_name(e, self.event_aliases.get(&e.abi_signature()).cloned()))
.collect::<Vec<_>>();

let enum_name = self.expand_event_enum_name();

let ethers_core = ethers_core_crate();
let ethers_contract = ethers_contract_crate();

// use the same derives as for events
let derives = util::expand_derives(&self.event_derives);
let enum_name = self.expand_event_enum_name();

quote! {
#[derive(Debug, Clone, PartialEq, Eq, #ethers_contract::EthAbiType)]
#[derive(Debug, Clone, PartialEq, Eq, #ethers_contract::EthAbiType, #derives)]
pub enum #enum_name {
#(#variants(#variants)),*
}
Expand Down
Expand Up @@ -105,11 +105,14 @@ impl Context {
let ethers_core = ethers_core_crate();
let ethers_contract = ethers_contract_crate();

// use the same derives as for events
let derives = util::expand_derives(&self.event_derives);
let enum_name = self.expand_calls_enum_name();

Ok(quote! {
#struct_def_tokens

#[derive(Debug, Clone, PartialEq, Eq, #ethers_contract::EthAbiType)]
#[derive(Debug, Clone, PartialEq, Eq, #ethers_contract::EthAbiType, #derives)]
pub enum #enum_name {
#(#variant_names(#struct_names)),*
}
Expand Down