git.delta.rocks / unique-network / refs/commits / 686ae3536232

difftreelog

CORE-302 Refactor collection for eth

Trubnikov Sergey2022-05-24parent: #ad8f1f0.patch.diff
in: master

20 files changed

modifiedCargo.lockdiffbeforeafterboth
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -5467,9 +5467,9 @@
 
 [[package]]
 name = "once_cell"
-version = "1.11.0"
+version = "1.12.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7b10983b38c53aebdf33f542c6275b0f58a238129d00c4ae0e6fb59738d783ca"
+checksum = "7709cef83f0c1f58f666e746a08b21e0085f7440fa6a29cc194d68aac97a4225"
 
 [[package]]
 name = "opal-runtime"
@@ -6830,7 +6830,6 @@
  "parity-scale-codec 3.1.2",
  "scale-info",
  "serde",
- "serde-json-core",
  "sp-core",
  "sp-io",
  "sp-runtime",
@@ -10735,16 +10734,6 @@
 ]
 
 [[package]]
-name = "serde-json-core"
-version = "0.4.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8014aeea272bca0f0779778d43253f2f3375b414185b30e6ecc4d3e4a9994781"
-dependencies = [
- "ryu",
- "serde",
-]
-
-[[package]]
 name = "serde_derive"
 version = "1.0.137"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -12025,9 +12014,9 @@
 
 [[package]]
 name = "target-lexicon"
-version = "0.12.3"
+version = "0.12.4"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d7fa7e55043acb85fca6b3c01485a2eeb6b69c5d21002e273c79e465f43b7ac1"
+checksum = "c02424087780c9b71cc96799eaeddff35af2bc513278cda5c99fc1f5d026d3c1"
 
 [[package]]
 name = "tempfile"
modifiedMakefilediffbeforeafterboth
--- a/Makefile
+++ b/Makefile
@@ -15,16 +15,13 @@
 CONTRACT_HELPERS_STUBS=./pallets/evm-contract-helpers/src/stubs/
 CONTRACT_HELPERS_ABI=./tests/src/eth/util/contractHelpersAbi.json
 
-COLLECTION_STUBS=./pallets/unique/src/eth/stubs/
-COLLECTION_ABI=./tests/src/eth/collectionAbi.json
-
 COLLECTION_HELPER_STUBS=$(COLLECTION_STUBS)
 COLLECTION_HELPER_ABI=./tests/src/eth/collectionHelperAbi.json
 
 TESTS_API=./tests/src/eth/api/
 
 .PHONY: regenerate_solidity
-regenerate_solidity: UniqueFungible.sol UniqueNFT.sol ContractHelpers.sol Collection.sol CollectionHelper.sol
+regenerate_solidity: UniqueFungible.sol UniqueNFT.sol ContractHelpers.sol CollectionHelper.sol
 
 UniqueFungible.sol:
 	PACKAGE=pallet-fungible NAME=erc::gen_iface OUTPUT=$(TESTS_API)/$@ ./.maintain/scripts/generate_sol.sh
@@ -38,10 +35,6 @@
 	PACKAGE=pallet-evm-contract-helpers NAME=eth::contract_helpers_iface OUTPUT=$(TESTS_API)/$@ ./.maintain/scripts/generate_sol.sh
 	PACKAGE=pallet-evm-contract-helpers NAME=eth::contract_helpers_impl OUTPUT=$(CONTRACT_HELPERS_STUBS)/$@ ./.maintain/scripts/generate_sol.sh
 
-Collection.sol:
-	PACKAGE=pallet-unique NAME=eth::evm_collection::collection_iface OUTPUT=$(TESTS_API)/$@ ./.maintain/scripts/generate_sol.sh
-	PACKAGE=pallet-unique NAME=eth::evm_collection::collection_impl OUTPUT=$(COLLECTION_STUBS)/$@ ./.maintain/scripts/generate_sol.sh
-
 CollectionHelper.sol:
 	PACKAGE=pallet-unique NAME=eth::evm_collection::collection_helper_iface OUTPUT=$(TESTS_API)/$@ ./.maintain/scripts/generate_sol.sh
 	PACKAGE=pallet-unique NAME=eth::evm_collection::collection_helper_impl OUTPUT=$(COLLECTION_HELPER_STUBS)/$@ ./.maintain/scripts/generate_sol.sh
@@ -58,15 +51,11 @@
 	INPUT=$(CONTRACT_HELPERS_STUBS)/$< OUTPUT=$(CONTRACT_HELPERS_STUBS)/ContractHelpers.raw ./.maintain/scripts/compile_stub.sh
 	INPUT=$(CONTRACT_HELPERS_STUBS)/$< OUTPUT=$(CONTRACT_HELPERS_ABI) ./.maintain/scripts/generate_abi.sh
 
-Collection: Collection.sol
-	INPUT=$(COLLECTION_STUBS)/$< OUTPUT=$(COLLECTION_STUBS)/Collection.raw ./.maintain/scripts/compile_stub.sh
-	INPUT=$(COLLECTION_STUBS)/$< OUTPUT=$(COLLECTION_ABI) ./.maintain/scripts/generate_abi.sh
-
 CollectionHelper: CollectionHelper.sol
 	INPUT=$(COLLECTION_HELPER_STUBS)/$< OUTPUT=$(COLLECTION_HELPER_STUBS)/CollectionHelper.raw ./.maintain/scripts/compile_stub.sh
 	INPUT=$(COLLECTION_HELPER_STUBS)/$< OUTPUT=$(COLLECTION_HELPER_ABI) ./.maintain/scripts/generate_abi.sh
 
-evm_stubs: UniqueFungible UniqueNFT ContractHelpers Collection CollectionHelper
+evm_stubs: UniqueFungible UniqueNFT ContractHelpers CollectionHelper
 
 .PHONY: _bench
 _bench:
modifiedpallets/common/src/erc.rsdiffbeforeafterboth
--- a/pallets/common/src/erc.rs
+++ b/pallets/common/src/erc.rs
@@ -14,9 +14,9 @@
 // You should have received a copy of the GNU General Public License
 // along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
 
-use evm_coder::{solidity_interface, types::*, execution::Result};
+use evm_coder::{solidity_interface, types::*, execution::{Result, Error}};
 pub use pallet_evm::{PrecompileOutput, PrecompileResult, account::CrossAccountId};
-use pallet_evm_coder_substrate::dispatch_to_evm;
+use pallet_evm_coder_substrate::{dispatch_to_evm, SubstrateRecorder};
 use sp_core::{H160, U256};
 use sp_std::vec::Vec;
 use up_data_structs::Property;
@@ -31,7 +31,7 @@
 	fn call(self, source: &H160, input: &[u8], value: U256) -> Option<PrecompileResult>;
 }
 
-#[solidity_interface(name = "CollectionProperties")]
+#[solidity_interface(name = "Collection")]
 impl<T: Config> CollectionHandle<T> {
 	fn set_collection_property(&mut self, caller: caller, key: string, value: bytes) -> Result<()> {
 		let caller = T::CrossAccountId::from_eth(caller);
@@ -64,4 +64,70 @@
 
 		Ok(prop.to_vec())
 	}
+
+	fn eth_set_sponsor(
+		&mut self,
+		caller: caller,
+		sponsor: address,
+	) -> Result<void> {
+		check_is_owner(caller, self)?;
+
+		let sponsor = T::CrossAccountId::from_eth(sponsor);
+		self.set_sponsor(sponsor.as_sub().clone());
+		save(self);
+		Ok(())
+	}
+
+	fn eth_confirm_sponsorship(&mut self, caller: caller) -> Result<void> {
+		let caller = T::CrossAccountId::from_eth(caller);
+		if !self.confirm_sponsorship(caller.as_sub()) {
+			return Err(Error::Revert("Caller is not set as sponsor".into()));
+		}
+		save(self);
+		Ok(())
+	}
+
+	fn set_limits(
+		&self,
+		caller: caller,
+		limits_json: string,
+	) -> Result<void> {
+		// let mut collection = collection_from_address::<T>(self.contract_address(caller).unwrap(), self.1.gas_left())?;
+		// check_is_owner(caller, &collection)?;
+
+		// let limits = serde_json_core::from_str(limits_json.as_ref())
+		// 	.map_err(|e| Error::Revert(format!("Parse JSON error: {}", e)))?;
+		// collection.limits = limits.0;
+		// collection.save().map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;
+		Ok(())
+	}
+
+	fn contract_address(&self, _caller: caller) -> Result<address> {
+		Ok(crate::eth::collection_id_to_address(self.id))
+	}
+}
+
+fn collection_from_address<T: Config>(
+	collection_address: address,
+	gas_limit: u64
+) -> Result<CollectionHandle<T>> {
+	let collection_id = crate::eth::map_eth_to_id(&collection_address)
+	.ok_or(Error::Revert("Contract is not an unique collection".into()))?;
+	let recorder = <SubstrateRecorder<T>>::new(gas_limit);
+	let collection =
+		CollectionHandle::new_with_recorder(collection_id, recorder)
+			.ok_or(Error::Revert("Create collection handle error".into()))?;
+	Ok(collection)
+}
+
+fn check_is_owner<T: Config>(caller: caller, collection: &CollectionHandle<T>) -> Result<()> {
+	let caller = T::CrossAccountId::from_eth(caller);
+	collection
+		.check_is_owner(&caller)
+		.map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;
+	Ok(())
 }
+
+fn save<T: Config>(collection: &CollectionHandle<T>) {
+	<crate::CollectionById<T>>::insert(collection.id, collection.collection.clone());
+}
\ No newline at end of file
modifiedpallets/common/src/lib.rsdiffbeforeafterboth
--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -20,7 +20,7 @@
 
 use core::ops::{Deref, DerefMut};
 use pallet_evm_coder_substrate::{SubstrateRecorder, WithRecorder};
-use sp_std::{vec::Vec, rc::Rc};
+use sp_std::vec::Vec;
 use pallet_evm::account::CrossAccountId;
 use frame_support::{
 	dispatch::{DispatchErrorWithPostInfo, DispatchResultWithPostInfo, Weight, PostDispatchInfo},
modifiedpallets/fungible/src/erc.rsdiffbeforeafterboth
--- a/pallets/fungible/src/erc.rs
+++ b/pallets/fungible/src/erc.rs
@@ -24,7 +24,7 @@
 use pallet_evm::account::CrossAccountId;
 use pallet_evm_coder_substrate::{call, dispatch_to_evm};
 use pallet_structure::{SelfWeightOf as StructureWeight, weights::WeightInfo as _};
-use pallet_common::{CollectionHandle, erc::CollectionPropertiesCall};
+use pallet_common::{CollectionHandle, erc::CollectionCall};
 
 use crate::{
 	Allowance, Balance, Config, FungibleHandle, Pallet, SelfWeightOf, TotalSupply,
@@ -150,7 +150,7 @@
 	is(
 		ERC20,
 		ERC20UniqueExtensions,
-		via("CollectionHandle<T>", common_mut, CollectionProperties)
+		via("CollectionHandle<T>", common_mut, Collection)
 	)
 )]
 impl<T: Config> FungibleHandle<T> {}
modifiedpallets/nonfungible/src/erc.rsdiffbeforeafterboth
before · pallets/nonfungible/src/erc.rs
1// 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::{TokenId, SchemaVersion, PropertyPermission, PropertyKeyPermission, Property};25use pallet_evm_coder_substrate::dispatch_to_evm;26use sp_core::{H160, U256};27use sp_std::vec::Vec;28use pallet_common::{29	erc::{CommonEvmHandler, PrecompileResult, CollectionPropertiesCall},30	CollectionHandle,31};32use pallet_evm::account::CrossAccountId;33use pallet_evm_coder_substrate::call;34use pallet_structure::{SelfWeightOf as StructureWeight, weights::WeightInfo as _};3536use crate::{37	AccountBalance, Config, CreateItemData, NonfungibleHandle, Pallet, TokenData, TokensMinted,38	SelfWeightOf, weights::WeightInfo, TokenProperties,39};4041#[solidity_interface(name = "TokenProperties")]42impl<T: Config> NonfungibleHandle<T> {43	fn set_token_property_permission(44		&mut self,45		caller: caller,46		key: string,47		is_mutable: bool,48		collection_admin: bool,49		token_owner: bool,50	) -> Result<()> {51		let caller = T::CrossAccountId::from_eth(caller);52		<Pallet<T>>::set_property_permission(53			self,54			&caller,55			PropertyKeyPermission {56				key: <Vec<u8>>::from(key)57					.try_into()58					.map_err(|_| "too long key")?,59				permission: PropertyPermission {60					mutable: is_mutable,61					collection_admin,62					token_owner,63				},64			},65		)66		.map_err(dispatch_to_evm::<T>)67	}6869	fn set_property(70		&mut self,71		caller: caller,72		token_id: uint256,73		key: string,74		value: bytes,75	) -> Result<()> {76		let caller = T::CrossAccountId::from_eth(caller);77		let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;78		let key = <Vec<u8>>::from(key)79			.try_into()80			.map_err(|_| "key too long")?;81		let value = value.try_into().map_err(|_| "value too long")?;8283		<Pallet<T>>::set_token_property(self, &caller, TokenId(token_id), Property { key, value })84			.map_err(dispatch_to_evm::<T>)85	}8687	fn delete_property(&mut self, token_id: uint256, caller: caller, key: string) -> Result<()> {88		let caller = T::CrossAccountId::from_eth(caller);89		let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;90		let key = <Vec<u8>>::from(key)91			.try_into()92			.map_err(|_| "key too long")?;9394		<Pallet<T>>::delete_token_property(self, &caller, TokenId(token_id), key)95			.map_err(dispatch_to_evm::<T>)96	}9798	/// Throws error if key not found99	fn property(&self, token_id: uint256, key: string) -> Result<bytes> {100		let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;101		let key = <Vec<u8>>::from(key)102			.try_into()103			.map_err(|_| "key too long")?;104105		let props = <TokenProperties<T>>::get((self.id, token_id));106		let prop = props.get(&key).ok_or("key not found")?;107108		Ok(prop.to_vec())109	}110}111112#[derive(ToLog)]113pub enum ERC721Events {114	Transfer {115		#[indexed]116		from: address,117		#[indexed]118		to: address,119		#[indexed]120		token_id: uint256,121	},122	Approval {123		#[indexed]124		owner: address,125		#[indexed]126		approved: address,127		#[indexed]128		token_id: uint256,129	},130	#[allow(dead_code)]131	ApprovalForAll {132		#[indexed]133		owner: address,134		#[indexed]135		operator: address,136		approved: bool,137	},138}139140#[derive(ToLog)]141pub enum ERC721MintableEvents {142	#[allow(dead_code)]143	MintingFinished {},144}145146#[solidity_interface(name = "ERC721Metadata")]147impl<T: Config> NonfungibleHandle<T> {148	fn name(&self) -> Result<string> {149		Ok(decode_utf16(self.name.iter().copied())150			.map(|r| r.unwrap_or(REPLACEMENT_CHARACTER))151			.collect::<string>())152	}153154	fn symbol(&self) -> Result<string> {155		Ok(string::from_utf8_lossy(&self.token_prefix).into())156	}157158	/// Returns token's const_metadata159	#[solidity(rename_selector = "tokenURI")]160	fn token_uri(&self, token_id: uint256) -> Result<string> {161		self.consume_store_reads(1)?;162		let _token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;163		Ok(string::from_utf8_lossy(164			todo!()165		)166		.into())167	}168}169170#[solidity_interface(name = "ERC721Enumerable")]171impl<T: Config> NonfungibleHandle<T> {172	fn token_by_index(&self, index: uint256) -> Result<uint256> {173		Ok(index)174	}175176	/// Not implemented177	fn token_of_owner_by_index(&self, _owner: address, _index: uint256) -> Result<uint256> {178		// TODO: Not implemetable179		Err("not implemented".into())180	}181182	fn total_supply(&self) -> Result<uint256> {183		self.consume_store_reads(1)?;184		Ok(<Pallet<T>>::total_supply(self).into())185	}186}187188#[solidity_interface(name = "ERC721", events(ERC721Events))]189impl<T: Config> NonfungibleHandle<T> {190	fn balance_of(&self, owner: address) -> Result<uint256> {191		self.consume_store_reads(1)?;192		let owner = T::CrossAccountId::from_eth(owner);193		let balance = <AccountBalance<T>>::get((self.id, owner));194		Ok(balance.into())195	}196	fn owner_of(&self, token_id: uint256) -> Result<address> {197		self.consume_store_reads(1)?;198		let token: TokenId = token_id.try_into()?;199		Ok(*<TokenData<T>>::get((self.id, token))200			.ok_or("token not found")?201			.owner202			.as_eth())203	}204	/// Not implemented205	fn safe_transfer_from_with_data(206		&mut self,207		_from: address,208		_to: address,209		_token_id: uint256,210		_data: bytes,211		_value: value,212	) -> Result<void> {213		// TODO: Not implemetable214		Err("not implemented".into())215	}216	/// Not implemented217	fn safe_transfer_from(218		&mut self,219		_from: address,220		_to: address,221		_token_id: uint256,222		_value: value,223	) -> Result<void> {224		// TODO: Not implemetable225		Err("not implemented".into())226	}227228	#[weight(<SelfWeightOf<T>>::transfer_from())]229	fn transfer_from(230		&mut self,231		caller: caller,232		from: address,233		to: address,234		token_id: uint256,235		_value: value,236	) -> Result<void> {237		let caller = T::CrossAccountId::from_eth(caller);238		let from = T::CrossAccountId::from_eth(from);239		let to = T::CrossAccountId::from_eth(to);240		let token = token_id.try_into()?;241		let budget = self242			.recorder243			.weight_calls_budget(<StructureWeight<T>>::find_parent());244245		<Pallet<T>>::transfer_from(self, &caller, &from, &to, token, &budget)246			.map_err(dispatch_to_evm::<T>)?;247		Ok(())248	}249250	#[weight(<SelfWeightOf<T>>::approve())]251	fn approve(252		&mut self,253		caller: caller,254		approved: address,255		token_id: uint256,256		_value: value,257	) -> Result<void> {258		let caller = T::CrossAccountId::from_eth(caller);259		let approved = T::CrossAccountId::from_eth(approved);260		let token = token_id.try_into()?;261262		<Pallet<T>>::set_allowance(self, &caller, token, Some(&approved))263			.map_err(dispatch_to_evm::<T>)?;264		Ok(())265	}266267	/// Not implemented268	fn set_approval_for_all(269		&mut self,270		_caller: caller,271		_operator: address,272		_approved: bool,273	) -> Result<void> {274		// TODO: Not implemetable275		Err("not implemented".into())276	}277278	/// Not implemented279	fn get_approved(&self, _token_id: uint256) -> Result<address> {280		// TODO: Not implemetable281		Err("not implemented".into())282	}283284	/// Not implemented285	fn is_approved_for_all(&self, _owner: address, _operator: address) -> Result<address> {286		// TODO: Not implemetable287		Err("not implemented".into())288	}289}290291#[solidity_interface(name = "ERC721Burnable")]292impl<T: Config> NonfungibleHandle<T> {293	#[weight(<SelfWeightOf<T>>::burn_item())]294	fn burn(&mut self, caller: caller, token_id: uint256) -> Result<void> {295		let caller = T::CrossAccountId::from_eth(caller);296		let token = token_id.try_into()?;297298		<Pallet<T>>::burn(self, &caller, token).map_err(dispatch_to_evm::<T>)?;299		Ok(())300	}301}302303#[solidity_interface(name = "ERC721Mintable", events(ERC721MintableEvents))]304impl<T: Config> NonfungibleHandle<T> {305	fn minting_finished(&self) -> Result<bool> {306		Ok(false)307	}308309	/// `token_id` should be obtained with `next_token_id` method,310	/// unlike standard, you can't specify it manually311	#[weight(<SelfWeightOf<T>>::create_item())]312	fn mint(&mut self, caller: caller, to: address, token_id: uint256) -> Result<bool> {313		let caller = T::CrossAccountId::from_eth(caller);314		let to = T::CrossAccountId::from_eth(to);315		let token_id: u32 = token_id.try_into()?;316		let budget = self317			.recorder318			.weight_calls_budget(<StructureWeight<T>>::find_parent());319320		if <TokensMinted<T>>::get(self.id)321			.checked_add(1)322			.ok_or("item id overflow")?323			!= token_id324		{325			return Err("item id should be next".into());326		}327328		<Pallet<T>>::create_item(329			self,330			&caller,331			CreateItemData::<T> {332				properties: BoundedVec::default(),333				owner: to,334			},335			&budget,336		)337		.map_err(dispatch_to_evm::<T>)?;338339		Ok(true)340	}341342	/// `token_id` should be obtained with `next_token_id` method,343	/// unlike standard, you can't specify it manually344	#[solidity(rename_selector = "mintWithTokenURI")]345	#[weight(<SelfWeightOf<T>>::create_item())]346	fn mint_with_token_uri(347		&mut self,348		caller: caller,349		to: address,350		token_id: uint256,351		token_uri: string,352	) -> Result<bool> {353		let caller = T::CrossAccountId::from_eth(caller);354		let to = T::CrossAccountId::from_eth(to);355		let token_id: u32 = token_id.try_into().map_err(|_| "amount overflow")?;356		let budget = self357			.recorder358			.weight_calls_budget(<StructureWeight<T>>::find_parent());359360		if <TokensMinted<T>>::get(self.id)361			.checked_add(1)362			.ok_or("item id overflow")?363			!= token_id364		{365			return Err("item id should be next".into());366		}367368		todo!("token uri");369370		<Pallet<T>>::create_item(371			self,372			&caller,373			CreateItemData::<T> {374				properties: BoundedVec::default(),375				owner: to,376			},377			&budget,378		)379		.map_err(dispatch_to_evm::<T>)?;380		Ok(true)381	}382383	/// Not implemented384	fn finish_minting(&mut self, _caller: caller) -> Result<bool> {385		Err("not implementable".into())386	}387}388389#[solidity_interface(name = "ERC721UniqueExtensions")]390impl<T: Config> NonfungibleHandle<T> {391	#[weight(<SelfWeightOf<T>>::transfer())]392	fn transfer(393		&mut self,394		caller: caller,395		to: address,396		token_id: uint256,397		_value: value,398	) -> Result<void> {399		let caller = T::CrossAccountId::from_eth(caller);400		let to = T::CrossAccountId::from_eth(to);401		let token = token_id.try_into()?;402		let budget = self403			.recorder404			.weight_calls_budget(<StructureWeight<T>>::find_parent());405406		<Pallet<T>>::transfer(self, &caller, &to, token, &budget).map_err(dispatch_to_evm::<T>)?;407		Ok(())408	}409410	#[weight(<SelfWeightOf<T>>::burn_from())]411	fn burn_from(412		&mut self,413		caller: caller,414		from: address,415		token_id: uint256,416		_value: value,417	) -> Result<void> {418		let caller = T::CrossAccountId::from_eth(caller);419		let from = T::CrossAccountId::from_eth(from);420		let token = token_id.try_into()?;421		let budget = self422			.recorder423			.weight_calls_budget(<StructureWeight<T>>::find_parent());424425		<Pallet<T>>::burn_from(self, &caller, &from, token, &budget)426			.map_err(dispatch_to_evm::<T>)?;427		Ok(())428	}429430	fn next_token_id(&self) -> Result<uint256> {431		self.consume_store_reads(1)?;432		Ok(<TokensMinted<T>>::get(self.id)433			.checked_add(1)434			.ok_or("item id overflow")?435			.into())436	}437438	#[weight(<SelfWeightOf<T>>::create_multiple_items(token_ids.len() as u32))]439	fn mint_bulk(&mut self, caller: caller, to: address, token_ids: Vec<uint256>) -> Result<bool> {440		let caller = T::CrossAccountId::from_eth(caller);441		let to = T::CrossAccountId::from_eth(to);442		let mut expected_index = <TokensMinted<T>>::get(self.id)443			.checked_add(1)444			.ok_or("item id overflow")?;445		let budget = self446			.recorder447			.weight_calls_budget(<StructureWeight<T>>::find_parent());448449		let total_tokens = token_ids.len();450		for id in token_ids.into_iter() {451			let id: u32 = id.try_into().map_err(|_| "token id overflow")?;452			if id != expected_index {453				return Err("item id should be next".into());454			}455			expected_index = expected_index.checked_add(1).ok_or("item id overflow")?;456		}457		let data = (0..total_tokens)458			.map(|_| CreateItemData::<T> {459				properties: BoundedVec::default(),460				owner: to.clone(),461			})462			.collect();463464		<Pallet<T>>::create_multiple_items(self, &caller, data, &budget)465			.map_err(dispatch_to_evm::<T>)?;466		Ok(true)467	}468469	#[solidity(rename_selector = "mintBulkWithTokenURI")]470	#[weight(<SelfWeightOf<T>>::create_multiple_items(tokens.len() as u32))]471	fn mint_bulk_with_token_uri(472		&mut self,473		caller: caller,474		to: address,475		tokens: Vec<(uint256, string)>,476	) -> Result<bool> {477		let caller = T::CrossAccountId::from_eth(caller);478		let to = T::CrossAccountId::from_eth(to);479		let mut expected_index = <TokensMinted<T>>::get(self.id)480			.checked_add(1)481			.ok_or("item id overflow")?;482		let budget = self483			.recorder484			.weight_calls_budget(<StructureWeight<T>>::find_parent());485486		let mut data = Vec::with_capacity(tokens.len());487		for (id, token_uri) in tokens {488			let id: u32 = id.try_into().map_err(|_| "token id overflow")?;489			if id != expected_index {490				return Err("item id should be next".into());491			}492			expected_index = expected_index.checked_add(1).ok_or("item id overflow")?;493494			todo!("token uri");495			data.push(CreateItemData::<T> {496				properties: BoundedVec::default(),497				owner: to.clone(),498			});499		}500501		<Pallet<T>>::create_multiple_items(self, &caller, data, &budget)502			.map_err(dispatch_to_evm::<T>)?;503		Ok(true)504	}505}506507#[solidity_interface(508	name = "UniqueNFT",509	is(510		ERC721,511		ERC721Metadata,512		ERC721Enumerable,513		ERC721UniqueExtensions,514		ERC721Mintable,515		ERC721Burnable,516		via("CollectionHandle<T>", common_mut, CollectionProperties),517		TokenProperties,518	)519)]520impl<T: Config> NonfungibleHandle<T> {}521522// Not a tests, but code generators523generate_stubgen!(gen_impl, UniqueNFTCall<()>, true);524generate_stubgen!(gen_iface, UniqueNFTCall<()>, false);525526impl<T: Config> CommonEvmHandler for NonfungibleHandle<T> {527	const CODE: &'static [u8] = include_bytes!("./stubs/UniqueNFT.raw");528529	fn call(self, source: &H160, input: &[u8], value: U256) -> Option<PrecompileResult> {530		call::<T, UniqueNFTCall<T>, _>(*source, self, value, input)531	}532}
after · pallets/nonfungible/src/erc.rs
1// 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::{TokenId, SchemaVersion, PropertyPermission, PropertyKeyPermission, Property};25use pallet_evm_coder_substrate::dispatch_to_evm;26use sp_core::{H160, U256};27use sp_std::vec::Vec;28use pallet_common::{29	erc::{CommonEvmHandler, PrecompileResult, CollectionCall},30	CollectionHandle,31};32use pallet_evm::account::CrossAccountId;33use pallet_evm_coder_substrate::call;34use pallet_structure::{SelfWeightOf as StructureWeight, weights::WeightInfo as _};3536use crate::{37	AccountBalance, Config, CreateItemData, NonfungibleHandle, Pallet, TokenData, TokensMinted,38	SelfWeightOf, weights::WeightInfo, TokenProperties,39};4041#[solidity_interface(name = "TokenProperties")]42impl<T: Config> NonfungibleHandle<T> {43	fn set_token_property_permission(44		&mut self,45		caller: caller,46		key: string,47		is_mutable: bool,48		collection_admin: bool,49		token_owner: bool,50	) -> Result<()> {51		let caller = T::CrossAccountId::from_eth(caller);52		<Pallet<T>>::set_property_permission(53			self,54			&caller,55			PropertyKeyPermission {56				key: <Vec<u8>>::from(key)57					.try_into()58					.map_err(|_| "too long key")?,59				permission: PropertyPermission {60					mutable: is_mutable,61					collection_admin,62					token_owner,63				},64			},65		)66		.map_err(dispatch_to_evm::<T>)67	}6869	fn set_property(70		&mut self,71		caller: caller,72		token_id: uint256,73		key: string,74		value: bytes,75	) -> Result<()> {76		let caller = T::CrossAccountId::from_eth(caller);77		let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;78		let key = <Vec<u8>>::from(key)79			.try_into()80			.map_err(|_| "key too long")?;81		let value = value.try_into().map_err(|_| "value too long")?;8283		<Pallet<T>>::set_token_property(self, &caller, TokenId(token_id), Property { key, value })84			.map_err(dispatch_to_evm::<T>)85	}8687	fn delete_property(&mut self, token_id: uint256, caller: caller, key: string) -> Result<()> {88		let caller = T::CrossAccountId::from_eth(caller);89		let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;90		let key = <Vec<u8>>::from(key)91			.try_into()92			.map_err(|_| "key too long")?;9394		<Pallet<T>>::delete_token_property(self, &caller, TokenId(token_id), key)95			.map_err(dispatch_to_evm::<T>)96	}9798	/// Throws error if key not found99	fn property(&self, token_id: uint256, key: string) -> Result<bytes> {100		let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;101		let key = <Vec<u8>>::from(key)102			.try_into()103			.map_err(|_| "key too long")?;104105		let props = <TokenProperties<T>>::get((self.id, token_id));106		let prop = props.get(&key).ok_or("key not found")?;107108		Ok(prop.to_vec())109	}110}111112#[derive(ToLog)]113pub enum ERC721Events {114	Transfer {115		#[indexed]116		from: address,117		#[indexed]118		to: address,119		#[indexed]120		token_id: uint256,121	},122	Approval {123		#[indexed]124		owner: address,125		#[indexed]126		approved: address,127		#[indexed]128		token_id: uint256,129	},130	#[allow(dead_code)]131	ApprovalForAll {132		#[indexed]133		owner: address,134		#[indexed]135		operator: address,136		approved: bool,137	},138}139140#[derive(ToLog)]141pub enum ERC721MintableEvents {142	#[allow(dead_code)]143	MintingFinished {},144}145146#[solidity_interface(name = "ERC721Metadata")]147impl<T: Config> NonfungibleHandle<T> {148	fn name(&self) -> Result<string> {149		Ok(decode_utf16(self.name.iter().copied())150			.map(|r| r.unwrap_or(REPLACEMENT_CHARACTER))151			.collect::<string>())152	}153154	fn symbol(&self) -> Result<string> {155		Ok(string::from_utf8_lossy(&self.token_prefix).into())156	}157158	/// Returns token's const_metadata159	#[solidity(rename_selector = "tokenURI")]160	fn token_uri(&self, token_id: uint256) -> Result<string> {161		self.consume_store_reads(1)?;162		let _token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;163		Ok(string::from_utf8_lossy(164			todo!()165		)166		.into())167	}168}169170#[solidity_interface(name = "ERC721Enumerable")]171impl<T: Config> NonfungibleHandle<T> {172	fn token_by_index(&self, index: uint256) -> Result<uint256> {173		Ok(index)174	}175176	/// Not implemented177	fn token_of_owner_by_index(&self, _owner: address, _index: uint256) -> Result<uint256> {178		// TODO: Not implemetable179		Err("not implemented".into())180	}181182	fn total_supply(&self) -> Result<uint256> {183		self.consume_store_reads(1)?;184		Ok(<Pallet<T>>::total_supply(self).into())185	}186}187188#[solidity_interface(name = "ERC721", events(ERC721Events))]189impl<T: Config> NonfungibleHandle<T> {190	fn balance_of(&self, owner: address) -> Result<uint256> {191		self.consume_store_reads(1)?;192		let owner = T::CrossAccountId::from_eth(owner);193		let balance = <AccountBalance<T>>::get((self.id, owner));194		Ok(balance.into())195	}196	fn owner_of(&self, token_id: uint256) -> Result<address> {197		self.consume_store_reads(1)?;198		let token: TokenId = token_id.try_into()?;199		Ok(*<TokenData<T>>::get((self.id, token))200			.ok_or("token not found")?201			.owner202			.as_eth())203	}204	/// Not implemented205	fn safe_transfer_from_with_data(206		&mut self,207		_from: address,208		_to: address,209		_token_id: uint256,210		_data: bytes,211		_value: value,212	) -> Result<void> {213		// TODO: Not implemetable214		Err("not implemented".into())215	}216	/// Not implemented217	fn safe_transfer_from(218		&mut self,219		_from: address,220		_to: address,221		_token_id: uint256,222		_value: value,223	) -> Result<void> {224		// TODO: Not implemetable225		Err("not implemented".into())226	}227228	#[weight(<SelfWeightOf<T>>::transfer_from())]229	fn transfer_from(230		&mut self,231		caller: caller,232		from: address,233		to: address,234		token_id: uint256,235		_value: value,236	) -> Result<void> {237		let caller = T::CrossAccountId::from_eth(caller);238		let from = T::CrossAccountId::from_eth(from);239		let to = T::CrossAccountId::from_eth(to);240		let token = token_id.try_into()?;241		let budget = self242			.recorder243			.weight_calls_budget(<StructureWeight<T>>::find_parent());244245		<Pallet<T>>::transfer_from(self, &caller, &from, &to, token, &budget)246			.map_err(dispatch_to_evm::<T>)?;247		Ok(())248	}249250	#[weight(<SelfWeightOf<T>>::approve())]251	fn approve(252		&mut self,253		caller: caller,254		approved: address,255		token_id: uint256,256		_value: value,257	) -> Result<void> {258		let caller = T::CrossAccountId::from_eth(caller);259		let approved = T::CrossAccountId::from_eth(approved);260		let token = token_id.try_into()?;261262		<Pallet<T>>::set_allowance(self, &caller, token, Some(&approved))263			.map_err(dispatch_to_evm::<T>)?;264		Ok(())265	}266267	/// Not implemented268	fn set_approval_for_all(269		&mut self,270		_caller: caller,271		_operator: address,272		_approved: bool,273	) -> Result<void> {274		// TODO: Not implemetable275		Err("not implemented".into())276	}277278	/// Not implemented279	fn get_approved(&self, _token_id: uint256) -> Result<address> {280		// TODO: Not implemetable281		Err("not implemented".into())282	}283284	/// Not implemented285	fn is_approved_for_all(&self, _owner: address, _operator: address) -> Result<address> {286		// TODO: Not implemetable287		Err("not implemented".into())288	}289}290291#[solidity_interface(name = "ERC721Burnable")]292impl<T: Config> NonfungibleHandle<T> {293	#[weight(<SelfWeightOf<T>>::burn_item())]294	fn burn(&mut self, caller: caller, token_id: uint256) -> Result<void> {295		let caller = T::CrossAccountId::from_eth(caller);296		let token = token_id.try_into()?;297298		<Pallet<T>>::burn(self, &caller, token).map_err(dispatch_to_evm::<T>)?;299		Ok(())300	}301}302303#[solidity_interface(name = "ERC721Mintable", events(ERC721MintableEvents))]304impl<T: Config> NonfungibleHandle<T> {305	fn minting_finished(&self) -> Result<bool> {306		Ok(false)307	}308309	/// `token_id` should be obtained with `next_token_id` method,310	/// unlike standard, you can't specify it manually311	#[weight(<SelfWeightOf<T>>::create_item())]312	fn mint(&mut self, caller: caller, to: address, token_id: uint256) -> Result<bool> {313		let caller = T::CrossAccountId::from_eth(caller);314		let to = T::CrossAccountId::from_eth(to);315		let token_id: u32 = token_id.try_into()?;316		let budget = self317			.recorder318			.weight_calls_budget(<StructureWeight<T>>::find_parent());319320		if <TokensMinted<T>>::get(self.id)321			.checked_add(1)322			.ok_or("item id overflow")?323			!= token_id324		{325			return Err("item id should be next".into());326		}327328		<Pallet<T>>::create_item(329			self,330			&caller,331			CreateItemData::<T> {332				properties: BoundedVec::default(),333				owner: to,334			},335			&budget,336		)337		.map_err(dispatch_to_evm::<T>)?;338339		Ok(true)340	}341342	/// `token_id` should be obtained with `next_token_id` method,343	/// unlike standard, you can't specify it manually344	#[solidity(rename_selector = "mintWithTokenURI")]345	#[weight(<SelfWeightOf<T>>::create_item())]346	fn mint_with_token_uri(347		&mut self,348		caller: caller,349		to: address,350		token_id: uint256,351		token_uri: string,352	) -> Result<bool> {353		let caller = T::CrossAccountId::from_eth(caller);354		let to = T::CrossAccountId::from_eth(to);355		let token_id: u32 = token_id.try_into().map_err(|_| "amount overflow")?;356		let budget = self357			.recorder358			.weight_calls_budget(<StructureWeight<T>>::find_parent());359360		if <TokensMinted<T>>::get(self.id)361			.checked_add(1)362			.ok_or("item id overflow")?363			!= token_id364		{365			return Err("item id should be next".into());366		}367368		todo!("token uri");369370		<Pallet<T>>::create_item(371			self,372			&caller,373			CreateItemData::<T> {374				properties: BoundedVec::default(),375				owner: to,376			},377			&budget,378		)379		.map_err(dispatch_to_evm::<T>)?;380		Ok(true)381	}382383	/// Not implemented384	fn finish_minting(&mut self, _caller: caller) -> Result<bool> {385		Err("not implementable".into())386	}387}388389#[solidity_interface(name = "ERC721UniqueExtensions")]390impl<T: Config> NonfungibleHandle<T> {391	#[weight(<SelfWeightOf<T>>::transfer())]392	fn transfer(393		&mut self,394		caller: caller,395		to: address,396		token_id: uint256,397		_value: value,398	) -> Result<void> {399		let caller = T::CrossAccountId::from_eth(caller);400		let to = T::CrossAccountId::from_eth(to);401		let token = token_id.try_into()?;402		let budget = self403			.recorder404			.weight_calls_budget(<StructureWeight<T>>::find_parent());405406		<Pallet<T>>::transfer(self, &caller, &to, token, &budget).map_err(dispatch_to_evm::<T>)?;407		Ok(())408	}409410	#[weight(<SelfWeightOf<T>>::burn_from())]411	fn burn_from(412		&mut self,413		caller: caller,414		from: address,415		token_id: uint256,416		_value: value,417	) -> Result<void> {418		let caller = T::CrossAccountId::from_eth(caller);419		let from = T::CrossAccountId::from_eth(from);420		let token = token_id.try_into()?;421		let budget = self422			.recorder423			.weight_calls_budget(<StructureWeight<T>>::find_parent());424425		<Pallet<T>>::burn_from(self, &caller, &from, token, &budget)426			.map_err(dispatch_to_evm::<T>)?;427		Ok(())428	}429430	fn next_token_id(&self) -> Result<uint256> {431		self.consume_store_reads(1)?;432		Ok(<TokensMinted<T>>::get(self.id)433			.checked_add(1)434			.ok_or("item id overflow")?435			.into())436	}437438	#[weight(<SelfWeightOf<T>>::create_multiple_items(token_ids.len() as u32))]439	fn mint_bulk(&mut self, caller: caller, to: address, token_ids: Vec<uint256>) -> Result<bool> {440		let caller = T::CrossAccountId::from_eth(caller);441		let to = T::CrossAccountId::from_eth(to);442		let mut expected_index = <TokensMinted<T>>::get(self.id)443			.checked_add(1)444			.ok_or("item id overflow")?;445		let budget = self446			.recorder447			.weight_calls_budget(<StructureWeight<T>>::find_parent());448449		let total_tokens = token_ids.len();450		for id in token_ids.into_iter() {451			let id: u32 = id.try_into().map_err(|_| "token id overflow")?;452			if id != expected_index {453				return Err("item id should be next".into());454			}455			expected_index = expected_index.checked_add(1).ok_or("item id overflow")?;456		}457		let data = (0..total_tokens)458			.map(|_| CreateItemData::<T> {459				properties: BoundedVec::default(),460				owner: to.clone(),461			})462			.collect();463464		<Pallet<T>>::create_multiple_items(self, &caller, data, &budget)465			.map_err(dispatch_to_evm::<T>)?;466		Ok(true)467	}468469	#[solidity(rename_selector = "mintBulkWithTokenURI")]470	#[weight(<SelfWeightOf<T>>::create_multiple_items(tokens.len() as u32))]471	fn mint_bulk_with_token_uri(472		&mut self,473		caller: caller,474		to: address,475		tokens: Vec<(uint256, string)>,476	) -> Result<bool> {477		let caller = T::CrossAccountId::from_eth(caller);478		let to = T::CrossAccountId::from_eth(to);479		let mut expected_index = <TokensMinted<T>>::get(self.id)480			.checked_add(1)481			.ok_or("item id overflow")?;482		let budget = self483			.recorder484			.weight_calls_budget(<StructureWeight<T>>::find_parent());485486		let mut data = Vec::with_capacity(tokens.len());487		for (id, token_uri) in tokens {488			let id: u32 = id.try_into().map_err(|_| "token id overflow")?;489			if id != expected_index {490				return Err("item id should be next".into());491			}492			expected_index = expected_index.checked_add(1).ok_or("item id overflow")?;493494			todo!("token uri");495			data.push(CreateItemData::<T> {496				properties: BoundedVec::default(),497				owner: to.clone(),498			});499		}500501		<Pallet<T>>::create_multiple_items(self, &caller, data, &budget)502			.map_err(dispatch_to_evm::<T>)?;503		Ok(true)504	}505}506507#[solidity_interface(508	name = "UniqueNFT",509	is(510		ERC721,511		ERC721Metadata,512		ERC721Enumerable,513		ERC721UniqueExtensions,514		ERC721Mintable,515		ERC721Burnable,516		via("CollectionHandle<T>", common_mut, Collection),517		TokenProperties,518	)519)]520impl<T: Config> NonfungibleHandle<T> {}521522// Not a tests, but code generators523generate_stubgen!(gen_impl, UniqueNFTCall<()>, true);524generate_stubgen!(gen_iface, UniqueNFTCall<()>, false);525526impl<T: Config> CommonEvmHandler for NonfungibleHandle<T> {527	const CODE: &'static [u8] = include_bytes!("./stubs/UniqueNFT.raw");528529	fn call(self, source: &H160, input: &[u8], value: U256) -> Option<PrecompileResult> {530		call::<T, UniqueNFTCall<T>, _>(*source, self, value, input)531	}532}
modifiedpallets/nonfungible/src/stubs/UniqueNFT.rawdiffbeforeafterboth

binary blob — no preview

modifiedpallets/nonfungible/src/stubs/UniqueNFT.soldiffbeforeafterboth
--- a/pallets/nonfungible/src/stubs/UniqueNFT.sol
+++ b/pallets/nonfungible/src/stubs/UniqueNFT.sol
@@ -51,6 +51,67 @@
 	event MintingFinished();
 }
 
+// Selector: 38e33c60
+contract Collection is Dummy, ERC165 {
+	// Selector: setCollectionProperty(string,bytes) 2f073f66
+	function setCollectionProperty(string memory key, bytes memory value)
+		public
+	{
+		require(false, stub_error);
+		key;
+		value;
+		dummy = 0;
+	}
+
+	// Selector: deleteCollectionProperty(string) 7b7debce
+	function deleteCollectionProperty(string memory key) public {
+		require(false, stub_error);
+		key;
+		dummy = 0;
+	}
+
+	// Throws error if key not found
+	//
+	// Selector: collectionProperty(string) cf24fd6d
+	function collectionProperty(string memory key)
+		public
+		view
+		returns (bytes memory)
+	{
+		require(false, stub_error);
+		key;
+		dummy;
+		return hex"";
+	}
+
+	// Selector: ethSetSponsor(address) 8f9af356
+	function ethSetSponsor(address sponsor) public {
+		require(false, stub_error);
+		sponsor;
+		dummy = 0;
+	}
+
+	// Selector: ethConfirmSponsorship() a8580d1a
+	function ethConfirmSponsorship() public {
+		require(false, stub_error);
+		dummy = 0;
+	}
+
+	// Selector: setLimits(string) 72cb345d
+	function setLimits(string memory limitsJson) public view {
+		require(false, stub_error);
+		limitsJson;
+		dummy;
+	}
+
+	// Selector: contractAddress() f6b4dfb4
+	function contractAddress() public view returns (address) {
+		require(false, stub_error);
+		dummy;
+		return 0x0000000000000000000000000000000000000000;
+	}
+}
+
 // Selector: 41369377
 contract TokenProperties is Dummy, ERC165 {
 	// Selector: setTokenPropertyPermission(string,bool,bool,bool) 222d97fa
@@ -327,40 +388,6 @@
 		require(false, stub_error);
 		dummy;
 		return 0;
-	}
-}
-
-// Selector: 9b5e29c5
-contract CollectionProperties is Dummy, ERC165 {
-	// Selector: setCollectionProperty(string,bytes) 2f073f66
-	function setCollectionProperty(string memory key, bytes memory value)
-		public
-	{
-		require(false, stub_error);
-		key;
-		value;
-		dummy = 0;
-	}
-
-	// Selector: deleteCollectionProperty(string) 7b7debce
-	function deleteCollectionProperty(string memory key) public {
-		require(false, stub_error);
-		key;
-		dummy = 0;
-	}
-
-	// Throws error if key not found
-	//
-	// Selector: collectionProperty(string) cf24fd6d
-	function collectionProperty(string memory key)
-		public
-		view
-		returns (bytes memory)
-	{
-		require(false, stub_error);
-		key;
-		dummy;
-		return hex"";
 	}
 }
 
@@ -423,6 +450,6 @@
 	ERC721UniqueExtensions,
 	ERC721Mintable,
 	ERC721Burnable,
-	CollectionProperties,
+	Collection,
 	TokenProperties
 {}
modifiedpallets/unique/Cargo.tomldiffbeforeafterboth
--- a/pallets/unique/Cargo.toml
+++ b/pallets/unique/Cargo.toml
@@ -20,7 +20,6 @@
 std = [
     'codec/std',
     'serde/std',
-    'serde-json-core/std',
     'frame-support/std',
     'frame-system/std',
     'pallet-evm/std',
@@ -42,10 +41,6 @@
 default-features = false
 features = ['derive']
 version = '1.0.130'
-
-[dependencies.serde-json-core]
-default-features = false
-version = "0.4"
 
 [dependencies.ethereum]
 version = "0.12.0"
modifiedpallets/unique/src/eth/mod.rsdiffbeforeafterboth
--- a/pallets/unique/src/eth/mod.rs
+++ b/pallets/unique/src/eth/mod.rs
@@ -110,17 +110,6 @@
 		}
 	}
 	
-	struct EvmCollection<T: Config>(H160, SubstrateRecorder<T>);
-	impl<T: Config> WithRecorder<T> for EvmCollection<T> {
-		fn recorder(&self) -> &SubstrateRecorder<T> {
-			&self.1
-		}
-	
-		fn into_recorder(self) -> SubstrateRecorder<T> {
-			self.1
-		}
-	}
-	
 	#[derive(ToLog)]
 	pub enum EthCollectionEvent {
 		CollectionCreated {
@@ -129,78 +118,7 @@
 			#[indexed]
 			collection_id: address,
 		},
-	}
-	
-	#[solidity_interface(name = "Collection")]
-	impl<T: Config> EvmCollection<T> {
-		fn set_sponsor(
-			&self,
-			caller: caller,
-			sponsor: address,
-		) -> Result<void> {
-			let mut collection = collection_from_address::<T>(self.contract_address(caller).unwrap(), self.1.gas_left())?;
-			check_is_owner(caller, &collection)?;
-	
-			let sponsor = T::CrossAccountId::from_eth(sponsor);
-			collection.set_sponsor(sponsor.as_sub().clone());
-			collection.save().map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;
-		Ok(())
-		}
-	
-		fn confirm_sponsorship(&self, caller: caller) -> Result<void> {
-			let mut collection = collection_from_address::<T>(self.contract_address(caller).unwrap(), self.1.gas_left())?;
-			let caller = T::CrossAccountId::from_eth(caller);
-			if !collection.confirm_sponsorship(caller.as_sub()) {
-				return Err(Error::Revert("Caller is not set as sponsor".into()));
-			}
-			collection.save().map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;
-		Ok(())
-		}
-	
-		fn set_limits(
-			&self,
-			caller: caller,
-			limits_json: string,
-		) -> Result<void> {
-			let mut collection = collection_from_address::<T>(self.contract_address(caller).unwrap(), self.1.gas_left())?;
-			check_is_owner(caller, &collection)?;
-	
-			let limits = serde_json_core::from_str(limits_json.as_ref())
-				.map_err(|e| Error::Revert(format!("Parse JSON error: {}", e)))?;
-			collection.limits = limits.0;
-			collection.save().map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;
-		Ok(())
-		}
-
-		fn contract_address(&self, _caller: caller) -> Result<address> {
-			Ok(self.0)
-		}
-	}
-	
-	fn error_feild_too_long(feild: &str, bound: u32) -> Error {
-		Error::Revert(format!("{} is too long. Max length is {}.", feild, bound))
 	}
-	
-	fn collection_from_address<T: Config>(
-		collection_address: address,
-		gas_limit: u64
-	) -> Result<CollectionHandle<T>> {
-		let collection_id = pallet_common::eth::map_eth_to_id(&collection_address)
-		.ok_or(Error::Revert("Contract is not an unique collection".into()))?;
-		let recorder = <SubstrateRecorder<T>>::new(gas_limit);
-		let collection =
-			pallet_common::CollectionHandle::new_with_recorder(collection_id, recorder)
-				.ok_or(Error::Revert("Create collection handle error".into()))?;
-		Ok(collection)
-	}
-	
-	fn check_is_owner<T: Config>(caller: caller, collection: &CollectionHandle<T>) -> Result<()> {
-		let caller = T::CrossAccountId::from_eth(caller);
-		collection
-			.check_is_owner(&caller)
-			.map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;
-		Ok(())
-	}
 
 	pub struct CollectionHelperOnMethodCall<T: Config>(PhantomData<*const T>);
 	impl<T: Config> OnMethodCall<T> for CollectionHelperOnMethodCall<T> {
@@ -235,38 +153,8 @@
 	
 	generate_stubgen!(collection_helper_impl, CollectionHelperCall<()>, true);
 	generate_stubgen!(collection_helper_iface, CollectionHelperCall<()>, false);
-	
-	pub struct CollectionOnMethodCall<T: Config>(PhantomData<*const T>);
-	impl<T: Config> OnMethodCall<T> for CollectionOnMethodCall<T> {
-		fn is_reserved(contract: &sp_core::H160) -> bool {
-			contract == &T::ContractAddress::get()
-		}
-	
-		fn is_used(contract: &sp_core::H160) -> bool {
-			contract == &T::ContractAddress::get()
-		}
-	
-		fn call(
-			source: &sp_core::H160,
-			target: &sp_core::H160,
-			gas_left: u64,
-			input: &[u8],
-			value: sp_core::U256,
-		) -> Option<PrecompileResult> {
-			if !pallet_common::eth::is_collection(target) {
-				return None;
-			}
 
-			let helpers = EvmCollection::<T>(*target, SubstrateRecorder::<T>::new(gas_left));
-			pallet_evm_coder_substrate::call(*source, helpers, value, input)
-		}
-	
-		fn get_code(contract: &sp_core::H160) -> Option<Vec<u8>> {
-			(contract == &T::ContractAddress::get())
-				.then(|| include_bytes!("./stubs/Collection.raw").to_vec())
-		}
+	fn error_feild_too_long(feild: &str, bound: u32) -> Error {
+		Error::Revert(format!("{} is too long. Max length is {}.", feild, bound))
 	}
-	
-	generate_stubgen!(collection_impl, CollectionCall<()>, true);
-	generate_stubgen!(collection_iface, CollectionCall<()>, false);
 }
deletedpallets/unique/src/eth/stubs/Collection.rawdiffbeforeafterboth

binary blob — no preview

deletedpallets/unique/src/eth/stubs/Collection.soldiffbeforeafterboth
--- a/pallets/unique/src/eth/stubs/Collection.sol
+++ /dev/null
@@ -1,52 +0,0 @@
-// SPDX-License-Identifier: OTHER
-// This code is automatically generated
-
-pragma solidity >=0.8.0 <0.9.0;
-
-// Common stubs holder
-contract Dummy {
-	uint8 dummy;
-	string stub_error = "this contract is implemented in native";
-}
-
-contract ERC165 is Dummy {
-	function supportsInterface(bytes4 interfaceID)
-		external
-		view
-		returns (bool)
-	{
-		require(false, stub_error);
-		interfaceID;
-		return true;
-	}
-}
-
-// Selector: 15cc740e
-contract Collection is Dummy, ERC165 {
-	// Selector: setSponsor(address) 59753fb1
-	function setSponsor(address sponsor) public view {
-		require(false, stub_error);
-		sponsor;
-		dummy;
-	}
-
-	// Selector: confirmSponsorship() c8c6a056
-	function confirmSponsorship() public view {
-		require(false, stub_error);
-		dummy;
-	}
-
-	// Selector: setLimits(string) 72cb345d
-	function setLimits(string memory limitsJson) public view {
-		require(false, stub_error);
-		limitsJson;
-		dummy;
-	}
-
-	// Selector: contractAddress() f6b4dfb4
-	function contractAddress() public view returns (address) {
-		require(false, stub_error);
-		dummy;
-		return 0x0000000000000000000000000000000000000000;
-	}
-}
modifiedruntime/opal/src/lib.rsdiffbeforeafterboth
--- a/runtime/opal/src/lib.rs
+++ b/runtime/opal/src/lib.rs
@@ -307,7 +307,6 @@
 		pallet_evm_migration::OnMethodCall<Self>,
 		pallet_evm_contract_helpers::HelpersOnMethodCall<Self>,
 		CollectionDispatchT<Self>,
-		evm_collection::CollectionOnMethodCall<Self>,
 		evm_collection::CollectionHelperOnMethodCall<Self>,
 	);
 	type OnCreate = pallet_evm_contract_helpers::HelpersOnCreate<Self>;
modifiedruntime/quartz/src/lib.rsdiffbeforeafterboth
--- a/runtime/quartz/src/lib.rs
+++ b/runtime/quartz/src/lib.rs
@@ -286,7 +286,6 @@
 		pallet_evm_migration::OnMethodCall<Self>,
 		pallet_evm_contract_helpers::HelpersOnMethodCall<Self>,
 		CollectionDispatchT<Self>,
-		evm_collection::CollectionOnMethodCall<Self>,
 		evm_collection::CollectionHelperOnMethodCall<Self>,
 	);
 	type OnCreate = pallet_evm_contract_helpers::HelpersOnCreate<Self>;
modifiedruntime/unique/src/lib.rsdiffbeforeafterboth
--- a/runtime/unique/src/lib.rs
+++ b/runtime/unique/src/lib.rs
@@ -291,7 +291,6 @@
 		pallet_evm_migration::OnMethodCall<Self>,
 		pallet_evm_contract_helpers::HelpersOnMethodCall<Self>,
 		CollectionDispatchT<Self>,
-		evm_collection::CollectionOnMethodCall<Self>,
 		evm_collection::CollectionHelperOnMethodCall<Self>,
 	);
 	type OnCreate = pallet_evm_contract_helpers::HelpersOnCreate<Self>;
modifiedtests/src/eth/api/UniqueNFT.soldiffbeforeafterboth
--- a/tests/src/eth/api/UniqueNFT.sol
+++ b/tests/src/eth/api/UniqueNFT.sol
@@ -42,6 +42,36 @@
 	event MintingFinished();
 }
 
+// Selector: 38e33c60
+interface Collection is Dummy, ERC165 {
+	// Selector: setCollectionProperty(string,bytes) 2f073f66
+	function setCollectionProperty(string memory key, bytes memory value)
+		external;
+
+	// Selector: deleteCollectionProperty(string) 7b7debce
+	function deleteCollectionProperty(string memory key) external;
+
+	// Throws error if key not found
+	//
+	// Selector: collectionProperty(string) cf24fd6d
+	function collectionProperty(string memory key)
+		external
+		view
+		returns (bytes memory);
+
+	// Selector: ethSetSponsor(address) 8f9af356
+	function ethSetSponsor(address sponsor) external;
+
+	// Selector: ethConfirmSponsorship() a8580d1a
+	function ethConfirmSponsorship() external;
+
+	// Selector: setLimits(string) 72cb345d
+	function setLimits(string memory limitsJson) external view;
+
+	// Selector: contractAddress() f6b4dfb4
+	function contractAddress() external view returns (address);
+}
+
 // Selector: 41369377
 interface TokenProperties is Dummy, ERC165 {
 	// Selector: setTokenPropertyPermission(string,bool,bool,bool) 222d97fa
@@ -191,24 +221,6 @@
 	function totalSupply() external view returns (uint256);
 }
 
-// Selector: 9b5e29c5
-interface CollectionProperties is Dummy, ERC165 {
-	// Selector: setCollectionProperty(string,bytes) 2f073f66
-	function setCollectionProperty(string memory key, bytes memory value)
-		external;
-
-	// Selector: deleteCollectionProperty(string) 7b7debce
-	function deleteCollectionProperty(string memory key) external;
-
-	// Throws error if key not found
-	//
-	// Selector: collectionProperty(string) cf24fd6d
-	function collectionProperty(string memory key)
-		external
-		view
-		returns (bytes memory);
-}
-
 // Selector: d74d154f
 interface ERC721UniqueExtensions is Dummy, ERC165 {
 	// Selector: transfer(address,uint256) a9059cbb
@@ -240,6 +252,6 @@
 	ERC721UniqueExtensions,
 	ERC721Mintable,
 	ERC721Burnable,
-	CollectionProperties,
+	Collection,
 	TokenProperties
 {}
deletedtests/src/eth/collectionAbi.jsondiffbeforeafterboth
--- a/tests/src/eth/collectionAbi.json
+++ /dev/null
@@ -1,43 +0,0 @@
-[
-  {
-    "inputs": [],
-    "name": "confirmSponsorship",
-    "outputs": [],
-    "stateMutability": "view",
-    "type": "function"
-  },
-  {
-    "inputs": [],
-    "name": "contractAddress",
-    "outputs": [{ "internalType": "address", "name": "", "type": "address" }],
-    "stateMutability": "view",
-    "type": "function"
-  },
-  {
-    "inputs": [
-      { "internalType": "string", "name": "limitsJson", "type": "string" }
-    ],
-    "name": "setLimits",
-    "outputs": [],
-    "stateMutability": "view",
-    "type": "function"
-  },
-  {
-    "inputs": [
-      { "internalType": "address", "name": "sponsor", "type": "address" }
-    ],
-    "name": "setSponsor",
-    "outputs": [],
-    "stateMutability": "view",
-    "type": "function"
-  },
-  {
-    "inputs": [
-      { "internalType": "bytes4", "name": "interfaceID", "type": "bytes4" }
-    ],
-    "name": "supportsInterface",
-    "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
-    "stateMutability": "view",
-    "type": "function"
-  }
-]
modifiedtests/src/eth/createCollection.test.tsdiffbeforeafterboth
--- a/tests/src/eth/createCollection.test.ts
+++ b/tests/src/eth/createCollection.test.ts
@@ -88,13 +88,13 @@
     const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);
     const sponsor = await createEthAccountWithBalance(api, web3);
     const collectionEvm = evmCollection(web3, owner, collectionIdAddress);
-    result = await collectionEvm.methods.setSponsor(sponsor).send();
+    result = await collectionEvm.methods.ethSetSponsor(sponsor).send();
     let collectionSub = (await getDetailedCollectionInfo(api, collectionId))!;
     expect(collectionSub.sponsorship.isUnconfirmed).to.be.true;
     expect(collectionSub.sponsorship.asUnconfirmed.toHuman()).to.be.eq(evmToAddress(sponsor));
-    await expect(collectionEvm.methods.confirmSponsorship().call()).to.be.rejectedWith('Caller is not set as sponsor');
+    await expect(collectionEvm.methods.ethConfirmSponsorship().call()).to.be.rejectedWith('Caller is not set as sponsor');
     const sponsorCollection = evmCollection(web3, sponsor, collectionIdAddress);
-    await sponsorCollection.methods.confirmSponsorship().send();
+    await sponsorCollection.methods.ethConfirmSponsorship().send();
     collectionSub = (await getDetailedCollectionInfo(api, collectionId))!;
     expect(collectionSub.sponsorship.isConfirmed).to.be.true;
     expect(collectionSub.sponsorship.asConfirmed.toHuman()).to.be.eq(evmToAddress(sponsor));
modifiedtests/src/eth/nonFungibleAbi.jsondiffbeforeafterboth
--- a/tests/src/eth/nonFungibleAbi.json
+++ b/tests/src/eth/nonFungibleAbi.json
@@ -126,6 +126,13 @@
     "type": "function"
   },
   {
+    "inputs": [],
+    "name": "contractAddress",
+    "outputs": [{ "internalType": "address", "name": "", "type": "address" }],
+    "stateMutability": "view",
+    "type": "function"
+  },
+  {
     "inputs": [{ "internalType": "string", "name": "key", "type": "string" }],
     "name": "deleteCollectionProperty",
     "outputs": [],
@@ -144,6 +151,22 @@
   },
   {
     "inputs": [],
+    "name": "ethConfirmSponsorship",
+    "outputs": [],
+    "stateMutability": "nonpayable",
+    "type": "function"
+  },
+  {
+    "inputs": [
+      { "internalType": "address", "name": "sponsor", "type": "address" }
+    ],
+    "name": "ethSetSponsor",
+    "outputs": [],
+    "stateMutability": "nonpayable",
+    "type": "function"
+  },
+  {
+    "inputs": [],
     "name": "finishMinting",
     "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
     "stateMutability": "nonpayable",
@@ -302,6 +325,15 @@
   },
   {
     "inputs": [
+      { "internalType": "string", "name": "limitsJson", "type": "string" }
+    ],
+    "name": "setLimits",
+    "outputs": [],
+    "stateMutability": "view",
+    "type": "function"
+  },
+  {
+    "inputs": [
       { "internalType": "uint256", "name": "tokenId", "type": "uint256" },
       { "internalType": "string", "name": "key", "type": "string" },
       { "internalType": "bytes", "name": "value", "type": "bytes" }
modifiedtests/src/eth/util/helpers.tsdiffbeforeafterboth
--- a/tests/src/eth/util/helpers.ts
+++ b/tests/src/eth/util/helpers.ts
@@ -28,7 +28,7 @@
 import config from '../../config';
 import privateKey from '../../substrate/privateKey';
 import contractHelpersAbi from './contractHelpersAbi.json';
-import collectionAbi from '../collectionAbi.json';
+import collectionAbi from '../nonFungibleAbi.json';
 import collectionHelperAbi from '../collectionHelperAbi.json';
 import getBalance from '../../substrate/get-balance';
 import waitNewBlocks from '../../substrate/wait-new-blocks';