difftreelog
doc: add documentstion for nonfungible EVM API
in: master
4 files changed
pallets/nonfungible/src/erc.rsdiffbeforeafterboth14// You should have received a copy of the GNU General Public License14// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617//! # Nonfungible Pallet EVM API18//! 19//! Provides ERC-721 standart support implementation and EVM API for unique extensions for Nonfungible Pallet.20//! Method implementations are mostly doing parameter conversion and calling Nonfungible Pallet methods.162117extern crate alloc;22extern crate alloc;18use core::{23use core::{40 SelfWeightOf, weights::WeightInfo, TokenProperties,45 SelfWeightOf, weights::WeightInfo, TokenProperties,41};46};424748/// @title A contract that allows to set and delete token properties and change token property permissions.49/// 43#[solidity_interface(name = "TokenProperties")]50#[solidity_interface(name = "TokenProperties")]44impl<T: Config> NonfungibleHandle<T> {51impl<T: Config> NonfungibleHandle<T> {52 /// @notice Set permissions for token property.53 /// @dev Throws error if `msg.sender` is not admin or owner of the collection.54 /// @param key Property key.55 /// @param is_mutable Permission to mutate property.56 /// @param collection_admin Permission to mutate property by collection admin if property is mutable.57 /// @param token_owner Permission to mutate property by token owner if property is mutable.45 fn set_token_property_permission(58 fn set_token_property_permission(46 &mut self,59 &mut self,47 caller: caller,60 caller: caller,68 .map_err(dispatch_to_evm::<T>)81 .map_err(dispatch_to_evm::<T>)69 }82 }708384 /// @notice Set token property value.85 /// @dev Throws error if `msg.sender` has no permission to edit the property.86 /// @param tokenId ID of the token.87 /// @param key Property key.88 /// @param value Property value.71 fn set_property(89 fn set_property(72 &mut self,90 &mut self,73 caller: caller,91 caller: caller,96 .map_err(dispatch_to_evm::<T>)114 .map_err(dispatch_to_evm::<T>)97 }115 }98116117 /// @notice Delete token property value.118 /// @dev Throws error if `msg.sender` has no permission to edit the property.119 /// @param tokenId ID of the token.120 /// @param key Property key.99 fn delete_property(&mut self, token_id: uint256, caller: caller, key: string) -> Result<()> {121 fn delete_property(&mut self, token_id: uint256, caller: caller, key: string) -> Result<()> {100 let caller = T::CrossAccountId::from_eth(caller);122 let caller = T::CrossAccountId::from_eth(caller);101 let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;123 let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;111 .map_err(dispatch_to_evm::<T>)133 .map_err(dispatch_to_evm::<T>)112 }134 }113135136 /// @notice Get token property value.114 /// Throws error if key not found137 /// @dev Throws error if key not found138 /// @param tokenId ID of the token.139 /// @param key Property key.115 fn property(&self, token_id: uint256, key: string) -> Result<bytes> {140 fn property(&self, token_id: uint256, key: string) -> Result<bytes> {116 let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;141 let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;117 let key = <Vec<u8>>::from(key)142 let key = <Vec<u8>>::from(key)127152128#[derive(ToLog)]153#[derive(ToLog)]129pub enum ERC721Events {154pub enum ERC721Events {155 /// @dev This emits when ownership of any NFT changes by any mechanism.156 /// This event emits when NFTs are created (`from` == 0) and destroyed157 /// (`to` == 0). Exception: during contract creation, any number of NFTs158 /// may be created and assigned without emitting Transfer. At the time of159 /// any transfer, the approved address for that NFT (if any) is reset to none.130 Transfer {160 Transfer {131 #[indexed]161 #[indexed]132 from: address,162 from: address,135 #[indexed]165 #[indexed]136 token_id: uint256,166 token_id: uint256,137 },167 },168 /// @dev This emits when the approved address for an NFT is changed or169 /// reaffirmed. The zero address indicates there is no approved address.170 /// When a Transfer event emits, this also indicates that the approved171 /// address for that NFT (if any) is reset to none.138 Approval {172 Approval {139 #[indexed]173 #[indexed]140 owner: address,174 owner: address,143 #[indexed]177 #[indexed]144 token_id: uint256,178 token_id: uint256,145 },179 },180 /// @dev This emits when an operator is enabled or disabled for an owner.181 /// The operator can manage all NFTs of the owner.146 #[allow(dead_code)]182 #[allow(dead_code)]147 ApprovalForAll {183 ApprovalForAll {148 #[indexed]184 #[indexed]159 MintingFinished {},195 MintingFinished {},160}196}161197198/// @title ERC-721 Non-Fungible Token Standard, optional metadata extension199/// @dev See https://eips.ethereum.org/EIPS/eip-721162#[solidity_interface(name = "ERC721Metadata")]200#[solidity_interface(name = "ERC721Metadata")]163impl<T: Config> NonfungibleHandle<T> {201impl<T: Config> NonfungibleHandle<T> {202 /// @notice A descriptive name for a collection of NFTs in this contract164 fn name(&self) -> Result<string> {203 fn name(&self) -> Result<string> {165 Ok(decode_utf16(self.name.iter().copied())204 Ok(decode_utf16(self.name.iter().copied())166 .map(|r| r.unwrap_or(REPLACEMENT_CHARACTER))205 .map(|r| r.unwrap_or(REPLACEMENT_CHARACTER))167 .collect::<string>())206 .collect::<string>())168 }207 }169208209 /// @notice An abbreviated name for NFTs in this contract170 fn symbol(&self) -> Result<string> {210 fn symbol(&self) -> Result<string> {171 Ok(string::from_utf8_lossy(&self.token_prefix).into())211 Ok(string::from_utf8_lossy(&self.token_prefix).into())172 }212 }173213214 /// @notice A distinct Uniform Resource Identifier (URI) for a given asset.215 /// @dev Throws if `tokenId` is not a valid NFT. URIs are defined in RFC216 /// 3986. The URI may point to a JSON file that conforms to the "ERC721217 /// Metadata JSON Schema".174 /// Returns token's const_metadata218 /// @return token's const_metadata175 #[solidity(rename_selector = "tokenURI")]219 #[solidity(rename_selector = "tokenURI")]176 fn token_uri(&self, token_id: uint256) -> Result<string> {220 fn token_uri(&self, token_id: uint256) -> Result<string> {177 let key = token_uri_key();221 let key = token_uri_key();192 }236 }193}237}194238239/// @title ERC-721 Non-Fungible Token Standard, optional enumeration extension240/// @dev See https://eips.ethereum.org/EIPS/eip-721195#[solidity_interface(name = "ERC721Enumerable")]241#[solidity_interface(name = "ERC721Enumerable")]196impl<T: Config> NonfungibleHandle<T> {242impl<T: Config> NonfungibleHandle<T> {243 /// @notice Enumerate valid NFTs244 /// @param index A counter less than `totalSupply()`245 /// @return The token identifier for the `index`th NFT,246 /// (sort order not specified)197 fn token_by_index(&self, index: uint256) -> Result<uint256> {247 fn token_by_index(&self, index: uint256) -> Result<uint256> {198 Ok(index)248 Ok(index)199 }249 }200250201 /// Not implemented251 /// @dev Not implemented202 fn token_of_owner_by_index(&self, _owner: address, _index: uint256) -> Result<uint256> {252 fn token_of_owner_by_index(&self, _owner: address, _index: uint256) -> Result<uint256> {203 // TODO: Not implemetable253 // TODO: Not implemetable204 Err("not implemented".into())254 Err("not implemented".into())205 }255 }206256257 /// @notice Count NFTs tracked by this contract258 /// @return A count of valid NFTs tracked by this contract, where each one of259 /// them has an assigned and queryable owner not equal to the zero address207 fn total_supply(&self) -> Result<uint256> {260 fn total_supply(&self) -> Result<uint256> {208 self.consume_store_reads(1)?;261 self.consume_store_reads(1)?;209 Ok(<Pallet<T>>::total_supply(self).into())262 Ok(<Pallet<T>>::total_supply(self).into())210 }263 }211}264}212265266/// @title ERC-721 Non-Fungible Token Standard267/// @dev See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md213#[solidity_interface(name = "ERC721", events(ERC721Events))]268#[solidity_interface(name = "ERC721", events(ERC721Events))]214impl<T: Config> NonfungibleHandle<T> {269impl<T: Config> NonfungibleHandle<T> {270 /// @notice Count all NFTs assigned to an owner271 /// @dev NFTs assigned to the zero address are considered invalid, and this272 /// function throws for queries about the zero address.273 /// @param owner An address for whom to query the balance274 /// @return The number of NFTs owned by `owner`, possibly zero215 fn balance_of(&self, owner: address) -> Result<uint256> {275 fn balance_of(&self, owner: address) -> Result<uint256> {216 self.consume_store_reads(1)?;276 self.consume_store_reads(1)?;217 let owner = T::CrossAccountId::from_eth(owner);277 let owner = T::CrossAccountId::from_eth(owner);218 let balance = <AccountBalance<T>>::get((self.id, owner));278 let balance = <AccountBalance<T>>::get((self.id, owner));219 Ok(balance.into())279 Ok(balance.into())220 }280 }281 /// @notice Find the owner of an NFT282 /// @dev NFTs assigned to zero address are considered invalid, and queries283 /// about them do throw.284 /// @param tokenId The identifier for an NFT285 /// @return The address of the owner of the NFT221 fn owner_of(&self, token_id: uint256) -> Result<address> {286 fn owner_of(&self, token_id: uint256) -> Result<address> {222 self.consume_store_reads(1)?;287 self.consume_store_reads(1)?;223 let token: TokenId = token_id.try_into()?;288 let token: TokenId = token_id.try_into()?;226 .owner291 .owner227 .as_eth())292 .as_eth())228 }293 }229 /// Not implemented294 /// @dev Not implemented230 fn safe_transfer_from_with_data(295 fn safe_transfer_from_with_data(231 &mut self,296 &mut self,232 _from: address,297 _from: address,238 // TODO: Not implemetable303 // TODO: Not implemetable239 Err("not implemented".into())304 Err("not implemented".into())240 }305 }241 /// Not implemented306 /// @dev Not implemented242 fn safe_transfer_from(307 fn safe_transfer_from(243 &mut self,308 &mut self,244 _from: address,309 _from: address,250 Err("not implemented".into())315 Err("not implemented".into())251 }316 }252317318 /// @notice Transfer ownership of an NFT -- THE CALLER IS RESPONSIBLE319 /// TO CONFIRM THAT `to` IS CAPABLE OF RECEIVING NFTS OR ELSE320 /// THEY MAY BE PERMANENTLY LOST321 /// @dev Throws unless `msg.sender` is the current owner or an authorized322 /// operator for this NFT. Throws if `from` is not the current owner. Throws323 /// if `to` is the zero address. Throws if `tokenId` is not a valid NFT.324 /// @param from The current owner of the NFT325 /// @param to The new owner326 /// @param tokenId The NFT to transfer327 /// @param _value Not used for an NFT253 #[weight(<SelfWeightOf<T>>::transfer_from())]328 #[weight(<SelfWeightOf<T>>::transfer_from())]254 fn transfer_from(329 fn transfer_from(255 &mut self,330 &mut self,272 Ok(())347 Ok(())273 }348 }274349350 /// @notice Set or reaffirm the approved address for an NFT351 /// @dev The zero address indicates there is no approved address.352 /// @dev Throws unless `msg.sender` is the current NFT owner, or an authorized353 /// operator of the current owner.354 /// @param approved The new approved NFT controller355 /// @param tokenId The NFT to approve275 #[weight(<SelfWeightOf<T>>::approve())]356 #[weight(<SelfWeightOf<T>>::approve())]276 fn approve(357 fn approve(277 &mut self,358 &mut self,289 Ok(())370 Ok(())290 }371 }291372292 /// Not implemented373 /// @dev Not implemented293 fn set_approval_for_all(374 fn set_approval_for_all(294 &mut self,375 &mut self,295 _caller: caller,376 _caller: caller,300 Err("not implemented".into())381 Err("not implemented".into())301 }382 }302383303 /// Not implemented384 /// @dev Not implemented304 fn get_approved(&self, _token_id: uint256) -> Result<address> {385 fn get_approved(&self, _token_id: uint256) -> Result<address> {305 // TODO: Not implemetable386 // TODO: Not implemetable306 Err("not implemented".into())387 Err("not implemented".into())307 }388 }308389309 /// Not implemented390 /// @dev Not implemented310 fn is_approved_for_all(&self, _owner: address, _operator: address) -> Result<address> {391 fn is_approved_for_all(&self, _owner: address, _operator: address) -> Result<address> {311 // TODO: Not implemetable392 // TODO: Not implemetable312 Err("not implemented".into())393 Err("not implemented".into())313 }394 }314}395}315396397/// @title ERC721 Token that can be irreversibly burned (destroyed).316#[solidity_interface(name = "ERC721Burnable")]398#[solidity_interface(name = "ERC721Burnable")]317impl<T: Config> NonfungibleHandle<T> {399impl<T: Config> NonfungibleHandle<T> {400 /// @notice Burns a specific ERC721 token.401 /// @dev Throws unless `msg.sender` is the current NFT owner, or an authorized402 /// operator of the current owner.403 /// @param tokenId The NFT to approve318 #[weight(<SelfWeightOf<T>>::burn_item())]404 #[weight(<SelfWeightOf<T>>::burn_item())]319 fn burn(&mut self, caller: caller, token_id: uint256) -> Result<void> {405 fn burn(&mut self, caller: caller, token_id: uint256) -> Result<void> {320 let caller = T::CrossAccountId::from_eth(caller);406 let caller = T::CrossAccountId::from_eth(caller);325 }411 }326}412}327413414/// @title ERC721 minting logic.328#[solidity_interface(name = "ERC721Mintable", events(ERC721MintableEvents))]415#[solidity_interface(name = "ERC721Mintable", events(ERC721MintableEvents))]329impl<T: Config> NonfungibleHandle<T> {416impl<T: Config> NonfungibleHandle<T> {330 fn minting_finished(&self) -> Result<bool> {417 fn minting_finished(&self) -> Result<bool> {331 Ok(false)418 Ok(false)332 }419 }333420421 /// @notice Function to mint token.334 /// `token_id` should be obtained with `next_token_id` method,422 /// @dev `tokenId` should be obtained with `nextTokenId` method,335 /// unlike standard, you can't specify it manually423 /// unlike standard, you can't specify it manually424 /// @param to The new owner425 /// @param tokenId ID of the minted NFT336 #[weight(<SelfWeightOf<T>>::create_item())]426 #[weight(<SelfWeightOf<T>>::create_item())]337 fn mint(&mut self, caller: caller, to: address, token_id: uint256) -> Result<bool> {427 fn mint(&mut self, caller: caller, to: address, token_id: uint256) -> Result<bool> {338 let caller = T::CrossAccountId::from_eth(caller);428 let caller = T::CrossAccountId::from_eth(caller);364 Ok(true)454 Ok(true)365 }455 }366456457 /// @notice Function to mint token with the given tokenUri.367 /// `token_id` should be obtained with `next_token_id` method,458 /// @dev `tokenId` should be obtained with `nextTokenId` method,368 /// unlike standard, you can't specify it manually459 /// unlike standard, you can't specify it manually460 /// @param to The new owner461 /// @param tokenId ID of the minted NFT462 /// @param tokenUri Token URI that would be stored in the NFT properties369 #[solidity(rename_selector = "mintWithTokenURI")]463 #[solidity(rename_selector = "mintWithTokenURI")]370 #[weight(<SelfWeightOf<T>>::create_item())]464 #[weight(<SelfWeightOf<T>>::create_item())]371 fn mint_with_token_uri(465 fn mint_with_token_uri(420 Ok(true)514 Ok(true)421 }515 }422516423 /// Not implemented517 /// @dev Not implemented424 fn finish_minting(&mut self, _caller: caller) -> Result<bool> {518 fn finish_minting(&mut self, _caller: caller) -> Result<bool> {425 Err("not implementable".into())519 Err("not implementable".into())426 }520 }449 false543 false450}544}451545546/// @title Unique extensions for ERC721.452#[solidity_interface(name = "ERC721UniqueExtensions")]547#[solidity_interface(name = "ERC721UniqueExtensions")]453impl<T: Config> NonfungibleHandle<T> {548impl<T: Config> NonfungibleHandle<T> {549 /// @notice Transfer ownership of an NFT550 /// @dev Throws unless `msg.sender` is the current owner. Throws if `to`551 /// is the zero address. Throws if `tokenId` is not a valid NFT.552 /// @param to The new owner553 /// @param tokenId The NFT to transfer554 /// @param _value Not used for an NFT454 #[weight(<SelfWeightOf<T>>::transfer())]555 #[weight(<SelfWeightOf<T>>::transfer())]455 fn transfer(556 fn transfer(456 &mut self,557 &mut self,470 Ok(())571 Ok(())471 }572 }472573574 /// @notice Burns a specific ERC721 token.575 /// @dev Throws unless `msg.sender` is the current owner or an authorized576 /// operator for this NFT. Throws if `from` is not the current owner. Throws577 /// if `to` is the zero address. Throws if `tokenId` is not a valid NFT.578 /// @param from The current owner of the NFT579 /// @param tokenId The NFT to transfer580 /// @param _value Not used for an NFT473 #[weight(<SelfWeightOf<T>>::burn_from())]581 #[weight(<SelfWeightOf<T>>::burn_from())]474 fn burn_from(582 fn burn_from(475 &mut self,583 &mut self,490 Ok(())598 Ok(())491 }599 }492600601 /// @notice Returns next free NFT ID.493 fn next_token_id(&self) -> Result<uint256> {602 fn next_token_id(&self) -> Result<uint256> {494 self.consume_store_reads(1)?;603 self.consume_store_reads(1)?;495 Ok(<TokensMinted<T>>::get(self.id)604 Ok(<TokensMinted<T>>::get(self.id)498 .into())607 .into())499 }608 }500609610 /// @notice Function to mint multiple tokens.611 /// @dev `tokenIds` should be an array of consecutive numbers and first number612 /// should be obtained with `nextTokenId` method613 /// @param to The new owner614 /// @param tokenIds IDs of the minted NFTs501 #[weight(<SelfWeightOf<T>>::create_multiple_items(token_ids.len() as u32))]615 #[weight(<SelfWeightOf<T>>::create_multiple_items(token_ids.len() as u32))]502 fn mint_bulk(&mut self, caller: caller, to: address, token_ids: Vec<uint256>) -> Result<bool> {616 fn mint_bulk(&mut self, caller: caller, to: address, token_ids: Vec<uint256>) -> Result<bool> {503 let caller = T::CrossAccountId::from_eth(caller);617 let caller = T::CrossAccountId::from_eth(caller);529 Ok(true)643 Ok(true)530 }644 }531645646 /// @notice Function to mint multiple tokens with the given tokenUris.647 /// @dev `tokenIds` is array of pairs of token ID and token URI. Token IDs should be consecutive648 /// numbers and first number should be obtained with `nextTokenId` method649 /// @param to The new owner650 /// @param tokens array of pairs of token ID and token URI for minted tokens532 #[solidity(rename_selector = "mintBulkWithTokenURI")]651 #[solidity(rename_selector = "mintBulkWithTokenURI")]533 #[weight(<SelfWeightOf<T>>::create_multiple_items(tokens.len() as u32))]652 #[weight(<SelfWeightOf<T>>::create_multiple_items(tokens.len() as u32))]534 fn mint_bulk_with_token_uri(653 fn mint_bulk_with_token_uri(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
@@ -53,6 +53,13 @@
// Selector: 41369377
contract TokenProperties is Dummy, ERC165 {
+ // @notice Set permissions for token property.
+ // @dev Throws error if `msg.sender` is not admin or owner of the collection.
+ // @param key Property key.
+ // @param is_mutable Permission to mutate property.
+ // @param collection_admin Permission to mutate property by collection admin if property is mutable.
+ // @param token_owner Permission to mutate property by token owner if property is mutable.
+ //
// Selector: setTokenPropertyPermission(string,bool,bool,bool) 222d97fa
function setTokenPropertyPermission(
string memory key,
@@ -68,6 +75,12 @@
dummy = 0;
}
+ // @notice Set token property value.
+ // @dev Throws error if `msg.sender` has no permission to edit the property.
+ // @param token_id ID of the token.
+ // @param key Property key.
+ // @param value Property value.
+ //
// Selector: setProperty(uint256,string,bytes) 1752d67b
function setProperty(
uint256 tokenId,
@@ -81,6 +94,11 @@
dummy = 0;
}
+ // @notice Delete token property value.
+ // @dev Throws error if `msg.sender` has no permission to edit the property.
+ // @param token_id ID of the token.
+ // @param key Property key.
+ //
// Selector: deleteProperty(uint256,string) 066111d1
function deleteProperty(uint256 tokenId, string memory key) public {
require(false, stub_error);
@@ -89,7 +107,10 @@
dummy = 0;
}
- // Throws error if key not found
+ // @notice Get token property value.
+ // @dev Throws error if key not found
+ // @param token_id ID of the token.
+ // @param key Property key.
//
// Selector: property(uint256,string) 7228c327
function property(uint256 tokenId, string memory key)
@@ -107,6 +128,11 @@
// Selector: 42966c68
contract ERC721Burnable is Dummy, ERC165 {
+ // @notice Burns a specific ERC721 token.
+ // @dev Throws unless `msg.sender` is the current NFT owner, or an authorized
+ // operator of the current owner.
+ // @param tokenId The NFT to approve
+ //
// Selector: burn(uint256) 42966c68
function burn(uint256 tokenId) public {
require(false, stub_error);
@@ -117,6 +143,12 @@
// Selector: 58800161
contract ERC721 is Dummy, ERC165, ERC721Events {
+ // @notice Count all NFTs assigned to an owner
+ // @dev NFTs assigned to the zero address are considered invalid, and this
+ // function throws for queries about the zero address.
+ // @param _owner An address for whom to query the balance
+ // @return The number of NFTs owned by `_owner`, possibly zero
+ //
// Selector: balanceOf(address) 70a08231
function balanceOf(address owner) public view returns (uint256) {
require(false, stub_error);
@@ -125,6 +157,12 @@
return 0;
}
+ // @notice Find the owner of an NFT
+ // @dev NFTs assigned to zero address are considered invalid, and queries
+ // about them do throw.
+ // @param _tokenId The identifier for an NFT
+ // @return The address of the owner of the NFT
+ //
// Selector: ownerOf(uint256) 6352211e
function ownerOf(uint256 tokenId) public view returns (address) {
require(false, stub_error);
@@ -133,7 +171,7 @@
return 0x0000000000000000000000000000000000000000;
}
- // Not implemented
+ // @dev Not implemented
//
// Selector: safeTransferFromWithData(address,address,uint256,bytes) 60a11672
function safeTransferFromWithData(
@@ -150,7 +188,7 @@
dummy = 0;
}
- // Not implemented
+ // @dev Not implemented
//
// Selector: safeTransferFrom(address,address,uint256) 42842e0e
function safeTransferFrom(
@@ -165,6 +203,17 @@
dummy = 0;
}
+ // @notice Transfer ownership of an NFT -- THE CALLER IS RESPONSIBLE
+ // TO CONFIRM THAT `to` IS CAPABLE OF RECEIVING NFTS OR ELSE
+ // THEY MAY BE PERMANENTLY LOST
+ // @dev Throws unless `msg.sender` is the current owner or an authorized
+ // operator for this NFT. Throws if `from` is not the current owner. Throws
+ // if `to` is the zero address. Throws if `tokenId` is not a valid NFT.
+ // @param from The current owner of the NFT
+ // @param to The new owner
+ // @param tokenId The NFT to transfer
+ // @param _value Not used for an NFT
+ //
// Selector: transferFrom(address,address,uint256) 23b872dd
function transferFrom(
address from,
@@ -178,6 +227,13 @@
dummy = 0;
}
+ // @notice Set or reaffirm the approved address for an NFT
+ // @dev The zero address indicates there is no approved address.
+ // @dev Throws unless `msg.sender` is the current NFT owner, or an authorized
+ // operator of the current owner.
+ // @param approved The new approved NFT controller
+ // @param tokenId The NFT to approve
+ //
// Selector: approve(address,uint256) 095ea7b3
function approve(address approved, uint256 tokenId) public {
require(false, stub_error);
@@ -186,7 +242,7 @@
dummy = 0;
}
- // Not implemented
+ // @dev Not implemented
//
// Selector: setApprovalForAll(address,bool) a22cb465
function setApprovalForAll(address operator, bool approved) public {
@@ -196,7 +252,7 @@
dummy = 0;
}
- // Not implemented
+ // @dev Not implemented
//
// Selector: getApproved(uint256) 081812fc
function getApproved(uint256 tokenId) public view returns (address) {
@@ -206,7 +262,7 @@
return 0x0000000000000000000000000000000000000000;
}
- // Not implemented
+ // @dev Not implemented
//
// Selector: isApprovedForAll(address,address) e985e9c5
function isApprovedForAll(address owner, address operator)
@@ -224,6 +280,8 @@
// Selector: 5b5e139f
contract ERC721Metadata is Dummy, ERC165 {
+ // @notice A descriptive name for a collection of NFTs in this contract
+ //
// Selector: name() 06fdde03
function name() public view returns (string memory) {
require(false, stub_error);
@@ -231,6 +289,8 @@
return "";
}
+ // @notice An abbreviated name for NFTs in this contract
+ //
// Selector: symbol() 95d89b41
function symbol() public view returns (string memory) {
require(false, stub_error);
@@ -238,7 +298,11 @@
return "";
}
- // Returns token's const_metadata
+ // @notice A distinct Uniform Resource Identifier (URI) for a given asset.
+ // @dev Throws if `tokenId` is not a valid NFT. URIs are defined in RFC
+ // 3986. The URI may point to a JSON file that conforms to the "ERC721
+ // Metadata JSON Schema".
+ // @return token's const_metadata
//
// Selector: tokenURI(uint256) c87b56dd
function tokenURI(uint256 tokenId) public view returns (string memory) {
@@ -258,8 +322,11 @@
return false;
}
- // `token_id` should be obtained with `next_token_id` method,
- // unlike standard, you can't specify it manually
+ // @notice Function to mint token.
+ // @dev `tokenId` should be obtained with `nextTokenId` method,
+ // unlike standard, you can't specify it manually
+ // @param to The new owner
+ // @param tokenId ID of the minted NFT
//
// Selector: mint(address,uint256) 40c10f19
function mint(address to, uint256 tokenId) public returns (bool) {
@@ -270,8 +337,12 @@
return false;
}
- // `token_id` should be obtained with `next_token_id` method,
- // unlike standard, you can't specify it manually
+ // @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
+ // @param to The new owner
+ // @param tokenId ID of the minted NFT
+ // @param tokenUri Token URI that would be stored in the NFT properties
//
// Selector: mintWithTokenURI(address,uint256,string) 50bb4e7f
function mintWithTokenURI(
@@ -287,7 +358,7 @@
return false;
}
- // Not implemented
+ // @dev Not implemented
//
// Selector: finishMinting() 7d64bcb4
function finishMinting() public returns (bool) {
@@ -299,6 +370,12 @@
// Selector: 780e9d63
contract ERC721Enumerable is Dummy, ERC165 {
+ // @notice Enumerate valid NFTs
+ // @dev Throws if `index` >= `totalSupply()`.
+ // @param index A counter less than `totalSupply()`
+ // @return The token identifier for the `index`th NFT,
+ // (sort order not specified)
+ //
// Selector: tokenByIndex(uint256) 4f6ccce7
function tokenByIndex(uint256 index) public view returns (uint256) {
require(false, stub_error);
@@ -307,7 +384,7 @@
return 0;
}
- // Not implemented
+ // @dev Not implemented
//
// Selector: tokenOfOwnerByIndex(address,uint256) 2f745c59
function tokenOfOwnerByIndex(address owner, uint256 index)
@@ -322,6 +399,10 @@
return 0;
}
+ // @notice Count NFTs tracked by this contract
+ // @return A count of valid NFTs tracked by this contract, where each one of
+ // them has an assigned and queryable owner not equal to the zero address
+ //
// Selector: totalSupply() 18160ddd
function totalSupply() public view returns (uint256) {
require(false, stub_error);
@@ -475,6 +556,15 @@
// Selector: d74d154f
contract ERC721UniqueExtensions is Dummy, ERC165 {
+ // @notice Transfer ownership of an NFT -- THE CALLER IS RESPONSIBLE
+ // TO CONFIRM THAT `to` IS CAPABLE OF RECEIVING NFTS OR ELSE
+ // THEY MAY BE PERMANENTLY LOST
+ // @dev Throws unless `msg.sender` is the current owner. Throws if `to`
+ // is the zero address. Throws if `tokenId` is not a valid NFT.
+ // @param to The new owner
+ // @param tokenId The NFT to transfer
+ // @param _value Not used for an NFT
+ //
// Selector: transfer(address,uint256) a9059cbb
function transfer(address to, uint256 tokenId) public {
require(false, stub_error);
@@ -483,6 +573,14 @@
dummy = 0;
}
+ // @notice Burns a specific ERC721 token.
+ // @dev Throws unless `msg.sender` is the current owner or an authorized
+ // operator for this NFT. Throws if `from` is not the current owner. Throws
+ // if `to` is the zero address. Throws if `tokenId` is not a valid NFT.
+ // @param from The current owner of the NFT
+ // @param tokenId The NFT to transfer
+ // @param _value Not used for an NFT
+ //
// Selector: burnFrom(address,uint256) 79cc6790
function burnFrom(address from, uint256 tokenId) public {
require(false, stub_error);
@@ -491,6 +589,8 @@
dummy = 0;
}
+ // @notice Returns next free NFT ID.
+ //
// Selector: nextTokenId() 75794a3c
function nextTokenId() public view returns (uint256) {
require(false, stub_error);
@@ -498,6 +598,12 @@
return 0;
}
+ // @notice Function to mint multiple tokens.
+ // @dev `tokenIds` should be an array of consecutive numbers and first number
+ // should be obtained with `nextTokenId` method
+ // @param to The new owner
+ // @param tokenIds IDs of the minted NFTs
+ //
// Selector: mintBulk(address,uint256[]) 44a9945e
function mintBulk(address to, uint256[] memory tokenIds)
public
@@ -510,6 +616,12 @@
return false;
}
+ // @notice Function to mint multiple tokens with the given tokenUris.
+ // @dev `tokenIds` is array of pairs of token ID and token URI. Token IDs should be consecutive
+ // numbers and first number should be obtained with `nextTokenId` method
+ // @param to The new owner
+ // @param tokens array of pairs of token ID and token URI for minted tokens
+ //
// Selector: mintBulkWithTokenURI(address,(uint256,string)[]) 36543006
function mintBulkWithTokenURI(address to, Tuple0[] memory tokens)
public
tests/src/eth/api/UniqueNFT.soldiffbeforeafterboth--- a/tests/src/eth/api/UniqueNFT.sol
+++ b/tests/src/eth/api/UniqueNFT.sol
@@ -44,6 +44,13 @@
// Selector: 41369377
interface TokenProperties is Dummy, ERC165 {
+ // @notice Set permissions for token property.
+ // @dev Throws error if `msg.sender` is not admin or owner of the collection.
+ // @param key Property key.
+ // @param is_mutable Permission to mutate property.
+ // @param collection_admin Permission to mutate property by collection admin if property is mutable.
+ // @param token_owner Permission to mutate property by token owner if property is mutable.
+ //
// Selector: setTokenPropertyPermission(string,bool,bool,bool) 222d97fa
function setTokenPropertyPermission(
string memory key,
@@ -52,6 +59,12 @@
bool tokenOwner
) external;
+ // @notice Set token property value.
+ // @dev Throws error if `msg.sender` has no permission to edit the property.
+ // @param token_id ID of the token.
+ // @param key Property key.
+ // @param value Property value.
+ //
// Selector: setProperty(uint256,string,bytes) 1752d67b
function setProperty(
uint256 tokenId,
@@ -59,10 +72,18 @@
bytes memory value
) external;
+ // @notice Delete token property value.
+ // @dev Throws error if `msg.sender` has no permission to edit the property.
+ // @param token_id ID of the token.
+ // @param key Property key.
+ //
// Selector: deleteProperty(uint256,string) 066111d1
function deleteProperty(uint256 tokenId, string memory key) external;
- // Throws error if key not found
+ // @notice Get token property value.
+ // @dev Throws error if key not found
+ // @param token_id ID of the token.
+ // @param key Property key.
//
// Selector: property(uint256,string) 7228c327
function property(uint256 tokenId, string memory key)
@@ -73,19 +94,36 @@
// Selector: 42966c68
interface ERC721Burnable is Dummy, ERC165 {
+ // @notice Burns a specific ERC721 token.
+ // @dev Throws unless `msg.sender` is the current NFT owner, or an authorized
+ // operator of the current owner.
+ // @param tokenId The NFT to approve
+ //
// Selector: burn(uint256) 42966c68
function burn(uint256 tokenId) external;
}
// Selector: 58800161
interface ERC721 is Dummy, ERC165, ERC721Events {
+ // @notice Count all NFTs assigned to an owner
+ // @dev NFTs assigned to the zero address are considered invalid, and this
+ // function throws for queries about the zero address.
+ // @param _owner An address for whom to query the balance
+ // @return The number of NFTs owned by `_owner`, possibly zero
+ //
// Selector: balanceOf(address) 70a08231
function balanceOf(address owner) external view returns (uint256);
+ // @notice Find the owner of an NFT
+ // @dev NFTs assigned to zero address are considered invalid, and queries
+ // about them do throw.
+ // @param _tokenId The identifier for an NFT
+ // @return The address of the owner of the NFT
+ //
// Selector: ownerOf(uint256) 6352211e
function ownerOf(uint256 tokenId) external view returns (address);
- // Not implemented
+ // @dev Not implemented
//
// Selector: safeTransferFromWithData(address,address,uint256,bytes) 60a11672
function safeTransferFromWithData(
@@ -95,7 +133,7 @@
bytes memory data
) external;
- // Not implemented
+ // @dev Not implemented
//
// Selector: safeTransferFrom(address,address,uint256) 42842e0e
function safeTransferFrom(
@@ -104,6 +142,17 @@
uint256 tokenId
) external;
+ // @notice Transfer ownership of an NFT -- THE CALLER IS RESPONSIBLE
+ // TO CONFIRM THAT `to` IS CAPABLE OF RECEIVING NFTS OR ELSE
+ // THEY MAY BE PERMANENTLY LOST
+ // @dev Throws unless `msg.sender` is the current owner or an authorized
+ // operator for this NFT. Throws if `from` is not the current owner. Throws
+ // if `to` is the zero address. Throws if `tokenId` is not a valid NFT.
+ // @param from The current owner of the NFT
+ // @param to The new owner
+ // @param tokenId The NFT to transfer
+ // @param _value Not used for an NFT
+ //
// Selector: transferFrom(address,address,uint256) 23b872dd
function transferFrom(
address from,
@@ -111,20 +160,27 @@
uint256 tokenId
) external;
+ // @notice Set or reaffirm the approved address for an NFT
+ // @dev The zero address indicates there is no approved address.
+ // @dev Throws unless `msg.sender` is the current NFT owner, or an authorized
+ // operator of the current owner.
+ // @param approved The new approved NFT controller
+ // @param tokenId The NFT to approve
+ //
// Selector: approve(address,uint256) 095ea7b3
function approve(address approved, uint256 tokenId) external;
- // Not implemented
+ // @dev Not implemented
//
// Selector: setApprovalForAll(address,bool) a22cb465
function setApprovalForAll(address operator, bool approved) external;
- // Not implemented
+ // @dev Not implemented
//
// Selector: getApproved(uint256) 081812fc
function getApproved(uint256 tokenId) external view returns (address);
- // Not implemented
+ // @dev Not implemented
//
// Selector: isApprovedForAll(address,address) e985e9c5
function isApprovedForAll(address owner, address operator)
@@ -135,13 +191,21 @@
// Selector: 5b5e139f
interface ERC721Metadata is Dummy, ERC165 {
+ // @notice A descriptive name for a collection of NFTs in this contract
+ //
// Selector: name() 06fdde03
function name() external view returns (string memory);
+ // @notice An abbreviated name for NFTs in this contract
+ //
// Selector: symbol() 95d89b41
function symbol() external view returns (string memory);
- // Returns token's const_metadata
+ // @notice A distinct Uniform Resource Identifier (URI) for a given asset.
+ // @dev Throws if `tokenId` is not a valid NFT. URIs are defined in RFC
+ // 3986. The URI may point to a JSON file that conforms to the "ERC721
+ // Metadata JSON Schema".
+ // @return token's const_metadata
//
// Selector: tokenURI(uint256) c87b56dd
function tokenURI(uint256 tokenId) external view returns (string memory);
@@ -152,14 +216,21 @@
// Selector: mintingFinished() 05d2035b
function mintingFinished() external view returns (bool);
- // `token_id` should be obtained with `next_token_id` method,
- // unlike standard, you can't specify it manually
+ // @notice Function to mint token.
+ // @dev `tokenId` should be obtained with `nextTokenId` method,
+ // unlike standard, you can't specify it manually
+ // @param to The new owner
+ // @param tokenId ID of the minted NFT
//
// Selector: mint(address,uint256) 40c10f19
function mint(address to, uint256 tokenId) external returns (bool);
- // `token_id` should be obtained with `next_token_id` method,
- // unlike standard, you can't specify it manually
+ // @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
+ // @param to The new owner
+ // @param tokenId ID of the minted NFT
+ // @param tokenUri Token URI that would be stored in the NFT properties
//
// Selector: mintWithTokenURI(address,uint256,string) 50bb4e7f
function mintWithTokenURI(
@@ -168,7 +239,7 @@
string memory tokenUri
) external returns (bool);
- // Not implemented
+ // @dev Not implemented
//
// Selector: finishMinting() 7d64bcb4
function finishMinting() external returns (bool);
@@ -176,10 +247,16 @@
// Selector: 780e9d63
interface ERC721Enumerable is Dummy, ERC165 {
+ // @notice Enumerate valid NFTs
+ // @dev Throws if `index` >= `totalSupply()`.
+ // @param index A counter less than `totalSupply()`
+ // @return The token identifier for the `index`th NFT,
+ // (sort order not specified)
+ //
// Selector: tokenByIndex(uint256) 4f6ccce7
function tokenByIndex(uint256 index) external view returns (uint256);
- // Not implemented
+ // @dev Not implemented
//
// Selector: tokenOfOwnerByIndex(address,uint256) 2f745c59
function tokenOfOwnerByIndex(address owner, uint256 index)
@@ -187,6 +264,10 @@
view
returns (uint256);
+ // @notice Count NFTs tracked by this contract
+ // @return A count of valid NFTs tracked by this contract, where each one of
+ // them has an assigned and queryable owner not equal to the zero address
+ //
// Selector: totalSupply() 18160ddd
function totalSupply() external view returns (uint256);
}
@@ -257,20 +338,51 @@
// Selector: d74d154f
interface ERC721UniqueExtensions is Dummy, ERC165 {
+ // @notice Transfer ownership of an NFT -- THE CALLER IS RESPONSIBLE
+ // TO CONFIRM THAT `to` IS CAPABLE OF RECEIVING NFTS OR ELSE
+ // THEY MAY BE PERMANENTLY LOST
+ // @dev Throws unless `msg.sender` is the current owner. Throws if `to`
+ // is the zero address. Throws if `tokenId` is not a valid NFT.
+ // @param to The new owner
+ // @param tokenId The NFT to transfer
+ // @param _value Not used for an NFT
+ //
// Selector: transfer(address,uint256) a9059cbb
function transfer(address to, uint256 tokenId) external;
+ // @notice Burns a specific ERC721 token.
+ // @dev Throws unless `msg.sender` is the current owner or an authorized
+ // operator for this NFT. Throws if `from` is not the current owner. Throws
+ // if `to` is the zero address. Throws if `tokenId` is not a valid NFT.
+ // @param from The current owner of the NFT
+ // @param tokenId The NFT to transfer
+ // @param _value Not used for an NFT
+ //
// Selector: burnFrom(address,uint256) 79cc6790
function burnFrom(address from, uint256 tokenId) external;
+ // @notice Returns next free NFT ID.
+ //
// Selector: nextTokenId() 75794a3c
function nextTokenId() external view returns (uint256);
+ // @notice Function to mint multiple tokens.
+ // @dev `tokenIds` should be an array of consecutive numbers and first number
+ // should be obtained with `nextTokenId` method
+ // @param to The new owner
+ // @param tokenIds IDs of the minted NFTs
+ //
// Selector: mintBulk(address,uint256[]) 44a9945e
function mintBulk(address to, uint256[] memory tokenIds)
external
returns (bool);
+ // @notice Function to mint multiple tokens with the given tokenUris.
+ // @dev `tokenIds` is array of pairs of token ID and token URI. Token IDs should be consecutive
+ // numbers and first number should be obtained with `nextTokenId` method
+ // @param to The new owner
+ // @param tokens array of pairs of token ID and token URI for minted tokens
+ //
// Selector: mintBulkWithTokenURI(address,(uint256,string)[]) 36543006
function mintBulkWithTokenURI(address to, Tuple0[] memory tokens)
external