2021-10-16 08:19:42 +00:00
|
|
|
//! Helper functions for deriving `EthEvent`
|
|
|
|
|
2021-11-05 13:00:01 +00:00
|
|
|
use ethers_contract_abigen::Source;
|
2021-10-16 08:19:42 +00:00
|
|
|
use proc_macro2::{Span, TokenStream};
|
|
|
|
use quote::quote;
|
2021-10-29 12:29:35 +00:00
|
|
|
use syn::{
|
2023-02-14 03:54:00 +00:00
|
|
|
parse::Error, spanned::Spanned, AttrStyle, Data, DeriveInput, Field, Fields, Lit, Meta,
|
2021-10-29 12:29:35 +00:00
|
|
|
NestedMeta,
|
|
|
|
};
|
2021-10-16 08:19:42 +00:00
|
|
|
|
2021-11-05 13:00:01 +00:00
|
|
|
use ethers_core::{
|
2022-06-27 00:26:43 +00:00
|
|
|
abi::{Event, EventExt, EventParam, HumanReadableParser},
|
2021-11-05 13:00:01 +00:00
|
|
|
macros::{ethers_contract_crate, ethers_core_crate},
|
|
|
|
};
|
2021-10-16 08:19:42 +00:00
|
|
|
use hex::FromHex;
|
|
|
|
|
2021-10-29 12:29:35 +00:00
|
|
|
use crate::{abi_ty, utils};
|
2021-10-16 08:19:42 +00:00
|
|
|
|
|
|
|
/// Generates the `EthEvent` trait support
|
2023-02-14 01:08:46 +00:00
|
|
|
pub(crate) fn derive_eth_event_impl(input: DeriveInput) -> Result<TokenStream, Error> {
|
2021-10-16 08:19:42 +00:00
|
|
|
let name = &input.ident;
|
2023-02-14 01:08:46 +00:00
|
|
|
let attributes = parse_event_attributes(&input)?;
|
2021-10-16 08:19:42 +00:00
|
|
|
|
|
|
|
let mut event = if let Some((src, span)) = attributes.abi {
|
2023-02-14 01:08:46 +00:00
|
|
|
// try to parse as a Solidity event
|
|
|
|
match HumanReadableParser::parse_event(&src) {
|
|
|
|
Ok(event) => Ok(event),
|
|
|
|
Err(parse_err) => {
|
|
|
|
match src.parse::<Source>().and_then(|s| s.get()) {
|
|
|
|
Ok(abi) => {
|
|
|
|
// try to derive the signature from the abi from the parsed abi
|
|
|
|
// TODO(mattsse): this will fail for events that contain other non
|
|
|
|
// elementary types in their abi because the parser
|
|
|
|
// doesn't know how to substitute the types.
|
|
|
|
// This could be mitigated by getting the ABI of each non elementary type
|
|
|
|
// at runtime and computing the the signature as a Lazy static.
|
|
|
|
match HumanReadableParser::parse_event(&abi) {
|
|
|
|
Ok(event) => Ok(event),
|
|
|
|
// Ignore parse_err since this is a valid [Source]
|
|
|
|
Err(err) => Err(Error::new(span, err)),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Err(source_err) => {
|
|
|
|
// Return both error messages
|
2023-02-14 03:54:00 +00:00
|
|
|
let mut error = Error::new(span, parse_err);
|
|
|
|
error.combine(Error::new(span, source_err));
|
|
|
|
Err(error)
|
2021-10-16 08:19:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// try to determine the abi from the fields
|
2023-02-14 01:08:46 +00:00
|
|
|
derive_abi_event_from_fields(&input)
|
|
|
|
}?;
|
2021-10-16 08:19:42 +00:00
|
|
|
|
2023-02-14 01:11:13 +00:00
|
|
|
if let Some((attribute_name, _)) = attributes.name {
|
|
|
|
event.name = attribute_name;
|
|
|
|
}
|
|
|
|
|
2021-10-16 08:19:42 +00:00
|
|
|
if let Some((anon, _)) = attributes.anonymous.as_ref() {
|
|
|
|
event.anonymous = *anon;
|
|
|
|
}
|
|
|
|
|
2023-02-14 01:08:46 +00:00
|
|
|
let decode_log_impl = derive_decode_from_log_impl(&input, &event)?;
|
2021-10-16 08:19:42 +00:00
|
|
|
|
2023-02-14 01:08:46 +00:00
|
|
|
let (abi, event_sig) = (event.abi_signature(), event.signature());
|
2021-10-16 08:19:42 +00:00
|
|
|
|
|
|
|
let signature = if let Some((hash, _)) = attributes.signature_hash {
|
|
|
|
utils::signature(&hash)
|
|
|
|
} else {
|
2023-02-14 01:08:46 +00:00
|
|
|
utils::signature(event_sig.as_bytes())
|
2021-10-16 08:19:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
let anon = attributes.anonymous.map(|(b, _)| b).unwrap_or_default();
|
2023-02-14 01:11:13 +00:00
|
|
|
let event_name = &event.name;
|
2021-10-16 08:19:42 +00:00
|
|
|
|
2023-02-14 01:08:46 +00:00
|
|
|
let ethers_core = ethers_core_crate();
|
|
|
|
let ethers_contract = ethers_contract_crate();
|
|
|
|
|
2021-10-16 08:19:42 +00:00
|
|
|
let ethevent_impl = quote! {
|
2023-02-14 01:08:46 +00:00
|
|
|
impl #ethers_contract::EthEvent for #name {
|
2021-10-16 08:19:42 +00:00
|
|
|
|
|
|
|
fn name() -> ::std::borrow::Cow<'static, str> {
|
|
|
|
#event_name.into()
|
|
|
|
}
|
|
|
|
|
2023-02-14 01:08:46 +00:00
|
|
|
fn signature() -> #ethers_core::types::H256 {
|
2021-10-16 08:19:42 +00:00
|
|
|
#signature
|
|
|
|
}
|
|
|
|
|
|
|
|
fn abi_signature() -> ::std::borrow::Cow<'static, str> {
|
|
|
|
#abi.into()
|
|
|
|
}
|
|
|
|
|
2023-02-14 01:08:46 +00:00
|
|
|
fn decode_log(log: &#ethers_core::abi::RawLog) -> ::std::result::Result<Self, #ethers_core::abi::Error> where Self: Sized {
|
2021-10-16 08:19:42 +00:00
|
|
|
#decode_log_impl
|
|
|
|
}
|
|
|
|
|
|
|
|
fn is_anonymous() -> bool {
|
|
|
|
#anon
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-02-14 03:54:00 +00:00
|
|
|
let tokenize_impl = abi_ty::derive_tokenizeable_impl(&input)?;
|
2021-10-16 08:19:42 +00:00
|
|
|
|
2023-02-14 01:08:46 +00:00
|
|
|
Ok(quote! {
|
2021-10-16 08:19:42 +00:00
|
|
|
#tokenize_impl
|
|
|
|
#ethevent_impl
|
2023-02-14 01:08:46 +00:00
|
|
|
})
|
2021-10-16 08:19:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Internal helper type for an event/log
|
|
|
|
struct EventField {
|
|
|
|
topic_name: Option<String>,
|
|
|
|
index: usize,
|
|
|
|
param: EventParam,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl EventField {
|
|
|
|
fn is_indexed(&self) -> bool {
|
|
|
|
self.topic_name.is_some()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn derive_decode_from_log_impl(
|
|
|
|
input: &DeriveInput,
|
|
|
|
event: &Event,
|
|
|
|
) -> Result<proc_macro2::TokenStream, Error> {
|
2023-02-14 01:08:46 +00:00
|
|
|
let ethers_core = ethers_core_crate();
|
2021-10-16 08:19:42 +00:00
|
|
|
|
|
|
|
let fields: Vec<_> = match input.data {
|
|
|
|
Data::Struct(ref data) => match data.fields {
|
|
|
|
Fields::Named(ref fields) => {
|
|
|
|
if fields.named.len() != event.inputs.len() {
|
|
|
|
return Err(Error::new(
|
|
|
|
fields.span(),
|
|
|
|
format!(
|
|
|
|
"EthEvent {}'s fields length don't match with signature inputs {}",
|
|
|
|
event.name,
|
|
|
|
event.abi_signature()
|
|
|
|
),
|
2021-10-29 12:29:35 +00:00
|
|
|
))
|
2021-10-16 08:19:42 +00:00
|
|
|
}
|
|
|
|
fields.named.iter().collect()
|
|
|
|
}
|
|
|
|
Fields::Unnamed(ref fields) => {
|
|
|
|
if fields.unnamed.len() != event.inputs.len() {
|
|
|
|
return Err(Error::new(
|
|
|
|
fields.span(),
|
|
|
|
format!(
|
|
|
|
"EthEvent {}'s fields length don't match with signature inputs {}",
|
|
|
|
event.name,
|
|
|
|
event.abi_signature()
|
|
|
|
),
|
2021-10-29 12:29:35 +00:00
|
|
|
))
|
2021-10-16 08:19:42 +00:00
|
|
|
}
|
|
|
|
fields.unnamed.iter().collect()
|
|
|
|
}
|
|
|
|
Fields::Unit => {
|
|
|
|
return Err(Error::new(
|
|
|
|
input.span(),
|
|
|
|
"EthEvent cannot be derived for empty structs and unit",
|
2021-10-29 12:29:35 +00:00
|
|
|
))
|
2021-10-16 08:19:42 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
Data::Enum(_) => {
|
2021-10-29 12:29:35 +00:00
|
|
|
return Err(Error::new(input.span(), "EthEvent cannot be derived for enums"))
|
2021-10-16 08:19:42 +00:00
|
|
|
}
|
|
|
|
Data::Union(_) => {
|
2021-10-29 12:29:35 +00:00
|
|
|
return Err(Error::new(input.span(), "EthEvent cannot be derived for unions"))
|
2021-10-16 08:19:42 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
let mut event_fields = Vec::with_capacity(fields.len());
|
|
|
|
for (index, field) in fields.iter().enumerate() {
|
|
|
|
let mut param = event.inputs[index].clone();
|
|
|
|
|
|
|
|
let (topic_name, indexed) = parse_field_attributes(field)?;
|
|
|
|
if indexed {
|
|
|
|
param.indexed = true;
|
|
|
|
}
|
2021-10-29 12:29:35 +00:00
|
|
|
let topic_name =
|
|
|
|
param.indexed.then(|| topic_name.or_else(|| Some(param.name.clone()))).flatten();
|
|
|
|
|
|
|
|
event_fields.push(EventField { topic_name, index, param });
|
2021-10-16 08:19:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// convert fields to params list
|
|
|
|
let topic_types = event_fields
|
|
|
|
.iter()
|
|
|
|
.filter(|f| f.is_indexed())
|
|
|
|
.map(|f| utils::topic_param_type_quote(&f.param.kind));
|
|
|
|
|
|
|
|
let topic_types_init = quote! {let topic_types = ::std::vec![#( #topic_types ),*];};
|
|
|
|
|
|
|
|
let data_types = event_fields
|
|
|
|
.iter()
|
|
|
|
.filter(|f| !f.is_indexed())
|
|
|
|
.map(|f| utils::param_type_quote(&f.param.kind));
|
|
|
|
|
|
|
|
let data_types_init = quote! {let data_types = [#( #data_types ),*];};
|
|
|
|
|
|
|
|
// decode
|
|
|
|
let (signature_check, flat_topics_init, topic_tokens_len_check) = if event.anonymous {
|
|
|
|
(
|
|
|
|
quote! {},
|
|
|
|
quote! {
|
|
|
|
let flat_topics = topics.iter().flat_map(|t| t.as_ref().to_vec()).collect::<Vec<u8>>();
|
|
|
|
},
|
|
|
|
quote! {
|
|
|
|
if topic_tokens.len() != topics.len() {
|
2023-02-14 01:08:46 +00:00
|
|
|
return Err(#ethers_core::abi::Error::InvalidData);
|
2021-10-16 08:19:42 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
(
|
|
|
|
quote! {
|
2023-02-14 01:08:46 +00:00
|
|
|
let event_signature = topics.get(0).ok_or(#ethers_core::abi::Error::InvalidData)?;
|
2021-10-16 08:19:42 +00:00
|
|
|
if event_signature != &Self::signature() {
|
2023-02-14 01:08:46 +00:00
|
|
|
return Err(#ethers_core::abi::Error::InvalidData);
|
2021-10-16 08:19:42 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
quote! {
|
|
|
|
let flat_topics = topics.iter().skip(1).flat_map(|t| t.as_ref().to_vec()).collect::<Vec<u8>>();
|
|
|
|
},
|
|
|
|
quote! {
|
|
|
|
if topic_tokens.len() != topics.len() - 1 {
|
2023-02-14 01:08:46 +00:00
|
|
|
return Err(#ethers_core::abi::Error::InvalidData);
|
2021-10-16 08:19:42 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
)
|
|
|
|
};
|
|
|
|
|
|
|
|
// check if indexed are sorted
|
|
|
|
let tokens_init = if event_fields
|
|
|
|
.iter()
|
|
|
|
.filter(|f| f.is_indexed())
|
|
|
|
.enumerate()
|
|
|
|
.all(|(idx, f)| f.index == idx)
|
|
|
|
{
|
|
|
|
quote! {
|
2023-02-14 01:08:46 +00:00
|
|
|
let topic_tokens = #ethers_core::abi::decode(&topic_types, &flat_topics)?;
|
2021-10-16 08:19:42 +00:00
|
|
|
#topic_tokens_len_check
|
2023-02-14 01:08:46 +00:00
|
|
|
let data_tokens = #ethers_core::abi::decode(&data_types, data)?;
|
2021-10-16 08:19:42 +00:00
|
|
|
let tokens:Vec<_> = topic_tokens.into_iter().chain(data_tokens.into_iter()).collect();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
let swap_tokens = event_fields.iter().map(|field| {
|
|
|
|
if field.is_indexed() {
|
|
|
|
quote! { topic_tokens.remove(0) }
|
|
|
|
} else {
|
|
|
|
quote! { data_tokens.remove(0) }
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
quote! {
|
2023-02-14 01:08:46 +00:00
|
|
|
let mut topic_tokens = #ethers_core::abi::decode(&topic_types, &flat_topics)?;
|
2021-10-16 08:19:42 +00:00
|
|
|
#topic_tokens_len_check
|
2023-02-14 01:08:46 +00:00
|
|
|
let mut data_tokens = #ethers_core::abi::decode(&data_types, &data)?;
|
2021-10-16 08:19:42 +00:00
|
|
|
let mut tokens = Vec::with_capacity(topics.len() + data_tokens.len());
|
|
|
|
#( tokens.push(#swap_tokens); )*
|
|
|
|
}
|
|
|
|
};
|
|
|
|
Ok(quote! {
|
|
|
|
|
2023-02-14 01:08:46 +00:00
|
|
|
let #ethers_core::abi::RawLog {data, topics} = log;
|
2021-10-16 08:19:42 +00:00
|
|
|
|
|
|
|
#signature_check
|
|
|
|
|
|
|
|
#topic_types_init
|
|
|
|
#data_types_init
|
|
|
|
|
|
|
|
#flat_topics_init
|
|
|
|
|
|
|
|
#tokens_init
|
|
|
|
|
2023-02-14 01:08:46 +00:00
|
|
|
#ethers_core::abi::Tokenizable::from_token(#ethers_core::abi::Token::Tuple(tokens)).map_err(|_|#ethers_core::abi::Error::InvalidData)
|
2021-10-16 08:19:42 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-10-18 10:28:38 +00:00
|
|
|
/// Determine the event's ABI by parsing the AST
|
2021-10-16 08:19:42 +00:00
|
|
|
fn derive_abi_event_from_fields(input: &DeriveInput) -> Result<Event, Error> {
|
|
|
|
let event = Event {
|
2023-02-14 01:11:13 +00:00
|
|
|
name: input.ident.to_string(),
|
2021-10-18 10:28:38 +00:00
|
|
|
inputs: utils::derive_abi_inputs_from_fields(input, "EthEvent")?
|
2021-10-16 08:19:42 +00:00
|
|
|
.into_iter()
|
2021-10-29 12:29:35 +00:00
|
|
|
.map(|(name, kind)| EventParam { name, kind, indexed: false })
|
2021-10-16 08:19:42 +00:00
|
|
|
.collect(),
|
|
|
|
anonymous: false,
|
|
|
|
};
|
|
|
|
Ok(event)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn parse_field_attributes(field: &Field) -> Result<(Option<String>, bool), Error> {
|
|
|
|
let mut indexed = false;
|
|
|
|
let mut topic_name = None;
|
|
|
|
for a in field.attrs.iter() {
|
|
|
|
if let AttrStyle::Outer = a.style {
|
|
|
|
if let Ok(Meta::List(meta)) = a.parse_meta() {
|
|
|
|
if meta.path.is_ident("ethevent") {
|
|
|
|
for n in meta.nested.iter() {
|
|
|
|
if let NestedMeta::Meta(meta) = n {
|
|
|
|
match meta {
|
|
|
|
Meta::Path(path) => {
|
|
|
|
if path.is_ident("indexed") {
|
|
|
|
indexed = true;
|
|
|
|
} else {
|
|
|
|
return Err(Error::new(
|
|
|
|
path.span(),
|
|
|
|
"unrecognized ethevent parameter",
|
2021-10-29 12:29:35 +00:00
|
|
|
))
|
2021-10-16 08:19:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
Meta::List(meta) => {
|
|
|
|
return Err(Error::new(
|
|
|
|
meta.path.span(),
|
|
|
|
"unrecognized ethevent parameter",
|
2021-10-29 12:29:35 +00:00
|
|
|
))
|
2021-10-16 08:19:42 +00:00
|
|
|
}
|
|
|
|
Meta::NameValue(meta) => {
|
|
|
|
if meta.path.is_ident("name") {
|
|
|
|
if let Lit::Str(ref lit_str) = meta.lit {
|
|
|
|
topic_name = Some(lit_str.value());
|
|
|
|
} else {
|
|
|
|
return Err(Error::new(
|
|
|
|
meta.span(),
|
|
|
|
"name attribute must be a string",
|
2021-10-29 12:29:35 +00:00
|
|
|
))
|
2021-10-16 08:19:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok((topic_name, indexed))
|
|
|
|
}
|
|
|
|
|
|
|
|
/// All the attributes the `EthEvent` macro supports
|
|
|
|
#[derive(Default)]
|
|
|
|
struct EthEventAttributes {
|
|
|
|
name: Option<(String, Span)>,
|
|
|
|
abi: Option<(String, Span)>,
|
|
|
|
signature_hash: Option<(Vec<u8>, Span)>,
|
|
|
|
anonymous: Option<(bool, Span)>,
|
|
|
|
}
|
|
|
|
|
|
|
|
/// extracts the attributes from the struct annotated with `EthEvent`
|
2023-02-14 01:08:46 +00:00
|
|
|
fn parse_event_attributes(input: &DeriveInput) -> Result<EthEventAttributes, Error> {
|
2021-10-16 08:19:42 +00:00
|
|
|
let mut result = EthEventAttributes::default();
|
|
|
|
for a in input.attrs.iter() {
|
|
|
|
if let AttrStyle::Outer = a.style {
|
|
|
|
if let Ok(Meta::List(meta)) = a.parse_meta() {
|
|
|
|
if meta.path.is_ident("ethevent") {
|
|
|
|
for n in meta.nested.iter() {
|
|
|
|
if let NestedMeta::Meta(meta) = n {
|
|
|
|
match meta {
|
|
|
|
Meta::Path(path) => {
|
|
|
|
if let Some(name) = path.get_ident() {
|
|
|
|
if &*name.to_string() == "anonymous" {
|
|
|
|
if result.anonymous.is_none() {
|
|
|
|
result.anonymous = Some((true, name.span()));
|
2021-10-29 12:29:35 +00:00
|
|
|
continue
|
2021-10-16 08:19:42 +00:00
|
|
|
} else {
|
|
|
|
return Err(Error::new(
|
|
|
|
name.span(),
|
|
|
|
"anonymous already specified",
|
2023-02-14 01:08:46 +00:00
|
|
|
))
|
2021-10-16 08:19:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Err(Error::new(
|
|
|
|
path.span(),
|
|
|
|
"unrecognized ethevent parameter",
|
2023-02-14 01:08:46 +00:00
|
|
|
))
|
2021-10-16 08:19:42 +00:00
|
|
|
}
|
|
|
|
Meta::List(meta) => {
|
|
|
|
return Err(Error::new(
|
|
|
|
meta.path.span(),
|
|
|
|
"unrecognized ethevent parameter",
|
2023-02-14 01:08:46 +00:00
|
|
|
))
|
2021-10-16 08:19:42 +00:00
|
|
|
}
|
|
|
|
Meta::NameValue(meta) => {
|
|
|
|
if meta.path.is_ident("anonymous") {
|
|
|
|
if let Lit::Bool(ref bool_lit) = meta.lit {
|
|
|
|
if result.anonymous.is_none() {
|
|
|
|
result.anonymous =
|
|
|
|
Some((bool_lit.value, bool_lit.span()));
|
|
|
|
} else {
|
|
|
|
return Err(Error::new(
|
|
|
|
meta.span(),
|
|
|
|
"anonymous already specified",
|
2023-02-14 01:08:46 +00:00
|
|
|
))
|
2021-10-16 08:19:42 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return Err(Error::new(
|
|
|
|
meta.span(),
|
|
|
|
"name must be a string",
|
2023-02-14 01:08:46 +00:00
|
|
|
))
|
2021-10-16 08:19:42 +00:00
|
|
|
}
|
|
|
|
} else if meta.path.is_ident("name") {
|
|
|
|
if let Lit::Str(ref lit_str) = meta.lit {
|
|
|
|
if result.name.is_none() {
|
|
|
|
result.name =
|
|
|
|
Some((lit_str.value(), lit_str.span()));
|
|
|
|
} else {
|
|
|
|
return Err(Error::new(
|
|
|
|
meta.span(),
|
|
|
|
"name already specified",
|
2023-02-14 01:08:46 +00:00
|
|
|
))
|
2021-10-16 08:19:42 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return Err(Error::new(
|
|
|
|
meta.span(),
|
|
|
|
"name must be a string",
|
2023-02-14 01:08:46 +00:00
|
|
|
))
|
2021-10-16 08:19:42 +00:00
|
|
|
}
|
|
|
|
} else if meta.path.is_ident("abi") {
|
|
|
|
if let Lit::Str(ref lit_str) = meta.lit {
|
|
|
|
if result.abi.is_none() {
|
|
|
|
result.abi =
|
|
|
|
Some((lit_str.value(), lit_str.span()));
|
|
|
|
} else {
|
|
|
|
return Err(Error::new(
|
|
|
|
meta.span(),
|
|
|
|
"abi already specified",
|
2023-02-14 01:08:46 +00:00
|
|
|
))
|
2021-10-16 08:19:42 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return Err(Error::new(
|
|
|
|
meta.span(),
|
|
|
|
"abi must be a string",
|
2023-02-14 01:08:46 +00:00
|
|
|
))
|
2021-10-16 08:19:42 +00:00
|
|
|
}
|
|
|
|
} else if meta.path.is_ident("signature") {
|
|
|
|
if let Lit::Str(ref lit_str) = meta.lit {
|
|
|
|
if result.signature_hash.is_none() {
|
|
|
|
match Vec::from_hex(lit_str.value()) {
|
|
|
|
Ok(sig) => {
|
|
|
|
result.signature_hash =
|
|
|
|
Some((sig, lit_str.span()))
|
|
|
|
}
|
|
|
|
Err(err) => {
|
|
|
|
return Err(Error::new(
|
|
|
|
meta.span(),
|
|
|
|
format!(
|
2022-12-06 06:05:33 +00:00
|
|
|
"Expected hex signature: {err:?}"
|
2021-10-16 08:19:42 +00:00
|
|
|
),
|
2023-02-14 01:08:46 +00:00
|
|
|
))
|
2021-10-16 08:19:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return Err(Error::new(
|
|
|
|
meta.span(),
|
|
|
|
"signature already specified",
|
2023-02-14 01:08:46 +00:00
|
|
|
))
|
2021-10-16 08:19:42 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return Err(Error::new(
|
|
|
|
meta.span(),
|
|
|
|
"signature must be a hex string",
|
2023-02-14 01:08:46 +00:00
|
|
|
))
|
2021-10-16 08:19:42 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return Err(Error::new(
|
|
|
|
meta.span(),
|
|
|
|
"unrecognized ethevent parameter",
|
2023-02-14 01:08:46 +00:00
|
|
|
))
|
2021-10-16 08:19:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Ok(result)
|
|
|
|
}
|