git.delta.rocks / unique-network / refs/commits / 69b68ba15862

difftreelog

refactor merge sealed::CanBePlacedInVec traits

Trubnikov Sergey2022-11-18parent: #220a989.patch.diff
in: master

7 files changed

modifiedcrates/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
@@ -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 {}
 	}
 }
 
modifiedcrates/evm-coder/src/abi/impls.rsdiffbeforeafterboth
--- 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};
modifiedcrates/evm-coder/src/abi/traits.rsdiffbeforeafterboth
before · crates/evm-coder/src/abi/traits.rs
1use super::{AbiReader, AbiWriter};2use crate::{3	custom_signature::*,4	execution::{Result, ResultWithPostInfo},5};6use core::str::from_utf8;78/// Helper for type.9pub trait AbiType {10	/// Signature for Etherium ABI.11	const SIGNATURE: SignatureUnit;1213	/// Signature as str.14	fn as_str() -> &'static str {15		from_utf8(&Self::SIGNATURE.data[..Self::SIGNATURE.len]).expect("bad utf-8")16	}1718	/// Is type dynamic sized.19	fn is_dynamic() -> bool;2021	/// Size for type aligned to [`ABI_ALIGNMENT`].22	fn size() -> usize;23}2425/// Sealed traits.26pub mod sealed {27	/// Not all types can be placed in vec, i.e `Vec<u8>` is restricted, `bytes` should be used instead28	pub trait CanBePlacedInVec {}29}3031/// [`AbiReader`] implements reading of many types.32pub trait AbiRead {33	/// Read item from current position, advanding decoder34	fn abi_read(reader: &mut AbiReader) -> Result<Self>35	where36		Self: Sized;37}3839/// For questions about inability to provide custom implementations,40/// see [`AbiRead`]41pub trait AbiWrite {42	/// Write value to end of specified encoder43	fn abi_write(&self, writer: &mut AbiWriter);44	/// Specialization for [`crate::solidity_interface`] implementation,45	/// see comment in `impl AbiWrite for ResultWithPostInfo`46	fn to_result(&self) -> ResultWithPostInfo<AbiWriter> {47		let mut writer = AbiWriter::new();48		self.abi_write(&mut writer);49		Ok(writer.into())50	}51}5253impl<T: AbiWrite> AbiWrite for &T {54	fn abi_write(&self, writer: &mut AbiWriter) {55		T::abi_write(self, writer);56	}57}
after · crates/evm-coder/src/abi/traits.rs
1use super::{AbiReader, AbiWriter};2use crate::{3	custom_signature::*,4	execution::{Result, ResultWithPostInfo},5};6use core::str::from_utf8;78/// Helper for type.9pub trait AbiType {10	/// Signature for Etherium ABI.11	const SIGNATURE: SignatureUnit;1213	/// Signature as str.14	fn as_str() -> &'static str {15		from_utf8(&Self::SIGNATURE.data[..Self::SIGNATURE.len]).expect("bad utf-8")16	}1718	/// Is type dynamic sized.19	fn is_dynamic() -> bool;2021	/// Size for type aligned to [`ABI_ALIGNMENT`].22	fn size() -> usize;23}2425/// [`AbiReader`] implements reading of many types.26pub trait AbiRead {27	/// Read item from current position, advanding decoder28	fn abi_read(reader: &mut AbiReader) -> Result<Self>29	where30		Self: Sized;31}3233/// For questions about inability to provide custom implementations,34/// see [`AbiRead`]35pub trait AbiWrite {36	/// Write value to end of specified encoder37	fn abi_write(&self, writer: &mut AbiWriter);38	/// Specialization for [`crate::solidity_interface`] implementation,39	/// see comment in `impl AbiWrite for ResultWithPostInfo`40	fn to_result(&self) -> ResultWithPostInfo<AbiWriter> {41		let mut writer = AbiWriter::new();42		self.abi_write(&mut writer);43		Ok(writer.into())44	}45}4647impl<T: AbiWrite> AbiWrite for &T {48	fn abi_write(&self, writer: &mut AbiWriter) {49		T::abi_write(self, writer);50	}51}
modifiedcrates/evm-coder/src/lib.rsdiffbeforeafterboth
--- 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<u8>`)
+	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
modifiedcrates/evm-coder/src/solidity/impls.rsdiffbeforeafterboth
--- 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<string> {
 				let mut collected = Vec::with_capacity(Self::len());
modifiedcrates/evm-coder/src/solidity/traits.rsdiffbeforeafterboth
--- 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<u8>`)
-	pub trait CanBePlacedInVec {}
-}
-
 pub trait StructCollect: 'static {
 	/// Structure name.
 	fn name() -> String;
modifiedpallets/common/src/eth.rsdiffbeforeafterboth
--- 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<String> {
 		let mut collected =