From 69b68ba158621874e940ec9b9708f45e4a9adc3e Mon Sep 17 00:00:00 2001 From: Trubnikov Sergey Date: Fri, 18 Nov 2022 14:00:41 +0000 Subject: [PATCH] refactor: merge sealed::CanBePlacedInVec traits --- --- a/crates/evm-coder/procedural/src/abi_derive.rs +++ b/crates/evm-coder/procedural/src/abi_derive.rs @@ -41,7 +41,7 @@ fn impl_can_be_placed_in_vec(ident: &syn::Ident) -> proc_macro2::TokenStream { quote! { - impl ::evm_coder::abi::sealed::CanBePlacedInVec for #ident {} + impl ::evm_coder::sealed::CanBePlacedInVec for #ident {} } } --- a/crates/evm-coder/src/abi/impls.rs +++ b/crates/evm-coder/src/abi/impls.rs @@ -1,8 +1,8 @@ use crate::{ + custom_signature::SignatureUnit, execution::{Result, ResultWithPostInfo, WithPostDispatchInfo}, + make_signature, sealed, types::*, - make_signature, - custom_signature::SignatureUnit, }; use super::{traits::*, ABI_ALIGNMENT, AbiReader, AbiWriter}; use primitive_types::{U256, H160}; --- a/crates/evm-coder/src/abi/traits.rs +++ b/crates/evm-coder/src/abi/traits.rs @@ -22,12 +22,6 @@ fn size() -> usize; } -/// Sealed traits. -pub mod sealed { - /// Not all types can be placed in vec, i.e `Vec` is restricted, `bytes` should be used instead - pub trait CanBePlacedInVec {} -} - /// [`AbiReader`] implements reading of many types. pub trait AbiRead { /// Read item from current position, advanding decoder --- a/crates/evm-coder/src/lib.rs +++ b/crates/evm-coder/src/lib.rs @@ -112,6 +112,15 @@ #[cfg(feature = "stubgen")] pub mod solidity; +/// Sealed traits. +pub mod sealed { + /// Not every type should be directly placed in vec. + /// Vec encoding is not memory efficient, as every item will be padded + /// to 32 bytes. + /// Instead you should use specialized types (`bytes` in case of `Vec`) + pub trait CanBePlacedInVec {} +} + /// Solidity type definitions (aliases from solidity name to rust type) /// To be used in [`solidity_interface`] definitions, to make sure there is no /// type conflict between Rust code and generated definitions --- a/crates/evm-coder/src/solidity/impls.rs +++ b/crates/evm-coder/src/solidity/impls.rs @@ -1,11 +1,7 @@ -use super::{TypeCollector, SolidityTypeName, SolidityTupleType, sealed}; -use crate::types::*; +use super::{TypeCollector, SolidityTypeName, SolidityTupleType}; +use crate::{sealed, types::*}; use core::fmt; -impl sealed::CanBePlacedInVec for uint256 {} -impl sealed::CanBePlacedInVec for string {} -impl sealed::CanBePlacedInVec for address {} - macro_rules! solidity_type_name { ($($ty:ty => $name:literal $simple:literal = $default:literal),* $(,)?) => { $( @@ -74,7 +70,6 @@ macro_rules! impl_tuples { ($($ident:ident)+) => { - impl<$($ident),+> sealed::CanBePlacedInVec for ($($ident,)+) {} impl<$($ident: SolidityTypeName + 'static),+> SolidityTupleType for ($($ident,)+) { fn names(tc: &TypeCollector) -> Vec { let mut collected = Vec::with_capacity(Self::len()); --- a/crates/evm-coder/src/solidity/traits.rs +++ b/crates/evm-coder/src/solidity/traits.rs @@ -1,14 +1,6 @@ use super::TypeCollector; use core::fmt; -pub mod sealed { - /// Not every type should be directly placed in vec. - /// Vec encoding is not memory efficient, as every item will be padded - /// to 32 bytes. - /// Instead you should use specialized types (`bytes` in case of `Vec`) - pub trait CanBePlacedInVec {} -} - pub trait StructCollect: 'static { /// Structure name. fn name() -> String; --- a/pallets/common/src/eth.rs +++ b/pallets/common/src/eth.rs @@ -156,9 +156,6 @@ } #[cfg(feature = "stubgen")] -impl ::evm_coder::solidity::sealed::CanBePlacedInVec for EthCrossAccount {} - -#[cfg(feature = "stubgen")] impl ::evm_coder::solidity::SolidityTupleType for EthCrossAccount { fn names(tc: &::evm_coder::solidity::TypeCollector) -> Vec { let mut collected = -- gitstuff