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

difftreelog

refactor do not receive token id as mint argument

Yaroslav Bolyukin2022-10-13parent: #1c71f62.patch.diff
in: master

2 files changed

modifiedpallets/nonfungible/src/erc.rsdiffbeforeafterboth
193}193}
194194
195#[derive(ToLog)]195#[derive(ToLog)]
196pub enum ERC721MintableEvents {196pub enum ERC721UniqueMintableEvents {
197 #[allow(dead_code)]197 #[allow(dead_code)]
198 MintingFinished {},198 MintingFinished {},
199}199}
431}431}
432432
433/// @title ERC721 minting logic.433/// @title ERC721 minting logic.
434#[solidity_interface(name = ERC721Mintable, events(ERC721MintableEvents))]434#[solidity_interface(name = ERC721UniqueMintable, events(ERC721UniqueMintableEvents))]
435impl<T: Config> NonfungibleHandle<T> {435impl<T: Config> NonfungibleHandle<T> {
436 fn minting_finished(&self) -> Result<bool> {436 fn minting_finished(&self) -> Result<bool> {
437 Ok(false)437 Ok(false)
438 }438 }
439
440 /// @notice Function to mint token.
441 /// @param to The new owner
442 /// @return uint256 The id of the newly minted token
443 #[weight(<SelfWeightOf<T>>::create_item())]
444 fn mint(&mut self, caller: caller, to: address) -> Result<uint256> {
445 let token_id: uint256 = <TokensMinted<T>>::get(self.id)
446 .checked_add(1)
447 .ok_or("item id overflow")?
448 .into();
449 self.mint_check_id(caller, to, token_id)?;
450 Ok(token_id)
451 }
439452
440 /// @notice Function to mint token.453 /// @notice Function to mint token.
441 /// @dev `tokenId` should be obtained with `nextTokenId` method,454 /// @dev `tokenId` should be obtained with `nextTokenId` method,
442 /// unlike standard, you can't specify it manually455 /// unlike standard, you can't specify it manually
443 /// @param to The new owner456 /// @param to The new owner
444 /// @param tokenId ID of the minted NFT457 /// @param tokenId ID of the minted NFT
458 #[solidity(hide, rename_selector = "mint")]
445 #[weight(<SelfWeightOf<T>>::create_item())]459 #[weight(<SelfWeightOf<T>>::create_item())]
446 fn mint(&mut self, caller: caller, to: address, token_id: uint256) -> Result<bool> {460 fn mint_check_id(&mut self, caller: caller, to: address, token_id: uint256) -> Result<bool> {
447 let caller = T::CrossAccountId::from_eth(caller);461 let caller = T::CrossAccountId::from_eth(caller);
448 let to = T::CrossAccountId::from_eth(to);462 let to = T::CrossAccountId::from_eth(to);
449 let token_id: u32 = token_id.try_into()?;463 let token_id: u32 = token_id.try_into()?;
473 Ok(true)487 Ok(true)
474 }488 }
489
490 /// @notice Function to mint token with the given tokenUri.
491 /// @param to The new owner
492 /// @param tokenUri Token URI that would be stored in the NFT properties
493 /// @return uint256 The id of the newly minted token
494 #[solidity(rename_selector = "mintWithTokenURI")]
495 #[weight(<SelfWeightOf<T>>::create_item())]
496 fn mint_with_token_uri(
497 &mut self,
498 caller: caller,
499 to: address,
500 token_uri: string,
501 ) -> Result<uint256> {
502 let token_id: uint256 = <TokensMinted<T>>::get(self.id)
503 .checked_add(1)
504 .ok_or("item id overflow")?
505 .into();
506 self.mint_with_token_uri_check_id(caller, to, token_id, token_uri)?;
507 Ok(token_id)
508 }
475509
476 /// @notice Function to mint token with the given tokenUri.510 /// @notice Function to mint token with the given tokenUri.
477 /// @dev `tokenId` should be obtained with `nextTokenId` method,511 /// @dev `tokenId` should be obtained with `nextTokenId` method,
478 /// unlike standard, you can't specify it manually512 /// unlike standard, you can't specify it manually
479 /// @param to The new owner513 /// @param to The new owner
480 /// @param tokenId ID of the minted NFT514 /// @param tokenId ID of the minted NFT
481 /// @param tokenUri Token URI that would be stored in the NFT properties515 /// @param tokenUri Token URI that would be stored in the NFT properties
482 #[solidity(rename_selector = "mintWithTokenURI")]516 #[solidity(hide, rename_selector = "mintWithTokenURI")]
483 #[weight(<SelfWeightOf<T>>::create_item())]517 #[weight(<SelfWeightOf<T>>::create_item())]
484 fn mint_with_token_uri(518 fn mint_with_token_uri_check_id(
485 &mut self,519 &mut self,
486 caller: caller,520 caller: caller,
487 to: address,521 to: address,
637 /// should be obtained with `nextTokenId` method671 /// should be obtained with `nextTokenId` method
638 /// @param to The new owner672 /// @param to The new owner
639 /// @param tokenIds IDs of the minted NFTs673 /// @param tokenIds IDs of the minted NFTs
674 #[solidity(hide)]
640 #[weight(<SelfWeightOf<T>>::create_multiple_items(token_ids.len() as u32))]675 #[weight(<SelfWeightOf<T>>::create_multiple_items(token_ids.len() as u32))]
641 fn mint_bulk(&mut self, caller: caller, to: address, token_ids: Vec<uint256>) -> Result<bool> {676 fn mint_bulk(&mut self, caller: caller, to: address, token_ids: Vec<uint256>) -> Result<bool> {
642 let caller = T::CrossAccountId::from_eth(caller);677 let caller = T::CrossAccountId::from_eth(caller);
673 /// numbers and first number should be obtained with `nextTokenId` method708 /// numbers and first number should be obtained with `nextTokenId` method
674 /// @param to The new owner709 /// @param to The new owner
675 /// @param tokens array of pairs of token ID and token URI for minted tokens710 /// @param tokens array of pairs of token ID and token URI for minted tokens
676 #[solidity(rename_selector = "mintBulkWithTokenURI")]711 #[solidity(hide, rename_selector = "mintBulkWithTokenURI")]
677 #[weight(<SelfWeightOf<T>>::create_multiple_items(tokens.len() as u32))]712 #[weight(<SelfWeightOf<T>>::create_multiple_items(tokens.len() as u32))]
678 fn mint_bulk_with_token_uri(713 fn mint_bulk_with_token_uri(
679 &mut self,714 &mut self,
728 ERC721,763 ERC721,
729 ERC721Enumerable,764 ERC721Enumerable,
730 ERC721UniqueExtensions,765 ERC721UniqueExtensions,
731 ERC721Mintable,766 ERC721UniqueMintable,
732 ERC721Burnable,767 ERC721Burnable,
733 ERC721Metadata(if(this.flags.erc721metadata)),768 ERC721Metadata(if(this.flags.erc721metadata)),
734 Collection(via(common_mut returns CollectionHandle<T>)),769 Collection(via(common_mut returns CollectionHandle<T>)),
modifiedpallets/refungible/src/erc.rsdiffbeforeafterboth
187}187}
188188
189#[derive(ToLog)]189#[derive(ToLog)]
190pub enum ERC721MintableEvents {190pub enum ERC721UniqueMintableEvents {
191 /// @dev Not supported191 /// @dev Not supported
192 #[allow(dead_code)]192 #[allow(dead_code)]
193 MintingFinished {},193 MintingFinished {},
449}449}
450450
451/// @title ERC721 minting logic.451/// @title ERC721 minting logic.
452#[solidity_interface(name = ERC721Mintable, events(ERC721MintableEvents))]452#[solidity_interface(name = ERC721UniqueMintable, events(ERC721UniqueMintableEvents))]
453impl<T: Config> RefungibleHandle<T> {453impl<T: Config> RefungibleHandle<T> {
454 fn minting_finished(&self) -> Result<bool> {454 fn minting_finished(&self) -> Result<bool> {
455 Ok(false)455 Ok(false)
456 }456 }
457
458 /// @notice Function to mint token.
459 /// @param to The new owner
460 /// @return uint256 The id of the newly minted token
461 #[weight(<SelfWeightOf<T>>::create_item())]
462 fn mint(&mut self, caller: caller, to: address) -> Result<uint256> {
463 let token_id: uint256 = <TokensMinted<T>>::get(self.id)
464 .checked_add(1)
465 .ok_or("item id overflow")?
466 .into();
467 self.mint_check_id(caller, to, token_id)?;
468 Ok(token_id)
469 }
457470
458 /// @notice Function to mint token.471 /// @notice Function to mint token.
459 /// @dev `tokenId` should be obtained with `nextTokenId` method,472 /// @dev `tokenId` should be obtained with `nextTokenId` method,
460 /// unlike standard, you can't specify it manually473 /// unlike standard, you can't specify it manually
461 /// @param to The new owner474 /// @param to The new owner
462 /// @param tokenId ID of the minted RFT475 /// @param tokenId ID of the minted RFT
476 #[solidity(hide, rename_selector = "mint")]
463 #[weight(<SelfWeightOf<T>>::create_item())]477 #[weight(<SelfWeightOf<T>>::create_item())]
464 fn mint(&mut self, caller: caller, to: address, token_id: uint256) -> Result<bool> {478 fn mint_check_id(&mut self, caller: caller, to: address, token_id: uint256) -> Result<bool> {
465 let caller = T::CrossAccountId::from_eth(caller);479 let caller = T::CrossAccountId::from_eth(caller);
466 let to = T::CrossAccountId::from_eth(to);480 let to = T::CrossAccountId::from_eth(to);
467 let token_id: u32 = token_id.try_into()?;481 let token_id: u32 = token_id.try_into()?;
496 Ok(true)510 Ok(true)
497 }511 }
512
513 /// @notice Function to mint token with the given tokenUri.
514 /// @param to The new owner
515 /// @param tokenUri Token URI that would be stored in the NFT properties
516 /// @return uint256 The id of the newly minted token
517 #[solidity(rename_selector = "mintWithTokenURI")]
518 #[weight(<SelfWeightOf<T>>::create_item())]
519 fn mint_with_token_uri(
520 &mut self,
521 caller: caller,
522 to: address,
523 token_uri: string,
524 ) -> Result<uint256> {
525 let token_id: uint256 = <TokensMinted<T>>::get(self.id)
526 .checked_add(1)
527 .ok_or("item id overflow")?
528 .into();
529 self.mint_with_token_uri_check_id(caller, to, token_id, token_uri)?;
530 Ok(token_id)
531 }
498532
499 /// @notice Function to mint token with the given tokenUri.533 /// @notice Function to mint token with the given tokenUri.
500 /// @dev `tokenId` should be obtained with `nextTokenId` method,534 /// @dev `tokenId` should be obtained with `nextTokenId` method,
501 /// unlike standard, you can't specify it manually535 /// unlike standard, you can't specify it manually
502 /// @param to The new owner536 /// @param to The new owner
503 /// @param tokenId ID of the minted RFT537 /// @param tokenId ID of the minted RFT
504 /// @param tokenUri Token URI that would be stored in the RFT properties538 /// @param tokenUri Token URI that would be stored in the RFT properties
505 #[solidity(rename_selector = "mintWithTokenURI")]539 #[solidity(hide, rename_selector = "mintWithTokenURI")]
506 #[weight(<SelfWeightOf<T>>::create_item())]540 #[weight(<SelfWeightOf<T>>::create_item())]
507 fn mint_with_token_uri(541 fn mint_with_token_uri_check_id(
508 &mut self,542 &mut self,
509 caller: caller,543 caller: caller,
510 to: address,544 to: address,
671 /// should be obtained with `nextTokenId` method705 /// should be obtained with `nextTokenId` method
672 /// @param to The new owner706 /// @param to The new owner
673 /// @param tokenIds IDs of the minted RFTs707 /// @param tokenIds IDs of the minted RFTs
708 #[solidity(hide)]
674 #[weight(<SelfWeightOf<T>>::create_multiple_items(token_ids.len() as u32))]709 #[weight(<SelfWeightOf<T>>::create_multiple_items(token_ids.len() as u32))]
675 fn mint_bulk(&mut self, caller: caller, to: address, token_ids: Vec<uint256>) -> Result<bool> {710 fn mint_bulk(&mut self, caller: caller, to: address, token_ids: Vec<uint256>) -> Result<bool> {
676 let caller = T::CrossAccountId::from_eth(caller);711 let caller = T::CrossAccountId::from_eth(caller);
713 /// numbers and first number should be obtained with `nextTokenId` method748 /// numbers and first number should be obtained with `nextTokenId` method
714 /// @param to The new owner749 /// @param to The new owner
715 /// @param tokens array of pairs of token ID and token URI for minted tokens750 /// @param tokens array of pairs of token ID and token URI for minted tokens
716 #[solidity(rename_selector = "mintBulkWithTokenURI")]751 #[solidity(hide, rename_selector = "mintBulkWithTokenURI")]
717 #[weight(<SelfWeightOf<T>>::create_multiple_items(tokens.len() as u32))]752 #[weight(<SelfWeightOf<T>>::create_multiple_items(tokens.len() as u32))]
718 fn mint_bulk_with_token_uri(753 fn mint_bulk_with_token_uri(
719 &mut self,754 &mut self,
784 ERC721,819 ERC721,
785 ERC721Enumerable,820 ERC721Enumerable,
786 ERC721UniqueExtensions,821 ERC721UniqueExtensions,
787 ERC721Mintable,822 ERC721UniqueMintable,
788 ERC721Burnable,823 ERC721Burnable,
789 ERC721Metadata(if(this.flags.erc721metadata)),824 ERC721Metadata(if(this.flags.erc721metadata)),
790 Collection(via(common_mut returns CollectionHandle<T>)),825 Collection(via(common_mut returns CollectionHandle<T>)),