--- a/crates/evm-coder/procedural/src/abi_derive.rs +++ b/crates/evm-coder/procedural/src/abi_derive.rs @@ -2,6 +2,29 @@ pub(crate) fn impl_abi_macro(ast: &syn::DeriveInput) -> syn::Result { let name = &ast.ident; + let docs = ast + .attrs + .iter() + .filter_map(|attr| { + if let Some(ps) = attr.path.segments.first() { + if ps.ident == "doc" { + let meta = match attr.parse_meta() { + Ok(meta) => meta, + Err(e) => return Some(Err(e)), + }; + match meta { + syn::Meta::NameValue(mnv) => match &mnv.lit { + syn::Lit::Str(ls) => return Some(Ok(ls.value())), + _ => unreachable!(), + }, + _ => unreachable!(), + } + } + } + None + }) + .collect::>>()?; + let (is_named_fields, field_names, field_types, params_count) = match &ast.data { syn::Data::Struct(ds) => match ds.fields { syn::Fields::Named(ref fields) => Ok(( @@ -37,7 +60,8 @@ let abi_write = impl_abi_write(name, is_named_fields, params_count, field_names.clone()); let solidity_type = impl_solidity_type(name, field_types.clone(), params_count); let solidity_type_name = impl_solidity_type_name(name, field_types.clone(), params_count); - let solidity_struct_collect = impl_solidity_struct_collect(name, field_names, field_types); + let solidity_struct_collect = + impl_solidity_struct_collect(name, field_names, field_types, &docs); Ok(quote! { #can_be_plcaed_in_vec @@ -259,6 +283,7 @@ name: &syn::Ident, field_names: impl Iterator + Clone, field_types: impl Iterator + Clone, + docs: &Vec, ) -> proc_macro2::TokenStream { let string_name = name.to_string(); let name_type = field_names @@ -271,6 +296,13 @@ write!(str, "{};", #name).unwrap(); ) }); + let docs = docs.iter().enumerate().map(|(i, doc)| { + let doc = doc.trim(); + let dev = if i == 0 { " @dev" } else { "" }; + quote! { + writeln!(str, "///{} {}", #dev, #doc).unwrap(); + } + }); quote! { #[cfg(feature = "stubgen")] @@ -283,7 +315,7 @@ use std::fmt::Write; let mut str = String::new(); - writeln!(str, "/// @dev Cross account struct").unwrap(); + #(#docs)* writeln!(str, "struct {} {{", Self::name()).unwrap(); #(#name_type)* writeln!(str, "}}").unwrap(); --- a/crates/evm-coder/src/solidity/impls.rs +++ b/crates/evm-coder/src/solidity/impls.rs @@ -1,6 +1,7 @@ use super::{TypeCollector, SolidityTypeName, SolidityType, StructCollect}; use crate::{sealed, types::*}; use core::fmt; +use primitive_types::{U256, H160}; macro_rules! solidity_type_name { ($($ty:ty => $name:literal $simple:literal = $default:literal),* $(,)?) => { @@ -31,13 +32,13 @@ } solidity_type_name! { - uint8 => "uint8" true = "0", - uint32 => "uint32" true = "0", - uint64 => "uint64" true = "0", - uint128 => "uint128" true = "0", - uint256 => "uint256" true = "0", + u8 => "uint8" true = "0", + u32 => "uint32" true = "0", + u64 => "uint64" true = "0", + u128 => "uint128" true = "0", + U256 => "uint256" true = "0", bytes4 => "bytes4" true = "bytes4(0)", - address => "address" true = "0x0000000000000000000000000000000000000000", + H160 => "address" true = "0x0000000000000000000000000000000000000000", string => "string" false = "\"\"", bytes => "bytes" false = "hex\"\"", bool => "bool" true = "false", --- a/crates/evm-coder/tests/abi_derive_generation.rs +++ b/crates/evm-coder/tests/abi_derive_generation.rs @@ -57,10 +57,16 @@ _b: TypeStruct2DynamicParam, } +/// Some docs +/// At multi +/// line #[derive(AbiCoder, PartialEq, Debug)] struct TypeStruct3DerivedMixedParam { + /// Docs for A _a: TypeStruct1SimpleParam, + /// Docs for B _b: TypeStruct2DynamicParam, + /// Docs for C _c: TypeStruct2MixedParam, } --- a/pallets/common/src/eth.rs +++ b/pallets/common/src/eth.rs @@ -113,6 +113,7 @@ } } +/// Cross account struct #[derive(Debug, Default, AbiCoder)] pub struct EthCrossAccount { pub(crate) eth: address,