git.delta.rocks / unique-network / refs/commits / e51699278c06

difftreelog

misk: docs & changelogs. Some refactor for func & mod names.

Trubnikov Sergey2022-07-25parent: #62c5b0c.patch.diff
in: master

15 files changed

modifiedMakefilediffbeforeafterboth
--- a/Makefile
+++ b/Makefile
@@ -37,7 +37,7 @@
 	PACKAGE=pallet-nonfungible NAME=erc::gen_iface OUTPUT=$(TESTS_API)/$@ ./.maintain/scripts/generate_sol.sh
 	PACKAGE=pallet-nonfungible NAME=erc::gen_impl OUTPUT=$(NONFUNGIBLE_EVM_STUBS)/$@ ./.maintain/scripts/generate_sol.sh
 	
-UniqueRFT.sol:
+UniqueRefungible.sol:
 	PACKAGE=pallet-refungible NAME=erc::gen_iface OUTPUT=$(TESTS_API)/$@ ./.maintain/scripts/generate_sol.sh
 	PACKAGE=pallet-refungible NAME=erc::gen_impl OUTPUT=$(REFUNGIBLE_EVM_STUBS)/$@ ./.maintain/scripts/generate_sol.sh
 
@@ -65,8 +65,8 @@
 	INPUT=$(REFUNGIBLE_EVM_STUBS)/$< OUTPUT=$(REFUNGIBLE_EVM_STUBS)/UniqueRefungibleToken.raw ./.maintain/scripts/compile_stub.sh
 	INPUT=$(REFUNGIBLE_EVM_STUBS)/$< OUTPUT=$(RENFUNGIBLE_TOKEN_EVM_ABI) ./.maintain/scripts/generate_abi.sh
 
-UniqueRefungible: UniqueRFT.sol
-	INPUT=$(REFUNGIBLE_EVM_STUBS)/$< OUTPUT=$(REFUNGIBLE_EVM_STUBS)/UniqueRFT.raw ./.maintain/scripts/compile_stub.sh
+UniqueRefungible: UniqueRefungible.sol
+	INPUT=$(REFUNGIBLE_EVM_STUBS)/$< OUTPUT=$(REFUNGIBLE_EVM_STUBS)/UniqueRefungible.raw ./.maintain/scripts/compile_stub.sh
 	INPUT=$(REFUNGIBLE_EVM_STUBS)/$< OUTPUT=$(REFUNGIBLE_EVM_ABI) ./.maintain/scripts/generate_abi.sh
 
 ContractHelpers: ContractHelpers.sol
modifiedpallets/common/CHANGELOG.MDdiffbeforeafterboth
--- a/pallets/common/CHANGELOG.MD
+++ b/pallets/common/CHANGELOG.MD
@@ -8,3 +8,8 @@
 
 -   Some methods in `#[solidity_interface]` for `CollectionHandle` had invalid
     mutability modifiers, causing invalid stub/abi generation.
+
+
+## [0.1.3] - 2022-07-25
+### Add
+-   Some static property keys and values.
\ No newline at end of file
modifiedpallets/common/Cargo.tomldiffbeforeafterboth
--- a/pallets/common/Cargo.toml
+++ b/pallets/common/Cargo.toml
@@ -1,6 +1,6 @@
 [package]
 name = "pallet-common"
-version = "0.1.2"
+version = "0.1.3"
 license = "GPLv3"
 edition = "2021"
 
modifiedpallets/common/src/erc.rsdiffbeforeafterboth
--- a/pallets/common/src/erc.rs
+++ b/pallets/common/src/erc.rs
@@ -430,7 +430,8 @@
 	Ok(())
 }
 
-pub mod static_property_key_value {
+/// Contains static property keys and values.
+pub mod static_property {
 	use evm_coder::{
 		execution::{Result, Error},
 	};
@@ -438,27 +439,45 @@
 
 	const EXPECT_CONVERT_ERROR: &str = "length < limit";
 
-	pub fn schema_name_key() -> up_data_structs::PropertyKey {
-		property_key_from_bytes(b"schemaName").expect(EXPECT_CONVERT_ERROR)
-	}
+	/// Keys.
+	pub mod key {
+		use super::*;
 
-	pub fn base_uri_key() -> up_data_structs::PropertyKey {
-		property_key_from_bytes(b"baseURI").expect(EXPECT_CONVERT_ERROR)
+		/// Key "schemaName".
+		pub fn schema_name() -> up_data_structs::PropertyKey {
+			property_key_from_bytes(b"schemaName").expect(EXPECT_CONVERT_ERROR)
+		}
+
+		/// Key "baseURI".
+		pub fn base_uri() -> up_data_structs::PropertyKey {
+			property_key_from_bytes(b"baseURI").expect(EXPECT_CONVERT_ERROR)
+		}
+
+		/// Key "url".
+		pub fn url() -> up_data_structs::PropertyKey {
+			property_key_from_bytes(b"url").expect(EXPECT_CONVERT_ERROR)
+		}
+
+		/// Key "suffix".
+		pub fn suffix() -> up_data_structs::PropertyKey {
+			property_key_from_bytes(b"suffix").expect(EXPECT_CONVERT_ERROR)
+		}
 	}
 
-	pub fn url_key() -> up_data_structs::PropertyKey {
-		property_key_from_bytes(b"url").expect(EXPECT_CONVERT_ERROR)
-	}
+	/// Values.
+	pub mod value {
+		use super::*;
 
-	pub fn suffix_key() -> up_data_structs::PropertyKey {
-		property_key_from_bytes(b"suffix").expect(EXPECT_CONVERT_ERROR)
-	}
+		/// Value "ERC721Metadata".
+		pub const ERC721_METADATA: &[u8] = b"ERC721Metadata";
 
-	pub const ERC721_METADATA: &[u8] = b"ERC721Metadata";
-	pub fn erc721_value() -> up_data_structs::PropertyValue {
-		property_value_from_bytes(ERC721_METADATA).expect(EXPECT_CONVERT_ERROR)
+		/// Value for [`ERC721_METADATA`].
+		pub fn erc721() -> up_data_structs::PropertyValue {
+			property_value_from_bytes(ERC721_METADATA).expect(EXPECT_CONVERT_ERROR)
+		}
 	}
 
+	/// Convert `byte` to [`PropertyKey`].
 	pub fn property_key_from_bytes(bytes: &[u8]) -> Result<up_data_structs::PropertyKey> {
 		bytes.to_vec().try_into().map_err(|_| {
 			Error::Revert(format!(
@@ -468,6 +487,7 @@
 		})
 	}
 
+	/// Convert `bytes` to [`PropertyValue`].
 	pub fn property_value_from_bytes(bytes: &[u8]) -> Result<up_data_structs::PropertyValue> {
 		bytes.to_vec().try_into().map_err(|_| {
 			Error::Revert(format!(
modifiedpallets/nonfungible/CHANGELOG.mddiffbeforeafterboth
--- a/pallets/nonfungible/CHANGELOG.md
+++ b/pallets/nonfungible/CHANGELOG.md
@@ -2,10 +2,13 @@
 
 All notable changes to this project will be documented in this file.
 
-## [0.1.1] - 2022-07-14
+## [0.1.2] - 2022-07-25
+### Changed
+- New alghoritm for retrieving `token_iri`.
 
+## [0.1.1] - 2022-07-14
 ### Added
 
 - Implementation of RPC method `token_owners`.
    For reasons of compatibility with this pallet, returns only one owner if token exists.
-   This was an internal request to improve the web interface and support fractionalization event. 
\ No newline at end of file
+   This was an internal request to improve the web interface and support fractionalization event. 
modifiedpallets/nonfungible/Cargo.tomldiffbeforeafterboth
--- a/pallets/nonfungible/Cargo.toml
+++ b/pallets/nonfungible/Cargo.toml
@@ -1,6 +1,6 @@
 [package]
 name = "pallet-nonfungible"
-version = "0.1.1"
+version = "0.1.2"
 license = "GPLv3"
 edition = "2021"
 
modifiedpallets/nonfungible/src/erc.rsdiffbeforeafterboth
--- a/pallets/nonfungible/src/erc.rs
+++ b/pallets/nonfungible/src/erc.rs
@@ -33,7 +33,7 @@
 use pallet_evm_coder_substrate::dispatch_to_evm;
 use sp_std::vec::Vec;
 use pallet_common::{
-	erc::{CommonEvmHandler, PrecompileResult, CollectionCall, static_property_key_value::*},
+	erc::{CommonEvmHandler, PrecompileResult, CollectionCall, static_property::{key, value as property_value}},
 	CollectionHandle, CollectionPropertyPermissions,
 };
 use pallet_evm::{account::CrossAccountId, PrecompileHandle};
@@ -221,10 +221,10 @@
 	fn token_uri(&self, token_id: uint256) -> Result<string> {
 		let is_erc721 = || {
 			if let Some(shema_name) =
-				pallet_common::Pallet::<T>::get_collection_property(self.id, &schema_name_key())
+				pallet_common::Pallet::<T>::get_collection_property(self.id, &key::schema_name())
 			{
 				let shema_name = shema_name.into_inner();
-				shema_name == ERC721_METADATA
+				shema_name == property_value::ERC721_METADATA
 			} else {
 				false
 			}
@@ -232,7 +232,7 @@
 
 		let token_id_u32: u32 = token_id.try_into().map_err(|_| "token id overflow")?;
 
-		if let Ok(url) = get_token_property(self, token_id_u32, &url_key()) {
+		if let Ok(url) = get_token_property(self, token_id_u32, &key::url()) {
 			if !url.is_empty() {
 				return Ok(url);
 			}
@@ -241,7 +241,7 @@
 		}
 
 		if let Some(base_uri) =
-			pallet_common::Pallet::<T>::get_collection_property(self.id, &base_uri_key())
+			pallet_common::Pallet::<T>::get_collection_property(self.id, &key::base_uri())
 		{
 			if !base_uri.is_empty() {
 				let base_uri = string::from_utf8(base_uri.into_inner()).map_err(|e| {
@@ -250,7 +250,7 @@
 						e
 					))
 				})?;
-				if let Ok(suffix) = get_token_property(self, token_id_u32, &suffix_key()) {
+				if let Ok(suffix) = get_token_property(self, token_id_u32, &key::suffix()) {
 					if !suffix.is_empty() {
 						return Ok(base_uri + suffix.as_str());
 					}
@@ -497,7 +497,7 @@
 		token_id: uint256,
 		token_uri: string,
 	) -> Result<bool> {
-		let key = url_key();
+		let key = key::url();
 		let permission = get_token_permission::<T>(self.id, &key)?;
 		if !permission.collection_admin {
 			return Err("Operation is not allowed".into());
@@ -702,7 +702,7 @@
 		to: address,
 		tokens: Vec<(uint256, string)>,
 	) -> Result<bool> {
-		let key = url_key();
+		let key = key::url();
 		let caller = T::CrossAccountId::from_eth(caller);
 		let to = T::CrossAccountId::from_eth(to);
 		let mut expected_index = <TokensMinted<T>>::get(self.id)
modifiedpallets/refungible/CHANGELOG.mddiffbeforeafterboth
--- a/pallets/refungible/CHANGELOG.md
+++ b/pallets/refungible/CHANGELOG.md
@@ -10,6 +10,8 @@
 test(refungible-pallet): add tests for ERC-20 EVM API for RFT token pieces ([#413](https://github.com/UniqueNetwork/unique-chain/pull/413))
 
 ## [v0.1.1] - 2022-07-14
+### Added
+- Support for properties for RFT collections and tokens.
 
 ### Other changes
 
deletedpallets/refungible/Changelog.mddiffbeforeafterboth
--- a/pallets/refungible/Changelog.md
+++ /dev/null
@@ -1,3 +0,0 @@
-### 0.1.1
----
-* Added support for properties for RFT collections and tokens.
modifiedpallets/refungible/src/erc.rsdiffbeforeafterboth
--- a/pallets/refungible/src/erc.rs
+++ b/pallets/refungible/src/erc.rs
@@ -25,24 +25,24 @@
 use crate::{Config, RefungibleHandle};
 
 #[solidity_interface(
-	name = "UniqueRFT",
+	name = "UniqueRefungible",
 	is(via("CollectionHandle<T>", common_mut, Collection),)
 )]
 impl<T: Config> RefungibleHandle<T> where T::AccountId: From<[u8; 32]> {}
 
 // Not a tests, but code generators
-generate_stubgen!(gen_impl, UniqueRFTCall<()>, true);
-generate_stubgen!(gen_iface, UniqueRFTCall<()>, false);
+generate_stubgen!(gen_impl, UniqueRefungibleCall<()>, true);
+generate_stubgen!(gen_iface, UniqueRefungibleCall<()>, false);
 
 impl<T: Config> CommonEvmHandler for RefungibleHandle<T>
 where
 	T::AccountId: From<[u8; 32]>,
 {
-	const CODE: &'static [u8] = include_bytes!("./stubs/UniqueRFT.raw");
+	const CODE: &'static [u8] = include_bytes!("./stubs/UniqueRefungible.raw");
 	fn call(
 		self,
 		handle: &mut impl PrecompileHandle,
 	) -> Option<pallet_common::erc::PrecompileResult> {
-		call::<T, UniqueRFTCall<T>, _, _>(handle, self)
+		call::<T, UniqueRefungibleCall<T>, _, _>(handle, self)
 	}
 }
deletedpallets/refungible/src/stubs/UniqueRFT.rawdiffbeforeafterboth

binary blob — no preview

deletedpallets/refungible/src/stubs/UniqueRFT.soldiffbeforeafterboth
--- a/pallets/refungible/src/stubs/UniqueRFT.sol
+++ /dev/null
@@ -1,251 +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: 7d9262e6
-contract Collection is Dummy, ERC165 {
-	// Set collection property.
-	//
-	// @param key Property key.
-	// @param value Propery value.
-	//
-	// Selector: setCollectionProperty(string,bytes) 2f073f66
-	function setCollectionProperty(string memory key, bytes memory value)
-		public
-	{
-		require(false, stub_error);
-		key;
-		value;
-		dummy = 0;
-	}
-
-	// Delete collection property.
-	//
-	// @param key Property key.
-	//
-	// Selector: deleteCollectionProperty(string) 7b7debce
-	function deleteCollectionProperty(string memory key) public {
-		require(false, stub_error);
-		key;
-		dummy = 0;
-	}
-
-	// Get collection property.
-	//
-	// @dev Throws error if key not found.
-	//
-	// @param key Property key.
-	// @return bytes The property corresponding to the key.
-	//
-	// Selector: collectionProperty(string) cf24fd6d
-	function collectionProperty(string memory key)
-		public
-		view
-		returns (bytes memory)
-	{
-		require(false, stub_error);
-		key;
-		dummy;
-		return hex"";
-	}
-
-	// Set the sponsor of the collection.
-	//
-	// @dev In order for sponsorship to work, it must be confirmed on behalf of the sponsor.
-	//
-	// @param sponsor Address of the sponsor from whose account funds will be debited for operations with the contract.
-	//
-	// Selector: setCollectionSponsor(address) 7623402e
-	function setCollectionSponsor(address sponsor) public {
-		require(false, stub_error);
-		sponsor;
-		dummy = 0;
-	}
-
-	// Collection sponsorship confirmation.
-	//
-	// @dev After setting the sponsor for the collection, it must be confirmed with this function.
-	//
-	// Selector: confirmCollectionSponsorship() 3c50e97a
-	function confirmCollectionSponsorship() public {
-		require(false, stub_error);
-		dummy = 0;
-	}
-
-	// Set limits for the collection.
-	// @dev Throws error if limit not found.
-	// @param limit Name of the limit. Valid names:
-	// 	"accountTokenOwnershipLimit",
-	// 	"sponsoredDataSize",
-	// 	"sponsoredDataRateLimit",
-	// 	"tokenLimit",
-	// 	"sponsorTransferTimeout",
-	// 	"sponsorApproveTimeout"
-	// @param value Value of the limit.
-	//
-	// Selector: setCollectionLimit(string,uint32) 6a3841db
-	function setCollectionLimit(string memory limit, uint32 value) public {
-		require(false, stub_error);
-		limit;
-		value;
-		dummy = 0;
-	}
-
-	// Set limits for the collection.
-	// @dev Throws error if limit not found.
-	// @param limit Name of the limit. Valid names:
-	// 	"ownerCanTransfer",
-	// 	"ownerCanDestroy",
-	// 	"transfersEnabled"
-	// @param value Value of the limit.
-	//
-	// Selector: setCollectionLimit(string,bool) 993b7fba
-	function setCollectionLimit(string memory limit, bool value) public {
-		require(false, stub_error);
-		limit;
-		value;
-		dummy = 0;
-	}
-
-	// Get contract address.
-	//
-	// Selector: contractAddress() f6b4dfb4
-	function contractAddress() public view returns (address) {
-		require(false, stub_error);
-		dummy;
-		return 0x0000000000000000000000000000000000000000;
-	}
-
-	// Add collection admin by substrate address.
-	// @param new_admin Substrate administrator address.
-	//
-	// Selector: addCollectionAdminSubstrate(uint256) 5730062b
-	function addCollectionAdminSubstrate(uint256 newAdmin) public {
-		require(false, stub_error);
-		newAdmin;
-		dummy = 0;
-	}
-
-	// Remove collection admin by substrate address.
-	// @param admin Substrate administrator address.
-	//
-	// Selector: removeCollectionAdminSubstrate(uint256) 4048fcf9
-	function removeCollectionAdminSubstrate(uint256 admin) public {
-		require(false, stub_error);
-		admin;
-		dummy = 0;
-	}
-
-	// Add collection admin.
-	// @param new_admin Address of the added administrator.
-	//
-	// Selector: addCollectionAdmin(address) 92e462c7
-	function addCollectionAdmin(address newAdmin) public {
-		require(false, stub_error);
-		newAdmin;
-		dummy = 0;
-	}
-
-	// Remove collection admin.
-	//
-	// @param new_admin Address of the removed administrator.
-	//
-	// Selector: removeCollectionAdmin(address) fafd7b42
-	function removeCollectionAdmin(address admin) public {
-		require(false, stub_error);
-		admin;
-		dummy = 0;
-	}
-
-	// Toggle accessibility of collection nesting.
-	//
-	// @param enable If "true" degenerates to nesting: 'Owner' else to nesting: 'Disabled'
-	//
-	// Selector: setCollectionNesting(bool) 112d4586
-	function setCollectionNesting(bool enable) public {
-		require(false, stub_error);
-		enable;
-		dummy = 0;
-	}
-
-	// Toggle accessibility of collection nesting.
-	//
-	// @param enable If "true" degenerates to nesting: {OwnerRestricted: [1, 2, 3]} else to nesting: 'Disabled'
-	// @param collections Addresses of collections that will be available for nesting.
-	//
-	// Selector: setCollectionNesting(bool,address[]) 64872396
-	function setCollectionNesting(bool enable, address[] memory collections)
-		public
-	{
-		require(false, stub_error);
-		enable;
-		collections;
-		dummy = 0;
-	}
-
-	// Set the collection access method.
-	// @param mode Access mode
-	// 	0 for Normal
-	// 	1 for AllowList
-	//
-	// Selector: setCollectionAccess(uint8) 41835d4c
-	function setCollectionAccess(uint8 mode) public {
-		require(false, stub_error);
-		mode;
-		dummy = 0;
-	}
-
-	// Add the user to the allowed list.
-	//
-	// @param user Address of a trusted user.
-	//
-	// Selector: addToCollectionAllowList(address) 67844fe6
-	function addToCollectionAllowList(address user) public {
-		require(false, stub_error);
-		user;
-		dummy = 0;
-	}
-
-	// Remove the user from the allowed list.
-	//
-	// @param user Address of a removed user.
-	//
-	// Selector: removeFromCollectionAllowList(address) 85c51acb
-	function removeFromCollectionAllowList(address user) public {
-		require(false, stub_error);
-		user;
-		dummy = 0;
-	}
-
-	// Switch permission for minting.
-	//
-	// @param mode Enable if "true".
-	//
-	// Selector: setCollectionMintMode(bool) 00018e84
-	function setCollectionMintMode(bool mode) public {
-		require(false, stub_error);
-		mode;
-		dummy = 0;
-	}
-}
-
-contract UniqueRFT is Dummy, ERC165, Collection {}
addedpallets/refungible/src/stubs/UniqueRefungible.rawdiffbeforeafterboth

binary blob — no preview

addedpallets/refungible/src/stubs/UniqueRefungible.soldiffbeforeafterboth
--- /dev/null
+++ b/pallets/refungible/src/stubs/UniqueRefungible.sol
@@ -0,0 +1,251 @@
+// 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: 7d9262e6
+contract Collection is Dummy, ERC165 {
+	// Set collection property.
+	//
+	// @param key Property key.
+	// @param value Propery value.
+	//
+	// Selector: setCollectionProperty(string,bytes) 2f073f66
+	function setCollectionProperty(string memory key, bytes memory value)
+		public
+	{
+		require(false, stub_error);
+		key;
+		value;
+		dummy = 0;
+	}
+
+	// Delete collection property.
+	//
+	// @param key Property key.
+	//
+	// Selector: deleteCollectionProperty(string) 7b7debce
+	function deleteCollectionProperty(string memory key) public {
+		require(false, stub_error);
+		key;
+		dummy = 0;
+	}
+
+	// Get collection property.
+	//
+	// @dev Throws error if key not found.
+	//
+	// @param key Property key.
+	// @return bytes The property corresponding to the key.
+	//
+	// Selector: collectionProperty(string) cf24fd6d
+	function collectionProperty(string memory key)
+		public
+		view
+		returns (bytes memory)
+	{
+		require(false, stub_error);
+		key;
+		dummy;
+		return hex"";
+	}
+
+	// Set the sponsor of the collection.
+	//
+	// @dev In order for sponsorship to work, it must be confirmed on behalf of the sponsor.
+	//
+	// @param sponsor Address of the sponsor from whose account funds will be debited for operations with the contract.
+	//
+	// Selector: setCollectionSponsor(address) 7623402e
+	function setCollectionSponsor(address sponsor) public {
+		require(false, stub_error);
+		sponsor;
+		dummy = 0;
+	}
+
+	// Collection sponsorship confirmation.
+	//
+	// @dev After setting the sponsor for the collection, it must be confirmed with this function.
+	//
+	// Selector: confirmCollectionSponsorship() 3c50e97a
+	function confirmCollectionSponsorship() public {
+		require(false, stub_error);
+		dummy = 0;
+	}
+
+	// Set limits for the collection.
+	// @dev Throws error if limit not found.
+	// @param limit Name of the limit. Valid names:
+	// 	"accountTokenOwnershipLimit",
+	// 	"sponsoredDataSize",
+	// 	"sponsoredDataRateLimit",
+	// 	"tokenLimit",
+	// 	"sponsorTransferTimeout",
+	// 	"sponsorApproveTimeout"
+	// @param value Value of the limit.
+	//
+	// Selector: setCollectionLimit(string,uint32) 6a3841db
+	function setCollectionLimit(string memory limit, uint32 value) public {
+		require(false, stub_error);
+		limit;
+		value;
+		dummy = 0;
+	}
+
+	// Set limits for the collection.
+	// @dev Throws error if limit not found.
+	// @param limit Name of the limit. Valid names:
+	// 	"ownerCanTransfer",
+	// 	"ownerCanDestroy",
+	// 	"transfersEnabled"
+	// @param value Value of the limit.
+	//
+	// Selector: setCollectionLimit(string,bool) 993b7fba
+	function setCollectionLimit(string memory limit, bool value) public {
+		require(false, stub_error);
+		limit;
+		value;
+		dummy = 0;
+	}
+
+	// Get contract address.
+	//
+	// Selector: contractAddress() f6b4dfb4
+	function contractAddress() public view returns (address) {
+		require(false, stub_error);
+		dummy;
+		return 0x0000000000000000000000000000000000000000;
+	}
+
+	// Add collection admin by substrate address.
+	// @param new_admin Substrate administrator address.
+	//
+	// Selector: addCollectionAdminSubstrate(uint256) 5730062b
+	function addCollectionAdminSubstrate(uint256 newAdmin) public {
+		require(false, stub_error);
+		newAdmin;
+		dummy = 0;
+	}
+
+	// Remove collection admin by substrate address.
+	// @param admin Substrate administrator address.
+	//
+	// Selector: removeCollectionAdminSubstrate(uint256) 4048fcf9
+	function removeCollectionAdminSubstrate(uint256 admin) public {
+		require(false, stub_error);
+		admin;
+		dummy = 0;
+	}
+
+	// Add collection admin.
+	// @param new_admin Address of the added administrator.
+	//
+	// Selector: addCollectionAdmin(address) 92e462c7
+	function addCollectionAdmin(address newAdmin) public {
+		require(false, stub_error);
+		newAdmin;
+		dummy = 0;
+	}
+
+	// Remove collection admin.
+	//
+	// @param new_admin Address of the removed administrator.
+	//
+	// Selector: removeCollectionAdmin(address) fafd7b42
+	function removeCollectionAdmin(address admin) public {
+		require(false, stub_error);
+		admin;
+		dummy = 0;
+	}
+
+	// Toggle accessibility of collection nesting.
+	//
+	// @param enable If "true" degenerates to nesting: 'Owner' else to nesting: 'Disabled'
+	//
+	// Selector: setCollectionNesting(bool) 112d4586
+	function setCollectionNesting(bool enable) public {
+		require(false, stub_error);
+		enable;
+		dummy = 0;
+	}
+
+	// Toggle accessibility of collection nesting.
+	//
+	// @param enable If "true" degenerates to nesting: {OwnerRestricted: [1, 2, 3]} else to nesting: 'Disabled'
+	// @param collections Addresses of collections that will be available for nesting.
+	//
+	// Selector: setCollectionNesting(bool,address[]) 64872396
+	function setCollectionNesting(bool enable, address[] memory collections)
+		public
+	{
+		require(false, stub_error);
+		enable;
+		collections;
+		dummy = 0;
+	}
+
+	// Set the collection access method.
+	// @param mode Access mode
+	// 	0 for Normal
+	// 	1 for AllowList
+	//
+	// Selector: setCollectionAccess(uint8) 41835d4c
+	function setCollectionAccess(uint8 mode) public {
+		require(false, stub_error);
+		mode;
+		dummy = 0;
+	}
+
+	// Add the user to the allowed list.
+	//
+	// @param user Address of a trusted user.
+	//
+	// Selector: addToCollectionAllowList(address) 67844fe6
+	function addToCollectionAllowList(address user) public {
+		require(false, stub_error);
+		user;
+		dummy = 0;
+	}
+
+	// Remove the user from the allowed list.
+	//
+	// @param user Address of a removed user.
+	//
+	// Selector: removeFromCollectionAllowList(address) 85c51acb
+	function removeFromCollectionAllowList(address user) public {
+		require(false, stub_error);
+		user;
+		dummy = 0;
+	}
+
+	// Switch permission for minting.
+	//
+	// @param mode Enable if "true".
+	//
+	// Selector: setCollectionMintMode(bool) 00018e84
+	function setCollectionMintMode(bool mode) public {
+		require(false, stub_error);
+		mode;
+		dummy = 0;
+	}
+}
+
+contract UniqueRefungible is Dummy, ERC165, Collection {}
modifiedpallets/unique/src/eth/mod.rsdiffbeforeafterboth
before · pallets/unique/src/eth/mod.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/>.1617//! Implementation of CollectionHelpers contract.1819use core::marker::PhantomData;20use evm_coder::{execution::*, generate_stubgen, solidity_interface, solidity, weight, types::*};21use ethereum as _;22use pallet_evm_coder_substrate::{SubstrateRecorder, WithRecorder};23use pallet_evm::{OnMethodCall, PrecompileResult, account::CrossAccountId, PrecompileHandle};24use up_data_structs::{25	CollectionName, CollectionDescription, CollectionTokenPrefix, CreateCollectionData,26	CollectionMode, PropertyValue,27};28use frame_support::traits::Get;29use pallet_common::{30	CollectionById,31	erc::{static_property_key_value::*, CollectionHelpersEvents},32};33use crate::{SelfWeightOf, Config, weights::WeightInfo};3435use sp_std::vec::Vec;36use alloc::format;3738/// See [`CollectionHelpersCall`]39pub struct EvmCollectionHelpers<T: Config>(SubstrateRecorder<T>);40impl<T: Config> WithRecorder<T> for EvmCollectionHelpers<T> {41	fn recorder(&self) -> &SubstrateRecorder<T> {42		&self.043	}4445	fn into_recorder(self) -> SubstrateRecorder<T> {46		self.047	}48}4950fn convert_data<T: Config>(51	caller: caller,52	name: string,53	description: string,54	token_prefix: string,55	base_uri: string,56) -> Result<(57	T::CrossAccountId,58	CollectionName,59	CollectionDescription,60	CollectionTokenPrefix,61	PropertyValue,62)> {63	let caller = T::CrossAccountId::from_eth(caller);64	let name = name65		.encode_utf16()66		.collect::<Vec<u16>>()67		.try_into()68		.map_err(|_| error_feild_too_long(stringify!(name), CollectionName::bound()))?;69	let description = description70		.encode_utf16()71		.collect::<Vec<u16>>()72		.try_into()73		.map_err(|_| {74			error_feild_too_long(stringify!(description), CollectionDescription::bound())75		})?;76	let token_prefix = token_prefix.into_bytes().try_into().map_err(|_| {77		error_feild_too_long(stringify!(token_prefix), CollectionTokenPrefix::bound())78	})?;79	let base_uri_value = base_uri80		.into_bytes()81		.try_into()82		.map_err(|_| error_feild_too_long(stringify!(token_prefix), PropertyValue::bound()))?;83	Ok((caller, name, description, token_prefix, base_uri_value))84}8586//87fn make_data<T: Config>(88	name: CollectionName,89	mode: CollectionMode,90	description: CollectionDescription,91	token_prefix: CollectionTokenPrefix,92	base_uri_value: PropertyValue,93	add_properties: bool,94) -> Result<CreateCollectionData<T::AccountId>> {95	let mut properties = up_data_structs::CollectionPropertiesVec::default();96	let mut token_property_permissions =97		up_data_structs::CollectionPropertiesPermissionsVec::default();9899	token_property_permissions100		.try_push(up_data_structs::PropertyKeyPermission {101			key: url_key(),102			permission: up_data_structs::PropertyPermission {103				mutable: false,104				collection_admin: true,105				token_owner: false,106			},107		})108		.map_err(|e| Error::Revert(format!("{:?}", e)))?;109110	if add_properties {111		token_property_permissions112			.try_push(up_data_structs::PropertyKeyPermission {113				key: suffix_key(),114				permission: up_data_structs::PropertyPermission {115					mutable: false,116					collection_admin: true,117					token_owner: false,118				},119			})120			.map_err(|e| Error::Revert(format!("{:?}", e)))?;121122		properties123			.try_push(up_data_structs::Property {124				key: schema_name_key(),125				value: erc721_value(),126			})127			.map_err(|e| Error::Revert(format!("{:?}", e)))?;128129		if !base_uri_value.is_empty() {130			properties131				.try_push(up_data_structs::Property {132					key: base_uri_key(),133					value: base_uri_value,134				})135				.map_err(|e| Error::Revert(format!("{:?}", e)))?;136		}137	}138139	let data = CreateCollectionData {140		name,141		mode,142		description,143		token_prefix,144		token_property_permissions,145		properties,146		..Default::default()147	};148	Ok(data)149}150151/// @title Contract, which allows users to operate with collections152#[solidity_interface(name = "CollectionHelpers", events(CollectionHelpersEvents))]153impl<T> EvmCollectionHelpers<T>154where155	T: Config + pallet_nonfungible::Config + pallet_refungible::Config 156{157	/// Create an NFT collection158	/// @param name Name of the collection159	/// @param description Informative description of the collection160	/// @param token_prefix Token prefix to represent the collection tokens in UI and user applications161	/// @return address Address of the newly created collection162	#[weight(<SelfWeightOf<T>>::create_collection())]163	fn create_nonfungible_collection(164		&mut self,165		caller: caller,166		name: string,167		description: string,168		token_prefix: string,169	) -> Result<address> {170		let (caller, name, description, token_prefix, _base_uri_value) =171			convert_data::<T>(caller, name, description, token_prefix, "".into())?;172		let data = make_data::<T>(173			name,174			CollectionMode::NFT,175			description,176			token_prefix,177			Default::default(),178			false,179		)?;180		let collection_id =181			<pallet_nonfungible::Pallet<T>>::init_collection(caller.clone(), data, false)182				.map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;183184		let address = pallet_common::eth::collection_id_to_address(collection_id);185		Ok(address)186	}187188	#[weight(<SelfWeightOf<T>>::create_collection())]189	#[solidity(rename_selector = "createERC721MetadataCompatibleCollection")]190	fn create_nonfungible_collection_with_properties(191		&mut self,192		caller: caller,193		name: string,194		description: string,195		token_prefix: string,196		base_uri: string,197	) -> Result<address> {198		let (caller, name, description, token_prefix, base_uri_value) =199			convert_data::<T>(caller, name, description, token_prefix, base_uri)?;200		let data = make_data::<T>(201			name,202			CollectionMode::NFT,203			description,204			token_prefix,205			base_uri_value,206			true,207		)?;208		let collection_id =209			<pallet_nonfungible::Pallet<T>>::init_collection(caller.clone(), data, true)210				.map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;211212		let address = pallet_common::eth::collection_id_to_address(collection_id);213		Ok(address)214	}215216	#[weight(<SelfWeightOf<T>>::create_collection())]217	fn create_refungible_collection(218		&self,219		caller: caller,220		name: string,221		description: string,222		token_prefix: string,223	) -> Result<address> {224		let (caller, name, description, token_prefix, _base_uri) =225			convert_data::<T>(caller, name, description, token_prefix, "".into())?;226		let data = make_data::<T>(227			name,228			CollectionMode::ReFungible,229			description,230			token_prefix,231			Default::default(),232			false,233		)?;234		let collection_id = <pallet_refungible::Pallet<T>>::init_collection(caller.clone(), data)235			.map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;236237		let address = pallet_common::eth::collection_id_to_address(collection_id);238		Ok(address)239	}240241	/// Check if a collection exists242	/// @param collection_address Address of the collection in question243	/// @return bool Does the collection exist?244	fn is_collection_exist(&self, _caller: caller, collection_address: address) -> Result<bool> {245		if let Some(id) = pallet_common::eth::map_eth_to_id(&collection_address) {246			let collection_id = id;247			return Ok(<CollectionById<T>>::contains_key(collection_id));248		}249250		Ok(false)251	}252}253254/// Implements [`OnMethodCall`], which delegates call to [`EvmCollectionHelpers`]255pub struct CollectionHelpersOnMethodCall<T: Config>(PhantomData<*const T>);256impl<T: Config + pallet_nonfungible::Config + pallet_refungible::Config> OnMethodCall<T>257	for CollectionHelpersOnMethodCall<T>258{259	fn is_reserved(contract: &sp_core::H160) -> bool {260		contract == &T::ContractAddress::get()261	}262263	fn is_used(contract: &sp_core::H160) -> bool {264		contract == &T::ContractAddress::get()265	}266267	fn call(handle: &mut impl PrecompileHandle) -> Option<PrecompileResult> {268		if handle.code_address() != T::ContractAddress::get() {269			return None;270		}271272		let helpers =273			EvmCollectionHelpers::<T>(SubstrateRecorder::<T>::new(handle.remaining_gas()));274		pallet_evm_coder_substrate::call(handle, helpers)275	}276277	fn get_code(contract: &sp_core::H160) -> Option<Vec<u8>> {278		(contract == &T::ContractAddress::get())279			.then(|| include_bytes!("./stubs/CollectionHelpers.raw").to_vec())280	}281}282283generate_stubgen!(collection_helper_impl, CollectionHelpersCall<()>, true);284generate_stubgen!(collection_helper_iface, CollectionHelpersCall<()>, false);285286fn error_feild_too_long(feild: &str, bound: usize) -> Error {287	Error::Revert(format!("{} is too long. Max length is {}.", feild, bound))288}
after · pallets/unique/src/eth/mod.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/>.1617//! Implementation of CollectionHelpers contract.1819use core::marker::PhantomData;20use evm_coder::{execution::*, generate_stubgen, solidity_interface, solidity, weight, types::*};21use ethereum as _;22use pallet_evm_coder_substrate::{SubstrateRecorder, WithRecorder};23use pallet_evm::{OnMethodCall, PrecompileResult, account::CrossAccountId, PrecompileHandle};24use up_data_structs::{25	CollectionName, CollectionDescription, CollectionTokenPrefix, CreateCollectionData,26	CollectionMode, PropertyValue,27};28use frame_support::traits::Get;29use pallet_common::{30	CollectionById,31	erc::{static_property::{key, value as property_value}, CollectionHelpersEvents},32};33use crate::{SelfWeightOf, Config, weights::WeightInfo};3435use sp_std::vec::Vec;36use alloc::format;3738/// See [`CollectionHelpersCall`]39pub struct EvmCollectionHelpers<T: Config>(SubstrateRecorder<T>);40impl<T: Config> WithRecorder<T> for EvmCollectionHelpers<T> {41	fn recorder(&self) -> &SubstrateRecorder<T> {42		&self.043	}4445	fn into_recorder(self) -> SubstrateRecorder<T> {46		self.047	}48}4950fn convert_data<T: Config>(51	caller: caller,52	name: string,53	description: string,54	token_prefix: string,55	base_uri: string,56) -> Result<(57	T::CrossAccountId,58	CollectionName,59	CollectionDescription,60	CollectionTokenPrefix,61	PropertyValue,62)> {63	let caller = T::CrossAccountId::from_eth(caller);64	let name = name65		.encode_utf16()66		.collect::<Vec<u16>>()67		.try_into()68		.map_err(|_| error_feild_too_long(stringify!(name), CollectionName::bound()))?;69	let description = description70		.encode_utf16()71		.collect::<Vec<u16>>()72		.try_into()73		.map_err(|_| {74			error_feild_too_long(stringify!(description), CollectionDescription::bound())75		})?;76	let token_prefix = token_prefix.into_bytes().try_into().map_err(|_| {77		error_feild_too_long(stringify!(token_prefix), CollectionTokenPrefix::bound())78	})?;79	let base_uri_value = base_uri80		.into_bytes()81		.try_into()82		.map_err(|_| error_feild_too_long(stringify!(token_prefix), PropertyValue::bound()))?;83	Ok((caller, name, description, token_prefix, base_uri_value))84}8586fn make_data<T: Config>(87	name: CollectionName,88	mode: CollectionMode,89	description: CollectionDescription,90	token_prefix: CollectionTokenPrefix,91	base_uri_value: PropertyValue,92	add_properties: bool,93) -> Result<CreateCollectionData<T::AccountId>> {94	let mut properties = up_data_structs::CollectionPropertiesVec::default();95	let mut token_property_permissions =96		up_data_structs::CollectionPropertiesPermissionsVec::default();9798	token_property_permissions99		.try_push(up_data_structs::PropertyKeyPermission {100			key: key::url(),101			permission: up_data_structs::PropertyPermission {102				mutable: false,103				collection_admin: true,104				token_owner: false,105			},106		})107		.map_err(|e| Error::Revert(format!("{:?}", e)))?;108109	if add_properties {110		token_property_permissions111			.try_push(up_data_structs::PropertyKeyPermission {112				key: key::suffix(),113				permission: up_data_structs::PropertyPermission {114					mutable: false,115					collection_admin: true,116					token_owner: false,117				},118			})119			.map_err(|e| Error::Revert(format!("{:?}", e)))?;120121		properties122			.try_push(up_data_structs::Property {123				key: key::schema_name(),124				value: property_value::erc721(),125			})126			.map_err(|e| Error::Revert(format!("{:?}", e)))?;127128		if !base_uri_value.is_empty() {129			properties130				.try_push(up_data_structs::Property {131					key: key::base_uri(),132					value: base_uri_value,133				})134				.map_err(|e| Error::Revert(format!("{:?}", e)))?;135		}136	}137138	let data = CreateCollectionData {139		name,140		mode,141		description,142		token_prefix,143		token_property_permissions,144		properties,145		..Default::default()146	};147	Ok(data)148}149150/// @title Contract, which allows users to operate with collections151#[solidity_interface(name = "CollectionHelpers", events(CollectionHelpersEvents))]152impl<T> EvmCollectionHelpers<T>153where154	T: Config + pallet_nonfungible::Config + pallet_refungible::Config,155{156	/// Create an NFT collection157	/// @param name Name of the collection158	/// @param description Informative description of the collection159	/// @param token_prefix Token prefix to represent the collection tokens in UI and user applications160	/// @return address Address of the newly created collection161	#[weight(<SelfWeightOf<T>>::create_collection())]162	fn create_nonfungible_collection(163		&mut self,164		caller: caller,165		name: string,166		description: string,167		token_prefix: string,168	) -> Result<address> {169		let (caller, name, description, token_prefix, _base_uri_value) =170			convert_data::<T>(caller, name, description, token_prefix, "".into())?;171		let data = make_data::<T>(172			name,173			CollectionMode::NFT,174			description,175			token_prefix,176			Default::default(),177			false,178		)?;179		let collection_id =180			<pallet_nonfungible::Pallet<T>>::init_collection(caller.clone(), data, false)181				.map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;182183		let address = pallet_common::eth::collection_id_to_address(collection_id);184		Ok(address)185	}186187	#[weight(<SelfWeightOf<T>>::create_collection())]188	#[solidity(rename_selector = "createERC721MetadataCompatibleCollection")]189	fn create_nonfungible_collection_with_properties(190		&mut self,191		caller: caller,192		name: string,193		description: string,194		token_prefix: string,195		base_uri: string,196	) -> Result<address> {197		let (caller, name, description, token_prefix, base_uri_value) =198			convert_data::<T>(caller, name, description, token_prefix, base_uri)?;199		let data = make_data::<T>(200			name,201			CollectionMode::NFT,202			description,203			token_prefix,204			base_uri_value,205			true,206		)?;207		let collection_id =208			<pallet_nonfungible::Pallet<T>>::init_collection(caller.clone(), data, true)209				.map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;210211		let address = pallet_common::eth::collection_id_to_address(collection_id);212		Ok(address)213	}214215	#[weight(<SelfWeightOf<T>>::create_collection())]216	fn create_refungible_collection(217		&self,218		caller: caller,219		name: string,220		description: string,221		token_prefix: string,222	) -> Result<address> {223		let (caller, name, description, token_prefix, _base_uri) =224			convert_data::<T>(caller, name, description, token_prefix, "".into())?;225		let data = make_data::<T>(226			name,227			CollectionMode::ReFungible,228			description,229			token_prefix,230			Default::default(),231			false,232		)?;233		let collection_id = <pallet_refungible::Pallet<T>>::init_collection(caller.clone(), data)234			.map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;235236		let address = pallet_common::eth::collection_id_to_address(collection_id);237		Ok(address)238	}239240	/// Check if a collection exists241	/// @param collection_address Address of the collection in question242	/// @return bool Does the collection exist?243	fn is_collection_exist(&self, _caller: caller, collection_address: address) -> Result<bool> {244		if let Some(id) = pallet_common::eth::map_eth_to_id(&collection_address) {245			let collection_id = id;246			return Ok(<CollectionById<T>>::contains_key(collection_id));247		}248249		Ok(false)250	}251}252253/// Implements [`OnMethodCall`], which delegates call to [`EvmCollectionHelpers`]254pub struct CollectionHelpersOnMethodCall<T: Config>(PhantomData<*const T>);255impl<T: Config + pallet_nonfungible::Config + pallet_refungible::Config> OnMethodCall<T>256	for CollectionHelpersOnMethodCall<T>257{258	fn is_reserved(contract: &sp_core::H160) -> bool {259		contract == &T::ContractAddress::get()260	}261262	fn is_used(contract: &sp_core::H160) -> bool {263		contract == &T::ContractAddress::get()264	}265266	fn call(handle: &mut impl PrecompileHandle) -> Option<PrecompileResult> {267		if handle.code_address() != T::ContractAddress::get() {268			return None;269		}270271		let helpers =272			EvmCollectionHelpers::<T>(SubstrateRecorder::<T>::new(handle.remaining_gas()));273		pallet_evm_coder_substrate::call(handle, helpers)274	}275276	fn get_code(contract: &sp_core::H160) -> Option<Vec<u8>> {277		(contract == &T::ContractAddress::get())278			.then(|| include_bytes!("./stubs/CollectionHelpers.raw").to_vec())279	}280}281282generate_stubgen!(collection_helper_impl, CollectionHelpersCall<()>, true);283generate_stubgen!(collection_helper_iface, CollectionHelpersCall<()>, false);284285fn error_feild_too_long(feild: &str, bound: usize) -> Error {286	Error::Revert(format!("{} is too long. Max length is {}.", feild, bound))287}