difftreelog
fix PR
in: master
10 files changed
crates/evm-coder/procedural/src/abi_derive/derive_enum.rsdiffbeforeafterboth1use quote::quote;23pub fn impl_solidity_option<'a>(4 name: &proc_macro2::Ident,5 enum_options: impl Iterator<Item = &'a syn::Ident>,6) -> proc_macro2::TokenStream {7 let enum_options = enum_options.map(|opt| {8 let s = name.to_string() + "." + opt.to_string().as_str();9 let as_string = proc_macro2::Literal::string(s.as_str());10 quote!(#name::#opt => #as_string,)11 });12 quote!(13 #[cfg(feature = "stubgen")]14 impl ::evm_coder::solidity::SolidityEnum for #name {15 fn solidity_option(&self) -> &str {16 match self {17 #(#enum_options)*18 }19 }20 }21 )22}2324pub fn impl_enum_from_u8<'a>(25 name: &proc_macro2::Ident,26 enum_options: impl Iterator<Item = &'a syn::Ident>,27) -> proc_macro2::TokenStream {28 let error_str = format!("Value not convertible into enum \"{name}\"");29 let error_str = proc_macro2::Literal::string(&error_str);30 let enum_options = enum_options.enumerate().map(|(i, opt)| {31 let n = proc_macro2::Literal::u8_suffixed(i as u8);32 quote! {#n => Ok(#name::#opt),}33 });3435 quote!(36 impl TryFrom<u8> for #name {37 type Error = &'static str;3839 fn try_from(value: u8) -> ::core::result::Result<Self, Self::Error> {40 const err: &'static str = #error_str;41 match value {42 #(#enum_options)*43 _ => Err(err)44 }45 }46 }47 )48}4950pub fn impl_enum_abi_type(name: &syn::Ident, option_count: usize) -> proc_macro2::TokenStream {51 quote! {52 impl ::evm_coder::abi::AbiType for #name {53 const SIGNATURE: ::evm_coder::custom_signature::SignatureUnit = <u8 as ::evm_coder::abi::AbiType>::SIGNATURE;54 const FIELDS_COUNT: usize = #option_count;5556 fn is_dynamic() -> bool {57 <u8 as ::evm_coder::abi::AbiType>::is_dynamic()58 }59 fn size() -> usize {60 <u8 as ::evm_coder::abi::AbiType>::size()61 }62 }63 }64}6566pub fn impl_enum_abi_read(name: &syn::Ident) -> proc_macro2::TokenStream {67 quote!(68 impl ::evm_coder::abi::AbiRead for #name {69 fn abi_read(reader: &mut ::evm_coder::abi::AbiReader) -> ::evm_coder::execution::Result<Self> {70 Ok(71 <u8 as ::evm_coder::abi::AbiRead>::abi_read(reader)?72 .try_into()?73 )74 }75 }76 )77}7879pub fn impl_enum_abi_write(name: &syn::Ident) -> proc_macro2::TokenStream {80 quote!(81 impl ::evm_coder::abi::AbiWrite for #name {82 fn abi_write(&self, writer: &mut ::evm_coder::abi::AbiWriter) {83 ::evm_coder::abi::AbiWrite::abi_write(&(*self as u8), writer);84 }85 }86 )87}8889pub fn impl_enum_solidity_type<'a>(name: &syn::Ident) -> proc_macro2::TokenStream {90 quote! {91 #[cfg(feature = "stubgen")]92 impl ::evm_coder::solidity::SolidityType for #name {93 fn names(tc: &::evm_coder::solidity::TypeCollector) -> Vec<String> {94 Vec::new()95 }9697 fn len() -> usize {98 199 }100 }101 }102}103104pub fn impl_enum_solidity_type_name(name: &syn::Ident) -> proc_macro2::TokenStream {105 quote!(106 #[cfg(feature = "stubgen")]107 impl ::evm_coder::solidity::SolidityTypeName for #name {108 fn solidity_name(109 writer: &mut impl ::core::fmt::Write,110 tc: &::evm_coder::solidity::TypeCollector,111 ) -> ::core::fmt::Result {112 write!(writer, "{}", tc.collect_struct::<Self>())113 }114115 fn is_simple() -> bool {116 true117 }118119 fn solidity_default(120 writer: &mut impl ::core::fmt::Write,121 tc: &::evm_coder::solidity::TypeCollector,122 ) -> ::core::fmt::Result {123 write!(writer, "{}", <#name as ::evm_coder::solidity::SolidityEnum>::solidity_option(&<#name>::default()))124 }125 }126 )127}128129pub fn impl_enum_solidity_struct_collect<'a>(130 name: &syn::Ident,131 enum_options: impl Iterator<Item = &'a syn::Ident>,132 option_count: usize,133 enum_options_docs: impl Iterator<Item = syn::Result<Vec<proc_macro2::TokenStream>>>,134 docs: &[proc_macro2::TokenStream],135) -> proc_macro2::TokenStream {136 let string_name = name.to_string();137 let enum_options = enum_options138 .zip(enum_options_docs)139 .enumerate()140 .map(|(i, (opt, doc))| {141 let opt = proc_macro2::Literal::string(opt.to_string().as_str());142 let doc = doc.expect("Doc parsing error");143 let comma = if i != option_count - 1 { "," } else { "" };144 quote! {145 #(#doc)*146 writeln!(str, "\t{}{}", #opt, #comma).expect("Enum format option");147 }148 });149150 quote!(151 #[cfg(feature = "stubgen")]152 impl ::evm_coder::solidity::StructCollect for #name {153 fn name() -> String {154 #string_name.into()155 }156157 fn declaration() -> String {158 use std::fmt::Write;159160 let mut str = String::new();161 #(#docs)*162 writeln!(str, "enum {} {{", <Self as ::evm_coder::solidity::StructCollect>::name()).unwrap();163 #(#enum_options)*164 writeln!(str, "}}").unwrap();165 str166 }167 }168 )169}170171pub fn check_and_count_options(de: &syn::DataEnum) -> syn::Result<usize> {172 let mut count = 0;173 for v in de.variants.iter() {174 if !v.fields.is_empty() {175 return Err(syn::Error::new(176 v.ident.span(),177 "Enumeration parameters should not have fields",178 ));179 } else if v.discriminant.is_some() {180 return Err(syn::Error::new(181 v.ident.span(),182 "Enumeration options should not have an explicit specified value",183 ));184 } else {185 count += 1;186 }187 }188189 Ok(count)190}191192pub fn check_repr_u8(name: &syn::Ident, attrs: &[syn::Attribute]) -> syn::Result<()> {193 let mut has_repr = false;194 for attr in attrs.iter() {195 if attr.path.is_ident("repr") {196 has_repr = true;197 let meta = attr.parse_meta()?;198 check_meta_u8(&meta)?;199 }200 }201202 if !has_repr {203 return Err(syn::Error::new(name.span(), "Enum is not \"repr(u8)\""));204 }205206 Ok(())207}208209fn check_meta_u8(meta: &syn::Meta) -> Result<(), syn::Error> {210 if let syn::Meta::List(p) = meta {211 for nm in p.nested.iter() {212 if let syn::NestedMeta::Meta(syn::Meta::Path(p)) = nm {213 if !p.is_ident("u8") {214 return Err(syn::Error::new(215 p.segments216 .first()217 .expect("repr segments are empty")218 .ident219 .span(),220 "Enum is not \"repr(u8)\"",221 ));222 }223 }224 }225 }226 Ok(())227}1use quote::quote;23pub fn impl_solidity_option<'a>(4 name: &proc_macro2::Ident,5 enum_options: impl Iterator<Item = &'a syn::Ident>,6) -> proc_macro2::TokenStream {7 let enum_options = enum_options.map(|opt| {8 let s = name.to_string() + "." + opt.to_string().as_str();9 let as_string = proc_macro2::Literal::string(s.as_str());10 quote!(#name::#opt => #as_string,)11 });12 quote!(13 #[cfg(feature = "stubgen")]14 impl ::evm_coder::solidity::SolidityEnum for #name {15 fn solidity_option(&self) -> &str {16 match self {17 #(#enum_options)*18 }19 }20 }21 )22}2324pub fn impl_enum_from_u8<'a>(25 name: &proc_macro2::Ident,26 enum_options: impl Iterator<Item = &'a syn::Ident>,27) -> proc_macro2::TokenStream {28 let error_str = format!("Value not convertible into enum \"{name}\"");29 let error_str = proc_macro2::Literal::string(&error_str);30 let enum_options = enum_options.enumerate().map(|(i, opt)| {31 let n = proc_macro2::Literal::u8_suffixed(i as u8);32 quote! {#n => Ok(#name::#opt),}33 });3435 quote!(36 impl TryFrom<u8> for #name {37 type Error = &'static str;3839 fn try_from(value: u8) -> ::core::result::Result<Self, Self::Error> {40 const err: &'static str = #error_str;41 match value {42 #(#enum_options)*43 _ => Err(err)44 }45 }46 }47 )48}4950pub fn impl_enum_abi_type(name: &syn::Ident) -> proc_macro2::TokenStream {51 quote! {52 impl ::evm_coder::abi::AbiType for #name {53 const SIGNATURE: ::evm_coder::custom_signature::SignatureUnit = <u8 as ::evm_coder::abi::AbiType>::SIGNATURE;5455 fn is_dynamic() -> bool {56 <u8 as ::evm_coder::abi::AbiType>::is_dynamic()57 }58 fn size() -> usize {59 <u8 as ::evm_coder::abi::AbiType>::size()60 }61 }62 }63}6465pub fn impl_enum_abi_read(name: &syn::Ident) -> proc_macro2::TokenStream {66 quote!(67 impl ::evm_coder::abi::AbiRead for #name {68 fn abi_read(reader: &mut ::evm_coder::abi::AbiReader) -> ::evm_coder::execution::Result<Self> {69 Ok(70 <u8 as ::evm_coder::abi::AbiRead>::abi_read(reader)?71 .try_into()?72 )73 }74 }75 )76}7778pub fn impl_enum_abi_write(name: &syn::Ident) -> proc_macro2::TokenStream {79 quote!(80 impl ::evm_coder::abi::AbiWrite for #name {81 fn abi_write(&self, writer: &mut ::evm_coder::abi::AbiWriter) {82 ::evm_coder::abi::AbiWrite::abi_write(&(*self as u8), writer);83 }84 }85 )86}8788pub fn impl_enum_solidity_type<'a>(name: &syn::Ident) -> proc_macro2::TokenStream {89 quote! {90 #[cfg(feature = "stubgen")]91 impl ::evm_coder::solidity::SolidityType for #name {92 fn names(tc: &::evm_coder::solidity::TypeCollector) -> Vec<String> {93 Vec::new()94 }9596 fn len() -> usize {97 198 }99 }100 }101}102103pub fn impl_enum_solidity_type_name(name: &syn::Ident) -> proc_macro2::TokenStream {104 quote!(105 #[cfg(feature = "stubgen")]106 impl ::evm_coder::solidity::SolidityTypeName for #name {107 fn solidity_name(108 writer: &mut impl ::core::fmt::Write,109 tc: &::evm_coder::solidity::TypeCollector,110 ) -> ::core::fmt::Result {111 write!(writer, "{}", tc.collect_struct::<Self>())112 }113114 fn is_simple() -> bool {115 true116 }117118 fn solidity_default(119 writer: &mut impl ::core::fmt::Write,120 tc: &::evm_coder::solidity::TypeCollector,121 ) -> ::core::fmt::Result {122 write!(writer, "{}", <#name as ::evm_coder::solidity::SolidityEnum>::solidity_option(&<#name>::default()))123 }124 }125 )126}127128pub fn impl_enum_solidity_struct_collect<'a>(129 name: &syn::Ident,130 enum_options: impl Iterator<Item = &'a syn::Ident>,131 option_count: usize,132 enum_options_docs: impl Iterator<Item = syn::Result<Vec<proc_macro2::TokenStream>>>,133 docs: &[proc_macro2::TokenStream],134) -> proc_macro2::TokenStream {135 let string_name = name.to_string();136 let enum_options = enum_options137 .zip(enum_options_docs)138 .enumerate()139 .map(|(i, (opt, doc))| {140 let opt = proc_macro2::Literal::string(opt.to_string().as_str());141 let doc = doc.expect("Doc parsing error");142 let comma = if i != option_count - 1 { "," } else { "" };143 quote! {144 #(#doc)*145 writeln!(str, "\t{}{}", #opt, #comma).expect("Enum format option");146 }147 });148149 quote!(150 #[cfg(feature = "stubgen")]151 impl ::evm_coder::solidity::StructCollect for #name {152 fn name() -> String {153 #string_name.into()154 }155156 fn declaration() -> String {157 use std::fmt::Write;158159 let mut str = String::new();160 #(#docs)*161 writeln!(str, "enum {} {{", <Self as ::evm_coder::solidity::StructCollect>::name()).unwrap();162 #(#enum_options)*163 writeln!(str, "}}").unwrap();164 str165 }166 }167 )168}169170pub fn check_and_count_options(de: &syn::DataEnum) -> syn::Result<usize> {171 let mut count = 0;172 for v in de.variants.iter() {173 if !v.fields.is_empty() {174 return Err(syn::Error::new(175 v.ident.span(),176 "Enumeration parameters should not have fields",177 ));178 } else if v.discriminant.is_some() {179 return Err(syn::Error::new(180 v.ident.span(),181 "Enumeration options should not have an explicit specified value",182 ));183 } else {184 count += 1;185 }186 }187188 Ok(count)189}190191pub fn check_repr_u8(name: &syn::Ident, attrs: &[syn::Attribute]) -> syn::Result<()> {192 let mut has_repr = false;193 for attr in attrs.iter() {194 if attr.path.is_ident("repr") {195 has_repr = true;196 let meta = attr.parse_meta()?;197 check_meta_u8(&meta)?;198 }199 }200201 if !has_repr {202 return Err(syn::Error::new(name.span(), "Enum is not \"repr(u8)\""));203 }204205 Ok(())206}207208fn check_meta_u8(meta: &syn::Meta) -> Result<(), syn::Error> {209 if let syn::Meta::List(p) = meta {210 for nm in p.nested.iter() {211 if let syn::NestedMeta::Meta(syn::Meta::Path(p)) = nm {212 if !p.is_ident("u8") {213 return Err(syn::Error::new(214 p.segments215 .first()216 .expect("repr segments are empty")217 .ident218 .span(),219 "Enum is not \"repr(u8)\"",220 ));221 }222 }223 }224 }225 Ok(())226}crates/evm-coder/procedural/src/abi_derive/derive_struct.rsdiffbeforeafterboth--- a/crates/evm-coder/procedural/src/abi_derive/derive_struct.rs
+++ b/crates/evm-coder/procedural/src/abi_derive/derive_struct.rs
@@ -100,12 +100,10 @@
pub fn impl_struct_abi_type(
name: &syn::Ident,
tuple_type: proc_macro2::TokenStream,
- fields_count: usize,
) -> proc_macro2::TokenStream {
quote! {
impl ::evm_coder::abi::AbiType for #name {
const SIGNATURE: ::evm_coder::custom_signature::SignatureUnit = <#tuple_type as ::evm_coder::abi::AbiType>::SIGNATURE;
- const FIELDS_COUNT: usize = #fields_count;
fn is_dynamic() -> bool {
<#tuple_type as ::evm_coder::abi::AbiType>::is_dynamic()
}
crates/evm-coder/procedural/src/abi_derive/mod.rsdiffbeforeafterboth--- a/crates/evm-coder/procedural/src/abi_derive/mod.rs
+++ b/crates/evm-coder/procedural/src/abi_derive/mod.rs
@@ -49,7 +49,7 @@
let struct_from_tuple = struct_from_tuple(name, is_named_fields, field_names.clone());
let can_be_plcaed_in_vec = impl_can_be_placed_in_vec(name);
- let abi_type = impl_struct_abi_type(name, tuple_type.clone(), params_count);
+ let abi_type = impl_struct_abi_type(name, tuple_type.clone());
let abi_read = impl_struct_abi_read(name, tuple_type, tuple_names, struct_from_tuple);
let abi_write = impl_struct_abi_write(name, is_named_fields, tuple_ref_type, tuple_data);
let solidity_type = impl_struct_solidity_type(name, field_types.clone(), params_count);
@@ -83,7 +83,7 @@
let from = impl_enum_from_u8(name, enum_options.clone());
let solidity_option = impl_solidity_option(name, enum_options.clone());
let can_be_plcaed_in_vec = impl_can_be_placed_in_vec(name);
- let abi_type = impl_enum_abi_type(name, option_count);
+ let abi_type = impl_enum_abi_type(name);
let abi_read = impl_enum_abi_read(name);
let abi_write = impl_enum_abi_write(name);
let solidity_type = impl_enum_solidity_type(name);
crates/evm-coder/src/abi/impls.rsdiffbeforeafterboth--- a/crates/evm-coder/src/abi/impls.rs
+++ b/crates/evm-coder/src/abi/impls.rs
@@ -16,7 +16,6 @@
impl AbiType for $ty {
const SIGNATURE: SignatureUnit = make_signature!(new fixed(stringify!($name)));
- const FIELDS_COUNT: usize = 1;
fn is_dynamic() -> bool {
$dynamic
@@ -97,7 +96,6 @@
impl<T: AbiType> AbiType for &T {
const SIGNATURE: SignatureUnit = T::SIGNATURE;
- const FIELDS_COUNT: usize = T::FIELDS_COUNT;
fn is_dynamic() -> bool {
T::is_dynamic()
@@ -127,7 +125,6 @@
impl<T: AbiType> AbiType for Vec<T> {
const SIGNATURE: SignatureUnit = make_signature!(new nameof(T::SIGNATURE) fixed("[]"));
- const FIELDS_COUNT: usize = 1;
fn is_dynamic() -> bool {
true
@@ -203,7 +200,6 @@
shift_left(1)
fixed(")")
);
- const FIELDS_COUNT: usize = count!($($ident)*);
fn is_dynamic() -> bool {
false
crates/evm-coder/src/abi/traits.rsdiffbeforeafterboth--- a/crates/evm-coder/src/abi/traits.rs
+++ b/crates/evm-coder/src/abi/traits.rs
@@ -10,9 +10,6 @@
/// Signature for Etherium ABI.
const SIGNATURE: SignatureUnit;
- /// Count of enum variants or struct fields.
- const FIELDS_COUNT: usize;
-
/// Signature as str.
fn as_str() -> &'static str {
from_utf8(&Self::SIGNATURE.data[..Self::SIGNATURE.len]).expect("bad utf-8")
crates/evm-coder/tests/abi_derive_generation.rsdiffbeforeafterboth--- a/crates/evm-coder/tests/abi_derive_generation.rs
+++ b/crates/evm-coder/tests/abi_derive_generation.rs
@@ -173,50 +173,6 @@
}
#[test]
- fn impl_abi_type_fields_count() {
- assert_eq!(
- <TypeStruct1SimpleParam as evm_coder::abi::AbiType>::FIELDS_COUNT,
- 1
- );
- assert_eq!(
- <TypeStruct1DynamicParam as evm_coder::abi::AbiType>::FIELDS_COUNT,
- 1
- );
- assert_eq!(
- <TypeStruct2SimpleParam as evm_coder::abi::AbiType>::FIELDS_COUNT,
- 2
- );
- assert_eq!(
- <TypeStruct2DynamicParam as evm_coder::abi::AbiType>::FIELDS_COUNT,
- 2
- );
- assert_eq!(
- <TypeStruct2MixedParam as evm_coder::abi::AbiType>::FIELDS_COUNT,
- 2
- );
- assert_eq!(
- <TypeStruct1DerivedSimpleParam as evm_coder::abi::AbiType>::FIELDS_COUNT,
- 1
- );
- assert_eq!(
- <TypeStruct2DerivedSimpleParam as evm_coder::abi::AbiType>::FIELDS_COUNT,
- 2
- );
- assert_eq!(
- <TypeStruct1DerivedDynamicParam as evm_coder::abi::AbiType>::FIELDS_COUNT,
- 1
- );
- assert_eq!(
- <TypeStruct2DerivedDynamicParam as evm_coder::abi::AbiType>::FIELDS_COUNT,
- 2
- );
- assert_eq!(
- <TypeStruct3DerivedMixedParam as evm_coder::abi::AbiType>::FIELDS_COUNT,
- 3
- );
- }
-
- #[test]
fn impl_abi_type_is_dynamic() {
assert_eq!(
<TypeStruct1SimpleParam as evm_coder::abi::AbiType>::is_dynamic(),
pallets/common/src/erc.rsdiffbeforeafterboth--- a/pallets/common/src/erc.rs
+++ b/pallets/common/src/erc.rs
@@ -347,6 +347,10 @@
) -> Result<void> {
self.consume_store_reads_and_writes(1, 1)?;
+ if !limit.has_value() {
+ return Err(Error::Revert("user can't disable limits".into()));
+ }
+
let caller = T::CrossAccountId::from_eth(caller);
<Pallet<T>>::update_limits(&caller, self, limit.try_into()?).map_err(dispatch_to_evm::<T>)
}
pallets/common/src/eth.rsdiffbeforeafterboth--- a/pallets/common/src/eth.rs
+++ b/pallets/common/src/eth.rs
@@ -264,16 +264,17 @@
value: value.into(),
}
}
+
+ /// Whether the field contains a value.
+ pub fn has_value(&self) -> bool {
+ self.value.status
+ }
}
impl TryInto<up_data_structs::CollectionLimits> for CollectionLimit {
type Error = evm_coder::execution::Error;
fn try_into(self) -> Result<up_data_structs::CollectionLimits, Self::Error> {
- if !self.value.status {
- return Err(Self::Error::Revert("user can't disable limits".into()));
- }
-
let value = self.value.value.try_into().map_err(|error| {
Self::Error::Revert(format!(
"can't convert value to u32 \"{}\" because: \"{error}\"",
@@ -433,17 +434,6 @@
let mut perms = Vec::new();
for TokenPropertyPermission { key, permissions } in permissions {
- if permissions.len() > <TokenPermissionField as evm_coder::abi::AbiType>::FIELDS_COUNT {
- return Err(alloc::format!(
- "Actual number of fields {} for {}, which exceeds the maximum value of {}",
- permissions.len(),
- stringify!(EthTokenPermissions),
- <TokenPermissionField as evm_coder::abi::AbiType>::FIELDS_COUNT
- )
- .as_str()
- .into());
- }
-
let token_permission = PropertyPermission::from_vec(permissions);
perms.push(up_data_structs::PropertyKeyPermission {
pallets/nonfungible/src/erc.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/erc.rs
+++ b/pallets/nonfungible/src/erc.rs
@@ -38,6 +38,7 @@
use pallet_common::{
CollectionHandle, CollectionPropertyPermissions, CommonCollectionOperations,
erc::{CommonEvmHandler, PrecompileResult, CollectionCall, static_property::key},
+ eth,
};
use pallet_evm::{account::CrossAccountId, PrecompileHandle};
use pallet_evm_coder_substrate::call;
@@ -93,25 +94,21 @@
fn set_token_property_permissions(
&mut self,
caller: caller,
- permissions: Vec<pallet_common::eth::TokenPropertyPermission>,
+ permissions: Vec<eth::TokenPropertyPermission>,
) -> Result<()> {
let caller = T::CrossAccountId::from_eth(caller);
- let perms = pallet_common::eth::TokenPropertyPermission::into_property_key_permissions(
- permissions,
- )?;
+ let perms = eth::TokenPropertyPermission::into_property_key_permissions(permissions)?;
<Pallet<T>>::set_token_property_permissions(self, &caller, perms)
.map_err(dispatch_to_evm::<T>)
}
/// @notice Get permissions for token properties.
- fn token_property_permissions(
- &self,
- ) -> Result<Vec<pallet_common::eth::TokenPropertyPermission>> {
+ fn token_property_permissions(&self) -> Result<Vec<eth::TokenPropertyPermission>> {
let perms = <Pallet<T>>::token_property_permission(self.id);
Ok(perms
.into_iter()
- .map(pallet_common::eth::TokenPropertyPermission::from)
+ .map(eth::TokenPropertyPermission::from)
.collect())
}
@@ -159,7 +156,7 @@
&mut self,
caller: caller,
token_id: uint256,
- properties: Vec<pallet_common::eth::Property>,
+ properties: Vec<eth::Property>,
) -> Result<()> {
let caller = T::CrossAccountId::from_eth(caller);
let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;
@@ -170,7 +167,7 @@
let properties = properties
.into_iter()
- .map(pallet_common::eth::Property::try_into)
+ .map(eth::Property::try_into)
.collect::<Result<Vec<_>>>()?;
<Pallet<T>>::set_token_properties(
@@ -753,9 +750,9 @@
/// Returns the owner (in cross format) of the token.
///
/// @param tokenId Id for the token.
- fn cross_owner_of(&self, token_id: uint256) -> Result<pallet_common::eth::CrossAddress> {
+ fn cross_owner_of(&self, token_id: uint256) -> Result<eth::CrossAddress> {
Self::token_owner(&self, token_id.try_into()?)
- .map(|o| pallet_common::eth::CrossAddress::from_sub_cross_account::<T>(&o))
+ .map(|o| eth::CrossAddress::from_sub_cross_account::<T>(&o))
.ok_or(Error::Revert("key too large".into()))
}
@@ -764,11 +761,7 @@
/// @param tokenId Id for the token.
/// @param keys Properties keys. Empty keys for all propertyes.
/// @return Vector of properties key/value pairs.
- fn properties(
- &self,
- token_id: uint256,
- keys: Vec<string>,
- ) -> Result<Vec<pallet_common::eth::Property>> {
+ fn properties(&self, token_id: uint256, keys: Vec<string>) -> Result<Vec<eth::Property>> {
let keys = keys
.into_iter()
.map(|key| {
@@ -784,7 +777,7 @@
if keys.is_empty() { None } else { Some(keys) },
)
.into_iter()
- .map(pallet_common::eth::Property::try_from)
+ .map(eth::Property::try_from)
.collect::<Result<Vec<_>>>()
}
@@ -798,7 +791,7 @@
fn approve_cross(
&mut self,
caller: caller,
- approved: pallet_common::eth::CrossAddress,
+ approved: eth::CrossAddress,
token_id: uint256,
) -> Result<void> {
let caller = T::CrossAccountId::from_eth(caller);
@@ -837,7 +830,7 @@
fn transfer_cross(
&mut self,
caller: caller,
- to: pallet_common::eth::CrossAddress,
+ to: eth::CrossAddress,
token_id: uint256,
) -> Result<void> {
let caller = T::CrossAccountId::from_eth(caller);
@@ -861,8 +854,8 @@
fn transfer_from_cross(
&mut self,
caller: caller,
- from: pallet_common::eth::CrossAddress,
- to: pallet_common::eth::CrossAddress,
+ from: eth::CrossAddress,
+ to: eth::CrossAddress,
token_id: uint256,
) -> Result<void> {
let caller = T::CrossAccountId::from_eth(caller);
@@ -908,7 +901,7 @@
fn burn_from_cross(
&mut self,
caller: caller,
- from: pallet_common::eth::CrossAddress,
+ from: eth::CrossAddress,
token_id: uint256,
) -> Result<void> {
let caller = T::CrossAccountId::from_eth(caller);
@@ -1030,8 +1023,8 @@
fn mint_cross(
&mut self,
caller: caller,
- to: pallet_common::eth::CrossAddress,
- properties: Vec<pallet_common::eth::Property>,
+ to: eth::CrossAddress,
+ properties: Vec<eth::Property>,
) -> Result<uint256> {
let token_id = <TokensMinted<T>>::get(self.id)
.checked_add(1)
@@ -1041,7 +1034,7 @@
let properties = properties
.into_iter()
- .map(pallet_common::eth::Property::try_into)
+ .map(eth::Property::try_into)
.collect::<Result<Vec<_>>>()?
.try_into()
.map_err(|_| Error::Revert(alloc::format!("too many properties")))?;
pallets/refungible/src/erc.rsdiffbeforeafterboth--- a/pallets/refungible/src/erc.rs
+++ b/pallets/refungible/src/erc.rs
@@ -32,8 +32,9 @@
use frame_support::{BoundedBTreeMap, BoundedVec};
use pallet_common::{
CollectionHandle, CollectionPropertyPermissions, CommonCollectionOperations,
+ Error as CommonError,
erc::{CommonEvmHandler, CollectionCall, static_property::key},
- Error as CommonError,
+ eth,
};
use pallet_evm::{account::CrossAccountId, PrecompileHandle};
use pallet_evm_coder_substrate::{call, dispatch_to_evm};
@@ -96,25 +97,21 @@
fn set_token_property_permissions(
&mut self,
caller: caller,
- permissions: Vec<pallet_common::eth::TokenPropertyPermission>,
+ permissions: Vec<eth::TokenPropertyPermission>,
) -> Result<()> {
let caller = T::CrossAccountId::from_eth(caller);
- let perms = pallet_common::eth::TokenPropertyPermission::into_property_key_permissions(
- permissions,
- )?;
+ let perms = eth::TokenPropertyPermission::into_property_key_permissions(permissions)?;
<Pallet<T>>::set_token_property_permissions(self, &caller, perms)
.map_err(dispatch_to_evm::<T>)
}
/// @notice Get permissions for token properties.
- fn token_property_permissions(
- &self,
- ) -> Result<Vec<pallet_common::eth::TokenPropertyPermission>> {
+ fn token_property_permissions(&self) -> Result<Vec<eth::TokenPropertyPermission>> {
let perms = <Pallet<T>>::token_property_permission(self.id);
Ok(perms
.into_iter()
- .map(pallet_common::eth::TokenPropertyPermission::from)
+ .map(eth::TokenPropertyPermission::from)
.collect())
}
@@ -162,7 +159,7 @@
&mut self,
caller: caller,
token_id: uint256,
- properties: Vec<pallet_common::eth::Property>,
+ properties: Vec<eth::Property>,
) -> Result<()> {
let caller = T::CrossAccountId::from_eth(caller);
let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;
@@ -173,7 +170,7 @@
let properties = properties
.into_iter()
- .map(pallet_common::eth::Property::try_into)
+ .map(eth::Property::try_into)
.collect::<Result<Vec<_>>>()?;
<Pallet<T>>::set_token_properties(
@@ -788,9 +785,9 @@
/// Returns the owner (in cross format) of the token.
///
/// @param tokenId Id for the token.
- fn cross_owner_of(&self, token_id: uint256) -> Result<pallet_common::eth::CrossAddress> {
+ fn cross_owner_of(&self, token_id: uint256) -> Result<eth::CrossAddress> {
Self::token_owner(&self, token_id.try_into()?)
- .map(|o| pallet_common::eth::CrossAddress::from_sub_cross_account::<T>(&o))
+ .map(|o| eth::CrossAddress::from_sub_cross_account::<T>(&o))
.ok_or(Error::Revert("key too large".into()))
}
@@ -799,11 +796,7 @@
/// @param tokenId Id for the token.
/// @param keys Properties keys. Empty keys for all propertyes.
/// @return Vector of properties key/value pairs.
- fn properties(
- &self,
- token_id: uint256,
- keys: Vec<string>,
- ) -> Result<Vec<pallet_common::eth::Property>> {
+ fn properties(&self, token_id: uint256, keys: Vec<string>) -> Result<Vec<eth::Property>> {
let keys = keys
.into_iter()
.map(|key| {
@@ -819,7 +812,7 @@
if keys.is_empty() { None } else { Some(keys) },
)
.into_iter()
- .map(pallet_common::eth::Property::try_from)
+ .map(eth::Property::try_from)
.collect::<Result<Vec<_>>>()
}
/// @notice Transfer ownership of an RFT
@@ -855,7 +848,7 @@
fn transfer_cross(
&mut self,
caller: caller,
- to: pallet_common::eth::CrossAddress,
+ to: eth::CrossAddress,
token_id: uint256,
) -> Result<void> {
let caller = T::CrossAccountId::from_eth(caller);
@@ -883,8 +876,8 @@
fn transfer_from_cross(
&mut self,
caller: caller,
- from: pallet_common::eth::CrossAddress,
- to: pallet_common::eth::CrossAddress,
+ from: eth::CrossAddress,
+ to: eth::CrossAddress,
token_id: uint256,
) -> Result<void> {
let caller = T::CrossAccountId::from_eth(caller);
@@ -939,7 +932,7 @@
fn burn_from_cross(
&mut self,
caller: caller,
- from: pallet_common::eth::CrossAddress,
+ from: eth::CrossAddress,
token_id: uint256,
) -> Result<void> {
let caller = T::CrossAccountId::from_eth(caller);
@@ -1076,8 +1069,8 @@
fn mint_cross(
&mut self,
caller: caller,
- to: pallet_common::eth::CrossAddress,
- properties: Vec<pallet_common::eth::Property>,
+ to: eth::CrossAddress,
+ properties: Vec<eth::Property>,
) -> Result<uint256> {
let token_id = <TokensMinted<T>>::get(self.id)
.checked_add(1)
@@ -1087,7 +1080,7 @@
let properties = properties
.into_iter()
- .map(pallet_common::eth::Property::try_into)
+ .map(eth::Property::try_into)
.collect::<Result<Vec<_>>>()?
.try_into()
.map_err(|_| Error::Revert(alloc::format!("too many properties")))?;