difftreelog
refacator: Move Property from evm_codet into pallet_common and derive AbiCoder
in: master
6 files changed
crates/evm-coder/src/abi/impls.rsdiffbeforeafterboth138 }138 }139}139}140141impl sealed::CanBePlacedInVec for Property {}142143impl AbiType for Property {144 const SIGNATURE: SignatureUnit = make_signature!(new fixed("(string,bytes)"));145 const FIELDS_COUNT: usize = 2;146147 fn is_dynamic() -> bool {148 string::is_dynamic() || bytes::is_dynamic()149 }150151 fn size() -> usize {152 <string as AbiType>::size() + <bytes as AbiType>::size()153 }154}155156impl 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 None162 };163 let mut subresult = reader.subresult(size)?;164 let key = <string>::abi_read(&mut subresult)?;165 let value = <bytes>::abi_read(&mut subresult)?;166167 Ok(Property { key, value })168 }169}170171impl AbiWrite for Property {172 fn abi_write(&self, writer: &mut AbiWriter) {173 (&self.key, &self.value).abi_write(writer);174 }175}176140177impl<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) {crates/evm-coder/src/lib.rsdiffbeforeafterboth197 }197 }198 }198 }199200 #[derive(Debug, Default)]201 pub struct Property {202 pub key: string,203 pub value: bytes,204 }205}199}206200207/// Parseable EVM call, this trait should be implemented with [`solidity_interface`] macro201/// Parseable EVM call, this trait should be implemented with [`solidity_interface`] macropallets/common/src/erc.rsdiffbeforeafterboth21 abi::AbiType,21 abi::AbiType,22 solidity_interface, solidity, ToLog,22 solidity_interface, solidity, ToLog,23 types::*,23 types::*,24 types::Property as PropertyStruct,25 execution::{Result, Error},24 execution::{Result, Error},26 weight,25 weight,27};26};36use crate::{35use crate::{37 Pallet, CollectionHandle, Config, CollectionProperties, SelfWeightOf,36 Pallet, CollectionHandle, Config, CollectionProperties, SelfWeightOf,38 eth::{37 eth::{39 EthCrossAccount, CollectionPermissions as EvmPermissions,38 Property as PropertyStruct, EthCrossAccount, CollectionPermissions as EvmPermissions,40 CollectionLimits as EvmCollectionLimits,39 CollectionLimits as EvmCollectionLimits,41 },40 },42 weights::WeightInfo,41 weights::WeightInfo,pallets/common/src/eth.rsdiffbeforeafterboth116 }116 }117}117}118119/// Ethereum representation of collection [`PropertyKey`](up_data_structs::PropertyKey) and [`PropertyValue`](up_data_structs::PropertyValue).120#[derive(Debug, Default, AbiCoder)]121pub struct Property {122 /// Property key.123 pub key: evm_coder::types::string,124 /// Property value.125 pub value: evm_coder::types::bytes,126}118127119/// [`CollectionLimits`](up_data_structs::CollectionLimits) representation for EVM.128/// [`CollectionLimits`](up_data_structs::CollectionLimits) representation for EVM.120#[derive(Debug, Default, Clone, Copy, AbiCoder)]129#[derive(Debug, Default, Clone, Copy, AbiCoder)]pallets/nonfungible/src/erc.rsdiffbeforeafterboth26};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;101102 let mut perms = Vec::new();100 let mut perms = Vec::new();103101104 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_COUNT111 )109 )112 .as_str()110 .as_str()113 .into());111 .into());pallets/refungible/src/erc.rsdiffbeforeafterboth27};27};28use evm_coder::{28use evm_coder::{29 abi::AbiType, ToLog, execution::*, generate_stubgen, solidity, solidity_interface, types::*,29 abi::AbiType, ToLog, execution::*, generate_stubgen, solidity, solidity_interface, types::*,30 types::Property as PropertyStruct, weight,30 weight,31};31};32use frame_support::{BoundedBTreeMap, BoundedVec};32use frame_support::{BoundedBTreeMap, BoundedVec};33use pallet_common::{33use pallet_common::{34 CollectionHandle, CollectionPropertyPermissions, CommonCollectionOperations,34 CollectionHandle, CollectionPropertyPermissions, CommonCollectionOperations,35 erc::{CommonEvmHandler, CollectionCall, static_property::key},35 erc::{CommonEvmHandler, CollectionCall, static_property::key},36 eth::{EthCrossAccount, EthTokenPermissions},36 eth::{Property as PropertyStruct, EthCrossAccount, EthTokenPermissions},37 Error as CommonError,37 Error as CommonError,38};38};39use pallet_evm::{account::CrossAccountId, PrecompileHandle};39use pallet_evm::{account::CrossAccountId, PrecompileHandle};