fix: use syn::Index for tuple access (#515)
* fix: use syn::Index for tuple access * rustfmt
This commit is contained in:
parent
956a87a924
commit
c3528b78db
|
@ -1,9 +1,9 @@
|
|||
//! Helper functions for deriving `Display`
|
||||
|
||||
use proc_macro2::TokenStream;
|
||||
use quote::{format_ident, quote};
|
||||
use quote::quote;
|
||||
use syn::spanned::Spanned as _;
|
||||
use syn::{parse::Error, Data, DeriveInput, Fields};
|
||||
use syn::{parse::Error, Data, DeriveInput, Fields, Index};
|
||||
|
||||
use ethers_contract_abigen::ethers_core_crate;
|
||||
use ethers_core::abi::ParamType;
|
||||
|
@ -40,7 +40,11 @@ pub(crate) fn derive_eth_display_impl(input: DeriveInput) -> Result<TokenStream,
|
|||
let ident = field
|
||||
.ident
|
||||
.clone()
|
||||
.unwrap_or_else(|| format_ident!("{}", idx));
|
||||
.map(|id| quote! {#id})
|
||||
.unwrap_or_else(|| {
|
||||
let idx = Index::from(idx);
|
||||
quote! {#idx}
|
||||
});
|
||||
let tokens = if let Ok(param) = utils::find_parameter_type(&field.ty) {
|
||||
match param {
|
||||
ParamType::Address | ParamType::Uint(_) | ParamType::Int(_) => {
|
||||
|
|
|
@ -212,9 +212,11 @@ impl<M: Middleware> Multicall<M> {
|
|||
/// If more than the maximum number of supported calls are added. The maximum
|
||||
/// limits is constrained due to tokenization/detokenization support for tuples
|
||||
pub fn add_call<D: Detokenize>(&mut self, call: ContractCall<M, D>) -> &mut Self {
|
||||
if self.calls.len() >= 16 {
|
||||
panic!("Cannot support more than {} calls", 16);
|
||||
}
|
||||
assert!(
|
||||
!(self.calls.len() >= 16),
|
||||
"Cannot support more than {} calls",
|
||||
16
|
||||
);
|
||||
|
||||
match (call.tx.to(), call.tx.data()) {
|
||||
(Some(NameOrAddress::Address(target)), Some(data)) => {
|
||||
|
|
|
@ -371,3 +371,21 @@ fn eth_display_works() {
|
|||
|
||||
assert_eq!(val, format!("{}", item));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn eth_display_works_for_human_readable() {
|
||||
ethers_contract::abigen!(
|
||||
HevmConsole,
|
||||
r#"[
|
||||
event log(string)
|
||||
event log2(string x)
|
||||
]"#,
|
||||
);
|
||||
|
||||
let log = LogFilter("abc".to_string());
|
||||
assert_eq!("abc".to_string(), format!("{}", log));
|
||||
let log = Log2Filter {
|
||||
x: "abc".to_string(),
|
||||
};
|
||||
assert_eq!("abc".to_string(), format!("{}", log));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue