git.delta.rocks / unique-network / refs/commits / ab6e8455f7d4

difftreelog

refacator: Move Property from evm_codet into pallet_common and derive AbiCoder

Trubnikov Sergey2022-12-19parent: #14137a1.patch.diff
in: master

6 files changed

modifiedcrates/evm-coder/src/abi/impls.rsdiffbeforeafterboth
--- a/crates/evm-coder/src/abi/impls.rs
+++ b/crates/evm-coder/src/abi/impls.rs
@@ -138,42 +138,6 @@
 	}
 }
 
-impl sealed::CanBePlacedInVec for Property {}
-
-impl AbiType for Property {
-	const SIGNATURE: SignatureUnit = make_signature!(new fixed("(string,bytes)"));
-	const FIELDS_COUNT: usize = 2;
-
-	fn is_dynamic() -> bool {
-		string::is_dynamic() || bytes::is_dynamic()
-	}
-
-	fn size() -> usize {
-		<string as AbiType>::size() + <bytes as AbiType>::size()
-	}
-}
-
-impl AbiRead for Property {
-	fn abi_read(reader: &mut AbiReader) -> Result<Property> {
-		let size = if !Property::is_dynamic() {
-			Some(<Property as AbiType>::size())
-		} else {
-			None
-		};
-		let mut subresult = reader.subresult(size)?;
-		let key = <string>::abi_read(&mut subresult)?;
-		let value = <bytes>::abi_read(&mut subresult)?;
-
-		Ok(Property { key, value })
-	}
-}
-
-impl AbiWrite for Property {
-	fn abi_write(&self, writer: &mut AbiWriter) {
-		(&self.key, &self.value).abi_write(writer);
-	}
-}
-
 impl<T: AbiWrite + AbiType> AbiWrite for Vec<T> {
 	fn abi_write(&self, writer: &mut AbiWriter) {
 		let is_dynamic = T::is_dynamic();
modifiedcrates/evm-coder/src/lib.rsdiffbeforeafterboth
197 }197 }
198 }198 }
199
200 #[derive(Debug, Default)]
201 pub struct Property {
202 pub key: string,
203 pub value: bytes,
204 }
205}199}
206200
207/// Parseable EVM call, this trait should be implemented with [`solidity_interface`] macro201/// Parseable EVM call, this trait should be implemented with [`solidity_interface`] macro
modifiedpallets/common/src/erc.rsdiffbeforeafterboth
--- a/pallets/common/src/erc.rs
+++ b/pallets/common/src/erc.rs
@@ -21,7 +21,6 @@
 	abi::AbiType,
 	solidity_interface, solidity, ToLog,
 	types::*,
-	types::Property as PropertyStruct,
 	execution::{Result, Error},
 	weight,
 };
@@ -36,7 +35,7 @@
 use crate::{
 	Pallet, CollectionHandle, Config, CollectionProperties, SelfWeightOf,
 	eth::{
-		EthCrossAccount, CollectionPermissions as EvmPermissions,
+		Property as PropertyStruct, EthCrossAccount, CollectionPermissions as EvmPermissions,
 		CollectionLimits as EvmCollectionLimits,
 	},
 	weights::WeightInfo,
modifiedpallets/common/src/eth.rsdiffbeforeafterboth
--- a/pallets/common/src/eth.rs
+++ b/pallets/common/src/eth.rs
@@ -116,6 +116,15 @@
 	}
 }
 
+/// Ethereum representation of collection [`PropertyKey`](up_data_structs::PropertyKey) and [`PropertyValue`](up_data_structs::PropertyValue).
+#[derive(Debug, Default, AbiCoder)]
+pub struct Property {
+	/// Property key.
+	pub key: evm_coder::types::string,
+	/// Property value.
+	pub value: evm_coder::types::bytes,
+}
+
 /// [`CollectionLimits`](up_data_structs::CollectionLimits) representation for EVM.
 #[derive(Debug, Default, Clone, Copy, AbiCoder)]
 #[repr(u8)]
modifiedpallets/nonfungible/src/erc.rsdiffbeforeafterboth
--- a/pallets/nonfungible/src/erc.rs
+++ b/pallets/nonfungible/src/erc.rs
@@ -26,7 +26,7 @@
 };
 use evm_coder::{
 	abi::AbiType, ToLog, execution::*, generate_stubgen, solidity, solidity_interface, types::*,
-	types::Property as PropertyStruct, weight,
+	weight,
 };
 use frame_support::BoundedVec;
 use up_data_structs::{
@@ -38,7 +38,7 @@
 use pallet_common::{
 	CollectionHandle, CollectionPropertyPermissions, CommonCollectionOperations,
 	erc::{CommonEvmHandler, PrecompileResult, CollectionCall, static_property::key},
-	eth::{EthCrossAccount, EthTokenPermissions},
+	eth::{Property as PropertyStruct, EthCrossAccount, EthTokenPermissions},
 };
 use pallet_evm::{account::CrossAccountId, PrecompileHandle};
 use pallet_evm_coder_substrate::call;
@@ -97,17 +97,15 @@
 		permissions: Vec<(string, Vec<(EthTokenPermissions, bool)>)>,
 	) -> Result<()> {
 		let caller = T::CrossAccountId::from_eth(caller);
-		const PERMISSIONS_FIELDS_COUNT: usize = 3;
-
 		let mut perms = Vec::new();
 
 		for (key, pp) in permissions {
-			if pp.len() > PERMISSIONS_FIELDS_COUNT {
+			if pp.len() > EthTokenPermissions::FIELDS_COUNT {
 				return Err(alloc::format!(
 					"Actual number of fields {} for {}, which exceeds the maximum value of {}",
 					pp.len(),
 					stringify!(EthTokenPermissions),
-					PERMISSIONS_FIELDS_COUNT
+					EthTokenPermissions::FIELDS_COUNT
 				)
 				.as_str()
 				.into());
modifiedpallets/refungible/src/erc.rsdiffbeforeafterboth
--- a/pallets/refungible/src/erc.rs
+++ b/pallets/refungible/src/erc.rs
@@ -27,13 +27,13 @@
 };
 use evm_coder::{
 	abi::AbiType, ToLog, execution::*, generate_stubgen, solidity, solidity_interface, types::*,
-	types::Property as PropertyStruct, weight,
+	weight,
 };
 use frame_support::{BoundedBTreeMap, BoundedVec};
 use pallet_common::{
 	CollectionHandle, CollectionPropertyPermissions, CommonCollectionOperations,
 	erc::{CommonEvmHandler, CollectionCall, static_property::key},
-	eth::{EthCrossAccount, EthTokenPermissions},
+	eth::{Property as PropertyStruct, EthCrossAccount, EthTokenPermissions},
 	Error as CommonError,
 };
 use pallet_evm::{account::CrossAccountId, PrecompileHandle};