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

difftreelog

feat add crossBalanceOf

Trubnikov Sergey2023-04-17parent: #ac9b5ee.patch.diff
in: master

11 files changed

modifiedpallets/nonfungible/src/erc.rsdiffbeforeafterboth
755 .map_err(|_| Error::Revert("token not found".into()))755 .map_err(|_| Error::Revert("token not found".into()))
756 }756 }
757
758 /// @notice Count all NFTs assigned to an owner
759 /// @dev NFTs assigned to the zero address are considered invalid, and this
760 /// function throws for queries about the zero address.
761 /// @param owner An cross address for whom to query the balance
762 /// @return The number of NFTs owned by `owner`, possibly zero
763 fn cross_balance_of(&self, owner: eth::CrossAddress) -> Result<U256> {
764 self.consume_store_reads(1)?;
765 let balance = <AccountBalance<T>>::get((self.id, owner.into_sub_cross_account::<T>()?));
766 Ok(balance.into())
767 }
757768
758 /// Returns the token properties.769 /// Returns the token properties.
759 ///770 ///
modifiedpallets/nonfungible/src/stubs/UniqueNFT.rawdiffbeforeafterboth

binary blob — no preview

modifiedpallets/nonfungible/src/stubs/UniqueNFT.soldiffbeforeafterboth
774}774}
775775
776/// @title Unique extensions for ERC721.776/// @title Unique extensions for ERC721.
777/// @dev the ERC-165 identifier for this interface is 0x16de3152777/// @dev the ERC-165 identifier for this interface is 0x323b1db8
778contract ERC721UniqueExtensions is Dummy, ERC165 {778contract ERC721UniqueExtensions is Dummy, ERC165 {
779 /// @notice A descriptive name for a collection of NFTs in this contract779 /// @notice A descriptive name for a collection of NFTs in this contract
780 /// @dev EVM selector for this function is: 0x06fdde03,780 /// @dev EVM selector for this function is: 0x06fdde03,
815 return CrossAddress(0x0000000000000000000000000000000000000000, 0);815 return CrossAddress(0x0000000000000000000000000000000000000000, 0);
816 }816 }
817
818 /// @notice Count all NFTs assigned to an owner
819 /// @dev NFTs assigned to the zero address are considered invalid, and this
820 /// function throws for queries about the zero address.
821 /// @param owner An cross address for whom to query the balance
822 /// @return The number of NFTs owned by `owner`, possibly zero
823 /// @dev EVM selector for this function is: 0x24e52cea,
824 /// or in textual repr: crossBalanceOf((address,uint256))
825 function crossBalanceOf(CrossAddress memory owner) public view returns (uint256) {
826 require(false, stub_error);
827 owner;
828 dummy;
829 return 0;
830 }
817831
818 /// Returns the token properties.832 /// Returns the token properties.
819 ///833 ///
modifiedpallets/refungible/src/erc.rsdiffbeforeafterboth
794 })794 })
795 }795 }
796
797 /// @notice Count all RFTs assigned to an owner
798 /// @dev RFTs assigned to the zero address are considered invalid, and this
799 /// function throws for queries about the zero address.
800 /// @param owner An cross address for whom to query the balance
801 /// @return The number of RFTs owned by `owner`, possibly zero
802 fn cross_balance_of(&self, owner: eth::CrossAddress) -> Result<U256> {
803 self.consume_store_reads(1)?;
804 let balance = <AccountBalance<T>>::get((self.id, owner.into_sub_cross_account::<T>()?));
805 Ok(balance.into())
806 }
796807
797 /// Returns the token properties.808 /// Returns the token properties.
798 ///809 ///
modifiedpallets/refungible/src/stubs/UniqueRefungible.soldiffbeforeafterboth
774}774}
775775
776/// @title Unique extensions for ERC721.776/// @title Unique extensions for ERC721.
777/// @dev the ERC-165 identifier for this interface is 0xb365c124777/// @dev the ERC-165 identifier for this interface is 0x9780edce
778contract ERC721UniqueExtensions is Dummy, ERC165 {778contract ERC721UniqueExtensions is Dummy, ERC165 {
779 /// @notice A descriptive name for a collection of NFTs in this contract779 /// @notice A descriptive name for a collection of NFTs in this contract
780 /// @dev EVM selector for this function is: 0x06fdde03,780 /// @dev EVM selector for this function is: 0x06fdde03,
815 return CrossAddress(0x0000000000000000000000000000000000000000, 0);815 return CrossAddress(0x0000000000000000000000000000000000000000, 0);
816 }816 }
817
818 /// @notice Count all RFTs assigned to an owner
819 /// @dev RFTs assigned to the zero address are considered invalid, and this
820 /// function throws for queries about the zero address.
821 /// @param owner An cross address for whom to query the balance
822 /// @return The number of RFTs owned by `owner`, possibly zero
823 /// @dev EVM selector for this function is: 0x24e52cea,
824 /// or in textual repr: crossBalanceOf((address,uint256))
825 function crossBalanceOf(CrossAddress memory owner) public view returns (uint256) {
826 require(false, stub_error);
827 owner;
828 dummy;
829 return 0;
830 }
817831
818 /// Returns the token properties.832 /// Returns the token properties.
819 ///833 ///
modifiedruntime/common/ethereum/sponsoring/refungible.rsdiffbeforeafterboth
227 | Symbol227 | Symbol
228 | Description228 | Description
229 | CrossOwnerOf { .. }229 | CrossOwnerOf { .. }
230 | CrossBalanceOf { .. }
230 | Properties { .. }231 | Properties { .. }
231 | NextTokenId232 | NextTokenId
232 | TokenContractAddress { .. }233 | TokenContractAddress { .. }
modifiedtests/src/eth/abi/nonFungible.jsondiffbeforeafterboth
384 "stateMutability": "view",384 "stateMutability": "view",
385 "type": "function"385 "type": "function"
386 },386 },
387 {
388 "inputs": [
389 {
390 "components": [
391 { "internalType": "address", "name": "eth", "type": "address" },
392 { "internalType": "uint256", "name": "sub", "type": "uint256" }
393 ],
394 "internalType": "struct CrossAddress",
395 "name": "owner",
396 "type": "tuple"
397 }
398 ],
399 "name": "crossBalanceOf",
400 "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
401 "stateMutability": "view",
402 "type": "function"
403 },
387 {404 {
388 "inputs": [405 "inputs": [
389 { "internalType": "uint256", "name": "tokenId", "type": "uint256" }406 { "internalType": "uint256", "name": "tokenId", "type": "uint256" }
modifiedtests/src/eth/api/UniqueNFT.soldiffbeforeafterboth
533}533}
534534
535/// @title Unique extensions for ERC721.535/// @title Unique extensions for ERC721.
536/// @dev the ERC-165 identifier for this interface is 0x16de3152536/// @dev the ERC-165 identifier for this interface is 0x323b1db8
537interface ERC721UniqueExtensions is Dummy, ERC165 {537interface ERC721UniqueExtensions is Dummy, ERC165 {
538 /// @notice A descriptive name for a collection of NFTs in this contract538 /// @notice A descriptive name for a collection of NFTs in this contract
539 /// @dev EVM selector for this function is: 0x06fdde03,539 /// @dev EVM selector for this function is: 0x06fdde03,
557 /// or in textual repr: crossOwnerOf(uint256)557 /// or in textual repr: crossOwnerOf(uint256)
558 function crossOwnerOf(uint256 tokenId) external view returns (CrossAddress memory);558 function crossOwnerOf(uint256 tokenId) external view returns (CrossAddress memory);
559
560 /// @notice Count all NFTs assigned to an owner
561 /// @dev NFTs assigned to the zero address are considered invalid, and this
562 /// function throws for queries about the zero address.
563 /// @param owner An cross address for whom to query the balance
564 /// @return The number of NFTs owned by `owner`, possibly zero
565 /// @dev EVM selector for this function is: 0x24e52cea,
566 /// or in textual repr: crossBalanceOf((address,uint256))
567 function crossBalanceOf(CrossAddress memory owner) external view returns (uint256);
559568
560 /// Returns the token properties.569 /// Returns the token properties.
561 ///570 ///
modifiedtests/src/eth/api/UniqueRefungible.soldiffbeforeafterboth
533}533}
534534
535/// @title Unique extensions for ERC721.535/// @title Unique extensions for ERC721.
536/// @dev the ERC-165 identifier for this interface is 0xb365c124536/// @dev the ERC-165 identifier for this interface is 0x9780edce
537interface ERC721UniqueExtensions is Dummy, ERC165 {537interface ERC721UniqueExtensions is Dummy, ERC165 {
538 /// @notice A descriptive name for a collection of NFTs in this contract538 /// @notice A descriptive name for a collection of NFTs in this contract
539 /// @dev EVM selector for this function is: 0x06fdde03,539 /// @dev EVM selector for this function is: 0x06fdde03,
557 /// or in textual repr: crossOwnerOf(uint256)557 /// or in textual repr: crossOwnerOf(uint256)
558 function crossOwnerOf(uint256 tokenId) external view returns (CrossAddress memory);558 function crossOwnerOf(uint256 tokenId) external view returns (CrossAddress memory);
559
560 /// @notice Count all RFTs assigned to an owner
561 /// @dev RFTs assigned to the zero address are considered invalid, and this
562 /// function throws for queries about the zero address.
563 /// @param owner An cross address for whom to query the balance
564 /// @return The number of RFTs owned by `owner`, possibly zero
565 /// @dev EVM selector for this function is: 0x24e52cea,
566 /// or in textual repr: crossBalanceOf((address,uint256))
567 function crossBalanceOf(CrossAddress memory owner) external view returns (uint256);
559568
560 /// Returns the token properties.569 /// Returns the token properties.
561 ///570 ///
modifiedtests/src/eth/nonFungible.test.tsdiffbeforeafterboth
663 await expect(collectionEvm.methods[testCase](receiver, 999999).send({from: sender})).to.be.rejected;663 await expect(collectionEvm.methods[testCase](receiver, 999999).send({from: sender})).to.be.rejected;
664 }));664 }));
665
666 itEth('Check crossBalanceOf()', async ({helper}) => {
667 const collection = await helper.nft.mintCollection(minter, {});
668 const owner = await helper.ethCrossAccount.createAccountWithBalance(donor);
669 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
670 const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner.eth);
671
672 expect(BigInt(await collectionEvm.methods.crossBalanceOf(owner).call({from: owner.eth})) === 0n).to.be.true;
673
674 for (let i = 1n; i < 100n; i++) {
675 await collection.mintToken(minter, {Ethereum: owner.eth});
676 expect(BigInt(await collectionEvm.methods.crossBalanceOf(owner).call({from: owner.eth})) === i).to.be.true;
677 }
678 });
679
680 itEth('Check crossOwnerOf()', async ({helper}) => {
681 const collection = await helper.nft.mintCollection(minter, {});
682 let owner = await helper.ethCrossAccount.createAccountWithBalance(donor);
683 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
684 const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner.eth);
685 const {tokenId} = await collection.mintToken(minter, {Ethereum: owner.eth});
686
687 for (let i = 1n; i < 100n; i++) {
688 const ownerCross = await collectionEvm.methods.crossOwnerOf(tokenId).call({from: owner.eth});
689 expect(ownerCross.eth).to.be.eq(owner.eth);
690 expect(ownerCross.sub).to.be.eq(owner.sub);
691
692 const newOwner = await helper.ethCrossAccount.createAccountWithBalance(donor);
693 await collectionEvm.methods.transferCross(newOwner, tokenId).send({from: owner.eth});
694 owner = newOwner;
695 }
696 });
665});697});
666698
667describe('NFT: Fees', () => {699describe('NFT: Fees', () => {
modifiedtests/src/eth/reFungible.test.tsdiffbeforeafterboth
585 expect(event.returnValues.tokenId).to.equal(tokenId.toString());585 expect(event.returnValues.tokenId).to.equal(tokenId.toString());
586 });586 });
587
588 itEth('Check crossBalanceOf()', async ({helper}) => {
589 const collection = await helper.rft.mintCollection(minter, {});
590 const owner = await helper.ethCrossAccount.createAccountWithBalance(donor);
591 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
592 const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner.eth);
593
594 expect(BigInt(await collectionEvm.methods.crossBalanceOf(owner).call({from: owner.eth})) === 0n).to.be.true;
595
596 for (let i = 1n; i < 100n; i++) {
597 await collection.mintToken(minter, 100n, {Ethereum: owner.eth});
598 expect(BigInt(await collectionEvm.methods.crossBalanceOf(owner).call({from: owner.eth})) === i).to.be.true;
599 }
600 });
601
602 itEth.only('Check crossOwnerOf()', async ({helper}) => {
603 const collection = await helper.rft.mintCollection(minter, {});
604 let owner = await helper.ethCrossAccount.createAccountWithBalance(donor);
605 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
606 const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner.eth);
607 const {tokenId} = await collection.mintToken(minter, 100n,{Ethereum: owner.eth});
608
609 for (let i = 1n; i < 100n; i++) {
610 const ownerCross = await collectionEvm.methods.crossOwnerOf(tokenId).call({from: owner.eth});
611 expect(ownerCross.eth).to.be.eq(owner.eth);
612 expect(ownerCross.sub).to.be.eq(owner.sub);
613
614 const newOwner = await helper.ethCrossAccount.createAccountWithBalance(donor);
615 await collectionEvm.methods.transferCross(newOwner, tokenId).send({from: owner.eth});
616 owner = newOwner;
617 }
618
619 const tokenAddress = helper.ethAddress.fromTokenId(collection.collectionId, tokenId);
620 const tokenContract = await helper.ethNativeContract.rftToken(tokenAddress, owner.eth, true);
621 const newOwner = await helper.ethCrossAccount.createAccountWithBalance(donor);
622 await tokenContract.methods.transferCross(newOwner, 50).send({from: owner.eth});
623 const ownerCross = await collectionEvm.methods.crossOwnerOf(tokenId).call({from: owner.eth});
624 expect(ownerCross.eth.toUpperCase()).to.be.eq('0XFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF');
625 expect(ownerCross.sub).to.be.eq('0');
626 });
587});627});
588628
589describe('RFT: Fees', () => {629describe('RFT: Fees', () => {