git.delta.rocks / unique-network / refs/commits / 5a3fe2c70832

difftreelog

refactor unify function and type signature handling

Yaroslav Bolyukin2022-11-02parent: #4c1a924.patch.diff
in: master

12 files changed

modifiedcrates/evm-coder/procedural/src/solidity_interface.rsdiffbeforeafterboth
--- a/crates/evm-coder/procedural/src/solidity_interface.rs
+++ b/crates/evm-coder/procedural/src/solidity_interface.rs
@@ -24,8 +24,8 @@
 use quote::{quote, format_ident};
 use inflector::cases;
 use syn::{
-	Expr, FnArg, GenericArgument, Generics, Ident, ImplItem, ImplItemMethod, ItemImpl, Lit, Meta,
-	MetaNameValue, PatType, PathArguments, ReturnType, Type,
+	Expr, FnArg, Generics, Ident, ImplItem, ImplItemMethod, ItemImpl, Lit, Meta, MetaNameValue,
+	PatType, ReturnType, Type,
 	spanned::Spanned,
 	parse::{Parse, ParseStream},
 	parenthesized, Token, LitInt, LitStr,
@@ -601,12 +601,12 @@
 		let screaming_name_signature = format_ident!("{}_SIGNATURE", &self.screaming_name);
 		let custom_signature = self.expand_custom_signature();
 		quote! {
-			const #screaming_name_signature: ::evm_coder::custom_signature::FunctionSignature = #custom_signature;
+			const #screaming_name_signature: ::evm_coder::custom_signature::SignatureUnit = #custom_signature;
 			const #screaming_name: ::evm_coder::types::bytes4 = {
 				let mut sum = ::evm_coder::sha3_const::Keccak256::new();
 				let mut pos = 0;
-				while pos < Self::#screaming_name_signature.unit.len {
-					sum = sum.update(&[Self::#screaming_name_signature.unit.data[pos]; 1]);
+				while pos < Self::#screaming_name_signature.len {
+					sum = sum.update(&[Self::#screaming_name_signature.data[pos]; 1]);
 					pos += 1;
 				}
 				let a = sum.finalize();
@@ -710,192 +710,28 @@
 			};
 			quote! {
 				Self::#pascal_name #matcher => ().into()
-			}
-		}
-	}
-
-	fn expand_type(ty: &Type, token_stream: &mut proc_macro2::TokenStream, read_signature: bool) {
-		match ty {
-			Type::Path(tp) => {
-				if let Some(qself) = &tp.qself {
-					panic!("no receiver expected {:?}", qself.ty.span());
-				}
-				let path = &tp.path;
-				if path.segments.len() != 1 {
-					panic!("expected path to have only one segment {:?}", path.span());
-				}
-				let last_segment = path.segments.last().unwrap();
-
-				if last_segment.ident == "Vec" {
-					let args = match &last_segment.arguments {
-						PathArguments::AngleBracketed(e) => e,
-						_ => {
-							panic!("missing Vec generic {:?}", last_segment.arguments.span());
-						}
-					};
-					let args = &args.args;
-					if args.len() != 1 {
-						panic!("expected only one generic for vec {:?}", args.span());
-					}
-					let arg = args.first().expect("first arg");
-
-					let ty = match arg {
-						GenericArgument::Type(ty) => ty,
-						_ => {
-							panic!("expected first generic to be type {:?}", arg.span());
-						}
-					};
-
-					let mut vec_token = proc_macro2::TokenStream::new();
-					Self::expand_type(ty, &mut vec_token, false);
-					vec_token = if read_signature {
-						quote! { (<Vec<#vec_token>>::SIGNATURE) }
-					} else {
-						quote! { <Vec<#vec_token>> }
-					};
-					token_stream.extend(vec_token);
-				} else {
-					if !last_segment.arguments.is_empty() {
-						panic!(
-							"unexpected generic arguments for non-vec type {:?}",
-							last_segment.arguments.span()
-						);
-					}
-
-					let ident = &last_segment.ident;
-					let plain_token = if read_signature {
-						quote! {
-							(<#ident>::SIGNATURE)
-						}
-					} else {
-						quote! {
-							#ident
-						}
-					};
-
-					token_stream.extend(plain_token);
-				}
-			}
-
-			Type::Tuple(tt) => {
-				// for ty in tt.elems.iter() {
-				// 	out.push(AbiType::try_from(ty)?)
-				// }
-
-				let mut tuple_types = proc_macro2::TokenStream::new();
-				let mut is_first = true;
-
-				for ty in tt.elems.iter() {
-					if is_first {
-						is_first = false
-					} else {
-						tuple_types.extend(quote!(,));
-					}
-					Self::expand_type(ty, &mut tuple_types, false);
-				}
-				tuple_types = if read_signature {
-					quote! { (<(#tuple_types)>::SIGNATURE) }
-				} else {
-					quote! { (#tuple_types) }
-				};
-				token_stream.extend(tuple_types);
 			}
-
-			// Type::Array(arr) => {
-			// 	let wrapped = AbiType::try_from(&arr.elem)?;
-			// 	match &arr.len {
-			// 		Expr::Lit(l) => match &l.lit {
-			// 			Lit::Int(i) => {
-			// 				let num = i.base10_parse::<usize>()?;
-			// 				Ok(AbiType::Array(Box::new(wrapped), num as usize))
-			// 			}
-			// 			_ => Err(syn::Error::new(arr.len.span(), "should be int literal")),
-			// 		},
-			// 		_ => Err(syn::Error::new(arr.len.span(), "should be literal")),
-			// 	}
-			// }
-			_ => panic!("Unexpected type {ty:?}"),
 		}
-		// match ty {
-		// 	AbiType::Plain(ref ident) => {
-		// 		let plain_token = if read_signature {
-		// 			quote! {
-		// 				(<#ident>::SIGNATURE)
-		// 			}
-		// 		} else {
-		// 			quote! {
-		// 				#ident
-		// 			}
-		// 		};
-
-		// 		token_stream.extend(plain_token);
-		// 	}
-
-		// 	AbiType::Tuple(ref tuple_type) => {
-		// 		let mut tuple_types = proc_macro2::TokenStream::new();
-		// 		let mut is_first = true;
-
-		// 		for ty in tuple_type {
-		// 			if is_first {
-		// 				is_first = false
-		// 			} else {
-		// 				tuple_types.extend(quote!(,));
-		// 			}
-		// 			Self::expand_type(ty, &mut tuple_types, false);
-		// 		}
-		// 		tuple_types = if read_signature {
-		// 			quote! { (<(#tuple_types)>::SIGNATURE) }
-		// 		} else {
-		// 			quote! { (#tuple_types) }
-		// 		};
-		// 		token_stream.extend(tuple_types);
-		// 	}
-
-		// 	AbiType::Vec(ref vec_type) => {
-		// 		let mut vec_token = proc_macro2::TokenStream::new();
-		// 		Self::expand_type(vec_type.as_ref(), &mut vec_token, false);
-		// 		vec_token = if read_signature {
-		// 			quote! { (<Vec<#vec_token>>::SIGNATURE) }
-		// 		} else {
-		// 			quote! { <Vec<#vec_token>> }
-		// 		};
-		// 		token_stream.extend(vec_token);
-		// 	}
-
-		// 	AbiType::Array(_, _) => todo!("Array eth signature"),
-		// };
 	}
 
 	fn expand_custom_signature(&self) -> proc_macro2::TokenStream {
-		let mut token_stream = TokenStream::new();
+		let mut args = TokenStream::new();
 
 		let mut is_first = true;
-		for arg in &self.args {
-			if arg.is_special() {
-				continue;
-			}
-
-			if is_first {
-				is_first = false;
-			} else {
-				token_stream.extend(quote!(,));
-			}
-			Self::expand_type(&arg.ty, &mut token_stream, true);
+		for arg in self.args.iter().filter(|a| !a.is_special()) {
+			is_first = false;
+			let ty = &arg.ty;
+			args.extend(quote! {nameof(#ty)});
+			args.extend(quote! {fixed(",")})
 		}
 
+		// Remove trailing comma
 		if !is_first {
-			token_stream.extend(quote!(,));
+			args.extend(quote! {shift_left(1)})
 		}
 
 		let func_name = self.camel_name.clone();
-		let func_name = quote!(SignaturePreferences {
-			open_name: Some(SignatureUnit::new(#func_name)),
-			open_delimiter: Some(SignatureUnit::new("(")),
-			param_delimiter: Some(SignatureUnit::new(",")),
-			close_delimiter: Some(SignatureUnit::new(")")),
-			close_name: None,
-		});
-		quote!({ ::evm_coder::make_signature!(new fn(#func_name), #token_stream) })
+		quote! { ::evm_coder::make_signature!(new fixed(#func_name) fixed("(") #args fixed(")")) }
 	}
 
 	fn expand_solidity_function(&self) -> proc_macro2::TokenStream {
@@ -916,12 +752,6 @@
 		let screaming_name = &self.screaming_name;
 		let hide = self.hide;
 		let custom_signature = self.expand_custom_signature();
-		let custom_signature = quote!(
-			{
-				const cs: FunctionSignature = #custom_signature;
-				cs
-			}
-		);
 		let is_payable = self.has_value_args;
 
 		quote! {
modifiedcrates/evm-coder/src/abi.rsdiffbeforeafterboth
--- a/crates/evm-coder/src/abi.rs
+++ b/crates/evm-coder/src/abi.rs
@@ -27,7 +27,7 @@
 	execution::{Error, ResultWithPostInfo, WithPostDispatchInfo},
 	types::*,
 	make_signature,
-	custom_signature::{SignatureUnit, SIGNATURE_SIZE_LIMIT},
+	custom_signature::{SignatureUnit},
 };
 use crate::execution::Result;
 
@@ -428,7 +428,7 @@
 }
 
 impl<R: Signature> Signature for Vec<R> {
-	make_signature!(new nameof(R) fixed("[]"));
+	const SIGNATURE: SignatureUnit = make_signature!(new nameof(R) fixed("[]"));
 }
 
 impl sealed::CanBePlacedInVec for EthCrossAccount {}
@@ -522,7 +522,7 @@
 		where
 		$($ident: Signature,)+
 		{
-			make_signature!(
+			const SIGNATURE: SignatureUnit = make_signature!(
 				new fixed("(")
 				$(nameof($ident) fixed(","))+
 				shift_left(1)
@@ -758,13 +758,13 @@
 				1ACF2D55
 				0000000000000000000000000000000000000000000000000000000000000020 // offset of (address, uint256)[]
 				0000000000000000000000000000000000000000000000000000000000000003 // length of (address, uint256)[]
-	
+
 				0000000000000000000000002D2FF76104B7BACB2E8F6731D5BFC184EBECDDBC // address
 				000000000000000000000000000000000000000000000000000000000000000A // uint256
-	
+
 				000000000000000000000000AB8E3D9134955566483B11E6825C9223B6737B10 // address
 				0000000000000000000000000000000000000000000000000000000000000014 // uint256
-	
+
 				0000000000000000000000008C582BDF2953046705FC56F189385255EFC1BE18 // address
 				000000000000000000000000000000000000000000000000000000000000001E // uint256
 			"
modifiedcrates/evm-coder/src/custom_signature.rsdiffbeforeafterboth
before · crates/evm-coder/src/custom_signature.rs
1//! # A module for custom signature support.2//!3//! ## Overview4//! This module allows you to create arbitrary signatures for types and functions in compile time.5//!6//! ### Type signatures7//! To create the desired type signature, you need to create your own trait with the `SIGNATURE` constant.8//! Then in the implementation, for the required type, use the macro [`make_signature`]9//! #### Example10//! ```11//! use std::str::from_utf8;12//! use evm_coder::make_signature;13//! use evm_coder::custom_signature::{14//! 	SignatureUnit,15//! 	SIGNATURE_SIZE_LIMIT16//! };17//!18//! // Create trait for our signature19//! trait SoliditySignature {20//!		const SIGNATURE: SignatureUnit;21//!22//!		fn name() -> &'static str {23//!			from_utf8(&Self::SIGNATURE.data[..Self::SIGNATURE.len]).expect("bad utf-8")24//!		}25//!	}26//!27//! // Make signatures for some types28//!	impl SoliditySignature for u8 {29//!		make_signature!(new fixed("uint8"));30//!	}31//!	impl SoliditySignature for u32 {32//!		make_signature!(new fixed("uint32"));33//!	}34//!	impl<T: SoliditySignature> SoliditySignature for Vec<T> {35//!		make_signature!(new nameof(T) fixed("[]"));36//!	}37//!	impl<A: SoliditySignature, B: SoliditySignature> SoliditySignature for (A, B) {38//!		make_signature!(new fixed("(") nameof(A) fixed(",") nameof(B) fixed(")"));39//!	}40//!	impl<A: SoliditySignature> SoliditySignature for (A,) {41//!		make_signature!(new fixed("(") nameof(A) fixed(",") shift_left(1) fixed(")"));42//!	}43//!44//! assert_eq!(u8::name(), "uint8");45//! assert_eq!(<Vec<u8>>::name(), "uint8[]");46//! assert_eq!(<(u32, u8)>::name(), "(uint32,uint8)");47//! ```48//!49//! ### Function signatures50//! To create a function signature, the macro [`make_signature`] is also used, which accepts51//! settings for the function format [`SignaturePreferences`] and function parameters [`SignatureUnit`]52//! #### Example53//! ```54//! use core::str::from_utf8;55//! use evm_coder::{56//!		make_signature,57//!		custom_signature::{58//!			SIGNATURE_SIZE_LIMIT, SignatureUnit, SignaturePreferences, FunctionSignature,59//!		},60//!	};61//! // Trait for our signature62//! trait SoliditySignature {63//!		const SIGNATURE: SignatureUnit;64//!65//!		fn name() -> &'static str {66//!			from_utf8(&Self::SIGNATURE.data[..Self::SIGNATURE.len]).expect("bad utf-8")67//!		}68//!	}69//!70//! // Make signatures for some types71//!	impl SoliditySignature for u8 {72//!		make_signature!(new fixed("uint8"));73//!	}74//!	impl<T: SoliditySignature> SoliditySignature for Vec<T> {75//!		make_signature!(new nameof(T) fixed("[]"));76//!	}77//!78//! // Function signature settings79//! const SIGNATURE_PREFERENCES: SignaturePreferences = SignaturePreferences {80//!		open_name: Some(SignatureUnit::new("some_funk")),81//!		open_delimiter: Some(SignatureUnit::new("(")),82//!		param_delimiter: Some(SignatureUnit::new(",")),83//!		close_delimiter: Some(SignatureUnit::new(")")),84//!		close_name: None,85//!	};86//!87//! // Create functions signatures88//! fn make_func_without_args() {89//!		const SIG: FunctionSignature = make_signature!(90//!			new fn(SIGNATURE_PREFERENCES),91//!		);92//!		let name = SIG.as_str();93//!		similar_asserts::assert_eq!(name, "some_funk()");94//!	}95//!96//! fn make_func_with_3_args() {97//!		const SIG: FunctionSignature = make_signature!(98//!			new fn(SIGNATURE_PREFERENCES),99//!			(<u8>::SIGNATURE),100//!			(<u8>::SIGNATURE),101//!			(<Vec<u8>>::SIGNATURE),102//!		);103//!		let name = SIG.as_str();104//!		similar_asserts::assert_eq!(name, "some_funk(uint8,uint8,uint8[])");105//!	}106//! ```107use core::str::from_utf8;108109/// The maximum length of the signature.110pub const SIGNATURE_SIZE_LIMIT: usize = 256;111112/// Function signature formatting preferences.113#[derive(Debug)]114pub struct SignaturePreferences {115	/// The name of the function before the list of parameters: `*some*(param1,param2)func`116	pub open_name: Option<SignatureUnit>,117	/// Opening separator: `some*(*param1,param2)func`118	pub open_delimiter: Option<SignatureUnit>,119	/// Parameters separator: `some(param1*,*param2)func`120	pub param_delimiter: Option<SignatureUnit>,121	/// Closinging separator: `some(param1,param2*)*func`122	pub close_delimiter: Option<SignatureUnit>,123	/// The name of the function after the list of parameters: `some(param1,param2)*func*`124	pub close_name: Option<SignatureUnit>,125}126127/// Constructs and stores the signature of the function.128#[derive(Debug)]129pub struct FunctionSignature {130	/// Storage for function signature.131	pub unit: SignatureUnit,132	preferences: SignaturePreferences,133}134135impl FunctionSignature {136	/// Start constructing the signature. It is written to the storage137	/// [`SignaturePreferences::open_name`] and [`SignaturePreferences::open_delimiter`].138	pub const fn new(preferences: SignaturePreferences) -> FunctionSignature {139		let mut dst = [0_u8; SIGNATURE_SIZE_LIMIT];140		let mut dst_offset = 0;141		if let Some(ref name) = preferences.open_name {142			crate::make_signature!(@copy(name.data, dst, name.len, dst_offset));143		}144		if let Some(ref delimiter) = preferences.open_delimiter {145			crate::make_signature!(@copy(delimiter.data, dst, delimiter.len, dst_offset));146		}147		FunctionSignature {148			unit: SignatureUnit {149				data: dst,150				len: dst_offset,151			},152			preferences,153		}154	}155156	/// Add a function parameter to the signature. It is written to the storage157	/// `param` [`SignatureUnit`] and [`SignaturePreferences::param_delimiter`].158	pub const fn add_param(159		signature: FunctionSignature,160		param: SignatureUnit,161	) -> FunctionSignature {162		let mut dst = signature.unit.data;163		let mut dst_offset = signature.unit.len;164		crate::make_signature!(@copy(param.data, dst, param.len, dst_offset));165		if let Some(ref delimiter) = signature.preferences.param_delimiter {166			crate::make_signature!(@copy(delimiter.data, dst, delimiter.len, dst_offset));167		}168		FunctionSignature {169			unit: SignatureUnit {170				data: dst,171				len: dst_offset,172			},173			..signature174		}175	}176177	/// Complete signature construction. It is written to the storage178	/// [`SignaturePreferences::close_delimiter`] and [`SignaturePreferences::close_name`].179	pub const fn done(signature: FunctionSignature, owerride: bool) -> FunctionSignature {180		let mut dst = signature.unit.data;181		let mut dst_offset = signature.unit.len - if owerride { 1 } else { 0 };182		if let Some(ref delimiter) = signature.preferences.close_delimiter {183			crate::make_signature!(@copy(delimiter.data, dst, delimiter.len, dst_offset));184		}185		if let Some(ref name) = signature.preferences.close_name {186			crate::make_signature!(@copy(name.data, dst, name.len, dst_offset));187		}188		FunctionSignature {189			unit: SignatureUnit {190				data: dst,191				len: dst_offset,192			},193			..signature194		}195	}196197	/// Represent the signature as `&str'.198	pub fn as_str(&self) -> &str {199		from_utf8(&self.unit.data[..self.unit.len]).expect("bad utf-8")200	}201}202203/// Storage for the signature or its elements.204#[derive(Debug)]205pub struct SignatureUnit {206	/// Signature data.207	pub data: [u8; SIGNATURE_SIZE_LIMIT],208	/// The actual size of the data.209	pub len: usize,210}211212impl SignatureUnit {213	/// Create a signature from `&str'.214	pub const fn new(name: &'static str) -> SignatureUnit {215		let mut signature = [0_u8; SIGNATURE_SIZE_LIMIT];216		let name = name.as_bytes();217		let name_len = name.len();218		let mut dst_offset = 0;219		crate::make_signature!(@copy(name, signature, name_len, dst_offset));220		SignatureUnit {221			data: signature,222			len: name_len,223		}224	}225}226227/// ### Macro to create signatures of types and functions.228///229/// Format for creating a type of signature:230/// ```ignore231/// make_signature!(new fixed("uint8")); // Simple type232/// make_signature!(new fixed("(") nameof(u8) fixed(",") nameof(u8) fixed(")")); // Composite type233/// ```234/// Format for creating a function of the function:235/// ```ignore236/// const SIG: FunctionSignature = make_signature!(237///		new fn(SIGNATURE_PREFERENCES),238///		(u8::SIGNATURE),239///		(<(u8,u8)>::SIGNATURE),240///	);241/// ```242#[macro_export]243macro_rules! make_signature {244	(new fn($func:expr)$(,)*) => {245		{246			let fs = FunctionSignature::new($func);247			let fs = FunctionSignature::done(fs, false);248			fs249		}250	};251	(new fn($func:expr), $($tt:tt,)*) => {252		{253			let fs = FunctionSignature::new($func);254			let fs = make_signature!(@param; fs, $($tt),*);255			fs256		}257	};258259	(@param; $func:expr) => {260		FunctionSignature::done($func, true)261	};262	(@param; $func:expr, $param:expr) => {263		make_signature!(@param; FunctionSignature::add_param($func, $param))264	};265	(@param; $func:expr, $param:expr, $($tt:tt),*) => {266		make_signature!(@param; FunctionSignature::add_param($func, $param), $($tt),*)267	};268269    (new $($tt:tt)*) => {270        const SIGNATURE: SignatureUnit = SignatureUnit {271			data: {272				let mut out = [0u8; SIGNATURE_SIZE_LIMIT];273				let mut dst_offset = 0;274				make_signature!(@data(out, dst_offset); $($tt)*);275				out276			},277			len: {0 + make_signature!(@size; $($tt)*)},278        };279    };280281    (@size;) => {282        0283    };284    (@size; fixed($expr:expr) $($tt:tt)*) => {285        $expr.len() + make_signature!(@size; $($tt)*)286    };287    (@size; nameof($expr:ty) $($tt:tt)*) => {288		<$expr>::SIGNATURE.len + make_signature!(@size; $($tt)*)289    };290	(@size; shift_left($expr:expr) $($tt:tt)*) => {291		make_signature!(@size; $($tt)*) - $expr292	};293294    (@data($dst:ident, $dst_offset:ident);) => {};295    (@data($dst:ident, $dst_offset:ident); fixed($expr:expr) $($tt:tt)*) => {296        {297            let data = $expr.as_bytes();298			let data_len = data.len();299			make_signature!(@copy(data, $dst, data_len, $dst_offset));300        }301        make_signature!(@data($dst, $dst_offset); $($tt)*)302    };303    (@data($dst:ident, $dst_offset:ident); nameof($expr:ty) $($tt:tt)*) => {304        {305            make_signature!(@copy(&<$expr>::SIGNATURE.data, $dst, <$expr>::SIGNATURE.len, $dst_offset));306        }307        make_signature!(@data($dst, $dst_offset); $($tt)*)308    };309	(@data($dst:ident, $dst_offset:ident); shift_left($expr:expr) $($tt:tt)*) => {310        $dst_offset -= $expr;311        make_signature!(@data($dst, $dst_offset); $($tt)*)312    };313314	(@copy($src:expr, $dst:expr, $src_len:expr, $dst_offset:ident)) => {315		{316			let mut src_offset = 0;317			let src_len: usize = $src_len;318			while src_offset < src_len {319				$dst[$dst_offset] = $src[src_offset];320				$dst_offset += 1;321				src_offset += 1;322			}323		}324	}325}326327#[cfg(test)]328mod test {329	use core::str::from_utf8;330331	use super::{SIGNATURE_SIZE_LIMIT, SignatureUnit, FunctionSignature, SignaturePreferences};332333	trait Name {334		const SIGNATURE: SignatureUnit;335336		fn name() -> &'static str {337			from_utf8(&Self::SIGNATURE.data[..Self::SIGNATURE.len]).expect("bad utf-8")338		}339	}340341	impl Name for u8 {342		make_signature!(new fixed("uint8"));343	}344	impl Name for u32 {345		make_signature!(new fixed("uint32"));346	}347	impl<T: Name> Name for Vec<T> {348		make_signature!(new nameof(T) fixed("[]"));349	}350	impl<A: Name, B: Name> Name for (A, B) {351		make_signature!(new fixed("(") nameof(A) fixed(",") nameof(B) fixed(")"));352	}353	impl<A: Name> Name for (A,) {354		make_signature!(new fixed("(") nameof(A) fixed(",") shift_left(1) fixed(")"));355	}356357	struct MaxSize();358	impl Name for MaxSize {359		const SIGNATURE: SignatureUnit = SignatureUnit {360			data: [b'!'; SIGNATURE_SIZE_LIMIT],361			len: SIGNATURE_SIZE_LIMIT,362		};363	}364365	const SIGNATURE_PREFERENCES: SignaturePreferences = SignaturePreferences {366		open_name: Some(SignatureUnit::new("some_funk")),367		open_delimiter: Some(SignatureUnit::new("(")),368		param_delimiter: Some(SignatureUnit::new(",")),369		close_delimiter: Some(SignatureUnit::new(")")),370		close_name: None,371	};372373	#[test]374	fn simple() {375		assert_eq!(u8::name(), "uint8");376		assert_eq!(u32::name(), "uint32");377	}378379	#[test]380	fn vector_of_simple() {381		assert_eq!(<Vec<u8>>::name(), "uint8[]");382		assert_eq!(<Vec<u32>>::name(), "uint32[]");383	}384385	#[test]386	fn vector_of_vector() {387		assert_eq!(<Vec<Vec<u8>>>::name(), "uint8[][]");388	}389390	#[test]391	fn tuple_of_simple() {392		assert_eq!(<(u32, u8)>::name(), "(uint32,uint8)");393	}394395	#[test]396	fn tuple_of_tuple() {397		assert_eq!(398			<((u32, u8), (u8, u32))>::name(),399			"((uint32,uint8),(uint8,uint32))"400		);401	}402403	#[test]404	fn vector_of_tuple() {405		assert_eq!(<Vec<(u32, u8)>>::name(), "(uint32,uint8)[]");406	}407408	#[test]409	fn tuple_of_vector() {410		assert_eq!(<(Vec<u32>, u8)>::name(), "(uint32[],uint8)");411	}412413	#[test]414	fn complex() {415		assert_eq!(416			<(Vec<u32>, (u32, Vec<u8>))>::name(),417			"(uint32[],(uint32,uint8[]))"418		);419	}420421	#[test]422	fn max_size() {423		assert_eq!(<MaxSize>::name(), "!".repeat(SIGNATURE_SIZE_LIMIT));424	}425426	#[test]427	fn make_func_without_args() {428		const SIG: FunctionSignature = make_signature!(429			new fn(SIGNATURE_PREFERENCES)430		);431		let name = SIG.as_str();432		similar_asserts::assert_eq!(name, "some_funk()");433	}434435	#[test]436	fn make_func_with_1_args() {437		const SIG: FunctionSignature = make_signature!(438			new fn(SIGNATURE_PREFERENCES),439			(<u8>::SIGNATURE),440		);441		let name = SIG.as_str();442		similar_asserts::assert_eq!(name, "some_funk(uint8)");443	}444445	#[test]446	fn make_func_with_2_args() {447		const SIG: FunctionSignature = make_signature!(448			new fn(SIGNATURE_PREFERENCES),449			(u8::SIGNATURE),450			(<Vec<u32>>::SIGNATURE),451		);452		let name = SIG.as_str();453		similar_asserts::assert_eq!(name, "some_funk(uint8,uint32[])");454	}455456	#[test]457	fn make_func_with_3_args() {458		const SIG: FunctionSignature = make_signature!(459			new fn(SIGNATURE_PREFERENCES),460			(<u8>::SIGNATURE),461			(<u32>::SIGNATURE),462			(<Vec<u32>>::SIGNATURE),463		);464		let name = SIG.as_str();465		similar_asserts::assert_eq!(name, "some_funk(uint8,uint32,uint32[])");466	}467468	#[test]469	fn make_slice_from_signature() {470		const SIG: FunctionSignature = make_signature!(471			new fn(SIGNATURE_PREFERENCES),472			(<u8>::SIGNATURE),473			(<u32>::SIGNATURE),474			(<Vec<u32>>::SIGNATURE),475		);476		const NAME: [u8; SIG.unit.len] = {477			let mut name: [u8; SIG.unit.len] = [0; SIG.unit.len];478			let mut i = 0;479			while i < SIG.unit.len {480				name[i] = SIG.unit.data[i];481				i += 1;482			}483			name484		};485		similar_asserts::assert_eq!(&NAME, b"some_funk(uint8,uint32,uint32[])");486	}487488	#[test]489	fn shift() {490		assert_eq!(<(u32,)>::name(), "(uint32)");491	}492493	#[test]494	fn over_max_size() {495		let t = trybuild::TestCases::new();496		t.compile_fail("tests/build_failed/custom_signature_over_max_size.rs");497	}498}
modifiedcrates/evm-coder/src/lib.rsdiffbeforeafterboth
--- a/crates/evm-coder/src/lib.rs
+++ b/crates/evm-coder/src/lib.rs
@@ -122,7 +122,7 @@
 	use primitive_types::{U256, H160, H256};
 	use core::str::from_utf8;
 
-	use crate::custom_signature::{SignatureUnit, SIGNATURE_SIZE_LIMIT};
+	use crate::custom_signature::SignatureUnit;
 
 	pub trait Signature {
 		const SIGNATURE: SignatureUnit;
@@ -133,14 +133,14 @@
 	}
 
 	impl Signature for bool {
-		make_signature!(new fixed("bool"));
+		const SIGNATURE: SignatureUnit = make_signature!(new fixed("bool"));
 	}
 
 	macro_rules! define_simple_type {
 		(type $ident:ident = $ty:ty) => {
 			pub type $ident = $ty;
 			impl Signature for $ty {
-				make_signature!(new fixed(stringify!($ident)));
+				const SIGNATURE: SignatureUnit = make_signature!(new fixed(stringify!($ident)));
 			}
 		};
 	}
@@ -165,7 +165,7 @@
 	#[derive(Default, Debug)]
 	pub struct bytes(pub Vec<u8>);
 	impl Signature for bytes {
-		make_signature!(new fixed("bytes"));
+		const SIGNATURE: SignatureUnit = make_signature!(new fixed("bytes"));
 	}
 
 	/// Solidity doesn't have `void` type, however we have special implementation
@@ -259,7 +259,7 @@
 	}
 
 	impl Signature for EthCrossAccount {
-		make_signature!(new fixed("(address,uint256)"));
+		const SIGNATURE: SignatureUnit = make_signature!(new fixed("(address,uint256)"));
 	}
 
 	/// Convert `CrossAccountId` to `uint256`.
modifiedcrates/evm-coder/src/solidity.rsdiffbeforeafterboth
--- a/crates/evm-coder/src/solidity.rs
+++ b/crates/evm-coder/src/solidity.rs
@@ -32,7 +32,7 @@
 	cmp::Reverse,
 };
 use impl_trait_for_tuples::impl_for_tuples;
-use crate::{types::*, custom_signature::FunctionSignature};
+use crate::{types::*, custom_signature::SignatureUnit};
 
 #[derive(Default)]
 pub struct TypeCollector {
@@ -486,7 +486,7 @@
 	pub docs: &'static [&'static str],
 	pub selector: u32,
 	pub hide: bool,
-	pub custom_signature: FunctionSignature,
+	pub custom_signature: SignatureUnit,
 	pub name: &'static str,
 	pub args: A,
 	pub result: R,
@@ -512,7 +512,7 @@
 		writeln!(
 			writer,
 			"\t{hide_comment}///  or in textual repr: {}",
-			self.custom_signature.as_str()
+			self.custom_signature.as_str().expect("bad utf-8")
 		)?;
 		write!(writer, "\t{hide_comment}function {}(", self.name)?;
 		self.args.solidity_name(writer, tc)?;
modifiedpallets/common/src/erc.rsdiffbeforeafterboth
--- a/pallets/common/src/erc.rs
+++ b/pallets/common/src/erc.rs
@@ -21,8 +21,6 @@
 	types::*,
 	execution::{Result, Error},
 	weight,
-	custom_signature::{SignatureUnit, FunctionSignature, SignaturePreferences},
-	make_signature,
 };
 pub use pallet_evm::{PrecompileOutput, PrecompileResult, PrecompileHandle, account::CrossAccountId};
 use pallet_evm_coder_substrate::dispatch_to_evm;
modifiedpallets/evm-contract-helpers/src/eth.rsdiffbeforeafterboth
--- a/pallets/evm-contract-helpers/src/eth.rs
+++ b/pallets/evm-contract-helpers/src/eth.rs
@@ -19,13 +19,7 @@
 extern crate alloc;
 use core::marker::PhantomData;
 use evm_coder::{
-	abi::AbiWriter,
-	execution::Result,
-	generate_stubgen, solidity_interface,
-	types::*,
-	ToLog,
-	custom_signature::{SignatureUnit, FunctionSignature, SignaturePreferences},
-	make_signature,
+	abi::AbiWriter, execution::Result, generate_stubgen, solidity_interface, types::*, ToLog,
 };
 use pallet_evm::{
 	ExitRevert, OnCreate, OnMethodCall, PrecompileResult, PrecompileFailure, PrecompileHandle,
modifiedpallets/fungible/src/erc.rsdiffbeforeafterboth
--- a/pallets/fungible/src/erc.rs
+++ b/pallets/fungible/src/erc.rs
@@ -19,15 +19,7 @@
 extern crate alloc;
 use core::char::{REPLACEMENT_CHARACTER, decode_utf16};
 use core::convert::TryInto;
-use evm_coder::{
-	ToLog,
-	execution::*,
-	generate_stubgen, solidity_interface,
-	types::*,
-	weight,
-	custom_signature::{SignatureUnit, FunctionSignature, SignaturePreferences},
-	make_signature,
-};
+use evm_coder::{ToLog, execution::*, generate_stubgen, solidity_interface, types::*, weight};
 use up_data_structs::CollectionMode;
 use pallet_common::erc::{CommonEvmHandler, PrecompileResult};
 use sp_std::vec::Vec;
modifiedpallets/nonfungible/src/erc.rsdiffbeforeafterboth
--- a/pallets/nonfungible/src/erc.rs
+++ b/pallets/nonfungible/src/erc.rs
@@ -24,15 +24,7 @@
 	char::{REPLACEMENT_CHARACTER, decode_utf16},
 	convert::TryInto,
 };
-use evm_coder::{
-	ToLog,
-	execution::*,
-	generate_stubgen, solidity, solidity_interface,
-	types::*,
-	weight,
-	custom_signature::{SignatureUnit, FunctionSignature, SignaturePreferences},
-	make_signature,
-};
+use evm_coder::{ToLog, execution::*, generate_stubgen, solidity, solidity_interface, types::*, weight};
 use frame_support::BoundedVec;
 use up_data_structs::{
 	TokenId, PropertyPermission, PropertyKeyPermission, Property, CollectionId, PropertyKey,
modifiedpallets/refungible/src/erc.rsdiffbeforeafterboth
--- a/pallets/refungible/src/erc.rs
+++ b/pallets/refungible/src/erc.rs
@@ -25,15 +25,7 @@
 	char::{REPLACEMENT_CHARACTER, decode_utf16},
 	convert::TryInto,
 };
-use evm_coder::{
-	ToLog,
-	execution::*,
-	generate_stubgen, solidity, solidity_interface,
-	types::*,
-	weight,
-	custom_signature::{SignatureUnit, FunctionSignature, SignaturePreferences},
-	make_signature,
-};
+use evm_coder::{ToLog, execution::*, generate_stubgen, solidity, solidity_interface, types::*, weight};
 use frame_support::{BoundedBTreeMap, BoundedVec};
 use pallet_common::{
 	CollectionHandle, CollectionPropertyPermissions,
modifiedpallets/refungible/src/erc_token.rsdiffbeforeafterboth
--- a/pallets/refungible/src/erc_token.rs
+++ b/pallets/refungible/src/erc_token.rs
@@ -29,15 +29,7 @@
 	convert::TryInto,
 	ops::Deref,
 };
-use evm_coder::{
-	ToLog,
-	execution::*,
-	generate_stubgen, solidity_interface,
-	types::*,
-	weight,
-	custom_signature::{SignatureUnit, FunctionSignature, SignaturePreferences},
-	make_signature,
-};
+use evm_coder::{ToLog, execution::*, generate_stubgen, solidity_interface, types::*, weight};
 use pallet_common::{
 	CommonWeightInfo,
 	erc::{CommonEvmHandler, PrecompileResult},
modifiedpallets/unique/src/eth/mod.rsdiffbeforeafterboth
--- a/pallets/unique/src/eth/mod.rs
+++ b/pallets/unique/src/eth/mod.rs
@@ -18,13 +18,7 @@
 
 use core::marker::PhantomData;
 use ethereum as _;
-use evm_coder::{
-	execution::*,
-	generate_stubgen, solidity, solidity_interface,
-	types::*,
-	custom_signature::{SignatureUnit, FunctionSignature, SignaturePreferences},
-	make_signature, weight,
-};
+use evm_coder::{execution::*, generate_stubgen, solidity, solidity_interface, types::*, weight};
 use frame_support::traits::Get;
 use crate::Pallet;