difftreelog
fix generate stubs build ans remove warnings
in: master
4 files changed
crates/evm-coder/procedural/src/abi_derive.rsdiffbeforeafterboth--- a/crates/evm-coder/procedural/src/abi_derive.rs
+++ b/crates/evm-coder/procedural/src/abi_derive.rs
@@ -1,4 +1,3 @@
-use proc_macro2::TokenStream;
use quote::quote;
pub(crate) fn impl_abi_macro(ast: &syn::DeriveInput) -> syn::Result<proc_macro2::TokenStream> {
@@ -128,7 +127,7 @@
}
}
-fn extract_docs(attrs: &Vec<syn::Attribute>) -> syn::Result<Vec<String>> {
+fn extract_docs(attrs: &[syn::Attribute]) -> syn::Result<Vec<String>> {
attrs
.iter()
.filter_map(|attr| {
@@ -163,7 +162,7 @@
}
}
-fn map_field_to_type<'a>(field: &'a syn::Field) -> &'a syn::Type {
+fn map_field_to_type(field: &syn::Field) -> &syn::Type {
&field.ty
}
@@ -177,7 +176,7 @@
}
}
-fn impl_abi_type<'a>(
+fn impl_abi_type(
name: &syn::Ident,
tuple_type: proc_macro2::TokenStream,
) -> proc_macro2::TokenStream {
@@ -194,7 +193,7 @@
}
}
-fn impl_abi_read<'a>(
+fn impl_abi_read(
name: &syn::Ident,
tuple_type: proc_macro2::TokenStream,
tuple_names: proc_macro2::TokenStream,
@@ -210,9 +209,9 @@
)
}
-fn impl_abi_write<'a>(
+fn impl_abi_write(
name: &syn::Ident,
- is_named_fields: bool,
+ _is_named_fields: bool,
tuple_type: proc_macro2::TokenStream,
tuple_data: proc_macro2::TokenStream,
) -> proc_macro2::TokenStream {
@@ -301,7 +300,7 @@
field_names: impl Iterator<Item = proc_macro2::Ident> + Clone,
field_types: impl Iterator<Item = &'a syn::Type> + Clone,
field_docs: impl Iterator<Item = syn::Result<Vec<String>>> + Clone,
- docs: &Vec<String>,
+ docs: &[String],
) -> syn::Result<proc_macro2::TokenStream> {
let string_name = name.to_string();
let name_type = field_names
crates/evm-coder/src/abi/impls.rsdiffbeforeafterboth--- a/crates/evm-coder/src/abi/impls.rs
+++ b/crates/evm-coder/src/abi/impls.rs
@@ -165,7 +165,7 @@
}
impl AbiWrite for Property {
- fn abi_write<'a>(&'a self, writer: &mut AbiWriter) {
+ fn abi_write(&self, writer: &mut AbiWriter) {
(&self.key, &self.value).abi_write(writer);
}
}
crates/evm-coder/src/lib.rsdiffbeforeafterboth--- a/crates/evm-coder/src/lib.rs
+++ b/crates/evm-coder/src/lib.rs
@@ -146,7 +146,7 @@
#[cfg(feature = "std")]
pub type string = ::std::string::String;
- #[derive(Default, Debug, PartialEq, Clone)]
+ #[derive(Default, Debug, PartialEq, Eq, Clone)]
pub struct bytes(pub Vec<u8>);
/// Solidity doesn't have `void` type, however we have special implementation
crates/evm-coder/src/solidity/impls.rsdiffbeforeafterboth1use super::{TypeCollector, SolidityTypeName, SolidityType, StructCollect};2use crate::{sealed, types::*};3use core::fmt;4use primitive_types::{U256, H160};56macro_rules! solidity_type_name {7 ($($ty:ty => $name:literal $simple:literal = $default:literal),* $(,)?) => {8 $(9 impl SolidityTypeName for $ty {10 fn solidity_name(writer: &mut impl core::fmt::Write, _tc: &TypeCollector) -> core::fmt::Result {11 write!(writer, $name)12 }13 fn is_simple() -> bool {14 $simple15 }16 fn solidity_default(writer: &mut impl core::fmt::Write, _tc: &TypeCollector) -> core::fmt::Result {17 write!(writer, $default)18 }19 }2021 impl StructCollect for $ty {22 fn name() -> String {23 $name.to_string()24 }2526 fn declaration() -> String {27 String::default()28 }29 }30 )*31 };32}3334solidity_type_name! {35 u8 => "uint8" true = "0",36 u32 => "uint32" true = "0",37 u64 => "uint64" true = "0",38 u128 => "uint128" true = "0",39 U256 => "uint256" true = "0",40 bytes4 => "bytes4" true = "bytes4(0)",41 H160 => "address" true = "0x0000000000000000000000000000000000000000",42 string => "string" false = "\"\"",43 bytes => "bytes" false = "hex\"\"",44 bool => "bool" true = "false",45}4647impl SolidityTypeName for void {48 fn solidity_name(_writer: &mut impl fmt::Write, _tc: &TypeCollector) -> fmt::Result {49 Ok(())50 }51 fn is_simple() -> bool {52 true53 }54 fn solidity_default(_writer: &mut impl fmt::Write, _tc: &TypeCollector) -> fmt::Result {55 Ok(())56 }57 fn is_void() -> bool {58 true59 }60}6162impl<T: SolidityTypeName + sealed::CanBePlacedInVec> SolidityTypeName for Vec<T> {63 fn solidity_name(writer: &mut impl fmt::Write, tc: &TypeCollector) -> fmt::Result {64 T::solidity_name(writer, tc)?;65 write!(writer, "[]")66 }67 fn is_simple() -> bool {68 false69 }70 fn solidity_default(writer: &mut impl fmt::Write, tc: &TypeCollector) -> fmt::Result {71 write!(writer, "new ")?;72 T::solidity_name(writer, tc)?;73 write!(writer, "[](0)")74 }75}7677macro_rules! count {78 () => (0usize);79 ( $x:tt $($xs:tt)* ) => (1usize + count!($($xs)*));80}8182macro_rules! impl_tuples {83 ($($ident:ident)+) => {84 impl<$($ident: SolidityTypeName + 'static),+> SolidityType for ($($ident,)+) {85 fn names(tc: &TypeCollector) -> Vec<string> {86 let mut collected = Vec::with_capacity(Self::len());87 $({88 let mut out = string::new();89 $ident::solidity_name(&mut out, tc).expect("no fmt error");90 collected.push(out);91 })*;92 collected93 }9495 fn len() -> usize {96 count!($($ident)*)97 }98 }99 impl<$($ident: SolidityTypeName + 'static),+> SolidityTypeName for ($($ident,)+) {100 fn solidity_name(writer: &mut impl fmt::Write, tc: &TypeCollector) -> fmt::Result {101 write!(writer, "{}", tc.collect_tuple::<Self>())102 }103 fn is_simple() -> bool {104 false105 }106 #[allow(unused_assignments)]107 fn solidity_default(writer: &mut impl fmt::Write, tc: &TypeCollector) -> fmt::Result {108 write!(writer, "{}(", tc.collect_tuple::<Self>())?;109 let mut first = true;110 $(111 if !first {112 write!(writer, ",")?;113 } else {114 first = false;115 }116 <$ident>::solidity_default(writer, tc)?;117 )*118 write!(writer, ")")119 }120 }121 };122}123124impl_tuples! {A}125impl_tuples! {A B}126impl_tuples! {A B C}127impl_tuples! {A B C D}128impl_tuples! {A B C D E}129impl_tuples! {A B C D E F}130impl_tuples! {A B C D E F G}131impl_tuples! {A B C D E F G H}132impl_tuples! {A B C D E F G H I}133impl_tuples! {A B C D E F G H I J}134135impl sealed::CanBePlacedInVec for Property {}136impl StructCollect for Property {137 fn name() -> String {138 "Property".into()139 }140141 fn declaration() -> String {142 let mut str = String::new();143 writeln!(str, "/// @dev Property struct").unwrap();144 writeln!(str, "struct {} {{", Self::name()).unwrap();145 writeln!(str, "\tstring key;").unwrap();146 writeln!(str, "\tbytes value;").unwrap();147 writeln!(str, "}}").unwrap();148 str149 }150}151152impl SolidityTypeName for Property {153 fn solidity_name(writer: &mut impl fmt::Write, tc: &TypeCollector) -> fmt::Result {154 write!(writer, "{}", tc.collect_struct::<Self>())155 }156157 fn is_simple() -> bool {158 false159 }160161 fn solidity_default(writer: &mut impl fmt::Write, tc: &TypeCollector) -> fmt::Result {162 write!(writer, "{}(", tc.collect_struct::<Self>())?;163 address::solidity_default(writer, tc)?;164 write!(writer, ",")?;165 uint256::solidity_default(writer, tc)?;166 write!(writer, ")")167 }168}169170impl SolidityTupleType for Property {171 fn names(tc: &TypeCollector) -> Vec<string> {172 let mut collected = Vec::with_capacity(Self::len());173 {174 let mut out = string::new();175 string::solidity_name(&mut out, tc).expect("no fmt error");176 collected.push(out);177 }178 {179 let mut out = string::new();180 bytes::solidity_name(&mut out, tc).expect("no fmt error");181 collected.push(out);182 }183 collected184 }185186 fn len() -> usize {187 2188 }189}1use super::{TypeCollector, SolidityTypeName, SolidityType, StructCollect};2use crate::{sealed, types::*};3use core::fmt;4use primitive_types::{U256, H160};56macro_rules! solidity_type_name {7 ($($ty:ty => $name:literal $simple:literal = $default:literal),* $(,)?) => {8 $(9 impl SolidityTypeName for $ty {10 fn solidity_name(writer: &mut impl core::fmt::Write, _tc: &TypeCollector) -> core::fmt::Result {11 write!(writer, $name)12 }13 fn is_simple() -> bool {14 $simple15 }16 fn solidity_default(writer: &mut impl core::fmt::Write, _tc: &TypeCollector) -> core::fmt::Result {17 write!(writer, $default)18 }19 }2021 impl StructCollect for $ty {22 fn name() -> String {23 $name.to_string()24 }2526 fn declaration() -> String {27 String::default()28 }29 }30 )*31 };32}3334solidity_type_name! {35 u8 => "uint8" true = "0",36 u32 => "uint32" true = "0",37 u64 => "uint64" true = "0",38 u128 => "uint128" true = "0",39 U256 => "uint256" true = "0",40 bytes4 => "bytes4" true = "bytes4(0)",41 H160 => "address" true = "0x0000000000000000000000000000000000000000",42 string => "string" false = "\"\"",43 bytes => "bytes" false = "hex\"\"",44 bool => "bool" true = "false",45}4647impl SolidityTypeName for void {48 fn solidity_name(_writer: &mut impl fmt::Write, _tc: &TypeCollector) -> fmt::Result {49 Ok(())50 }51 fn is_simple() -> bool {52 true53 }54 fn solidity_default(_writer: &mut impl fmt::Write, _tc: &TypeCollector) -> fmt::Result {55 Ok(())56 }57 fn is_void() -> bool {58 true59 }60}6162impl<T: SolidityTypeName + sealed::CanBePlacedInVec> SolidityTypeName for Vec<T> {63 fn solidity_name(writer: &mut impl fmt::Write, tc: &TypeCollector) -> fmt::Result {64 T::solidity_name(writer, tc)?;65 write!(writer, "[]")66 }67 fn is_simple() -> bool {68 false69 }70 fn solidity_default(writer: &mut impl fmt::Write, tc: &TypeCollector) -> fmt::Result {71 write!(writer, "new ")?;72 T::solidity_name(writer, tc)?;73 write!(writer, "[](0)")74 }75}7677macro_rules! count {78 () => (0usize);79 ( $x:tt $($xs:tt)* ) => (1usize + count!($($xs)*));80}8182macro_rules! impl_tuples {83 ($($ident:ident)+) => {84 impl<$($ident: SolidityTypeName + 'static),+> SolidityType for ($($ident,)+) {85 fn names(tc: &TypeCollector) -> Vec<string> {86 let mut collected = Vec::with_capacity(Self::len());87 $({88 let mut out = string::new();89 $ident::solidity_name(&mut out, tc).expect("no fmt error");90 collected.push(out);91 })*;92 collected93 }9495 fn len() -> usize {96 count!($($ident)*)97 }98 }99 impl<$($ident: SolidityTypeName + 'static),+> SolidityTypeName for ($($ident,)+) {100 fn solidity_name(writer: &mut impl fmt::Write, tc: &TypeCollector) -> fmt::Result {101 write!(writer, "{}", tc.collect_tuple::<Self>())102 }103 fn is_simple() -> bool {104 false105 }106 #[allow(unused_assignments)]107 fn solidity_default(writer: &mut impl fmt::Write, tc: &TypeCollector) -> fmt::Result {108 write!(writer, "{}(", tc.collect_tuple::<Self>())?;109 let mut first = true;110 $(111 if !first {112 write!(writer, ",")?;113 } else {114 first = false;115 }116 <$ident>::solidity_default(writer, tc)?;117 )*118 write!(writer, ")")119 }120 }121 };122}123124impl_tuples! {A}125impl_tuples! {A B}126impl_tuples! {A B C}127impl_tuples! {A B C D}128impl_tuples! {A B C D E}129impl_tuples! {A B C D E F}130impl_tuples! {A B C D E F G}131impl_tuples! {A B C D E F G H}132impl_tuples! {A B C D E F G H I}133impl_tuples! {A B C D E F G H I J}134135impl StructCollect for Property {136 fn name() -> String {137 "Property".into()138 }139140 fn declaration() -> String {141 use std::fmt::Write;142143 let mut str = String::new();144 writeln!(str, "/// @dev Property struct").unwrap();145 writeln!(str, "struct {} {{", Self::name()).unwrap();146 writeln!(str, "\tstring key;").unwrap();147 writeln!(str, "\tbytes value;").unwrap();148 writeln!(str, "}}").unwrap();149 str150 }151}152153impl SolidityTypeName for Property {154 fn solidity_name(writer: &mut impl fmt::Write, tc: &TypeCollector) -> fmt::Result {155 write!(writer, "{}", tc.collect_struct::<Self>())156 }157158 fn is_simple() -> bool {159 false160 }161162 fn solidity_default(writer: &mut impl fmt::Write, tc: &TypeCollector) -> fmt::Result {163 write!(writer, "{}(", tc.collect_struct::<Self>())?;164 address::solidity_default(writer, tc)?;165 write!(writer, ",")?;166 uint256::solidity_default(writer, tc)?;167 write!(writer, ")")168 }169}170171impl SolidityType for Property {172 fn names(tc: &TypeCollector) -> Vec<string> {173 let mut collected = Vec::with_capacity(Self::len());174 {175 let mut out = string::new();176 string::solidity_name(&mut out, tc).expect("no fmt error");177 collected.push(out);178 }179 {180 let mut out = string::new();181 bytes::solidity_name(&mut out, tc).expect("no fmt error");182 collected.push(out);183 }184 collected185 }186187 fn len() -> usize {188 2189 }190}