git.delta.rocks / unique-network / refs/commits / 4c1a924fb18b

difftreelog

refactor CanBePlacedInVec

Trubnikov Sergey2022-11-02parent: #527498b.patch.diff
in: master

2 files changed

modifiedcrates/evm-coder/procedural/src/solidity_interface.rsdiffbeforeafterboth
21// https://doc.rust-lang.org/reference/procedural-macros.html21// https://doc.rust-lang.org/reference/procedural-macros.html
2222
23use proc_macro2::TokenStream;23use proc_macro2::TokenStream;
24use quote::{quote, ToTokens, format_ident};24use quote::{quote, format_ident};
25use inflector::cases;25use inflector::cases;
26use std::fmt::Write;
27use syn::{26use syn::{
28 Expr, FnArg, GenericArgument, Generics, Ident, ImplItem, ImplItemMethod, ItemImpl, Lit, Meta,27 Expr, FnArg, GenericArgument, Generics, Ident, ImplItem, ImplItemMethod, ItemImpl, Lit, Meta,
29 MetaNameValue, PatType, PathArguments, ReturnType, Type,28 MetaNameValue, PatType, PathArguments, ReturnType, Type,
33};32};
3433
35use crate::{34use crate::{
36 fn_selector_str, parse_ident_from_pat, parse_ident_from_path, parse_path, parse_path_segment,35 parse_ident_from_pat, parse_ident_from_path, parse_path, parse_path_segment, parse_result_ok,
37 parse_result_ok, pascal_ident_to_call, pascal_ident_to_snake_call, snake_ident_to_pascal,36 pascal_ident_to_call, pascal_ident_to_snake_call, snake_ident_to_pascal,
38 snake_ident_to_screaming,37 snake_ident_to_screaming,
39};38};
modifiedcrates/evm-coder/src/abi.rsdiffbeforeafterboth
--- a/crates/evm-coder/src/abi.rs
+++ b/crates/evm-coder/src/abi.rs
@@ -352,6 +352,8 @@
 
 macro_rules! impl_abi_readable {
 	($ty:ty, $method:ident, $dynamic:literal) => {
+		impl sealed::CanBePlacedInVec for $ty {}
+
 		impl TypeHelper for $ty {
 			fn is_dynamic() -> bool {
 				$dynamic
@@ -361,6 +363,7 @@
 				ABI_ALIGNMENT
 			}
 		}
+
 		impl AbiRead for $ty {
 			fn abi_read(reader: &mut AbiReader) -> Result<$ty> {
 				reader.$method()
@@ -370,7 +373,6 @@
 }
 
 impl_abi_readable!(bool, bool, false);
-impl_abi_readable!(uint8, uint8, false);
 impl_abi_readable!(uint32, uint32, false);
 impl_abi_readable!(uint64, uint64, false);
 impl_abi_readable!(uint128, uint128, false);
@@ -379,6 +381,20 @@
 impl_abi_readable!(address, address, false);
 impl_abi_readable!(string, string, true);
 
+impl TypeHelper for uint8 {
+	fn is_dynamic() -> bool {
+		false
+	}
+	fn size() -> usize {
+		ABI_ALIGNMENT
+	}
+}
+impl AbiRead for uint8 {
+	fn abi_read(reader: &mut AbiReader) -> Result<uint8> {
+		reader.uint8()
+	}
+}
+
 impl TypeHelper for bytes {
 	fn is_dynamic() -> bool {
 		true
@@ -397,11 +413,6 @@
 	/// Not all types can be placed in vec, i.e `Vec<u8>` is restricted, `bytes` should be used instead
 	pub trait CanBePlacedInVec {}
 }
-
-impl sealed::CanBePlacedInVec for U256 {}
-impl sealed::CanBePlacedInVec for string {}
-impl sealed::CanBePlacedInVec for H160 {}
-impl sealed::CanBePlacedInVec for EthCrossAccount {}
 
 impl<R: AbiRead + sealed::CanBePlacedInVec> AbiRead for Vec<R> {
 	fn abi_read(reader: &mut AbiReader) -> Result<Vec<R>> {
@@ -420,6 +431,8 @@
 	make_signature!(new nameof(R) fixed("[]"));
 }
 
+impl sealed::CanBePlacedInVec for EthCrossAccount {}
+
 impl TypeHelper for EthCrossAccount {
 	fn is_dynamic() -> bool {
 		address::is_dynamic() || uint256::is_dynamic()