From 4c1a924fb18b66fb36a9bb289b5322c6d6915eb8 Mon Sep 17 00:00:00 2001 From: Trubnikov Sergey Date: Wed, 02 Nov 2022 14:38:12 +0000 Subject: [PATCH] refactor: CanBePlacedInVec --- --- a/crates/evm-coder/procedural/src/solidity_interface.rs +++ b/crates/evm-coder/procedural/src/solidity_interface.rs @@ -21,9 +21,8 @@ // https://doc.rust-lang.org/reference/procedural-macros.html use proc_macro2::TokenStream; -use quote::{quote, ToTokens, format_ident}; +use quote::{quote, format_ident}; use inflector::cases; -use std::fmt::Write; use syn::{ Expr, FnArg, GenericArgument, Generics, Ident, ImplItem, ImplItemMethod, ItemImpl, Lit, Meta, MetaNameValue, PatType, PathArguments, ReturnType, Type, @@ -33,8 +32,8 @@ }; use crate::{ - fn_selector_str, parse_ident_from_pat, parse_ident_from_path, parse_path, parse_path_segment, - parse_result_ok, pascal_ident_to_call, pascal_ident_to_snake_call, snake_ident_to_pascal, + parse_ident_from_pat, parse_ident_from_path, parse_path, parse_path_segment, parse_result_ok, + pascal_ident_to_call, pascal_ident_to_snake_call, snake_ident_to_pascal, snake_ident_to_screaming, }; --- 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 { + 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` 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 AbiRead for Vec { fn abi_read(reader: &mut AbiReader) -> Result> { @@ -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() -- gitstuff