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
--- a/crates/evm-coder/src/lib.rs
+++ b/crates/evm-coder/src/lib.rs
@@ -196,12 +196,6 @@
 			self.len() == 0
 		}
 	}
-
-	#[derive(Debug, Default)]
-	pub struct Property {
-		pub key: string,
-		pub value: bytes,
-	}
 }
 
 /// 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
26};26};
27use evm_coder::{27use evm_coder::{
28 abi::AbiType, ToLog, execution::*, generate_stubgen, solidity, solidity_interface, types::*,28 abi::AbiType, ToLog, execution::*, generate_stubgen, solidity, solidity_interface, types::*,
29 types::Property as PropertyStruct, weight,29 weight,
30};30};
31use frame_support::BoundedVec;31use frame_support::BoundedVec;
32use up_data_structs::{32use up_data_structs::{
38use pallet_common::{38use pallet_common::{
39 CollectionHandle, CollectionPropertyPermissions, CommonCollectionOperations,39 CollectionHandle, CollectionPropertyPermissions, CommonCollectionOperations,
40 erc::{CommonEvmHandler, PrecompileResult, CollectionCall, static_property::key},40 erc::{CommonEvmHandler, PrecompileResult, CollectionCall, static_property::key},
41 eth::{EthCrossAccount, EthTokenPermissions},41 eth::{Property as PropertyStruct, EthCrossAccount, EthTokenPermissions},
42};42};
43use pallet_evm::{account::CrossAccountId, PrecompileHandle};43use pallet_evm::{account::CrossAccountId, PrecompileHandle};
44use pallet_evm_coder_substrate::call;44use pallet_evm_coder_substrate::call;
97 permissions: Vec<(string, Vec<(EthTokenPermissions, bool)>)>,97 permissions: Vec<(string, Vec<(EthTokenPermissions, bool)>)>,
98 ) -> Result<()> {98 ) -> Result<()> {
99 let caller = T::CrossAccountId::from_eth(caller);99 let caller = T::CrossAccountId::from_eth(caller);
100 const PERMISSIONS_FIELDS_COUNT: usize = 3;
101
102 let mut perms = Vec::new();100 let mut perms = Vec::new();
103101
104 for (key, pp) in permissions {102 for (key, pp) in permissions {
105 if pp.len() > PERMISSIONS_FIELDS_COUNT {103 if pp.len() > EthTokenPermissions::FIELDS_COUNT {
106 return Err(alloc::format!(104 return Err(alloc::format!(
107 "Actual number of fields {} for {}, which exceeds the maximum value of {}",105 "Actual number of fields {} for {}, which exceeds the maximum value of {}",
108 pp.len(),106 pp.len(),
109 stringify!(EthTokenPermissions),107 stringify!(EthTokenPermissions),
110 PERMISSIONS_FIELDS_COUNT108 EthTokenPermissions::FIELDS_COUNT
111 )109 )
112 .as_str()110 .as_str()
113 .into());111 .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};