difftreelog
fix evm nitpicks
in: master
11 files changed
Cargo.lockdiffbeforeafterboth--- a/Cargo.lock
+++ b/Cargo.lock
@@ -4290,9 +4290,6 @@
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
-dependencies = [
- "spin",
-]
[[package]]
name = "lazycell"
@@ -5920,7 +5917,6 @@
"frame-benchmarking",
"frame-support",
"frame-system",
- "lazy_static",
"pallet-evm",
"pallet-evm-coder-substrate",
"parity-scale-codec 3.1.2",
pallets/common/Cargo.tomldiffbeforeafterboth--- a/pallets/common/Cargo.toml
+++ b/pallets/common/Cargo.toml
@@ -27,7 +27,6 @@
scale-info = { version = "2.0.1", default-features = false, features = [
"derive",
] }
-lazy_static = { version = "1.4.0", default-features = false, features = ["spin_no_std"] }
[features]
default = ["std"]
pallets/common/src/erc.rsdiffbeforeafterboth--- a/pallets/common/src/erc.rs
+++ b/pallets/common/src/erc.rs
@@ -15,7 +15,7 @@
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
use evm_coder::{
- solidity_interface,
+ solidity_interface, solidity,
types::*,
execution::{Result, Error},
};
@@ -88,40 +88,64 @@
Ok(())
}
- fn set_limit(&mut self, caller: caller, limit: string, value: string) -> Result<void> {
+ #[solidity(rename_selector = "setLimit")]
+ fn set_int_limit(&mut self, caller: caller, limit: string, value: uint32) -> Result<void> {
check_is_owner(caller, self)?;
let mut limits = self.limits.clone();
match limit.as_str() {
"accountTokenOwnershipLimit" => {
- limits.account_token_ownership_limit = parse_int(value)?;
+ limits.account_token_ownership_limit = Some(value);
}
"sponsoredDataSize" => {
- limits.sponsored_data_size = parse_int(value)?;
+ limits.sponsored_data_size = Some(value);
}
"sponsoredDataRateLimit" => {
- limits.sponsored_data_rate_limit =
- Some(SponsoringRateLimit::Blocks(parse_int(value)?.unwrap()));
+ limits.sponsored_data_rate_limit = Some(SponsoringRateLimit::Blocks(value));
}
"tokenLimit" => {
- limits.token_limit = parse_int(value)?;
+ limits.token_limit = Some(value);
}
"sponsorTransferTimeout" => {
- limits.sponsor_transfer_timeout = parse_int(value)?;
+ limits.sponsor_transfer_timeout = Some(value);
}
"sponsorApproveTimeout" => {
- limits.sponsor_approve_timeout = parse_int(value)?;
+ limits.sponsor_approve_timeout = Some(value);
}
+ _ => {
+ return Err(Error::Revert(format!(
+ "Unknown integer limit \"{}\"",
+ limit
+ )))
+ }
+ }
+ self.limits = <Pallet<T>>::clamp_limits(self.mode.clone(), &self.limits, limits)
+ .map_err(dispatch_to_evm::<T>)?;
+ save(self);
+ Ok(())
+ }
+
+ #[solidity(rename_selector = "setLimit")]
+ fn set_bool_limit(&mut self, caller: caller, limit: string, value: bool) -> Result<void> {
+ check_is_owner(caller, self)?;
+ let mut limits = self.limits.clone();
+
+ match limit.as_str() {
"ownerCanTransfer" => {
- limits.owner_can_transfer = parse_bool(value)?;
+ limits.owner_can_transfer = Some(value);
}
"ownerCanDestroy" => {
- limits.owner_can_destroy = parse_bool(value)?;
+ limits.owner_can_destroy = Some(value);
}
"transfersEnabled" => {
- limits.transfers_enabled = parse_bool(value)?;
+ limits.transfers_enabled = Some(value);
}
- _ => return Err(Error::Revert(format!("Unknown limit \"{}\"", limit))),
+ _ => {
+ return Err(Error::Revert(format!(
+ "Unknown boolean limit \"{}\"",
+ limit
+ )))
+ }
}
self.limits = <Pallet<T>>::clamp_limits(self.mode.clone(), &self.limits, limits)
.map_err(dispatch_to_evm::<T>)?;
@@ -146,16 +170,9 @@
<crate::CollectionById<T>>::insert(collection.id, collection.collection.clone());
}
-fn parse_int(value: string) -> Result<Option<u32>> {
- value
- .parse::<u32>()
- .map_err(|e| Error::Revert(format!("Int value \"{}\" parse error: {}", value, e)))
- .map(|value| Some(value))
-}
-
-fn parse_bool(value: string) -> Result<Option<bool>> {
- value
- .parse::<bool>()
- .map_err(|e| Error::Revert(format!("Bool value \"{}\" parse error: {}", value, e)))
- .map(|value| Some(value))
+pub fn token_uri_key() -> up_data_structs::PropertyKey {
+ b"tokenURI"
+ .to_vec()
+ .try_into()
+ .expect("length < limit; qed")
}
pallets/common/src/eth.rsdiffbeforeafterboth--- a/pallets/common/src/eth.rs
+++ b/pallets/common/src/eth.rs
@@ -17,14 +17,6 @@
use up_data_structs::CollectionId;
use sp_core::H160;
-lazy_static::lazy_static! {
- pub static ref KEY_TOKEN_URI: up_data_structs::PropertyKey = {
- let key: evm_coder::types::string = "tokenURI".into(); //TODO: make static
- let key: up_data_structs::PropertyKey = key.into_bytes().try_into().expect("Can't create \"tokenURI\" key");
- key
- };
-}
-
// 0x17c4e6453Cc49AAAaEACA894e6D9683e00000001 - collection 1
// TODO: Unhardcode prefix
const ETH_COLLECTION_PREFIX: [u8; 16] = [
pallets/nonfungible/src/erc.rsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617extern crate alloc;18use core::{19 char::{REPLACEMENT_CHARACTER, decode_utf16},20 convert::TryInto,21};22use evm_coder::{ToLog, execution::*, generate_stubgen, solidity, solidity_interface, types::*, weight};23use frame_support::BoundedVec;24use up_data_structs::{25 TokenId, SchemaVersion, PropertyPermission, PropertyKeyPermission, Property, CollectionId,26 PropertyKey, CollectionPropertiesVec,27};28use pallet_evm_coder_substrate::dispatch_to_evm;29use sp_core::{H160, U256};30use sp_std::vec::Vec;31use pallet_common::{32 erc::{CommonEvmHandler, PrecompileResult, CollectionCall},33 CollectionHandle, CollectionPropertyPermissions,34};35use pallet_evm::account::CrossAccountId;36use pallet_evm_coder_substrate::call;37use pallet_structure::{SelfWeightOf as StructureWeight, weights::WeightInfo as _};3839use crate::{40 AccountBalance, Config, CreateItemData, NonfungibleHandle, Pallet, TokenData, TokensMinted,41 SelfWeightOf, weights::WeightInfo, TokenProperties,42};4344#[solidity_interface(name = "TokenProperties")]45impl<T: Config> NonfungibleHandle<T> {46 fn set_token_property_permission(47 &mut self,48 caller: caller,49 key: string,50 is_mutable: bool,51 collection_admin: bool,52 token_owner: bool,53 ) -> Result<()> {54 let caller = T::CrossAccountId::from_eth(caller);55 <Pallet<T>>::set_property_permission(56 self,57 &caller,58 PropertyKeyPermission {59 key: <Vec<u8>>::from(key)60 .try_into()61 .map_err(|_| "too long key")?,62 permission: PropertyPermission {63 mutable: is_mutable,64 collection_admin,65 token_owner,66 },67 },68 )69 .map_err(dispatch_to_evm::<T>)70 }7172 fn set_property(73 &mut self,74 caller: caller,75 token_id: uint256,76 key: string,77 value: bytes,78 ) -> Result<()> {79 let caller = T::CrossAccountId::from_eth(caller);80 let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;81 let key = <Vec<u8>>::from(key)82 .try_into()83 .map_err(|_| "key too long")?;84 let value = value.try_into().map_err(|_| "value too long")?;8586 <Pallet<T>>::set_token_property(self, &caller, TokenId(token_id), Property { key, value })87 .map_err(dispatch_to_evm::<T>)88 }8990 fn delete_property(&mut self, token_id: uint256, caller: caller, key: string) -> Result<()> {91 let caller = T::CrossAccountId::from_eth(caller);92 let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;93 let key = <Vec<u8>>::from(key)94 .try_into()95 .map_err(|_| "key too long")?;9697 <Pallet<T>>::delete_token_property(self, &caller, TokenId(token_id), key)98 .map_err(dispatch_to_evm::<T>)99 }100101 /// Throws error if key not found102 fn property(&self, token_id: uint256, key: string) -> Result<bytes> {103 let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;104 let key = <Vec<u8>>::from(key)105 .try_into()106 .map_err(|_| "key too long")?;107108 let props = <TokenProperties<T>>::get((self.id, token_id));109 let prop = props.get(&key).ok_or("key not found")?;110111 Ok(prop.to_vec())112 }113}114115#[derive(ToLog)]116pub enum ERC721Events {117 Transfer {118 #[indexed]119 from: address,120 #[indexed]121 to: address,122 #[indexed]123 token_id: uint256,124 },125 Approval {126 #[indexed]127 owner: address,128 #[indexed]129 approved: address,130 #[indexed]131 token_id: uint256,132 },133 #[allow(dead_code)]134 ApprovalForAll {135 #[indexed]136 owner: address,137 #[indexed]138 operator: address,139 approved: bool,140 },141}142143#[derive(ToLog)]144pub enum ERC721MintableEvents {145 #[allow(dead_code)]146 MintingFinished {},147}148149#[solidity_interface(name = "ERC721Metadata")]150impl<T: Config> NonfungibleHandle<T> {151 fn name(&self) -> Result<string> {152 Ok(decode_utf16(self.name.iter().copied())153 .map(|r| r.unwrap_or(REPLACEMENT_CHARACTER))154 .collect::<string>())155 }156157 fn symbol(&self) -> Result<string> {158 Ok(string::from_utf8_lossy(&self.token_prefix).into())159 }160161 /// Returns token's const_metadata162 #[solidity(rename_selector = "tokenURI")]163 fn token_uri(&self, token_id: uint256) -> Result<string> {164 let key = pallet_common::eth::KEY_TOKEN_URI.clone();165 if !has_token_permission::<T>(self.id, &key) {166 return Err("No tokenURI permission".into());167 }168169 self.consume_store_reads(1)?;170 let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;171172 let properties = <TokenProperties<T>>::try_get((self.id, token_id))173 .map_err(|_| Error::Revert("Token properties not found".into()))?;174 if let Some(property) = properties.get(&key) {175 return Ok(string::from_utf8_lossy(property).into());176 }177178 Err("Property tokenURI not found".into())179 }180}181182#[solidity_interface(name = "ERC721Enumerable")]183impl<T: Config> NonfungibleHandle<T> {184 fn token_by_index(&self, index: uint256) -> Result<uint256> {185 Ok(index)186 }187188 /// Not implemented189 fn token_of_owner_by_index(&self, _owner: address, _index: uint256) -> Result<uint256> {190 // TODO: Not implemetable191 Err("not implemented".into())192 }193194 fn total_supply(&self) -> Result<uint256> {195 self.consume_store_reads(1)?;196 Ok(<Pallet<T>>::total_supply(self).into())197 }198}199200#[solidity_interface(name = "ERC721", events(ERC721Events))]201impl<T: Config> NonfungibleHandle<T> {202 fn balance_of(&self, owner: address) -> Result<uint256> {203 self.consume_store_reads(1)?;204 let owner = T::CrossAccountId::from_eth(owner);205 let balance = <AccountBalance<T>>::get((self.id, owner));206 Ok(balance.into())207 }208 fn owner_of(&self, token_id: uint256) -> Result<address> {209 self.consume_store_reads(1)?;210 let token: TokenId = token_id.try_into()?;211 Ok(*<TokenData<T>>::get((self.id, token))212 .ok_or("token not found")?213 .owner214 .as_eth())215 }216 /// Not implemented217 fn safe_transfer_from_with_data(218 &mut self,219 _from: address,220 _to: address,221 _token_id: uint256,222 _data: bytes,223 _value: value,224 ) -> Result<void> {225 // TODO: Not implemetable226 Err("not implemented".into())227 }228 /// Not implemented229 fn safe_transfer_from(230 &mut self,231 _from: address,232 _to: address,233 _token_id: uint256,234 _value: value,235 ) -> Result<void> {236 // TODO: Not implemetable237 Err("not implemented".into())238 }239240 #[weight(<SelfWeightOf<T>>::transfer_from())]241 fn transfer_from(242 &mut self,243 caller: caller,244 from: address,245 to: address,246 token_id: uint256,247 _value: value,248 ) -> Result<void> {249 let caller = T::CrossAccountId::from_eth(caller);250 let from = T::CrossAccountId::from_eth(from);251 let to = T::CrossAccountId::from_eth(to);252 let token = token_id.try_into()?;253 let budget = self254 .recorder255 .weight_calls_budget(<StructureWeight<T>>::find_parent());256257 <Pallet<T>>::transfer_from(self, &caller, &from, &to, token, &budget)258 .map_err(dispatch_to_evm::<T>)?;259 Ok(())260 }261262 #[weight(<SelfWeightOf<T>>::approve())]263 fn approve(264 &mut self,265 caller: caller,266 approved: address,267 token_id: uint256,268 _value: value,269 ) -> Result<void> {270 let caller = T::CrossAccountId::from_eth(caller);271 let approved = T::CrossAccountId::from_eth(approved);272 let token = token_id.try_into()?;273274 <Pallet<T>>::set_allowance(self, &caller, token, Some(&approved))275 .map_err(dispatch_to_evm::<T>)?;276 Ok(())277 }278279 /// Not implemented280 fn set_approval_for_all(281 &mut self,282 _caller: caller,283 _operator: address,284 _approved: bool,285 ) -> Result<void> {286 // TODO: Not implemetable287 Err("not implemented".into())288 }289290 /// Not implemented291 fn get_approved(&self, _token_id: uint256) -> Result<address> {292 // TODO: Not implemetable293 Err("not implemented".into())294 }295296 /// Not implemented297 fn is_approved_for_all(&self, _owner: address, _operator: address) -> Result<address> {298 // TODO: Not implemetable299 Err("not implemented".into())300 }301}302303#[solidity_interface(name = "ERC721Burnable")]304impl<T: Config> NonfungibleHandle<T> {305 #[weight(<SelfWeightOf<T>>::burn_item())]306 fn burn(&mut self, caller: caller, token_id: uint256) -> Result<void> {307 let caller = T::CrossAccountId::from_eth(caller);308 let token = token_id.try_into()?;309310 <Pallet<T>>::burn(self, &caller, token).map_err(dispatch_to_evm::<T>)?;311 Ok(())312 }313}314315#[solidity_interface(name = "ERC721Mintable", events(ERC721MintableEvents))]316impl<T: Config> NonfungibleHandle<T> {317 fn minting_finished(&self) -> Result<bool> {318 Ok(false)319 }320321 /// `token_id` should be obtained with `next_token_id` method,322 /// unlike standard, you can't specify it manually323 #[weight(<SelfWeightOf<T>>::create_item())]324 fn mint(&mut self, caller: caller, to: address, token_id: uint256) -> Result<bool> {325 let caller = T::CrossAccountId::from_eth(caller);326 let to = T::CrossAccountId::from_eth(to);327 let token_id: u32 = token_id.try_into()?;328 let budget = self329 .recorder330 .weight_calls_budget(<StructureWeight<T>>::find_parent());331332 if <TokensMinted<T>>::get(self.id)333 .checked_add(1)334 .ok_or("item id overflow")?335 != token_id336 {337 return Err("item id should be next".into());338 }339340 <Pallet<T>>::create_item(341 self,342 &caller,343 CreateItemData::<T> {344 properties: BoundedVec::default(),345 owner: to,346 },347 &budget,348 )349 .map_err(dispatch_to_evm::<T>)?;350351 Ok(true)352 }353354 /// `token_id` should be obtained with `next_token_id` method,355 /// unlike standard, you can't specify it manually356 #[solidity(rename_selector = "mintWithTokenURI")]357 #[weight(<SelfWeightOf<T>>::create_item())]358 fn mint_with_token_uri(359 &mut self,360 caller: caller,361 to: address,362 token_id: uint256,363 token_uri: string,364 ) -> Result<bool> {365 let key = pallet_common::eth::KEY_TOKEN_URI.clone();366 let permission = get_token_permission::<T>(self.id, &key)?;367 if !permission.collection_admin {368 return Err("Operation is not allowed".into());369 }370371 let caller = T::CrossAccountId::from_eth(caller);372 let to = T::CrossAccountId::from_eth(to);373 let token_id: u32 = token_id.try_into().map_err(|_| "amount overflow")?;374 let budget = self375 .recorder376 .weight_calls_budget(<StructureWeight<T>>::find_parent());377378 if <TokensMinted<T>>::get(self.id)379 .checked_add(1)380 .ok_or("item id overflow")?381 != token_id382 {383 return Err("item id should be next".into());384 }385386 let mut properties = CollectionPropertiesVec::default();387 properties388 .try_push(Property {389 key,390 value: token_uri391 .into_bytes()392 .try_into()393 .map_err(|_| "token uri is too long")?,394 })395 .map_err(|e| Error::Revert(alloc::format!("Can't add property: {:?}", e)))?;396397 <Pallet<T>>::create_item(398 self,399 &caller,400 CreateItemData::<T> {401 properties,402 owner: to,403 },404 &budget,405 )406 .map_err(dispatch_to_evm::<T>)?;407 Ok(true)408 }409410 /// Not implemented411 fn finish_minting(&mut self, _caller: caller) -> Result<bool> {412 Err("not implementable".into())413 }414}415416fn get_token_permission<T: Config>(417 collection_id: CollectionId,418 key: &PropertyKey,419) -> Result<PropertyPermission> {420 let token_property_permissions = CollectionPropertyPermissions::<T>::try_get(collection_id)421 .map_err(|_| Error::Revert("No permissions for collection".into()))?;422 let a = token_property_permissions423 .get(key)424 .map(|p| p.clone())425 .ok_or_else(|| Error::Revert("No permission".into()))?;426 Ok(a)427}428429fn has_token_permission<T: Config>(collection_id: CollectionId, key: &PropertyKey) -> bool {430 if let Ok(token_property_permissions) =431 CollectionPropertyPermissions::<T>::try_get(collection_id)432 {433 return token_property_permissions.contains_key(key);434 }435436 false437}438439#[solidity_interface(name = "ERC721UniqueExtensions")]440impl<T: Config> NonfungibleHandle<T> {441 #[weight(<SelfWeightOf<T>>::transfer())]442 fn transfer(443 &mut self,444 caller: caller,445 to: address,446 token_id: uint256,447 _value: value,448 ) -> Result<void> {449 let caller = T::CrossAccountId::from_eth(caller);450 let to = T::CrossAccountId::from_eth(to);451 let token = token_id.try_into()?;452 let budget = self453 .recorder454 .weight_calls_budget(<StructureWeight<T>>::find_parent());455456 <Pallet<T>>::transfer(self, &caller, &to, token, &budget).map_err(dispatch_to_evm::<T>)?;457 Ok(())458 }459460 #[weight(<SelfWeightOf<T>>::burn_from())]461 fn burn_from(462 &mut self,463 caller: caller,464 from: address,465 token_id: uint256,466 _value: value,467 ) -> Result<void> {468 let caller = T::CrossAccountId::from_eth(caller);469 let from = T::CrossAccountId::from_eth(from);470 let token = token_id.try_into()?;471 let budget = self472 .recorder473 .weight_calls_budget(<StructureWeight<T>>::find_parent());474475 <Pallet<T>>::burn_from(self, &caller, &from, token, &budget)476 .map_err(dispatch_to_evm::<T>)?;477 Ok(())478 }479480 fn next_token_id(&self) -> Result<uint256> {481 self.consume_store_reads(1)?;482 Ok(<TokensMinted<T>>::get(self.id)483 .checked_add(1)484 .ok_or("item id overflow")?485 .into())486 }487488 #[weight(<SelfWeightOf<T>>::create_multiple_items(token_ids.len() as u32))]489 fn mint_bulk(&mut self, caller: caller, to: address, token_ids: Vec<uint256>) -> Result<bool> {490 let caller = T::CrossAccountId::from_eth(caller);491 let to = T::CrossAccountId::from_eth(to);492 let mut expected_index = <TokensMinted<T>>::get(self.id)493 .checked_add(1)494 .ok_or("item id overflow")?;495 let budget = self496 .recorder497 .weight_calls_budget(<StructureWeight<T>>::find_parent());498499 let total_tokens = token_ids.len();500 for id in token_ids.into_iter() {501 let id: u32 = id.try_into().map_err(|_| "token id overflow")?;502 if id != expected_index {503 return Err("item id should be next".into());504 }505 expected_index = expected_index.checked_add(1).ok_or("item id overflow")?;506 }507 let data = (0..total_tokens)508 .map(|_| CreateItemData::<T> {509 properties: BoundedVec::default(),510 owner: to.clone(),511 })512 .collect();513514 <Pallet<T>>::create_multiple_items(self, &caller, data, &budget)515 .map_err(dispatch_to_evm::<T>)?;516 Ok(true)517 }518519 #[solidity(rename_selector = "mintBulkWithTokenURI")]520 #[weight(<SelfWeightOf<T>>::create_multiple_items(tokens.len() as u32))]521 fn mint_bulk_with_token_uri(522 &mut self,523 caller: caller,524 to: address,525 tokens: Vec<(uint256, string)>,526 ) -> Result<bool> {527 let caller = T::CrossAccountId::from_eth(caller);528 let to = T::CrossAccountId::from_eth(to);529 let mut expected_index = <TokensMinted<T>>::get(self.id)530 .checked_add(1)531 .ok_or("item id overflow")?;532 let budget = self533 .recorder534 .weight_calls_budget(<StructureWeight<T>>::find_parent());535536 let mut data = Vec::with_capacity(tokens.len());537 for (id, token_uri) in tokens {538 let id: u32 = id.try_into().map_err(|_| "token id overflow")?;539 if id != expected_index {540 return Err("item id should be next".into());541 }542 expected_index = expected_index.checked_add(1).ok_or("item id overflow")?;543544 data.push(CreateItemData::<T> {545 properties: BoundedVec::default(),546 owner: to.clone(),547 });548 }549550 <Pallet<T>>::create_multiple_items(self, &caller, data, &budget)551 .map_err(dispatch_to_evm::<T>)?;552 Ok(true)553 }554}555556#[solidity_interface(557 name = "UniqueNFT",558 is(559 ERC721,560 ERC721Metadata,561 ERC721Enumerable,562 ERC721UniqueExtensions,563 ERC721Mintable,564 ERC721Burnable,565 via("CollectionHandle<T>", common_mut, Collection),566 TokenProperties,567 )568)]569impl<T: Config> NonfungibleHandle<T> {}570571// Not a tests, but code generators572generate_stubgen!(gen_impl, UniqueNFTCall<()>, true);573generate_stubgen!(gen_iface, UniqueNFTCall<()>, false);574575impl<T: Config> CommonEvmHandler for NonfungibleHandle<T> {576 const CODE: &'static [u8] = include_bytes!("./stubs/UniqueNFT.raw");577578 fn call(self, source: &H160, input: &[u8], value: U256) -> Option<PrecompileResult> {579 call::<T, UniqueNFTCall<T>, _>(*source, self, value, input)580 }581}pallets/unique/src/eth/mod.rsdiffbeforeafterboth--- a/pallets/unique/src/eth/mod.rs
+++ b/pallets/unique/src/eth/mod.rs
@@ -15,29 +15,20 @@
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
use core::marker::PhantomData;
-use evm_coder::{execution::*, generate_stubgen, solidity_interface, types::*, ToLog};
+use evm_coder::{execution::*, generate_stubgen, solidity_interface, weight, types::*};
use ethereum as _;
use pallet_evm_coder_substrate::{SubstrateRecorder, WithRecorder};
-use pallet_evm::{OnMethodCall, PrecompileResult, account::CrossAccountId, Pallet as PalletEvm};
+use pallet_evm::{OnMethodCall, PrecompileResult, account::CrossAccountId};
use up_data_structs::{
CreateCollectionData, MAX_COLLECTION_DESCRIPTION_LENGTH, MAX_TOKEN_PREFIX_LENGTH,
MAX_COLLECTION_NAME_LENGTH,
};
use frame_support::traits::Get;
-use sp_core::H160;
-use pallet_common::CollectionById;
+use pallet_common::{CollectionById, erc::token_uri_key};
+use crate::{SelfWeightOf, Config, weights::WeightInfo};
use sp_std::vec::Vec;
use alloc::format;
-
-pub trait Config:
- frame_system::Config
- + pallet_evm_coder_substrate::Config
- + pallet_evm::account::Config
- + pallet_nonfungible::Config
-{
- type ContractAddress: Get<H160>;
-}
struct EvmCollectionHelper<T: Config>(SubstrateRecorder<T>);
impl<T: Config> WithRecorder<T> for EvmCollectionHelper<T> {
@@ -51,8 +42,9 @@
}
#[solidity_interface(name = "CollectionHelper")]
-impl<T: Config> EvmCollectionHelper<T> {
- fn create_721_collection(
+impl<T: Config + pallet_nonfungible::Config> EvmCollectionHelper<T> {
+ #[weight(<SelfWeightOf<T>>::create_collection())]
+ fn create_nonfungible_collection(
&self,
caller: caller,
name: string,
@@ -77,7 +69,7 @@
.try_into()
.map_err(|_| error_feild_too_long(stringify!(token_prefix), MAX_TOKEN_PREFIX_LENGTH))?;
- let key = pallet_common::eth::KEY_TOKEN_URI.clone();
+ let key = token_uri_key();
let permission = up_data_structs::PropertyPermission {
mutable: true,
collection_admin: true,
@@ -102,13 +94,6 @@
.map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;
let address = pallet_common::eth::collection_id_to_address(collection_id);
- <PalletEvm<T>>::deposit_log(
- EthCollectionEvent::CollectionCreated {
- owner: *caller.as_eth(),
- collection_id: address,
- }
- .to_log(address),
- );
Ok(address)
}
@@ -122,18 +107,8 @@
}
}
-#[derive(ToLog)]
-pub enum EthCollectionEvent {
- CollectionCreated {
- #[indexed]
- owner: address,
- #[indexed]
- collection_id: address,
- },
-}
-
pub struct CollectionHelperOnMethodCall<T: Config>(PhantomData<*const T>);
-impl<T: Config> OnMethodCall<T> for CollectionHelperOnMethodCall<T> {
+impl<T: Config + pallet_nonfungible::Config> OnMethodCall<T> for CollectionHelperOnMethodCall<T> {
fn is_reserved(contract: &sp_core::H160) -> bool {
contract == &T::ContractAddress::get()
}
pallets/unique/src/lib.rsdiffbeforeafterboth--- a/pallets/unique/src/lib.rs
+++ b/pallets/unique/src/lib.rs
@@ -30,17 +30,18 @@
ensure,
weights::{Weight},
transactional,
- pallet_prelude::{DispatchResultWithPostInfo, ConstU32},
+ pallet_prelude::{DispatchResultWithPostInfo, ConstU32, Get},
BoundedVec,
};
+use sp_core::H160;
use scale_info::TypeInfo;
use frame_system::{self as system, ensure_signed};
use sp_runtime::{sp_std::prelude::Vec};
use up_data_structs::{
MAX_COLLECTION_NAME_LENGTH, MAX_COLLECTION_DESCRIPTION_LENGTH, MAX_TOKEN_PREFIX_LENGTH,
- AccessMode, CreateItemData, CollectionLimits, CollectionPermissions, CollectionId,
- CollectionMode, TokenId, SponsorshipState, CreateCollectionData, CreateItemExData, budget,
- Property, PropertyKey, PropertyKeyPermission,
+ CreateItemData, CollectionLimits, CollectionPermissions, CollectionId, CollectionMode, TokenId,
+ SponsorshipState, CreateCollectionData, CreateItemExData, budget, Property, PropertyKey,
+ PropertyKeyPermission,
};
use pallet_evm::account::CrossAccountId;
use pallet_common::{
@@ -74,6 +75,7 @@
/// Weight information for extrinsics in this pallet.
type WeightInfo: WeightInfo;
type CommonWeightInfo: CommonWeightInfo<Self::CrossAccountId>;
+ type ContractAddress: Get<H160>;
}
decl_event! {
runtime/opal/src/lib.rsdiffbeforeafterboth--- a/runtime/opal/src/lib.rs
+++ b/runtime/opal/src/lib.rs
@@ -917,6 +917,7 @@
type Event = Event;
type WeightInfo = pallet_unique::weights::SubstrateWeight<Self>;
type CommonWeightInfo = CommonWeights<Self>;
+ type ContractAddress = EvmCollectionHelperAddress;
}
parameter_types! {
@@ -987,10 +988,6 @@
impl pallet_evm_contract_helpers::Config for Runtime {
type ContractAddress = HelpersContractAddress;
type DefaultSponsoringRateLimit = DefaultSponsoringRateLimit;
-}
-
-impl pallet_unique::eth::Config for Runtime {
- type ContractAddress = EvmCollectionHelperAddress;
}
construct_runtime!(
runtime/quartz/src/lib.rsdiffbeforeafterboth--- a/runtime/quartz/src/lib.rs
+++ b/runtime/quartz/src/lib.rs
@@ -900,6 +900,7 @@
type Event = Event;
type WeightInfo = pallet_unique::weights::SubstrateWeight<Self>;
type CommonWeightInfo = CommonWeights<Self>;
+ type ContractAddress = EvmCollectionHelperAddress;
}
parameter_types! {
@@ -970,10 +971,6 @@
impl pallet_evm_contract_helpers::Config for Runtime {
type ContractAddress = HelpersContractAddress;
type DefaultSponsoringRateLimit = DefaultSponsoringRateLimit;
-}
-
-impl pallet_unique::eth::Config for Runtime {
- type ContractAddress = EvmCollectionHelperAddress;
}
construct_runtime!(
runtime/tests/src/lib.rsdiffbeforeafterboth--- a/runtime/tests/src/lib.rs
+++ b/runtime/tests/src/lib.rs
@@ -16,7 +16,7 @@
#![allow(clippy::from_over_into)]
-use sp_core::{H256, U256};
+use sp_core::{H160, H256, U256};
use frame_support::{
parameter_types,
traits::{Everything, ConstU32, ConstU64},
@@ -245,10 +245,18 @@
type WeightInfo = ();
}
+parameter_types! {
+ // 0x6c4e9fe1ae37a41e93cee429e8e1881abdcbb54f
+ pub const EvmCollectionHelperAddress: H160 = H160([
+ 0x6c, 0x4e, 0x9f, 0xe1, 0xae, 0x37, 0xa4, 0x1e, 0x93, 0xce, 0xe4, 0x29, 0xe8, 0xe1, 0x88, 0x1a, 0xbd, 0xcb, 0xb5, 0x4f,
+ ]);
+}
+
impl pallet_unique::Config for Test {
type Event = ();
type WeightInfo = ();
type CommonWeightInfo = CommonWeights<Self>;
+ type ContractAddress = EvmCollectionHelperAddress;
}
// Build genesis storage according to the mock runtime.
runtime/unique/src/lib.rsdiffbeforeafterboth--- a/runtime/unique/src/lib.rs
+++ b/runtime/unique/src/lib.rs
@@ -905,6 +905,7 @@
type Event = Event;
type WeightInfo = pallet_unique::weights::SubstrateWeight<Self>;
type CommonWeightInfo = CommonWeights<Self>;
+ type ContractAddress = EvmCollectionHelperAddress;
}
parameter_types! {
@@ -975,10 +976,6 @@
impl pallet_evm_contract_helpers::Config for Runtime {
type ContractAddress = HelpersContractAddress;
type DefaultSponsoringRateLimit = DefaultSponsoringRateLimit;
-}
-
-impl pallet_unique::eth::Config for Runtime {
- type ContractAddress = EvmCollectionHelperAddress;
}
construct_runtime!(