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
138 }138 }
139}139}
140
141impl sealed::CanBePlacedInVec for Property {}
142
143impl AbiType for Property {
144 const SIGNATURE: SignatureUnit = make_signature!(new fixed("(string,bytes)"));
145 const FIELDS_COUNT: usize = 2;
146
147 fn is_dynamic() -> bool {
148 string::is_dynamic() || bytes::is_dynamic()
149 }
150
151 fn size() -> usize {
152 <string as AbiType>::size() + <bytes as AbiType>::size()
153 }
154}
155
156impl AbiRead for Property {
157 fn abi_read(reader: &mut AbiReader) -> Result<Property> {
158 let size = if !Property::is_dynamic() {
159 Some(<Property as AbiType>::size())
160 } else {
161 None
162 };
163 let mut subresult = reader.subresult(size)?;
164 let key = <string>::abi_read(&mut subresult)?;
165 let value = <bytes>::abi_read(&mut subresult)?;
166
167 Ok(Property { key, value })
168 }
169}
170
171impl AbiWrite for Property {
172 fn abi_write(&self, writer: &mut AbiWriter) {
173 (&self.key, &self.value).abi_write(writer);
174 }
175}
176140
177impl<T: AbiWrite + AbiType> AbiWrite for Vec<T> {141impl<T: AbiWrite + AbiType> AbiWrite for Vec<T> {
178 fn abi_write(&self, writer: &mut AbiWriter) {142 fn abi_write(&self, writer: &mut AbiWriter) {
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
--- 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};