difftreelog
fix review remarks
in: master
1 file changed
tests/src/util/playgrounds/unique.tsdiffbeforeafterboth923 return this.helper.util.isTokenTransferSuccess(result.result.events, collectionId, tokenId, {Substrate: typeof signer === 'string' ? signer : signer.address}, addressObj, amount);923 return this.helper.util.isTokenTransferSuccess(result.result.events, collectionId, tokenId, {Substrate: typeof signer === 'string' ? signer : signer.address}, addressObj, amount);924 }924 }925925926 /**926 /**927 * 927 * 928 * Change ownership of a NFT on behalf of the owner. 928 * Change ownership of a token(s) on behalf of the owner. 929 * 929 * 930 * @param signer keyring of signer930 * @param signer keyring of signer931 * @param collectionId ID of collection931 * @param collectionId ID of collection932 * @param tokenId ID of token932 * @param tokenId ID of token933 * @param fromAddressObj address on behalf of which the token will be sent933 * @param fromAddressObj address on behalf of which the token will be sent934 * @param toAddressObj new token owner934 * @param toAddressObj new token owner935 * @param amount amount of tokens to be transfered. For NFT must be set to 1n935 * @param amount amount of tokens to be transfered. For NFT must be set to 1n936 * @example transferTokenFrom(aliceKeyring, 10, 5, {Substrate: "5DyN4Y92vZCjv38fg"}, {Ethereum: "0x9F0583DbB85..."})936 * @example transferTokenFrom(aliceKeyring, 10, 5, {Substrate: "5DyN4Y92vZCjv38fg"}, {Ethereum: "0x9F0583DbB85..."})937 * @returns true if the token success, otherwise false937 * @returns true if the token success, otherwise false938 */938 */939 async transferTokenFrom(signer: TSigner, collectionId: number, tokenId: number, fromAddressObj: ICrossAccountId, toAddressObj: ICrossAccountId, amount=1n): Promise<boolean> {939 async transferTokenFrom(signer: TSigner, collectionId: number, tokenId: number, fromAddressObj: ICrossAccountId, toAddressObj: ICrossAccountId, amount=1n): Promise<boolean> {940 const result = await this.helper.executeExtrinsic(940 const result = await this.helper.executeExtrinsic(941 signer,941 signer,945 return this.helper.util.isTokenTransferSuccess(result.result.events, collectionId, tokenId, fromAddressObj, toAddressObj, amount);945 return this.helper.util.isTokenTransferSuccess(result.result.events, collectionId, tokenId, fromAddressObj, toAddressObj, amount);946 }946 }947947948 /**948 /**949 * 949 * 950 * Destroys a concrete instance of NFT.950 * Destroys a concrete instance of NFT/RFT or burns a specified amount of fungible tokens.951 * 951 * 952 * @param signer keyring of signer952 * @param signer keyring of signer953 * @param collectionId ID of collection953 * @param collectionId ID of collection954 * @param tokenId ID of token954 * @param tokenId ID of token955 * @param label 955 * @param label 956 * @param amount amount of tokens to be burned. For NFT must be set to 1n956 * @param amount amount of tokens to be burned. For NFT must be set to 1n957 * @example burnToken(aliceKeyring, 10, 5);957 * @example burnToken(aliceKeyring, 10, 5);958 * @returns ```true``` and burnt token number is extrinsic success. Otherwise ```false``` and ```null```958 * @returns ```true``` and burnt token number is extrinsic success. Otherwise ```false``` and ```null```959 */959 */960 async burnToken(signer: TSigner, collectionId: number, tokenId: number, label?: string, amount=1n): Promise<{960 async burnToken(signer: TSigner, collectionId: number, tokenId: number, label?: string, amount=1n): Promise<{961 success: boolean,961 success: boolean,962 token: number | null962 token: number | null1017 return this.helper.util.findCollectionInEvents(approveResult.result.events, collectionId, 'common', 'Approved', label);1017 return this.helper.util.findCollectionInEvents(approveResult.result.events, collectionId, 'common', 'Approved', label);1018 }1018 }101910191020 /**1020 /**1021 * Get amount of RFT pieces approved to transfer1021 * Get the amount of token pieces approved to transfer1022 * @param collectionId ID of collection1022 * @param collectionId ID of collection1023 * @param tokenId ID of token1023 * @param tokenId ID of token1024 * @param toAccountObj 1024 * @param toAccountObj 1025 * @param fromAccountObj1025 * @param fromAccountObj1026 * @example getTokenApprovedPieces(10, 5, {Substrate: "5DyN4Y92vZCjv38fg..."}, {Substrate: "5ERZNF88Mm7UGfPP3mdG..."})1026 * @example getTokenApprovedPieces(10, 5, {Substrate: "5DyN4Y92vZCjv38fg..."}, {Substrate: "5ERZNF88Mm7UGfPP3mdG..."})1027 * @returns number of approved to transfer pieces1027 * @returns number of approved to transfer pieces1028 */1028 */1029 async getTokenApprovedPieces(collectionId: number, tokenId: number, toAccountObj: ICrossAccountId, fromAccountObj: ICrossAccountId): Promise<bigint> {1029 async getTokenApprovedPieces(collectionId: number, tokenId: number, toAccountObj: ICrossAccountId, fromAccountObj: ICrossAccountId): Promise<bigint> {1030 return (await this.helper.callRpc('api.rpc.unique.allowance', [collectionId, fromAccountObj, toAccountObj, tokenId])).toBigInt();1030 return (await this.helper.callRpc('api.rpc.unique.allowance', [collectionId, fromAccountObj, toAccountObj, tokenId])).toBigInt();1031 }1031 }14941494149514951496class RFTGroup extends NFTnRFT {1496class RFTGroup extends NFTnRFT {1497 /**1497 /**1498 * Get collection object1498 * Get collection object1499 * @param collectionId ID of collection1499 * @param collectionId ID of collection1500 * @example getCollectionObject(2);1500 * @example getCollectionObject(2);1501 * @returns instance of UniqueNFTCollection1501 * @returns instance of UniqueRFTCollection1502 */1502 */1503 getCollectionObject(collectionId: number): UniqueRFTCollection {1503 getCollectionObject(collectionId: number): UniqueRFTCollection {1504 return new UniqueRFTCollection(collectionId, this.helper);1504 return new UniqueRFTCollection(collectionId, this.helper);1505 }1505 }17141714171517151716class FTGroup extends CollectionGroup {1716class FTGroup extends CollectionGroup {1717 /**1717 /**1718 * Get collection object1718 * Get collection object1719 * @param collectionId ID of collection1719 * @param collectionId ID of collection1720 * @example getCollectionObject(2);1720 * @example getCollectionObject(2);1721 * @returns instance of UniqueNFTCollection1721 * @returns instance of UniqueFTCollection1722 */1722 */1723 getCollectionObject(collectionId: number): UniqueFTCollection {1723 getCollectionObject(collectionId: number): UniqueFTCollection {1724 return new UniqueFTCollection(collectionId, this.helper);1724 return new UniqueFTCollection(collectionId, this.helper);1725 }1725 }1777 return this.helper.util.findCollectionInEvents(creationResult.result.events, collectionId, 'common', 'ItemCreated', label);1777 return this.helper.util.findCollectionInEvents(creationResult.result.events, collectionId, 'common', 'ItemCreated', label);1778 }1778 }17791780 /**1781 * Mint multiple RFT tokens with one owner1782 * @param signer keyring of signer1783 * @param collectionId ID of collection1784 * @param owner tokens owner1785 * @param tokens array of tokens with properties and pieces1786 * @param label 1787 * @example mintMultipleTokensWithOneOwner(aliceKeyring, 10, {Substrate: "5GHoZe9c73RYbVzq..."}, [{pieces: 100000n, properties: [{key: "gender", value: "male"}]}]);1788 * @returns array of newly created RFT tokens1789 */179017791791 /**1780 /**1792 * Mint multiple Fungible tokens with one owner1781 * Mint multiple Fungible tokens with one owner1812 return this.helper.util.findCollectionInEvents(creationResult.result.events, collectionId, 'common', 'ItemCreated', label);1801 return this.helper.util.findCollectionInEvents(creationResult.result.events, collectionId, 'common', 'ItemCreated', label);1813 }1802 }181418031815 /**1804 /**1816 * Get top 10 token owners1805 * Get the top 10 owners with the largest balance for the Fungible collection 1817 * @param collectionId ID of collection1806 * @param collectionId ID of collection1818 * @example getTop10Owners(10);1807 * @example getTop10Owners(10);1819 * @returns array of ```ICrossAccountId```1808 * @returns array of ```ICrossAccountId```1820 */1809 */1821 async getTop10Owners(collectionId: number): Promise<ICrossAccountId[]> {1810 async getTop10Owners(collectionId: number): Promise<ICrossAccountId[]> {1822 return (await this.helper.callRpc('api.rpc.unique.tokenOwners', [collectionId, 0])).toJSON().map(crossAccountIdFromLower);1811 return (await this.helper.callRpc('api.rpc.unique.tokenOwners', [collectionId, 0])).toJSON().map(crossAccountIdFromLower);1823 }1812 }1887 return await super.burnTokenFrom(signer, collectionId, fromAddressObj, 0, label, amount);1876 return await super.burnTokenFrom(signer, collectionId, fromAddressObj, 0, label, amount);1888 }1877 }188918781890 /**1879 /**1891 * 1880 * Get total collection supply1892 * @param collectionId 1881 * @param collectionId 1893 * @returns 1882 * @returns 1894 */1883 */1895 async getTotalPieces(collectionId: number): Promise<bigint> {1884 async getTotalPieces(collectionId: number): Promise<bigint> {1896 return (await this.helper.callRpc('api.rpc.unique.totalPieces', [collectionId, 0])).unwrap().toBigInt();1885 return (await this.helper.callRpc('api.rpc.unique.totalPieces', [collectionId, 0])).unwrap().toBigInt();1897 }1886 }19731962197419631975class BalanceGroup extends HelperGroup {1964class BalanceGroup extends HelperGroup {1965 /**1966 * Representation of the native token in the smallest unit1967 * @example getOneTokenNominal()1968 * @returns ```BigInt``` representation of the native token in the smallest unit, e.g. ```1_000_000_000_000_000_000n``` for QTZ.1969 */1976 getOneTokenNominal(): bigint {1970 getOneTokenNominal(): bigint {1977 const chainProperties = this.helper.chain.getChainProperties();1971 const chainProperties = this.helper.chain.getChainProperties();1978 return 10n ** BigInt((chainProperties.tokenDecimals || [18])[0]);1972 return 10n ** BigInt((chainProperties.tokenDecimals || [18])[0]);20282022202920232030class AddressGroup extends HelperGroup {2024class AddressGroup extends HelperGroup {2025 /**2026 * Normalizes the address to the specified ss58 format, by default ```42```.2027 * @param address substrate address2028 * @param ss58Format format for address conversion, by default ```42```2029 * @example normalizeSubstrate("unjKJQJrRd238pkUZZvzDQrfKuM39zBSnQ5zjAGAGcdRhaJTx") // returns 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY2030 * @returns substrate address converted to normalized (i.e., starting with 5) or specified explicitly representation2031 */2031 normalizeSubstrate(address: TSubstrateAccount, ss58Format = 42): TSubstrateAccount {2032 normalizeSubstrate(address: TSubstrateAccount, ss58Format = 42): TSubstrateAccount {2032 return this.helper.util.normalizeSubstrateAddress(address, ss58Format);2033 return this.helper.util.normalizeSubstrateAddress(address, ss58Format);2033 }2034 }