difftreelog
refacator: Move Property from evm_codet into pallet_common and derive AbiCoder
in: master
6 files changed
crates/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();
crates/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
pallets/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,
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.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());
pallets/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};