Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Commit

Permalink
fix(abigen): add indexed attribute when deriving EthEvent (#255)
Browse files Browse the repository at this point in the history
* fix(abigen): add indexed attribute when deriving EthEvent

* chore(clippy): make clippy happy
  • Loading branch information
mattsse authored Apr 2, 2021
1 parent 5eb31ce commit 32b4e9e
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions ethers-contract/ethers-contract-abigen/src/contract/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ impl Context {
}

/// Expands an ABI event into name-type pairs for each of its parameters.
fn expand_params(&self, event: &Event) -> Result<Vec<(TokenStream, TokenStream)>> {
fn expand_params(&self, event: &Event) -> Result<Vec<(TokenStream, TokenStream, bool)>> {
event
.inputs
.iter()
Expand All @@ -206,7 +206,7 @@ impl Context {
let name = util::expand_input_name(i, &input.name);
let ty = self.expand_input_type(&input)?;

Ok((name, ty))
Ok((name, ty, input.indexed))
})
.collect()
}
Expand Down Expand Up @@ -308,21 +308,30 @@ fn expand_struct_name(event: &Event) -> Ident {
/// Expands an event data structure from its name-type parameter pairs. Returns
/// a tuple with the type definition (i.e. the struct declaration) and
/// construction (i.e. code for creating an instance of the event data).
fn expand_data_struct(name: &Ident, params: &[(TokenStream, TokenStream)]) -> TokenStream {
fn expand_data_struct(name: &Ident, params: &[(TokenStream, TokenStream, bool)]) -> TokenStream {
let fields = params
.iter()
.map(|(name, ty)| quote! { pub #name: #ty })
.map(|(name, ty, indexed)| {
if *indexed {
quote! {
#[ethevent(indexed)]
pub #name: #ty
}
} else {
quote! { pub #name: #ty }
}
})
.collect::<Vec<_>>();

quote! { struct #name { #( #fields, )* } }
}

/// Expands an event data named tuple from its name-type parameter pairs.
/// Returns a tuple with the type definition and construction.
fn expand_data_tuple(name: &Ident, params: &[(TokenStream, TokenStream)]) -> TokenStream {
fn expand_data_tuple(name: &Ident, params: &[(TokenStream, TokenStream, bool)]) -> TokenStream {
let fields = params
.iter()
.map(|(_, ty)| quote! { pub #ty })
.map(|(_, ty, _)| quote! { pub #ty })
.collect::<Vec<_>>();

quote! { struct #name( #( #fields ),* ); }
Expand Down

0 comments on commit 32b4e9e

Please sign in to comment.