difftreelog
Merge pull request #829 from UniqueNetwork/feature/remove_and_hide_some_minting_methods_and_events
in: master
24 files changed
pallets/nonfungible/src/erc.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/erc.rs
+++ b/pallets/nonfungible/src/erc.rs
@@ -291,12 +291,6 @@
},
}
-#[derive(ToLog)]
-pub enum ERC721UniqueMintableEvents {
- #[allow(dead_code)]
- MintingFinished {},
-}
-
/// @title ERC-721 Non-Fungible Token Standard, optional metadata extension
/// @dev See https://eips.ethereum.org/EIPS/eip-721
#[solidity_interface(name = ERC721Metadata, expect_selector = 0x5b5e139f)]
@@ -544,12 +538,8 @@
}
/// @title ERC721 minting logic.
-#[solidity_interface(name = ERC721UniqueMintable, events(ERC721UniqueMintableEvents))]
+#[solidity_interface(name = ERC721UniqueMintable)]
impl<T: Config> NonfungibleHandle<T> {
- fn minting_finished(&self) -> Result<bool> {
- Ok(false)
- }
-
/// @notice Function to mint a token.
/// @param to The new owner
/// @return uint256 The id of the newly minted token
@@ -678,11 +668,6 @@
)
.map_err(dispatch_to_evm::<T>)?;
Ok(true)
- }
-
- /// @dev Not implemented
- fn finish_minting(&mut self, _caller: caller) -> Result<bool> {
- Err("not implementable".into())
}
}
pallets/nonfungible/src/stubs/UniqueNFT.rawdiffbeforeafterbothbinary blob — no preview
pallets/nonfungible/src/stubs/UniqueNFT.soldiffbeforeafterboth--- a/pallets/nonfungible/src/stubs/UniqueNFT.sol
+++ b/pallets/nonfungible/src/stubs/UniqueNFT.sol
@@ -700,22 +700,9 @@
}
}
-/// @dev inlined interface
-contract ERC721UniqueMintableEvents {
- event MintingFinished();
-}
-
/// @title ERC721 minting logic.
-/// @dev the ERC-165 identifier for this interface is 0x476ff149
-contract ERC721UniqueMintable is Dummy, ERC165, ERC721UniqueMintableEvents {
- /// @dev EVM selector for this function is: 0x05d2035b,
- /// or in textual repr: mintingFinished()
- function mintingFinished() public view returns (bool) {
- require(false, stub_error);
- dummy;
- return false;
- }
-
+/// @dev the ERC-165 identifier for this interface is 0x3fd94ea6
+contract ERC721UniqueMintable is Dummy, ERC165 {
/// @notice Function to mint a token.
/// @param to The new owner
/// @return uint256 The id of the newly minted token
@@ -756,7 +743,6 @@
dummy = 0;
return 0;
}
-
// /// @notice Function to mint token with the given tokenUri.
// /// @dev `tokenId` should be obtained with `nextTokenId` method,
// /// unlike standard, you can't specify it manually
@@ -774,14 +760,6 @@
// return false;
// }
- /// @dev Not implemented
- /// @dev EVM selector for this function is: 0x7d64bcb4,
- /// or in textual repr: finishMinting()
- function finishMinting() public returns (bool) {
- require(false, stub_error);
- dummy = 0;
- return false;
- }
}
/// @title Unique extensions for ERC721.
pallets/refungible/src/erc.rsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617//! # Refungible Pallet EVM API for tokens18//!19//! Provides ERC-721 standart support implementation and EVM API for unique extensions for Refungible Pallet.20//! Method implementations are mostly doing parameter conversion and calling Refungible Pallet methods.2122extern crate alloc;2324use core::{25 char::{REPLACEMENT_CHARACTER, decode_utf16},26 convert::TryInto,27};28use evm_coder::{29 abi::AbiType, ToLog, execution::*, generate_stubgen, solidity, solidity_interface, types::*,30 weight,31};32use frame_support::{BoundedBTreeMap, BoundedVec};33use pallet_common::{34 CollectionHandle, CollectionPropertyPermissions, CommonCollectionOperations,35 Error as CommonError,36 erc::{CommonEvmHandler, CollectionCall, static_property::key},37 eth,38};39use pallet_evm::{account::CrossAccountId, PrecompileHandle};40use pallet_evm_coder_substrate::{call, dispatch_to_evm};41use pallet_structure::{SelfWeightOf as StructureWeight, weights::WeightInfo as _};42use sp_core::{H160, Get};43use sp_std::{collections::btree_map::BTreeMap, vec::Vec, vec};44use up_data_structs::{45 CollectionId, CollectionPropertiesVec, mapping::TokenAddressMapping, Property, PropertyKey,46 PropertyKeyPermission, PropertyPermission, TokenId,47};4849use crate::{50 AccountBalance, Balance, Config, CreateItemData, Pallet, RefungibleHandle, SelfWeightOf,51 TokenProperties, TokensMinted, TotalSupply, weights::WeightInfo,52};5354pub const ADDRESS_FOR_PARTIALLY_OWNED_TOKENS: H160 = H160::repeat_byte(0xff);5556/// @title A contract that allows to set and delete token properties and change token property permissions.57#[solidity_interface(name = TokenProperties)]58impl<T: Config> RefungibleHandle<T> {59 /// @notice Set permissions for token property.60 /// @dev Throws error if `msg.sender` is not admin or owner of the collection.61 /// @param key Property key.62 /// @param isMutable Permission to mutate property.63 /// @param collectionAdmin Permission to mutate property by collection admin if property is mutable.64 /// @param tokenOwner Permission to mutate property by token owner if property is mutable.65 #[weight(<SelfWeightOf<T>>::set_token_property_permissions(1))]66 #[solidity(hide)]67 fn set_token_property_permission(68 &mut self,69 caller: caller,70 key: string,71 is_mutable: bool,72 collection_admin: bool,73 token_owner: bool,74 ) -> Result<()> {75 let caller = T::CrossAccountId::from_eth(caller);76 <Pallet<T>>::set_token_property_permissions(77 self,78 &caller,79 vec![PropertyKeyPermission {80 key: <Vec<u8>>::from(key)81 .try_into()82 .map_err(|_| "too long key")?,83 permission: PropertyPermission {84 mutable: is_mutable,85 collection_admin,86 token_owner,87 },88 }],89 )90 .map_err(dispatch_to_evm::<T>)91 }9293 /// @notice Set permissions for token property.94 /// @dev Throws error if `msg.sender` is not admin or owner of the collection.95 /// @param permissions Permissions for keys.96 #[weight(<SelfWeightOf<T>>::set_token_property_permissions(permissions.len() as u32))]97 fn set_token_property_permissions(98 &mut self,99 caller: caller,100 permissions: Vec<eth::TokenPropertyPermission>,101 ) -> Result<()> {102 let caller = T::CrossAccountId::from_eth(caller);103 let perms = eth::TokenPropertyPermission::into_property_key_permissions(permissions)?;104105 <Pallet<T>>::set_token_property_permissions(self, &caller, perms)106 .map_err(dispatch_to_evm::<T>)107 }108109 /// @notice Get permissions for token properties.110 fn token_property_permissions(&self) -> Result<Vec<eth::TokenPropertyPermission>> {111 let perms = <Pallet<T>>::token_property_permission(self.id);112 Ok(perms113 .into_iter()114 .map(eth::TokenPropertyPermission::from)115 .collect())116 }117118 /// @notice Set token property value.119 /// @dev Throws error if `msg.sender` has no permission to edit the property.120 /// @param tokenId ID of the token.121 /// @param key Property key.122 /// @param value Property value.123 #[solidity(hide)]124 #[weight(<SelfWeightOf<T>>::set_token_properties(1))]125 fn set_property(126 &mut self,127 caller: caller,128 token_id: uint256,129 key: string,130 value: bytes,131 ) -> Result<()> {132 let caller = T::CrossAccountId::from_eth(caller);133 let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;134 let key = <Vec<u8>>::from(key)135 .try_into()136 .map_err(|_| "key too long")?;137 let value = value.0.try_into().map_err(|_| "value too long")?;138139 let nesting_budget = self140 .recorder141 .weight_calls_budget(<StructureWeight<T>>::find_parent());142143 <Pallet<T>>::set_token_property(144 self,145 &caller,146 TokenId(token_id),147 Property { key, value },148 &nesting_budget,149 )150 .map_err(dispatch_to_evm::<T>)151 }152153 /// @notice Set token properties value.154 /// @dev Throws error if `msg.sender` has no permission to edit the property.155 /// @param tokenId ID of the token.156 /// @param properties settable properties157 #[weight(<SelfWeightOf<T>>::set_token_properties(properties.len() as u32))]158 fn set_properties(159 &mut self,160 caller: caller,161 token_id: uint256,162 properties: Vec<eth::Property>,163 ) -> Result<()> {164 let caller = T::CrossAccountId::from_eth(caller);165 let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;166167 let nesting_budget = self168 .recorder169 .weight_calls_budget(<StructureWeight<T>>::find_parent());170171 let properties = properties172 .into_iter()173 .map(eth::Property::try_into)174 .collect::<Result<Vec<_>>>()?;175176 <Pallet<T>>::set_token_properties(177 self,178 &caller,179 TokenId(token_id),180 properties.into_iter(),181 false,182 &nesting_budget,183 )184 .map_err(dispatch_to_evm::<T>)185 }186187 /// @notice Delete token property value.188 /// @dev Throws error if `msg.sender` has no permission to edit the property.189 /// @param tokenId ID of the token.190 /// @param key Property key.191 #[solidity(hide)]192 #[weight(<SelfWeightOf<T>>::delete_token_properties(1))]193 fn delete_property(&mut self, token_id: uint256, caller: caller, key: string) -> Result<()> {194 let caller = T::CrossAccountId::from_eth(caller);195 let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;196 let key = <Vec<u8>>::from(key)197 .try_into()198 .map_err(|_| "key too long")?;199200 let nesting_budget = self201 .recorder202 .weight_calls_budget(<StructureWeight<T>>::find_parent());203204 <Pallet<T>>::delete_token_property(self, &caller, TokenId(token_id), key, &nesting_budget)205 .map_err(dispatch_to_evm::<T>)206 }207208 /// @notice Delete token properties value.209 /// @dev Throws error if `msg.sender` has no permission to edit the property.210 /// @param tokenId ID of the token.211 /// @param keys Properties key.212 #[weight(<SelfWeightOf<T>>::delete_token_properties(keys.len() as u32))]213 fn delete_properties(214 &mut self,215 token_id: uint256,216 caller: caller,217 keys: Vec<string>,218 ) -> Result<()> {219 let caller = T::CrossAccountId::from_eth(caller);220 let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;221 let keys = keys222 .into_iter()223 .map(|k| Ok(<Vec<u8>>::from(k).try_into().map_err(|_| "key too long")?))224 .collect::<Result<Vec<_>>>()?;225226 let nesting_budget = self227 .recorder228 .weight_calls_budget(<StructureWeight<T>>::find_parent());229230 <Pallet<T>>::delete_token_properties(231 self,232 &caller,233 TokenId(token_id),234 keys.into_iter(),235 &nesting_budget,236 )237 .map_err(dispatch_to_evm::<T>)238 }239240 /// @notice Get token property value.241 /// @dev Throws error if key not found242 /// @param tokenId ID of the token.243 /// @param key Property key.244 /// @return Property value bytes245 fn property(&self, token_id: uint256, key: string) -> Result<bytes> {246 let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;247 let key = <Vec<u8>>::from(key)248 .try_into()249 .map_err(|_| "key too long")?;250251 let props = <TokenProperties<T>>::get((self.id, token_id));252 let prop = props.get(&key).ok_or("key not found")?;253254 Ok(prop.to_vec().into())255 }256}257258#[derive(ToLog)]259pub enum ERC721Events {260 /// @dev This event emits when NFTs are created (`from` == 0) and destroyed261 /// (`to` == 0). Exception: during contract creation, any number of RFTs262 /// may be created and assigned without emitting Transfer.263 Transfer {264 #[indexed]265 from: address,266 #[indexed]267 to: address,268 #[indexed]269 token_id: uint256,270 },271 /// @dev Not supported272 Approval {273 #[indexed]274 owner: address,275 #[indexed]276 approved: address,277 #[indexed]278 token_id: uint256,279 },280 /// @dev Not supported281 #[allow(dead_code)]282 ApprovalForAll {283 #[indexed]284 owner: address,285 #[indexed]286 operator: address,287 approved: bool,288 },289}290291#[derive(ToLog)]292pub enum ERC721UniqueMintableEvents {293 /// @dev Not supported294 #[allow(dead_code)]295 MintingFinished {},296}297298/// @title ERC-721 Non-Fungible Token Standard, optional metadata extension299/// @dev See https://eips.ethereum.org/EIPS/eip-721300#[solidity_interface(name = ERC721Metadata, expect_selector = 0x5b5e139f)]301impl<T: Config> RefungibleHandle<T>302where303 T::AccountId: From<[u8; 32]> + AsRef<[u8; 32]>,304{305 /// @notice A descriptive name for a collection of NFTs in this contract306 /// @dev real implementation of this function lies in `ERC721UniqueExtensions`307 #[solidity(hide, rename_selector = "name")]308 fn name_proxy(&self) -> Result<string> {309 self.name()310 }311312 /// @notice An abbreviated name for NFTs in this contract313 /// @dev real implementation of this function lies in `ERC721UniqueExtensions`314 #[solidity(hide, rename_selector = "symbol")]315 fn symbol_proxy(&self) -> Result<string> {316 self.symbol()317 }318319 /// @notice A distinct Uniform Resource Identifier (URI) for a given asset.320 ///321 /// @dev If the token has a `url` property and it is not empty, it is returned.322 /// Else If the collection does not have a property with key `schemaName` or its value is not equal to `ERC721Metadata`, it return an error `tokenURI not set`.323 /// If the collection property `baseURI` is empty or absent, return "" (empty string)324 /// otherwise, if token property `suffix` present and is non-empty, return concatenation of baseURI and suffix325 /// otherwise, return concatenation of `baseURI` and stringified token id (decimal stringifying, without paddings).326 ///327 /// @return token's const_metadata328 #[solidity(rename_selector = "tokenURI")]329 fn token_uri(&self, token_id: uint256) -> Result<string> {330 let token_id_u32: u32 = token_id.try_into().map_err(|_| "token id overflow")?;331332 match get_token_property(self, token_id_u32, &key::url()).as_deref() {333 Err(_) | Ok("") => (),334 Ok(url) => {335 return Ok(url.into());336 }337 };338339 let base_uri =340 pallet_common::Pallet::<T>::get_collection_property(self.id, &key::base_uri())341 .map(BoundedVec::into_inner)342 .map(string::from_utf8)343 .transpose()344 .map_err(|e| {345 Error::Revert(alloc::format!(346 "Can not convert value \"baseURI\" to string with error \"{}\"",347 e348 ))349 })?;350351 let base_uri = match base_uri.as_deref() {352 None | Some("") => {353 return Ok("".into());354 }355 Some(base_uri) => base_uri.into(),356 };357358 Ok(359 match get_token_property(self, token_id_u32, &key::suffix()).as_deref() {360 Err(_) | Ok("") => base_uri,361 Ok(suffix) => base_uri + suffix,362 },363 )364 }365}366367/// @title ERC-721 Non-Fungible Token Standard, optional enumeration extension368/// @dev See https://eips.ethereum.org/EIPS/eip-721369#[solidity_interface(name = ERC721Enumerable, expect_selector = 0x780e9d63)]370impl<T: Config> RefungibleHandle<T> {371 /// @notice Enumerate valid RFTs372 /// @param index A counter less than `totalSupply()`373 /// @return The token identifier for the `index`th NFT,374 /// (sort order not specified)375 fn token_by_index(&self, index: uint256) -> Result<uint256> {376 Ok(index)377 }378379 /// Not implemented380 fn token_of_owner_by_index(&self, _owner: address, _index: uint256) -> Result<uint256> {381 // TODO: Not implemetable382 Err("not implemented".into())383 }384385 /// @notice Count RFTs tracked by this contract386 /// @return A count of valid RFTs tracked by this contract, where each one of387 /// them has an assigned and queryable owner not equal to the zero address388 fn total_supply(&self) -> Result<uint256> {389 self.consume_store_reads(1)?;390 Ok(<Pallet<T>>::total_supply(self).into())391 }392}393394/// @title ERC-721 Non-Fungible Token Standard395/// @dev See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md396#[solidity_interface(name = ERC721, events(ERC721Events), expect_selector = 0x80ac58cd)]397impl<T: Config> RefungibleHandle<T> {398 /// @notice Count all RFTs assigned to an owner399 /// @dev RFTs assigned to the zero address are considered invalid, and this400 /// function throws for queries about the zero address.401 /// @param owner An address for whom to query the balance402 /// @return The number of RFTs owned by `owner`, possibly zero403 fn balance_of(&self, owner: address) -> Result<uint256> {404 self.consume_store_reads(1)?;405 let owner = T::CrossAccountId::from_eth(owner);406 let balance = <AccountBalance<T>>::get((self.id, owner));407 Ok(balance.into())408 }409410 /// @notice Find the owner of an RFT411 /// @dev RFTs assigned to zero address are considered invalid, and queries412 /// about them do throw.413 /// Returns special 0xffffffffffffffffffffffffffffffffffffffff address for414 /// the tokens that are partially owned.415 /// @param tokenId The identifier for an RFT416 /// @return The address of the owner of the RFT417 fn owner_of(&self, token_id: uint256) -> Result<address> {418 self.consume_store_reads(2)?;419 let token = token_id.try_into()?;420 let owner = <Pallet<T>>::token_owner(self.id, token);421 Ok(owner422 .map(|address| *address.as_eth())423 .unwrap_or_else(|| ADDRESS_FOR_PARTIALLY_OWNED_TOKENS))424 }425426 /// @dev Not implemented427 #[solidity(rename_selector = "safeTransferFrom")]428 fn safe_transfer_from_with_data(429 &mut self,430 _from: address,431 _to: address,432 _token_id: uint256,433 _data: bytes,434 ) -> Result<void> {435 // TODO: Not implemetable436 Err("not implemented".into())437 }438439 /// @dev Not implemented440 #[solidity(rename_selector = "safeTransferFrom")]441 fn safe_transfer_from(442 &mut self,443 _from: address,444 _to: address,445 _token_id: uint256,446 ) -> Result<void> {447 // TODO: Not implemetable448 Err("not implemented".into())449 }450451 /// @notice Transfer ownership of an RFT -- THE CALLER IS RESPONSIBLE452 /// TO CONFIRM THAT `to` IS CAPABLE OF RECEIVING NFTS OR ELSE453 /// THEY MAY BE PERMANENTLY LOST454 /// @dev Throws unless `msg.sender` is the current owner or an authorized455 /// operator for this RFT. Throws if `from` is not the current owner. Throws456 /// if `to` is the zero address. Throws if `tokenId` is not a valid RFT.457 /// Throws if RFT pieces have multiple owners.458 /// @param from The current owner of the NFT459 /// @param to The new owner460 /// @param tokenId The NFT to transfer461 #[weight(<SelfWeightOf<T>>::transfer_from_creating_removing())]462 fn transfer_from(463 &mut self,464 caller: caller,465 from: address,466 to: address,467 token_id: uint256,468 ) -> Result<void> {469 let caller = T::CrossAccountId::from_eth(caller);470 let from = T::CrossAccountId::from_eth(from);471 let to = T::CrossAccountId::from_eth(to);472 let token = token_id.try_into()?;473 let budget = self474 .recorder475 .weight_calls_budget(<StructureWeight<T>>::find_parent());476477 let balance = balance(&self, token, &from)?;478 ensure_single_owner(&self, token, balance)?;479480 <Pallet<T>>::transfer_from(self, &caller, &from, &to, token, balance, &budget)481 .map_err(dispatch_to_evm::<T>)?;482483 Ok(())484 }485486 /// @dev Not implemented487 fn approve(&mut self, _caller: caller, _approved: address, _token_id: uint256) -> Result<void> {488 Err("not implemented".into())489 }490491 /// @notice Sets or unsets the approval of a given operator.492 /// The `operator` is allowed to transfer all token pieces of the `caller` on their behalf.493 /// @param operator Operator494 /// @param approved Should operator status be granted or revoked?495 #[weight(<SelfWeightOf<T>>::set_allowance_for_all())]496 fn set_approval_for_all(497 &mut self,498 caller: caller,499 operator: address,500 approved: bool,501 ) -> Result<void> {502 let caller = T::CrossAccountId::from_eth(caller);503 let operator = T::CrossAccountId::from_eth(operator);504505 <Pallet<T>>::set_allowance_for_all(self, &caller, &operator, approved)506 .map_err(dispatch_to_evm::<T>)?;507 Ok(())508 }509510 /// @dev Not implemented511 fn get_approved(&self, _token_id: uint256) -> Result<address> {512 // TODO: Not implemetable513 Err("not implemented".into())514 }515516 /// @notice Tells whether the given `owner` approves the `operator`.517 #[weight(<SelfWeightOf<T>>::allowance_for_all())]518 fn is_approved_for_all(&self, owner: address, operator: address) -> Result<bool> {519 let owner = T::CrossAccountId::from_eth(owner);520 let operator = T::CrossAccountId::from_eth(operator);521522 Ok(<Pallet<T>>::allowance_for_all(self, &owner, &operator))523 }524}525526/// Returns amount of pieces of `token` that `owner` have527pub fn balance<T: Config>(528 collection: &RefungibleHandle<T>,529 token: TokenId,530 owner: &T::CrossAccountId,531) -> Result<u128> {532 collection.consume_store_reads(1)?;533 let balance = <Balance<T>>::get((collection.id, token, &owner));534 Ok(balance)535}536537/// Throws if `owner_balance` is lower than total amount of `token` pieces538pub fn ensure_single_owner<T: Config>(539 collection: &RefungibleHandle<T>,540 token: TokenId,541 owner_balance: u128,542) -> Result<()> {543 collection.consume_store_reads(1)?;544 let total_supply = <TotalSupply<T>>::get((collection.id, token));545546 if owner_balance == 0 {547 return Err(dispatch_to_evm::<T>(548 <CommonError<T>>::MustBeTokenOwner.into(),549 ));550 }551552 if total_supply != owner_balance {553 return Err("token has multiple owners".into());554 }555 Ok(())556}557558/// @title ERC721 Token that can be irreversibly burned (destroyed).559#[solidity_interface(name = ERC721Burnable)]560impl<T: Config> RefungibleHandle<T> {561 /// @notice Burns a specific ERC721 token.562 /// @dev Throws unless `msg.sender` is the current RFT owner, or an authorized563 /// operator of the current owner.564 /// @param tokenId The RFT to approve565 #[weight(<SelfWeightOf<T>>::burn_item_fully())]566 fn burn(&mut self, caller: caller, token_id: uint256) -> Result<void> {567 let caller = T::CrossAccountId::from_eth(caller);568 let token = token_id.try_into()?;569570 let balance = balance(&self, token, &caller)?;571 ensure_single_owner(&self, token, balance)?;572573 <Pallet<T>>::burn(self, &caller, token, balance).map_err(dispatch_to_evm::<T>)?;574 Ok(())575 }576}577578/// @title ERC721 minting logic.579#[solidity_interface(name = ERC721UniqueMintable, events(ERC721UniqueMintableEvents))]580impl<T: Config> RefungibleHandle<T> {581 fn minting_finished(&self) -> Result<bool> {582 Ok(false)583 }584585 /// @notice Function to mint a token.586 /// @param to The new owner587 /// @return uint256 The id of the newly minted token588 #[weight(<SelfWeightOf<T>>::create_item())]589 fn mint(&mut self, caller: caller, to: address) -> Result<uint256> {590 let token_id: uint256 = <TokensMinted<T>>::get(self.id)591 .checked_add(1)592 .ok_or("item id overflow")?593 .into();594 self.mint_check_id(caller, to, token_id)?;595 Ok(token_id)596 }597598 /// @notice Function to mint a token.599 /// @dev `tokenId` should be obtained with `nextTokenId` method,600 /// unlike standard, you can't specify it manually601 /// @param to The new owner602 /// @param tokenId ID of the minted RFT603 #[solidity(hide, rename_selector = "mint")]604 #[weight(<SelfWeightOf<T>>::create_item())]605 fn mint_check_id(&mut self, caller: caller, to: address, token_id: uint256) -> Result<bool> {606 let caller = T::CrossAccountId::from_eth(caller);607 let to = T::CrossAccountId::from_eth(to);608 let token_id: u32 = token_id.try_into()?;609 let budget = self610 .recorder611 .weight_calls_budget(<StructureWeight<T>>::find_parent());612613 if <TokensMinted<T>>::get(self.id)614 .checked_add(1)615 .ok_or("item id overflow")?616 != token_id617 {618 return Err("item id should be next".into());619 }620621 let users = [(to.clone(), 1)]622 .into_iter()623 .collect::<BTreeMap<_, _>>()624 .try_into()625 .unwrap();626 <Pallet<T>>::create_item(627 self,628 &caller,629 CreateItemData::<T> {630 users,631 properties: CollectionPropertiesVec::default(),632 },633 &budget,634 )635 .map_err(dispatch_to_evm::<T>)?;636637 Ok(true)638 }639640 /// @notice Function to mint token with the given tokenUri.641 /// @param to The new owner642 /// @param tokenUri Token URI that would be stored in the NFT properties643 /// @return uint256 The id of the newly minted token644 #[solidity(rename_selector = "mintWithTokenURI")]645 #[weight(<SelfWeightOf<T>>::create_item())]646 fn mint_with_token_uri(647 &mut self,648 caller: caller,649 to: address,650 token_uri: string,651 ) -> Result<uint256> {652 let token_id: uint256 = <TokensMinted<T>>::get(self.id)653 .checked_add(1)654 .ok_or("item id overflow")?655 .into();656 self.mint_with_token_uri_check_id(caller, to, token_id, token_uri)?;657 Ok(token_id)658 }659660 /// @notice Function to mint token with the given tokenUri.661 /// @dev `tokenId` should be obtained with `nextTokenId` method,662 /// unlike standard, you can't specify it manually663 /// @param to The new owner664 /// @param tokenId ID of the minted RFT665 /// @param tokenUri Token URI that would be stored in the RFT properties666 #[solidity(hide, rename_selector = "mintWithTokenURI")]667 #[weight(<SelfWeightOf<T>>::create_item())]668 fn mint_with_token_uri_check_id(669 &mut self,670 caller: caller,671 to: address,672 token_id: uint256,673 token_uri: string,674 ) -> Result<bool> {675 let key = key::url();676 let permission = get_token_permission::<T>(self.id, &key)?;677 if !permission.collection_admin {678 return Err("Operation is not allowed".into());679 }680681 let caller = T::CrossAccountId::from_eth(caller);682 let to = T::CrossAccountId::from_eth(to);683 let token_id: u32 = token_id.try_into().map_err(|_| "amount overflow")?;684 let budget = self685 .recorder686 .weight_calls_budget(<StructureWeight<T>>::find_parent());687688 if <TokensMinted<T>>::get(self.id)689 .checked_add(1)690 .ok_or("item id overflow")?691 != token_id692 {693 return Err("item id should be next".into());694 }695696 let mut properties = CollectionPropertiesVec::default();697 properties698 .try_push(Property {699 key,700 value: token_uri701 .into_bytes()702 .try_into()703 .map_err(|_| "token uri is too long")?,704 })705 .map_err(|e| Error::Revert(alloc::format!("Can't add property: {:?}", e)))?;706707 let users = [(to.clone(), 1)]708 .into_iter()709 .collect::<BTreeMap<_, _>>()710 .try_into()711 .unwrap();712 <Pallet<T>>::create_item(713 self,714 &caller,715 CreateItemData::<T> { users, properties },716 &budget,717 )718 .map_err(dispatch_to_evm::<T>)?;719 Ok(true)720 }721722 /// @dev Not implemented723 fn finish_minting(&mut self, _caller: caller) -> Result<bool> {724 Err("not implementable".into())725 }726}727728fn get_token_property<T: Config>(729 collection: &CollectionHandle<T>,730 token_id: u32,731 key: &up_data_structs::PropertyKey,732) -> Result<string> {733 collection.consume_store_reads(1)?;734 let properties = <TokenProperties<T>>::try_get((collection.id, token_id))735 .map_err(|_| Error::Revert("Token properties not found".into()))?;736 if let Some(property) = properties.get(key) {737 return Ok(string::from_utf8_lossy(property).into());738 }739740 Err("Property tokenURI not found".into())741}742743fn get_token_permission<T: Config>(744 collection_id: CollectionId,745 key: &PropertyKey,746) -> Result<PropertyPermission> {747 let token_property_permissions = CollectionPropertyPermissions::<T>::try_get(collection_id)748 .map_err(|_| Error::Revert("No permissions for collection".into()))?;749 let a = token_property_permissions750 .get(key)751 .map(Clone::clone)752 .ok_or_else(|| {753 let key = string::from_utf8(key.clone().into_inner()).unwrap_or_default();754 Error::Revert(alloc::format!("No permission for key {}", key))755 })?;756 Ok(a)757}758759/// @title Unique extensions for ERC721.760#[solidity_interface(name = ERC721UniqueExtensions)]761impl<T: Config> RefungibleHandle<T>762where763 T::AccountId: From<[u8; 32]> + AsRef<[u8; 32]>,764{765 /// @notice A descriptive name for a collection of NFTs in this contract766 fn name(&self) -> Result<string> {767 Ok(decode_utf16(self.name.iter().copied())768 .map(|r| r.unwrap_or(REPLACEMENT_CHARACTER))769 .collect::<string>())770 }771772 /// @notice An abbreviated name for NFTs in this contract773 fn symbol(&self) -> Result<string> {774 Ok(string::from_utf8_lossy(&self.token_prefix).into())775 }776777 /// @notice A description for the collection.778 fn description(&self) -> Result<string> {779 Ok(decode_utf16(self.description.iter().copied())780 .map(|r| r.unwrap_or(REPLACEMENT_CHARACTER))781 .collect::<string>())782 }783784 /// Returns the owner (in cross format) of the token.785 ///786 /// @param tokenId Id for the token.787 fn cross_owner_of(&self, token_id: uint256) -> Result<eth::CrossAddress> {788 Self::token_owner(&self, token_id.try_into()?)789 .map(|o| eth::CrossAddress::from_sub_cross_account::<T>(&o))790 .ok_or(Error::Revert("key too large".into()))791 }792793 /// Returns the token properties.794 ///795 /// @param tokenId Id for the token.796 /// @param keys Properties keys. Empty keys for all propertyes.797 /// @return Vector of properties key/value pairs.798 fn properties(&self, token_id: uint256, keys: Vec<string>) -> Result<Vec<eth::Property>> {799 let keys = keys800 .into_iter()801 .map(|key| {802 <Vec<u8>>::from(key)803 .try_into()804 .map_err(|_| Error::Revert("key too large".into()))805 })806 .collect::<Result<Vec<_>>>()?;807808 <Self as CommonCollectionOperations<T>>::token_properties(809 &self,810 token_id.try_into()?,811 if keys.is_empty() { None } else { Some(keys) },812 )813 .into_iter()814 .map(eth::Property::try_from)815 .collect::<Result<Vec<_>>>()816 }817 /// @notice Transfer ownership of an RFT818 /// @dev Throws unless `msg.sender` is the current owner. Throws if `to`819 /// is the zero address. Throws if `tokenId` is not a valid RFT.820 /// Throws if RFT pieces have multiple owners.821 /// @param to The new owner822 /// @param tokenId The RFT to transfer823 #[weight(<SelfWeightOf<T>>::transfer_creating_removing())]824 fn transfer(&mut self, caller: caller, to: address, token_id: uint256) -> Result<void> {825 let caller = T::CrossAccountId::from_eth(caller);826 let to = T::CrossAccountId::from_eth(to);827 let token = token_id.try_into()?;828 let budget = self829 .recorder830 .weight_calls_budget(<StructureWeight<T>>::find_parent());831832 let balance = balance(self, token, &caller)?;833 ensure_single_owner(self, token, balance)?;834835 <Pallet<T>>::transfer(self, &caller, &to, token, balance, &budget)836 .map_err(dispatch_to_evm::<T>)?;837 Ok(())838 }839840 /// @notice Transfer ownership of an RFT841 /// @dev Throws unless `msg.sender` is the current owner. Throws if `to`842 /// is the zero address. Throws if `tokenId` is not a valid RFT.843 /// Throws if RFT pieces have multiple owners.844 /// @param to The new owner845 /// @param tokenId The RFT to transfer846 #[weight(<SelfWeightOf<T>>::transfer_creating_removing())]847 fn transfer_cross(848 &mut self,849 caller: caller,850 to: eth::CrossAddress,851 token_id: uint256,852 ) -> Result<void> {853 let caller = T::CrossAccountId::from_eth(caller);854 let to = to.into_sub_cross_account::<T>()?;855 let token = token_id.try_into()?;856 let budget = self857 .recorder858 .weight_calls_budget(<StructureWeight<T>>::find_parent());859860 let balance = balance(self, token, &caller)?;861 ensure_single_owner(self, token, balance)?;862863 <Pallet<T>>::transfer(self, &caller, &to, token, balance, &budget)864 .map_err(dispatch_to_evm::<T>)?;865 Ok(())866 }867868 /// @notice Transfer ownership of an RFT869 /// @dev Throws unless `msg.sender` is the current owner. Throws if `to`870 /// is the zero address. Throws if `tokenId` is not a valid RFT.871 /// Throws if RFT pieces have multiple owners.872 /// @param to The new owner873 /// @param tokenId The RFT to transfer874 #[weight(<SelfWeightOf<T>>::transfer_creating_removing())]875 fn transfer_from_cross(876 &mut self,877 caller: caller,878 from: eth::CrossAddress,879 to: eth::CrossAddress,880 token_id: uint256,881 ) -> Result<void> {882 let caller = T::CrossAccountId::from_eth(caller);883 let from = from.into_sub_cross_account::<T>()?;884 let to = to.into_sub_cross_account::<T>()?;885 let token_id = token_id.try_into()?;886 let budget = self887 .recorder888 .weight_calls_budget(<StructureWeight<T>>::find_parent());889890 let balance = balance(self, token_id, &from)?;891 ensure_single_owner(self, token_id, balance)?;892893 Pallet::<T>::transfer_from(self, &caller, &from, &to, token_id, balance, &budget)894 .map_err(dispatch_to_evm::<T>)?;895 Ok(())896 }897898 /// @notice Burns a specific ERC721 token.899 /// @dev Throws unless `msg.sender` is the current owner or an authorized900 /// operator for this RFT. Throws if `from` is not the current owner. Throws901 /// if `to` is the zero address. Throws if `tokenId` is not a valid RFT.902 /// Throws if RFT pieces have multiple owners.903 /// @param from The current owner of the RFT904 /// @param tokenId The RFT to transfer905 #[solidity(hide)]906 #[weight(<SelfWeightOf<T>>::burn_from())]907 fn burn_from(&mut self, caller: caller, from: address, token_id: uint256) -> Result<void> {908 let caller = T::CrossAccountId::from_eth(caller);909 let from = T::CrossAccountId::from_eth(from);910 let token = token_id.try_into()?;911 let budget = self912 .recorder913 .weight_calls_budget(<StructureWeight<T>>::find_parent());914915 let balance = balance(self, token, &from)?;916 ensure_single_owner(self, token, balance)?;917918 <Pallet<T>>::burn_from(self, &caller, &from, token, balance, &budget)919 .map_err(dispatch_to_evm::<T>)?;920 Ok(())921 }922923 /// @notice Burns a specific ERC721 token.924 /// @dev Throws unless `msg.sender` is the current owner or an authorized925 /// operator for this RFT. Throws if `from` is not the current owner. Throws926 /// if `to` is the zero address. Throws if `tokenId` is not a valid RFT.927 /// Throws if RFT pieces have multiple owners.928 /// @param from The current owner of the RFT929 /// @param tokenId The RFT to transfer930 #[weight(<SelfWeightOf<T>>::burn_from())]931 fn burn_from_cross(932 &mut self,933 caller: caller,934 from: eth::CrossAddress,935 token_id: uint256,936 ) -> Result<void> {937 let caller = T::CrossAccountId::from_eth(caller);938 let from = from.into_sub_cross_account::<T>()?;939 let token = token_id.try_into()?;940 let budget = self941 .recorder942 .weight_calls_budget(<StructureWeight<T>>::find_parent());943944 let balance = balance(self, token, &from)?;945 ensure_single_owner(self, token, balance)?;946947 <Pallet<T>>::burn_from(self, &caller, &from, token, balance, &budget)948 .map_err(dispatch_to_evm::<T>)?;949 Ok(())950 }951952 /// @notice Returns next free RFT ID.953 fn next_token_id(&self) -> Result<uint256> {954 self.consume_store_reads(1)?;955 Ok(<TokensMinted<T>>::get(self.id)956 .checked_add(1)957 .ok_or("item id overflow")?958 .into())959 }960961 /// @notice Function to mint multiple tokens.962 /// @dev `tokenIds` should be an array of consecutive numbers and first number963 /// should be obtained with `nextTokenId` method964 /// @param to The new owner965 /// @param tokenIds IDs of the minted RFTs966 #[solidity(hide)]967 #[weight(<SelfWeightOf<T>>::create_multiple_items(token_ids.len() as u32))]968 fn mint_bulk(&mut self, caller: caller, to: address, token_ids: Vec<uint256>) -> Result<bool> {969 let caller = T::CrossAccountId::from_eth(caller);970 let to = T::CrossAccountId::from_eth(to);971 let mut expected_index = <TokensMinted<T>>::get(self.id)972 .checked_add(1)973 .ok_or("item id overflow")?;974 let budget = self975 .recorder976 .weight_calls_budget(<StructureWeight<T>>::find_parent());977978 let total_tokens = token_ids.len();979 for id in token_ids.into_iter() {980 let id: u32 = id.try_into().map_err(|_| "token id overflow")?;981 if id != expected_index {982 return Err("item id should be next".into());983 }984 expected_index = expected_index.checked_add(1).ok_or("item id overflow")?;985 }986 let users = [(to.clone(), 1)]987 .into_iter()988 .collect::<BTreeMap<_, _>>()989 .try_into()990 .unwrap();991 let create_item_data = CreateItemData::<T> {992 users,993 properties: CollectionPropertiesVec::default(),994 };995 let data = (0..total_tokens)996 .map(|_| create_item_data.clone())997 .collect();998999 <Pallet<T>>::create_multiple_items(self, &caller, data, &budget)1000 .map_err(dispatch_to_evm::<T>)?;1001 Ok(true)1002 }10031004 /// @notice Function to mint multiple tokens with the given tokenUris.1005 /// @dev `tokenIds` is array of pairs of token ID and token URI. Token IDs should be consecutive1006 /// numbers and first number should be obtained with `nextTokenId` method1007 /// @param to The new owner1008 /// @param tokens array of pairs of token ID and token URI for minted tokens1009 #[solidity(hide, rename_selector = "mintBulkWithTokenURI")]1010 #[weight(<SelfWeightOf<T>>::create_multiple_items(tokens.len() as u32))]1011 fn mint_bulk_with_token_uri(1012 &mut self,1013 caller: caller,1014 to: address,1015 tokens: Vec<(uint256, string)>,1016 ) -> Result<bool> {1017 let key = key::url();1018 let caller = T::CrossAccountId::from_eth(caller);1019 let to = T::CrossAccountId::from_eth(to);1020 let mut expected_index = <TokensMinted<T>>::get(self.id)1021 .checked_add(1)1022 .ok_or("item id overflow")?;1023 let budget = self1024 .recorder1025 .weight_calls_budget(<StructureWeight<T>>::find_parent());10261027 let mut data = Vec::with_capacity(tokens.len());1028 let users: BoundedBTreeMap<_, _, _> = [(to.clone(), 1)]1029 .into_iter()1030 .collect::<BTreeMap<_, _>>()1031 .try_into()1032 .unwrap();1033 for (id, token_uri) in tokens {1034 let id: u32 = id.try_into().map_err(|_| "token id overflow")?;1035 if id != expected_index {1036 return Err("item id should be next".into());1037 }1038 expected_index = expected_index.checked_add(1).ok_or("item id overflow")?;10391040 let mut properties = CollectionPropertiesVec::default();1041 properties1042 .try_push(Property {1043 key: key.clone(),1044 value: token_uri1045 .into_bytes()1046 .try_into()1047 .map_err(|_| "token uri is too long")?,1048 })1049 .map_err(|e| Error::Revert(alloc::format!("Can't add property: {:?}", e)))?;10501051 let create_item_data = CreateItemData::<T> {1052 users: users.clone(),1053 properties,1054 };1055 data.push(create_item_data);1056 }10571058 <Pallet<T>>::create_multiple_items(self, &caller, data, &budget)1059 .map_err(dispatch_to_evm::<T>)?;1060 Ok(true)1061 }10621063 /// @notice Function to mint a token.1064 /// @param to The new owner crossAccountId1065 /// @param properties Properties of minted token1066 /// @return uint256 The id of the newly minted token1067 #[weight(<SelfWeightOf<T>>::create_item())]1068 fn mint_cross(1069 &mut self,1070 caller: caller,1071 to: eth::CrossAddress,1072 properties: Vec<eth::Property>,1073 ) -> Result<uint256> {1074 let token_id = <TokensMinted<T>>::get(self.id)1075 .checked_add(1)1076 .ok_or("item id overflow")?;10771078 let to = to.into_sub_cross_account::<T>()?;10791080 let properties = properties1081 .into_iter()1082 .map(eth::Property::try_into)1083 .collect::<Result<Vec<_>>>()?1084 .try_into()1085 .map_err(|_| Error::Revert(alloc::format!("too many properties")))?;10861087 let caller = T::CrossAccountId::from_eth(caller);10881089 let budget = self1090 .recorder1091 .weight_calls_budget(<StructureWeight<T>>::find_parent());10921093 let users = [(to, 1)]1094 .into_iter()1095 .collect::<BTreeMap<_, _>>()1096 .try_into()1097 .unwrap();1098 <Pallet<T>>::create_item(1099 self,1100 &caller,1101 CreateItemData::<T> { users, properties },1102 &budget,1103 )1104 .map_err(dispatch_to_evm::<T>)?;11051106 Ok(token_id.into())1107 }11081109 /// Returns EVM address for refungible token1110 ///1111 /// @param token ID of the token1112 fn token_contract_address(&self, token: uint256) -> Result<address> {1113 Ok(T::EvmTokenAddressMapping::token_to_address(1114 self.id,1115 token.try_into().map_err(|_| "token id overflow")?,1116 ))1117 }11181119 /// @notice Returns collection helper contract address1120 fn collection_helper_address(&self) -> Result<address> {1121 Ok(T::ContractAddress::get())1122 }1123}11241125#[solidity_interface(1126 name = UniqueRefungible,1127 is(1128 ERC721,1129 ERC721Enumerable,1130 ERC721UniqueExtensions,1131 ERC721UniqueMintable,1132 ERC721Burnable,1133 ERC721Metadata(if(this.flags.erc721metadata)),1134 Collection(via(common_mut returns CollectionHandle<T>)),1135 TokenProperties,1136 )1137)]1138impl<T: Config> RefungibleHandle<T> where T::AccountId: From<[u8; 32]> + AsRef<[u8; 32]> {}11391140// Not a tests, but code generators1141generate_stubgen!(gen_impl, UniqueRefungibleCall<()>, true);1142generate_stubgen!(gen_iface, UniqueRefungibleCall<()>, false);11431144impl<T: Config> CommonEvmHandler for RefungibleHandle<T>1145where1146 T::AccountId: From<[u8; 32]> + AsRef<[u8; 32]>,1147{1148 const CODE: &'static [u8] = include_bytes!("./stubs/UniqueRefungible.raw");1149 fn call(1150 self,1151 handle: &mut impl PrecompileHandle,1152 ) -> Option<pallet_common::erc::PrecompileResult> {1153 call::<T, UniqueRefungibleCall<T>, _, _>(handle, self)1154 }1155}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//! # Refungible Pallet EVM API for tokens18//!19//! Provides ERC-721 standart support implementation and EVM API for unique extensions for Refungible Pallet.20//! Method implementations are mostly doing parameter conversion and calling Refungible Pallet methods.2122extern crate alloc;2324use core::{25 char::{REPLACEMENT_CHARACTER, decode_utf16},26 convert::TryInto,27};28use evm_coder::{29 abi::AbiType, ToLog, execution::*, generate_stubgen, solidity, solidity_interface, types::*,30 weight,31};32use frame_support::{BoundedBTreeMap, BoundedVec};33use pallet_common::{34 CollectionHandle, CollectionPropertyPermissions, CommonCollectionOperations,35 Error as CommonError,36 erc::{CommonEvmHandler, CollectionCall, static_property::key},37 eth,38};39use pallet_evm::{account::CrossAccountId, PrecompileHandle};40use pallet_evm_coder_substrate::{call, dispatch_to_evm};41use pallet_structure::{SelfWeightOf as StructureWeight, weights::WeightInfo as _};42use sp_core::{H160, Get};43use sp_std::{collections::btree_map::BTreeMap, vec::Vec, vec};44use up_data_structs::{45 CollectionId, CollectionPropertiesVec, mapping::TokenAddressMapping, Property, PropertyKey,46 PropertyKeyPermission, PropertyPermission, TokenId,47};4849use crate::{50 AccountBalance, Balance, Config, CreateItemData, Pallet, RefungibleHandle, SelfWeightOf,51 TokenProperties, TokensMinted, TotalSupply, weights::WeightInfo,52};5354pub const ADDRESS_FOR_PARTIALLY_OWNED_TOKENS: H160 = H160::repeat_byte(0xff);5556/// @title A contract that allows to set and delete token properties and change token property permissions.57#[solidity_interface(name = TokenProperties)]58impl<T: Config> RefungibleHandle<T> {59 /// @notice Set permissions for token property.60 /// @dev Throws error if `msg.sender` is not admin or owner of the collection.61 /// @param key Property key.62 /// @param isMutable Permission to mutate property.63 /// @param collectionAdmin Permission to mutate property by collection admin if property is mutable.64 /// @param tokenOwner Permission to mutate property by token owner if property is mutable.65 #[weight(<SelfWeightOf<T>>::set_token_property_permissions(1))]66 #[solidity(hide)]67 fn set_token_property_permission(68 &mut self,69 caller: caller,70 key: string,71 is_mutable: bool,72 collection_admin: bool,73 token_owner: bool,74 ) -> Result<()> {75 let caller = T::CrossAccountId::from_eth(caller);76 <Pallet<T>>::set_token_property_permissions(77 self,78 &caller,79 vec![PropertyKeyPermission {80 key: <Vec<u8>>::from(key)81 .try_into()82 .map_err(|_| "too long key")?,83 permission: PropertyPermission {84 mutable: is_mutable,85 collection_admin,86 token_owner,87 },88 }],89 )90 .map_err(dispatch_to_evm::<T>)91 }9293 /// @notice Set permissions for token property.94 /// @dev Throws error if `msg.sender` is not admin or owner of the collection.95 /// @param permissions Permissions for keys.96 #[weight(<SelfWeightOf<T>>::set_token_property_permissions(permissions.len() as u32))]97 fn set_token_property_permissions(98 &mut self,99 caller: caller,100 permissions: Vec<eth::TokenPropertyPermission>,101 ) -> Result<()> {102 let caller = T::CrossAccountId::from_eth(caller);103 let perms = eth::TokenPropertyPermission::into_property_key_permissions(permissions)?;104105 <Pallet<T>>::set_token_property_permissions(self, &caller, perms)106 .map_err(dispatch_to_evm::<T>)107 }108109 /// @notice Get permissions for token properties.110 fn token_property_permissions(&self) -> Result<Vec<eth::TokenPropertyPermission>> {111 let perms = <Pallet<T>>::token_property_permission(self.id);112 Ok(perms113 .into_iter()114 .map(eth::TokenPropertyPermission::from)115 .collect())116 }117118 /// @notice Set token property value.119 /// @dev Throws error if `msg.sender` has no permission to edit the property.120 /// @param tokenId ID of the token.121 /// @param key Property key.122 /// @param value Property value.123 #[solidity(hide)]124 #[weight(<SelfWeightOf<T>>::set_token_properties(1))]125 fn set_property(126 &mut self,127 caller: caller,128 token_id: uint256,129 key: string,130 value: bytes,131 ) -> Result<()> {132 let caller = T::CrossAccountId::from_eth(caller);133 let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;134 let key = <Vec<u8>>::from(key)135 .try_into()136 .map_err(|_| "key too long")?;137 let value = value.0.try_into().map_err(|_| "value too long")?;138139 let nesting_budget = self140 .recorder141 .weight_calls_budget(<StructureWeight<T>>::find_parent());142143 <Pallet<T>>::set_token_property(144 self,145 &caller,146 TokenId(token_id),147 Property { key, value },148 &nesting_budget,149 )150 .map_err(dispatch_to_evm::<T>)151 }152153 /// @notice Set token properties value.154 /// @dev Throws error if `msg.sender` has no permission to edit the property.155 /// @param tokenId ID of the token.156 /// @param properties settable properties157 #[weight(<SelfWeightOf<T>>::set_token_properties(properties.len() as u32))]158 fn set_properties(159 &mut self,160 caller: caller,161 token_id: uint256,162 properties: Vec<eth::Property>,163 ) -> Result<()> {164 let caller = T::CrossAccountId::from_eth(caller);165 let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;166167 let nesting_budget = self168 .recorder169 .weight_calls_budget(<StructureWeight<T>>::find_parent());170171 let properties = properties172 .into_iter()173 .map(eth::Property::try_into)174 .collect::<Result<Vec<_>>>()?;175176 <Pallet<T>>::set_token_properties(177 self,178 &caller,179 TokenId(token_id),180 properties.into_iter(),181 false,182 &nesting_budget,183 )184 .map_err(dispatch_to_evm::<T>)185 }186187 /// @notice Delete token property value.188 /// @dev Throws error if `msg.sender` has no permission to edit the property.189 /// @param tokenId ID of the token.190 /// @param key Property key.191 #[solidity(hide)]192 #[weight(<SelfWeightOf<T>>::delete_token_properties(1))]193 fn delete_property(&mut self, token_id: uint256, caller: caller, key: string) -> Result<()> {194 let caller = T::CrossAccountId::from_eth(caller);195 let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;196 let key = <Vec<u8>>::from(key)197 .try_into()198 .map_err(|_| "key too long")?;199200 let nesting_budget = self201 .recorder202 .weight_calls_budget(<StructureWeight<T>>::find_parent());203204 <Pallet<T>>::delete_token_property(self, &caller, TokenId(token_id), key, &nesting_budget)205 .map_err(dispatch_to_evm::<T>)206 }207208 /// @notice Delete token properties value.209 /// @dev Throws error if `msg.sender` has no permission to edit the property.210 /// @param tokenId ID of the token.211 /// @param keys Properties key.212 #[weight(<SelfWeightOf<T>>::delete_token_properties(keys.len() as u32))]213 fn delete_properties(214 &mut self,215 token_id: uint256,216 caller: caller,217 keys: Vec<string>,218 ) -> Result<()> {219 let caller = T::CrossAccountId::from_eth(caller);220 let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;221 let keys = keys222 .into_iter()223 .map(|k| Ok(<Vec<u8>>::from(k).try_into().map_err(|_| "key too long")?))224 .collect::<Result<Vec<_>>>()?;225226 let nesting_budget = self227 .recorder228 .weight_calls_budget(<StructureWeight<T>>::find_parent());229230 <Pallet<T>>::delete_token_properties(231 self,232 &caller,233 TokenId(token_id),234 keys.into_iter(),235 &nesting_budget,236 )237 .map_err(dispatch_to_evm::<T>)238 }239240 /// @notice Get token property value.241 /// @dev Throws error if key not found242 /// @param tokenId ID of the token.243 /// @param key Property key.244 /// @return Property value bytes245 fn property(&self, token_id: uint256, key: string) -> Result<bytes> {246 let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;247 let key = <Vec<u8>>::from(key)248 .try_into()249 .map_err(|_| "key too long")?;250251 let props = <TokenProperties<T>>::get((self.id, token_id));252 let prop = props.get(&key).ok_or("key not found")?;253254 Ok(prop.to_vec().into())255 }256}257258#[derive(ToLog)]259pub enum ERC721Events {260 /// @dev This event emits when NFTs are created (`from` == 0) and destroyed261 /// (`to` == 0). Exception: during contract creation, any number of RFTs262 /// may be created and assigned without emitting Transfer.263 Transfer {264 #[indexed]265 from: address,266 #[indexed]267 to: address,268 #[indexed]269 token_id: uint256,270 },271 /// @dev Not supported272 Approval {273 #[indexed]274 owner: address,275 #[indexed]276 approved: address,277 #[indexed]278 token_id: uint256,279 },280 /// @dev Not supported281 #[allow(dead_code)]282 ApprovalForAll {283 #[indexed]284 owner: address,285 #[indexed]286 operator: address,287 approved: bool,288 },289}290291/// @title ERC-721 Non-Fungible Token Standard, optional metadata extension292/// @dev See https://eips.ethereum.org/EIPS/eip-721293#[solidity_interface(name = ERC721Metadata, expect_selector = 0x5b5e139f)]294impl<T: Config> RefungibleHandle<T>295where296 T::AccountId: From<[u8; 32]> + AsRef<[u8; 32]>,297{298 /// @notice A descriptive name for a collection of NFTs in this contract299 /// @dev real implementation of this function lies in `ERC721UniqueExtensions`300 #[solidity(hide, rename_selector = "name")]301 fn name_proxy(&self) -> Result<string> {302 self.name()303 }304305 /// @notice An abbreviated name for NFTs in this contract306 /// @dev real implementation of this function lies in `ERC721UniqueExtensions`307 #[solidity(hide, rename_selector = "symbol")]308 fn symbol_proxy(&self) -> Result<string> {309 self.symbol()310 }311312 /// @notice A distinct Uniform Resource Identifier (URI) for a given asset.313 ///314 /// @dev If the token has a `url` property and it is not empty, it is returned.315 /// Else If the collection does not have a property with key `schemaName` or its value is not equal to `ERC721Metadata`, it return an error `tokenURI not set`.316 /// If the collection property `baseURI` is empty or absent, return "" (empty string)317 /// otherwise, if token property `suffix` present and is non-empty, return concatenation of baseURI and suffix318 /// otherwise, return concatenation of `baseURI` and stringified token id (decimal stringifying, without paddings).319 ///320 /// @return token's const_metadata321 #[solidity(rename_selector = "tokenURI")]322 fn token_uri(&self, token_id: uint256) -> Result<string> {323 let token_id_u32: u32 = token_id.try_into().map_err(|_| "token id overflow")?;324325 match get_token_property(self, token_id_u32, &key::url()).as_deref() {326 Err(_) | Ok("") => (),327 Ok(url) => {328 return Ok(url.into());329 }330 };331332 let base_uri =333 pallet_common::Pallet::<T>::get_collection_property(self.id, &key::base_uri())334 .map(BoundedVec::into_inner)335 .map(string::from_utf8)336 .transpose()337 .map_err(|e| {338 Error::Revert(alloc::format!(339 "Can not convert value \"baseURI\" to string with error \"{}\"",340 e341 ))342 })?;343344 let base_uri = match base_uri.as_deref() {345 None | Some("") => {346 return Ok("".into());347 }348 Some(base_uri) => base_uri.into(),349 };350351 Ok(352 match get_token_property(self, token_id_u32, &key::suffix()).as_deref() {353 Err(_) | Ok("") => base_uri,354 Ok(suffix) => base_uri + suffix,355 },356 )357 }358}359360/// @title ERC-721 Non-Fungible Token Standard, optional enumeration extension361/// @dev See https://eips.ethereum.org/EIPS/eip-721362#[solidity_interface(name = ERC721Enumerable, expect_selector = 0x780e9d63)]363impl<T: Config> RefungibleHandle<T> {364 /// @notice Enumerate valid RFTs365 /// @param index A counter less than `totalSupply()`366 /// @return The token identifier for the `index`th NFT,367 /// (sort order not specified)368 fn token_by_index(&self, index: uint256) -> Result<uint256> {369 Ok(index)370 }371372 /// Not implemented373 fn token_of_owner_by_index(&self, _owner: address, _index: uint256) -> Result<uint256> {374 // TODO: Not implemetable375 Err("not implemented".into())376 }377378 /// @notice Count RFTs tracked by this contract379 /// @return A count of valid RFTs tracked by this contract, where each one of380 /// them has an assigned and queryable owner not equal to the zero address381 fn total_supply(&self) -> Result<uint256> {382 self.consume_store_reads(1)?;383 Ok(<Pallet<T>>::total_supply(self).into())384 }385}386387/// @title ERC-721 Non-Fungible Token Standard388/// @dev See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md389#[solidity_interface(name = ERC721, events(ERC721Events), expect_selector = 0x80ac58cd)]390impl<T: Config> RefungibleHandle<T> {391 /// @notice Count all RFTs assigned to an owner392 /// @dev RFTs assigned to the zero address are considered invalid, and this393 /// function throws for queries about the zero address.394 /// @param owner An address for whom to query the balance395 /// @return The number of RFTs owned by `owner`, possibly zero396 fn balance_of(&self, owner: address) -> Result<uint256> {397 self.consume_store_reads(1)?;398 let owner = T::CrossAccountId::from_eth(owner);399 let balance = <AccountBalance<T>>::get((self.id, owner));400 Ok(balance.into())401 }402403 /// @notice Find the owner of an RFT404 /// @dev RFTs assigned to zero address are considered invalid, and queries405 /// about them do throw.406 /// Returns special 0xffffffffffffffffffffffffffffffffffffffff address for407 /// the tokens that are partially owned.408 /// @param tokenId The identifier for an RFT409 /// @return The address of the owner of the RFT410 fn owner_of(&self, token_id: uint256) -> Result<address> {411 self.consume_store_reads(2)?;412 let token = token_id.try_into()?;413 let owner = <Pallet<T>>::token_owner(self.id, token);414 Ok(owner415 .map(|address| *address.as_eth())416 .unwrap_or_else(|| ADDRESS_FOR_PARTIALLY_OWNED_TOKENS))417 }418419 /// @dev Not implemented420 #[solidity(rename_selector = "safeTransferFrom")]421 fn safe_transfer_from_with_data(422 &mut self,423 _from: address,424 _to: address,425 _token_id: uint256,426 _data: bytes,427 ) -> Result<void> {428 // TODO: Not implemetable429 Err("not implemented".into())430 }431432 /// @dev Not implemented433 #[solidity(rename_selector = "safeTransferFrom")]434 fn safe_transfer_from(435 &mut self,436 _from: address,437 _to: address,438 _token_id: uint256,439 ) -> Result<void> {440 // TODO: Not implemetable441 Err("not implemented".into())442 }443444 /// @notice Transfer ownership of an RFT -- THE CALLER IS RESPONSIBLE445 /// TO CONFIRM THAT `to` IS CAPABLE OF RECEIVING NFTS OR ELSE446 /// THEY MAY BE PERMANENTLY LOST447 /// @dev Throws unless `msg.sender` is the current owner or an authorized448 /// operator for this RFT. Throws if `from` is not the current owner. Throws449 /// if `to` is the zero address. Throws if `tokenId` is not a valid RFT.450 /// Throws if RFT pieces have multiple owners.451 /// @param from The current owner of the NFT452 /// @param to The new owner453 /// @param tokenId The NFT to transfer454 #[weight(<SelfWeightOf<T>>::transfer_from_creating_removing())]455 fn transfer_from(456 &mut self,457 caller: caller,458 from: address,459 to: address,460 token_id: uint256,461 ) -> Result<void> {462 let caller = T::CrossAccountId::from_eth(caller);463 let from = T::CrossAccountId::from_eth(from);464 let to = T::CrossAccountId::from_eth(to);465 let token = token_id.try_into()?;466 let budget = self467 .recorder468 .weight_calls_budget(<StructureWeight<T>>::find_parent());469470 let balance = balance(&self, token, &from)?;471 ensure_single_owner(&self, token, balance)?;472473 <Pallet<T>>::transfer_from(self, &caller, &from, &to, token, balance, &budget)474 .map_err(dispatch_to_evm::<T>)?;475476 Ok(())477 }478479 /// @dev Not implemented480 fn approve(&mut self, _caller: caller, _approved: address, _token_id: uint256) -> Result<void> {481 Err("not implemented".into())482 }483484 /// @notice Sets or unsets the approval of a given operator.485 /// The `operator` is allowed to transfer all token pieces of the `caller` on their behalf.486 /// @param operator Operator487 /// @param approved Should operator status be granted or revoked?488 #[weight(<SelfWeightOf<T>>::set_allowance_for_all())]489 fn set_approval_for_all(490 &mut self,491 caller: caller,492 operator: address,493 approved: bool,494 ) -> Result<void> {495 let caller = T::CrossAccountId::from_eth(caller);496 let operator = T::CrossAccountId::from_eth(operator);497498 <Pallet<T>>::set_allowance_for_all(self, &caller, &operator, approved)499 .map_err(dispatch_to_evm::<T>)?;500 Ok(())501 }502503 /// @dev Not implemented504 fn get_approved(&self, _token_id: uint256) -> Result<address> {505 // TODO: Not implemetable506 Err("not implemented".into())507 }508509 /// @notice Tells whether the given `owner` approves the `operator`.510 #[weight(<SelfWeightOf<T>>::allowance_for_all())]511 fn is_approved_for_all(&self, owner: address, operator: address) -> Result<bool> {512 let owner = T::CrossAccountId::from_eth(owner);513 let operator = T::CrossAccountId::from_eth(operator);514515 Ok(<Pallet<T>>::allowance_for_all(self, &owner, &operator))516 }517}518519/// Returns amount of pieces of `token` that `owner` have520pub fn balance<T: Config>(521 collection: &RefungibleHandle<T>,522 token: TokenId,523 owner: &T::CrossAccountId,524) -> Result<u128> {525 collection.consume_store_reads(1)?;526 let balance = <Balance<T>>::get((collection.id, token, &owner));527 Ok(balance)528}529530/// Throws if `owner_balance` is lower than total amount of `token` pieces531pub fn ensure_single_owner<T: Config>(532 collection: &RefungibleHandle<T>,533 token: TokenId,534 owner_balance: u128,535) -> Result<()> {536 collection.consume_store_reads(1)?;537 let total_supply = <TotalSupply<T>>::get((collection.id, token));538539 if owner_balance == 0 {540 return Err(dispatch_to_evm::<T>(541 <CommonError<T>>::MustBeTokenOwner.into(),542 ));543 }544545 if total_supply != owner_balance {546 return Err("token has multiple owners".into());547 }548 Ok(())549}550551/// @title ERC721 Token that can be irreversibly burned (destroyed).552#[solidity_interface(name = ERC721Burnable)]553impl<T: Config> RefungibleHandle<T> {554 /// @notice Burns a specific ERC721 token.555 /// @dev Throws unless `msg.sender` is the current RFT owner, or an authorized556 /// operator of the current owner.557 /// @param tokenId The RFT to approve558 #[weight(<SelfWeightOf<T>>::burn_item_fully())]559 fn burn(&mut self, caller: caller, token_id: uint256) -> Result<void> {560 let caller = T::CrossAccountId::from_eth(caller);561 let token = token_id.try_into()?;562563 let balance = balance(&self, token, &caller)?;564 ensure_single_owner(&self, token, balance)?;565566 <Pallet<T>>::burn(self, &caller, token, balance).map_err(dispatch_to_evm::<T>)?;567 Ok(())568 }569}570571/// @title ERC721 minting logic.572#[solidity_interface(name = ERC721UniqueMintable)]573impl<T: Config> RefungibleHandle<T> {574 /// @notice Function to mint a token.575 /// @param to The new owner576 /// @return uint256 The id of the newly minted token577 #[weight(<SelfWeightOf<T>>::create_item())]578 fn mint(&mut self, caller: caller, to: address) -> Result<uint256> {579 let token_id: uint256 = <TokensMinted<T>>::get(self.id)580 .checked_add(1)581 .ok_or("item id overflow")?582 .into();583 self.mint_check_id(caller, to, token_id)?;584 Ok(token_id)585 }586587 /// @notice Function to mint a token.588 /// @dev `tokenId` should be obtained with `nextTokenId` method,589 /// unlike standard, you can't specify it manually590 /// @param to The new owner591 /// @param tokenId ID of the minted RFT592 #[solidity(hide, rename_selector = "mint")]593 #[weight(<SelfWeightOf<T>>::create_item())]594 fn mint_check_id(&mut self, caller: caller, to: address, token_id: uint256) -> Result<bool> {595 let caller = T::CrossAccountId::from_eth(caller);596 let to = T::CrossAccountId::from_eth(to);597 let token_id: u32 = token_id.try_into()?;598 let budget = self599 .recorder600 .weight_calls_budget(<StructureWeight<T>>::find_parent());601602 if <TokensMinted<T>>::get(self.id)603 .checked_add(1)604 .ok_or("item id overflow")?605 != token_id606 {607 return Err("item id should be next".into());608 }609610 let users = [(to.clone(), 1)]611 .into_iter()612 .collect::<BTreeMap<_, _>>()613 .try_into()614 .unwrap();615 <Pallet<T>>::create_item(616 self,617 &caller,618 CreateItemData::<T> {619 users,620 properties: CollectionPropertiesVec::default(),621 },622 &budget,623 )624 .map_err(dispatch_to_evm::<T>)?;625626 Ok(true)627 }628629 /// @notice Function to mint token with the given tokenUri.630 /// @param to The new owner631 /// @param tokenUri Token URI that would be stored in the NFT properties632 /// @return uint256 The id of the newly minted token633 #[solidity(rename_selector = "mintWithTokenURI")]634 #[weight(<SelfWeightOf<T>>::create_item())]635 fn mint_with_token_uri(636 &mut self,637 caller: caller,638 to: address,639 token_uri: string,640 ) -> Result<uint256> {641 let token_id: uint256 = <TokensMinted<T>>::get(self.id)642 .checked_add(1)643 .ok_or("item id overflow")?644 .into();645 self.mint_with_token_uri_check_id(caller, to, token_id, token_uri)?;646 Ok(token_id)647 }648649 /// @notice Function to mint token with the given tokenUri.650 /// @dev `tokenId` should be obtained with `nextTokenId` method,651 /// unlike standard, you can't specify it manually652 /// @param to The new owner653 /// @param tokenId ID of the minted RFT654 /// @param tokenUri Token URI that would be stored in the RFT properties655 #[solidity(hide, rename_selector = "mintWithTokenURI")]656 #[weight(<SelfWeightOf<T>>::create_item())]657 fn mint_with_token_uri_check_id(658 &mut self,659 caller: caller,660 to: address,661 token_id: uint256,662 token_uri: string,663 ) -> Result<bool> {664 let key = key::url();665 let permission = get_token_permission::<T>(self.id, &key)?;666 if !permission.collection_admin {667 return Err("Operation is not allowed".into());668 }669670 let caller = T::CrossAccountId::from_eth(caller);671 let to = T::CrossAccountId::from_eth(to);672 let token_id: u32 = token_id.try_into().map_err(|_| "amount overflow")?;673 let budget = self674 .recorder675 .weight_calls_budget(<StructureWeight<T>>::find_parent());676677 if <TokensMinted<T>>::get(self.id)678 .checked_add(1)679 .ok_or("item id overflow")?680 != token_id681 {682 return Err("item id should be next".into());683 }684685 let mut properties = CollectionPropertiesVec::default();686 properties687 .try_push(Property {688 key,689 value: token_uri690 .into_bytes()691 .try_into()692 .map_err(|_| "token uri is too long")?,693 })694 .map_err(|e| Error::Revert(alloc::format!("Can't add property: {:?}", e)))?;695696 let users = [(to.clone(), 1)]697 .into_iter()698 .collect::<BTreeMap<_, _>>()699 .try_into()700 .unwrap();701 <Pallet<T>>::create_item(702 self,703 &caller,704 CreateItemData::<T> { users, properties },705 &budget,706 )707 .map_err(dispatch_to_evm::<T>)?;708 Ok(true)709 }710}711712fn get_token_property<T: Config>(713 collection: &CollectionHandle<T>,714 token_id: u32,715 key: &up_data_structs::PropertyKey,716) -> Result<string> {717 collection.consume_store_reads(1)?;718 let properties = <TokenProperties<T>>::try_get((collection.id, token_id))719 .map_err(|_| Error::Revert("Token properties not found".into()))?;720 if let Some(property) = properties.get(key) {721 return Ok(string::from_utf8_lossy(property).into());722 }723724 Err("Property tokenURI not found".into())725}726727fn get_token_permission<T: Config>(728 collection_id: CollectionId,729 key: &PropertyKey,730) -> Result<PropertyPermission> {731 let token_property_permissions = CollectionPropertyPermissions::<T>::try_get(collection_id)732 .map_err(|_| Error::Revert("No permissions for collection".into()))?;733 let a = token_property_permissions734 .get(key)735 .map(Clone::clone)736 .ok_or_else(|| {737 let key = string::from_utf8(key.clone().into_inner()).unwrap_or_default();738 Error::Revert(alloc::format!("No permission for key {}", key))739 })?;740 Ok(a)741}742743/// @title Unique extensions for ERC721.744#[solidity_interface(name = ERC721UniqueExtensions)]745impl<T: Config> RefungibleHandle<T>746where747 T::AccountId: From<[u8; 32]> + AsRef<[u8; 32]>,748{749 /// @notice A descriptive name for a collection of NFTs in this contract750 fn name(&self) -> Result<string> {751 Ok(decode_utf16(self.name.iter().copied())752 .map(|r| r.unwrap_or(REPLACEMENT_CHARACTER))753 .collect::<string>())754 }755756 /// @notice An abbreviated name for NFTs in this contract757 fn symbol(&self) -> Result<string> {758 Ok(string::from_utf8_lossy(&self.token_prefix).into())759 }760761 /// @notice A description for the collection.762 fn description(&self) -> Result<string> {763 Ok(decode_utf16(self.description.iter().copied())764 .map(|r| r.unwrap_or(REPLACEMENT_CHARACTER))765 .collect::<string>())766 }767768 /// Returns the owner (in cross format) of the token.769 ///770 /// @param tokenId Id for the token.771 fn cross_owner_of(&self, token_id: uint256) -> Result<eth::CrossAddress> {772 Self::token_owner(&self, token_id.try_into()?)773 .map(|o| eth::CrossAddress::from_sub_cross_account::<T>(&o))774 .ok_or(Error::Revert("key too large".into()))775 }776777 /// Returns the token properties.778 ///779 /// @param tokenId Id for the token.780 /// @param keys Properties keys. Empty keys for all propertyes.781 /// @return Vector of properties key/value pairs.782 fn properties(&self, token_id: uint256, keys: Vec<string>) -> Result<Vec<eth::Property>> {783 let keys = keys784 .into_iter()785 .map(|key| {786 <Vec<u8>>::from(key)787 .try_into()788 .map_err(|_| Error::Revert("key too large".into()))789 })790 .collect::<Result<Vec<_>>>()?;791792 <Self as CommonCollectionOperations<T>>::token_properties(793 &self,794 token_id.try_into()?,795 if keys.is_empty() { None } else { Some(keys) },796 )797 .into_iter()798 .map(eth::Property::try_from)799 .collect::<Result<Vec<_>>>()800 }801 /// @notice Transfer ownership of an RFT802 /// @dev Throws unless `msg.sender` is the current owner. Throws if `to`803 /// is the zero address. Throws if `tokenId` is not a valid RFT.804 /// Throws if RFT pieces have multiple owners.805 /// @param to The new owner806 /// @param tokenId The RFT to transfer807 #[weight(<SelfWeightOf<T>>::transfer_creating_removing())]808 fn transfer(&mut self, caller: caller, to: address, token_id: uint256) -> Result<void> {809 let caller = T::CrossAccountId::from_eth(caller);810 let to = T::CrossAccountId::from_eth(to);811 let token = token_id.try_into()?;812 let budget = self813 .recorder814 .weight_calls_budget(<StructureWeight<T>>::find_parent());815816 let balance = balance(self, token, &caller)?;817 ensure_single_owner(self, token, balance)?;818819 <Pallet<T>>::transfer(self, &caller, &to, token, balance, &budget)820 .map_err(dispatch_to_evm::<T>)?;821 Ok(())822 }823824 /// @notice Transfer ownership of an RFT825 /// @dev Throws unless `msg.sender` is the current owner. Throws if `to`826 /// is the zero address. Throws if `tokenId` is not a valid RFT.827 /// Throws if RFT pieces have multiple owners.828 /// @param to The new owner829 /// @param tokenId The RFT to transfer830 #[weight(<SelfWeightOf<T>>::transfer_creating_removing())]831 fn transfer_cross(832 &mut self,833 caller: caller,834 to: eth::CrossAddress,835 token_id: uint256,836 ) -> Result<void> {837 let caller = T::CrossAccountId::from_eth(caller);838 let to = to.into_sub_cross_account::<T>()?;839 let token = token_id.try_into()?;840 let budget = self841 .recorder842 .weight_calls_budget(<StructureWeight<T>>::find_parent());843844 let balance = balance(self, token, &caller)?;845 ensure_single_owner(self, token, balance)?;846847 <Pallet<T>>::transfer(self, &caller, &to, token, balance, &budget)848 .map_err(dispatch_to_evm::<T>)?;849 Ok(())850 }851852 /// @notice Transfer ownership of an RFT853 /// @dev Throws unless `msg.sender` is the current owner. Throws if `to`854 /// is the zero address. Throws if `tokenId` is not a valid RFT.855 /// Throws if RFT pieces have multiple owners.856 /// @param to The new owner857 /// @param tokenId The RFT to transfer858 #[weight(<SelfWeightOf<T>>::transfer_creating_removing())]859 fn transfer_from_cross(860 &mut self,861 caller: caller,862 from: eth::CrossAddress,863 to: eth::CrossAddress,864 token_id: uint256,865 ) -> Result<void> {866 let caller = T::CrossAccountId::from_eth(caller);867 let from = from.into_sub_cross_account::<T>()?;868 let to = to.into_sub_cross_account::<T>()?;869 let token_id = token_id.try_into()?;870 let budget = self871 .recorder872 .weight_calls_budget(<StructureWeight<T>>::find_parent());873874 let balance = balance(self, token_id, &from)?;875 ensure_single_owner(self, token_id, balance)?;876877 Pallet::<T>::transfer_from(self, &caller, &from, &to, token_id, balance, &budget)878 .map_err(dispatch_to_evm::<T>)?;879 Ok(())880 }881882 /// @notice Burns a specific ERC721 token.883 /// @dev Throws unless `msg.sender` is the current owner or an authorized884 /// operator for this RFT. Throws if `from` is not the current owner. Throws885 /// if `to` is the zero address. Throws if `tokenId` is not a valid RFT.886 /// Throws if RFT pieces have multiple owners.887 /// @param from The current owner of the RFT888 /// @param tokenId The RFT to transfer889 #[solidity(hide)]890 #[weight(<SelfWeightOf<T>>::burn_from())]891 fn burn_from(&mut self, caller: caller, from: address, token_id: uint256) -> Result<void> {892 let caller = T::CrossAccountId::from_eth(caller);893 let from = T::CrossAccountId::from_eth(from);894 let token = token_id.try_into()?;895 let budget = self896 .recorder897 .weight_calls_budget(<StructureWeight<T>>::find_parent());898899 let balance = balance(self, token, &from)?;900 ensure_single_owner(self, token, balance)?;901902 <Pallet<T>>::burn_from(self, &caller, &from, token, balance, &budget)903 .map_err(dispatch_to_evm::<T>)?;904 Ok(())905 }906907 /// @notice Burns a specific ERC721 token.908 /// @dev Throws unless `msg.sender` is the current owner or an authorized909 /// operator for this RFT. Throws if `from` is not the current owner. Throws910 /// if `to` is the zero address. Throws if `tokenId` is not a valid RFT.911 /// Throws if RFT pieces have multiple owners.912 /// @param from The current owner of the RFT913 /// @param tokenId The RFT to transfer914 #[weight(<SelfWeightOf<T>>::burn_from())]915 fn burn_from_cross(916 &mut self,917 caller: caller,918 from: eth::CrossAddress,919 token_id: uint256,920 ) -> Result<void> {921 let caller = T::CrossAccountId::from_eth(caller);922 let from = from.into_sub_cross_account::<T>()?;923 let token = token_id.try_into()?;924 let budget = self925 .recorder926 .weight_calls_budget(<StructureWeight<T>>::find_parent());927928 let balance = balance(self, token, &from)?;929 ensure_single_owner(self, token, balance)?;930931 <Pallet<T>>::burn_from(self, &caller, &from, token, balance, &budget)932 .map_err(dispatch_to_evm::<T>)?;933 Ok(())934 }935936 /// @notice Returns next free RFT ID.937 fn next_token_id(&self) -> Result<uint256> {938 self.consume_store_reads(1)?;939 Ok(<TokensMinted<T>>::get(self.id)940 .checked_add(1)941 .ok_or("item id overflow")?942 .into())943 }944945 /// @notice Function to mint multiple tokens.946 /// @dev `tokenIds` should be an array of consecutive numbers and first number947 /// should be obtained with `nextTokenId` method948 /// @param to The new owner949 /// @param tokenIds IDs of the minted RFTs950 #[solidity(hide)]951 #[weight(<SelfWeightOf<T>>::create_multiple_items(token_ids.len() as u32))]952 fn mint_bulk(&mut self, caller: caller, to: address, token_ids: Vec<uint256>) -> Result<bool> {953 let caller = T::CrossAccountId::from_eth(caller);954 let to = T::CrossAccountId::from_eth(to);955 let mut expected_index = <TokensMinted<T>>::get(self.id)956 .checked_add(1)957 .ok_or("item id overflow")?;958 let budget = self959 .recorder960 .weight_calls_budget(<StructureWeight<T>>::find_parent());961962 let total_tokens = token_ids.len();963 for id in token_ids.into_iter() {964 let id: u32 = id.try_into().map_err(|_| "token id overflow")?;965 if id != expected_index {966 return Err("item id should be next".into());967 }968 expected_index = expected_index.checked_add(1).ok_or("item id overflow")?;969 }970 let users = [(to.clone(), 1)]971 .into_iter()972 .collect::<BTreeMap<_, _>>()973 .try_into()974 .unwrap();975 let create_item_data = CreateItemData::<T> {976 users,977 properties: CollectionPropertiesVec::default(),978 };979 let data = (0..total_tokens)980 .map(|_| create_item_data.clone())981 .collect();982983 <Pallet<T>>::create_multiple_items(self, &caller, data, &budget)984 .map_err(dispatch_to_evm::<T>)?;985 Ok(true)986 }987988 /// @notice Function to mint multiple tokens with the given tokenUris.989 /// @dev `tokenIds` is array of pairs of token ID and token URI. Token IDs should be consecutive990 /// numbers and first number should be obtained with `nextTokenId` method991 /// @param to The new owner992 /// @param tokens array of pairs of token ID and token URI for minted tokens993 #[solidity(hide, rename_selector = "mintBulkWithTokenURI")]994 #[weight(<SelfWeightOf<T>>::create_multiple_items(tokens.len() as u32))]995 fn mint_bulk_with_token_uri(996 &mut self,997 caller: caller,998 to: address,999 tokens: Vec<(uint256, string)>,1000 ) -> Result<bool> {1001 let key = key::url();1002 let caller = T::CrossAccountId::from_eth(caller);1003 let to = T::CrossAccountId::from_eth(to);1004 let mut expected_index = <TokensMinted<T>>::get(self.id)1005 .checked_add(1)1006 .ok_or("item id overflow")?;1007 let budget = self1008 .recorder1009 .weight_calls_budget(<StructureWeight<T>>::find_parent());10101011 let mut data = Vec::with_capacity(tokens.len());1012 let users: BoundedBTreeMap<_, _, _> = [(to.clone(), 1)]1013 .into_iter()1014 .collect::<BTreeMap<_, _>>()1015 .try_into()1016 .unwrap();1017 for (id, token_uri) in tokens {1018 let id: u32 = id.try_into().map_err(|_| "token id overflow")?;1019 if id != expected_index {1020 return Err("item id should be next".into());1021 }1022 expected_index = expected_index.checked_add(1).ok_or("item id overflow")?;10231024 let mut properties = CollectionPropertiesVec::default();1025 properties1026 .try_push(Property {1027 key: key.clone(),1028 value: token_uri1029 .into_bytes()1030 .try_into()1031 .map_err(|_| "token uri is too long")?,1032 })1033 .map_err(|e| Error::Revert(alloc::format!("Can't add property: {:?}", e)))?;10341035 let create_item_data = CreateItemData::<T> {1036 users: users.clone(),1037 properties,1038 };1039 data.push(create_item_data);1040 }10411042 <Pallet<T>>::create_multiple_items(self, &caller, data, &budget)1043 .map_err(dispatch_to_evm::<T>)?;1044 Ok(true)1045 }10461047 /// @notice Function to mint a token.1048 /// @param to The new owner crossAccountId1049 /// @param properties Properties of minted token1050 /// @return uint256 The id of the newly minted token1051 #[weight(<SelfWeightOf<T>>::create_item())]1052 fn mint_cross(1053 &mut self,1054 caller: caller,1055 to: eth::CrossAddress,1056 properties: Vec<eth::Property>,1057 ) -> Result<uint256> {1058 let token_id = <TokensMinted<T>>::get(self.id)1059 .checked_add(1)1060 .ok_or("item id overflow")?;10611062 let to = to.into_sub_cross_account::<T>()?;10631064 let properties = properties1065 .into_iter()1066 .map(eth::Property::try_into)1067 .collect::<Result<Vec<_>>>()?1068 .try_into()1069 .map_err(|_| Error::Revert(alloc::format!("too many properties")))?;10701071 let caller = T::CrossAccountId::from_eth(caller);10721073 let budget = self1074 .recorder1075 .weight_calls_budget(<StructureWeight<T>>::find_parent());10761077 let users = [(to, 1)]1078 .into_iter()1079 .collect::<BTreeMap<_, _>>()1080 .try_into()1081 .unwrap();1082 <Pallet<T>>::create_item(1083 self,1084 &caller,1085 CreateItemData::<T> { users, properties },1086 &budget,1087 )1088 .map_err(dispatch_to_evm::<T>)?;10891090 Ok(token_id.into())1091 }10921093 /// Returns EVM address for refungible token1094 ///1095 /// @param token ID of the token1096 fn token_contract_address(&self, token: uint256) -> Result<address> {1097 Ok(T::EvmTokenAddressMapping::token_to_address(1098 self.id,1099 token.try_into().map_err(|_| "token id overflow")?,1100 ))1101 }11021103 /// @notice Returns collection helper contract address1104 fn collection_helper_address(&self) -> Result<address> {1105 Ok(T::ContractAddress::get())1106 }1107}11081109#[solidity_interface(1110 name = UniqueRefungible,1111 is(1112 ERC721,1113 ERC721Enumerable,1114 ERC721UniqueExtensions,1115 ERC721UniqueMintable,1116 ERC721Burnable,1117 ERC721Metadata(if(this.flags.erc721metadata)),1118 Collection(via(common_mut returns CollectionHandle<T>)),1119 TokenProperties,1120 )1121)]1122impl<T: Config> RefungibleHandle<T> where T::AccountId: From<[u8; 32]> + AsRef<[u8; 32]> {}11231124// Not a tests, but code generators1125generate_stubgen!(gen_impl, UniqueRefungibleCall<()>, true);1126generate_stubgen!(gen_iface, UniqueRefungibleCall<()>, false);11271128impl<T: Config> CommonEvmHandler for RefungibleHandle<T>1129where1130 T::AccountId: From<[u8; 32]> + AsRef<[u8; 32]>,1131{1132 const CODE: &'static [u8] = include_bytes!("./stubs/UniqueRefungible.raw");1133 fn call(1134 self,1135 handle: &mut impl PrecompileHandle,1136 ) -> Option<pallet_common::erc::PrecompileResult> {1137 call::<T, UniqueRefungibleCall<T>, _, _>(handle, self)1138 }1139}pallets/refungible/src/erc_token.rsdiffbeforeafterboth--- a/pallets/refungible/src/erc_token.rs
+++ b/pallets/refungible/src/erc_token.rs
@@ -25,7 +25,8 @@
ops::Deref,
};
use evm_coder::{
- abi::AbiType, ToLog, execution::*, generate_stubgen, solidity_interface, types::*, weight,
+ abi::AbiType, ToLog, execution::*, generate_stubgen, solidity_interface, solidity, types::*,
+ weight,
};
use pallet_common::{
CommonWeightInfo,
@@ -206,6 +207,7 @@
/// @param from The account whose tokens will be burnt.
/// @param amount The amount that will be burnt.
#[weight(<SelfWeightOf<T>>::burn_from())]
+ #[solidity(hide)]
fn burn_from(&mut self, caller: caller, from: address, amount: uint256) -> Result<bool> {
let caller = T::CrossAccountId::from_eth(caller);
let from = T::CrossAccountId::from_eth(from);
pallets/refungible/src/stubs/UniqueRefungible.rawdiffbeforeafterbothbinary blob — no preview
pallets/refungible/src/stubs/UniqueRefungible.soldiffbeforeafterboth--- a/pallets/refungible/src/stubs/UniqueRefungible.sol
+++ b/pallets/refungible/src/stubs/UniqueRefungible.sol
@@ -700,22 +700,9 @@
}
}
-/// @dev inlined interface
-contract ERC721UniqueMintableEvents {
- event MintingFinished();
-}
-
/// @title ERC721 minting logic.
-/// @dev the ERC-165 identifier for this interface is 0x476ff149
-contract ERC721UniqueMintable is Dummy, ERC165, ERC721UniqueMintableEvents {
- /// @dev EVM selector for this function is: 0x05d2035b,
- /// or in textual repr: mintingFinished()
- function mintingFinished() public view returns (bool) {
- require(false, stub_error);
- dummy;
- return false;
- }
-
+/// @dev the ERC-165 identifier for this interface is 0x3fd94ea6
+contract ERC721UniqueMintable is Dummy, ERC165 {
/// @notice Function to mint a token.
/// @param to The new owner
/// @return uint256 The id of the newly minted token
@@ -756,7 +743,6 @@
dummy = 0;
return 0;
}
-
// /// @notice Function to mint token with the given tokenUri.
// /// @dev `tokenId` should be obtained with `nextTokenId` method,
// /// unlike standard, you can't specify it manually
@@ -774,14 +760,6 @@
// return false;
// }
- /// @dev Not implemented
- /// @dev EVM selector for this function is: 0x7d64bcb4,
- /// or in textual repr: finishMinting()
- function finishMinting() public returns (bool) {
- require(false, stub_error);
- dummy = 0;
- return false;
- }
}
/// @title Unique extensions for ERC721.
pallets/refungible/src/stubs/UniqueRefungibleToken.rawdiffbeforeafterbothbinary blob — no preview
pallets/refungible/src/stubs/UniqueRefungibleToken.soldiffbeforeafterboth--- a/pallets/refungible/src/stubs/UniqueRefungibleToken.sol
+++ b/pallets/refungible/src/stubs/UniqueRefungibleToken.sol
@@ -38,19 +38,19 @@
/// @dev the ERC-165 identifier for this interface is 0xe17a7d2b
contract ERC20UniqueExtensions is Dummy, ERC165 {
- /// @dev Function that burns an amount of the token of a given account,
- /// deducting from the sender's allowance for said account.
- /// @param from The account whose tokens will be burnt.
- /// @param amount The amount that will be burnt.
- /// @dev EVM selector for this function is: 0x79cc6790,
- /// or in textual repr: burnFrom(address,uint256)
- function burnFrom(address from, uint256 amount) public returns (bool) {
- require(false, stub_error);
- from;
- amount;
- dummy = 0;
- return false;
- }
+ // /// @dev Function that burns an amount of the token of a given account,
+ // /// deducting from the sender's allowance for said account.
+ // /// @param from The account whose tokens will be burnt.
+ // /// @param amount The amount that will be burnt.
+ // /// @dev EVM selector for this function is: 0x79cc6790,
+ // /// or in textual repr: burnFrom(address,uint256)
+ // function burnFrom(address from, uint256 amount) public returns (bool) {
+ // require(false, stub_error);
+ // from;
+ // amount;
+ // dummy = 0;
+ // return false;
+ // }
/// @dev Function that burns an amount of the token of a given account,
/// deducting from the sender's allowance for said account.
runtime/common/ethereum/sponsoring/refungible.rsdiffbeforeafterboth--- a/runtime/common/ethereum/sponsoring/refungible.rs
+++ b/runtime/common/ethereum/sponsoring/refungible.rs
@@ -265,11 +265,9 @@
match call {
// Readonly
- ERC165Call(_, _) | MintingFinished => None,
+ ERC165Call(_, _) => None,
- // Not sponsored
- FinishMinting => None,
-
+ // Sponsored
Mint { .. }
| MintCheckId { .. }
| MintWithTokenUri { .. }
tests/src/check-event/burnItemEvent.test.tsdiffbeforeafterboth--- a/tests/src/check-event/burnItemEvent.test.ts
+++ b/tests/src/check-event/burnItemEvent.test.ts
@@ -32,6 +32,7 @@
const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
const token = await collection.mintToken(alice, {Substrate: alice.address});
await token.burn(alice);
+ await helper.wait.newBlocks(1);
const event = helper.chainLog[helper.chainLog.length - 1].events as IEvent[];
const eventStrings = event.map(e => `${e.section}.${e.method}`);
tests/src/check-event/createCollectionEvent.test.tsdiffbeforeafterboth--- a/tests/src/check-event/createCollectionEvent.test.ts
+++ b/tests/src/check-event/createCollectionEvent.test.ts
@@ -29,6 +29,7 @@
});
itSub('Check event from createCollection(): ', async ({helper}) => {
await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
+ await helper.wait.newBlocks(1);
const event = helper.chainLog[helper.chainLog.length - 1].events as IEvent[];
const eventStrings = event.map(e => `${e.section}.${e.method}`);
tests/src/check-event/createItemEvent.test.tsdiffbeforeafterboth--- a/tests/src/check-event/createItemEvent.test.ts
+++ b/tests/src/check-event/createItemEvent.test.ts
@@ -30,6 +30,7 @@
itSub('Check event from createItem(): ', async ({helper}) => {
const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
await collection.mintToken(alice, {Substrate: alice.address});
+ await helper.wait.newBlocks(1);
const event = helper.chainLog[helper.chainLog.length - 1].events as IEvent[];
const eventStrings = event.map(e => `${e.section}.${e.method}`);
tests/src/check-event/createMultipleItemsEvent.test.tsdiffbeforeafterboth--- a/tests/src/check-event/createMultipleItemsEvent.test.ts
+++ b/tests/src/check-event/createMultipleItemsEvent.test.ts
@@ -35,6 +35,7 @@
{owner: {Substrate: alice.address}},
]);
+ await helper.wait.newBlocks(1);
const event = helper.chainLog[helper.chainLog.length - 1].events as IEvent[];
const eventStrings = event.map(e => `${e.section}.${e.method}`);
tests/src/check-event/destroyCollectionEvent.test.tsdiffbeforeafterboth--- a/tests/src/check-event/destroyCollectionEvent.test.ts
+++ b/tests/src/check-event/destroyCollectionEvent.test.ts
@@ -31,6 +31,7 @@
itSub('Check event from destroyCollection(): ', async ({helper}) => {
const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
await collection.burn(alice);
+ await helper.wait.newBlocks(1);
const event = helper.chainLog[helper.chainLog.length - 1].events as IEvent[];
const eventStrings = event.map(e => `${e.section}.${e.method}`);
tests/src/check-event/transferEvent.test.tsdiffbeforeafterboth--- a/tests/src/check-event/transferEvent.test.ts
+++ b/tests/src/check-event/transferEvent.test.ts
@@ -34,6 +34,7 @@
const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
const token = await collection.mintToken(alice, {Substrate: alice.address});
await token.transfer(alice, {Substrate: bob.address});
+ await helper.wait.newBlocks(1);
const event = helper.chainLog[helper.chainLog.length - 1].events as IEvent[];
const eventStrings = event.map(e => `${e.section}.${e.method}`);
tests/src/check-event/transferFromEvent.test.tsdiffbeforeafterboth--- a/tests/src/check-event/transferFromEvent.test.ts
+++ b/tests/src/check-event/transferFromEvent.test.ts
@@ -33,6 +33,7 @@
const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
const token = await collection.mintToken(alice, {Substrate: alice.address});
await token.transferFrom(alice, {Substrate: alice.address}, {Substrate: bob.address});
+ await helper.wait.newBlocks(1);
const event = helper.chainLog[helper.chainLog.length - 1].events as IEvent[];
const eventStrings = event.map(e => `${e.section}.${e.method}`);
tests/src/eth/abi/nonFungible.jsondiffbeforeafterboth--- a/tests/src/eth/abi/nonFungible.json
+++ b/tests/src/eth/abi/nonFungible.json
@@ -51,12 +51,6 @@
},
{
"anonymous": false,
- "inputs": [],
- "name": "MintingFinished",
- "type": "event"
- },
- {
- "anonymous": false,
"inputs": [
{
"indexed": true,
@@ -420,13 +414,6 @@
"name": "description",
"outputs": [{ "internalType": "string", "name": "", "type": "string" }],
"stateMutability": "view",
- "type": "function"
- },
- {
- "inputs": [],
- "name": "finishMinting",
- "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
- "stateMutability": "nonpayable",
"type": "function"
},
{
@@ -513,13 +500,6 @@
"name": "mintWithTokenURI",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"stateMutability": "nonpayable",
- "type": "function"
- },
- {
- "inputs": [],
- "name": "mintingFinished",
- "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
- "stateMutability": "view",
"type": "function"
},
{
tests/src/eth/abi/reFungible.jsondiffbeforeafterboth--- a/tests/src/eth/abi/reFungible.json
+++ b/tests/src/eth/abi/reFungible.json
@@ -51,12 +51,6 @@
},
{
"anonymous": false,
- "inputs": [],
- "name": "MintingFinished",
- "type": "event"
- },
- {
- "anonymous": false,
"inputs": [
{
"indexed": true,
@@ -402,13 +396,6 @@
"name": "description",
"outputs": [{ "internalType": "string", "name": "", "type": "string" }],
"stateMutability": "view",
- "type": "function"
- },
- {
- "inputs": [],
- "name": "finishMinting",
- "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
- "stateMutability": "nonpayable",
"type": "function"
},
{
@@ -495,13 +482,6 @@
"name": "mintWithTokenURI",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"stateMutability": "nonpayable",
- "type": "function"
- },
- {
- "inputs": [],
- "name": "mintingFinished",
- "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
- "stateMutability": "view",
"type": "function"
},
{
tests/src/eth/abi/reFungibleToken.jsondiffbeforeafterboth--- a/tests/src/eth/abi/reFungibleToken.json
+++ b/tests/src/eth/abi/reFungibleToken.json
@@ -98,16 +98,6 @@
},
{
"inputs": [
- { "internalType": "address", "name": "from", "type": "address" },
- { "internalType": "uint256", "name": "amount", "type": "uint256" }
- ],
- "name": "burnFrom",
- "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
- "stateMutability": "nonpayable",
- "type": "function"
- },
- {
- "inputs": [
{
"components": [
{ "internalType": "address", "name": "eth", "type": "address" },
tests/src/eth/api/UniqueNFT.soldiffbeforeafterboth--- a/tests/src/eth/api/UniqueNFT.sol
+++ b/tests/src/eth/api/UniqueNFT.sol
@@ -483,18 +483,9 @@
function burn(uint256 tokenId) external;
}
-/// @dev inlined interface
-interface ERC721UniqueMintableEvents {
- event MintingFinished();
-}
-
/// @title ERC721 minting logic.
-/// @dev the ERC-165 identifier for this interface is 0x476ff149
-interface ERC721UniqueMintable is Dummy, ERC165, ERC721UniqueMintableEvents {
- /// @dev EVM selector for this function is: 0x05d2035b,
- /// or in textual repr: mintingFinished()
- function mintingFinished() external view returns (bool);
-
+/// @dev the ERC-165 identifier for this interface is 0x3fd94ea6
+interface ERC721UniqueMintable is Dummy, ERC165 {
/// @notice Function to mint a token.
/// @param to The new owner
/// @return uint256 The id of the newly minted token
@@ -518,7 +509,6 @@
/// @dev EVM selector for this function is: 0x45c17782,
/// or in textual repr: mintWithTokenURI(address,string)
function mintWithTokenURI(address to, string memory tokenUri) external returns (uint256);
-
// /// @notice Function to mint token with the given tokenUri.
// /// @dev `tokenId` should be obtained with `nextTokenId` method,
// /// unlike standard, you can't specify it manually
@@ -529,10 +519,6 @@
// /// or in textual repr: mintWithTokenURI(address,uint256,string)
// function mintWithTokenURI(address to, uint256 tokenId, string memory tokenUri) external returns (bool);
- /// @dev Not implemented
- /// @dev EVM selector for this function is: 0x7d64bcb4,
- /// or in textual repr: finishMinting()
- function finishMinting() external returns (bool);
}
/// @title Unique extensions for ERC721.
tests/src/eth/api/UniqueRefungible.soldiffbeforeafterboth--- a/tests/src/eth/api/UniqueRefungible.sol
+++ b/tests/src/eth/api/UniqueRefungible.sol
@@ -483,18 +483,9 @@
function burn(uint256 tokenId) external;
}
-/// @dev inlined interface
-interface ERC721UniqueMintableEvents {
- event MintingFinished();
-}
-
/// @title ERC721 minting logic.
-/// @dev the ERC-165 identifier for this interface is 0x476ff149
-interface ERC721UniqueMintable is Dummy, ERC165, ERC721UniqueMintableEvents {
- /// @dev EVM selector for this function is: 0x05d2035b,
- /// or in textual repr: mintingFinished()
- function mintingFinished() external view returns (bool);
-
+/// @dev the ERC-165 identifier for this interface is 0x3fd94ea6
+interface ERC721UniqueMintable is Dummy, ERC165 {
/// @notice Function to mint a token.
/// @param to The new owner
/// @return uint256 The id of the newly minted token
@@ -518,7 +509,6 @@
/// @dev EVM selector for this function is: 0x45c17782,
/// or in textual repr: mintWithTokenURI(address,string)
function mintWithTokenURI(address to, string memory tokenUri) external returns (uint256);
-
// /// @notice Function to mint token with the given tokenUri.
// /// @dev `tokenId` should be obtained with `nextTokenId` method,
// /// unlike standard, you can't specify it manually
@@ -529,10 +519,6 @@
// /// or in textual repr: mintWithTokenURI(address,uint256,string)
// function mintWithTokenURI(address to, uint256 tokenId, string memory tokenUri) external returns (bool);
- /// @dev Not implemented
- /// @dev EVM selector for this function is: 0x7d64bcb4,
- /// or in textual repr: finishMinting()
- function finishMinting() external returns (bool);
}
/// @title Unique extensions for ERC721.
tests/src/eth/api/UniqueRefungibleToken.soldiffbeforeafterboth--- a/tests/src/eth/api/UniqueRefungibleToken.sol
+++ b/tests/src/eth/api/UniqueRefungibleToken.sol
@@ -25,13 +25,13 @@
/// @dev the ERC-165 identifier for this interface is 0xe17a7d2b
interface ERC20UniqueExtensions is Dummy, ERC165 {
- /// @dev Function that burns an amount of the token of a given account,
- /// deducting from the sender's allowance for said account.
- /// @param from The account whose tokens will be burnt.
- /// @param amount The amount that will be burnt.
- /// @dev EVM selector for this function is: 0x79cc6790,
- /// or in textual repr: burnFrom(address,uint256)
- function burnFrom(address from, uint256 amount) external returns (bool);
+ // /// @dev Function that burns an amount of the token of a given account,
+ // /// deducting from the sender's allowance for said account.
+ // /// @param from The account whose tokens will be burnt.
+ // /// @param amount The amount that will be burnt.
+ // /// @dev EVM selector for this function is: 0x79cc6790,
+ // /// or in textual repr: burnFrom(address,uint256)
+ // function burnFrom(address from, uint256 amount) external returns (bool);
/// @dev Function that burns an amount of the token of a given account,
/// deducting from the sender's allowance for said account.
tests/src/eth/base.test.tsdiffbeforeafterboth--- a/tests/src/eth/base.test.ts
+++ b/tests/src/eth/base.test.ts
@@ -108,10 +108,6 @@
await checkInterface(helper, '0x5b5e139f', false, true);
});
- itEth('ERC721UniqueMintable - 0x476ff149 - support', async ({helper}) => {
- await checkInterface(helper, '0x476ff149', true, true);
- });
-
itEth('ERC721Enumerable - 0x780e9d63 - support', async ({helper}) => {
await checkInterface(helper, '0x780e9d63', true, true);
});