git.delta.rocks / unique-network / refs/commits / 97bc0a17e0b7

difftreelog

test(util) addtional docs + minor refactoring

Fahrrader2022-09-02parent: #9df3a53.patch.diff
in: master

1 file changed

modifiedtests/src/util/playgrounds/unique.tsdiffbeforeafterboth
967 return (await this.helper.callRpc('api.rpc.unique.accountTokens', [collectionId, addressObj])).toJSON();967 return (await this.helper.callRpc('api.rpc.unique.accountTokens', [collectionId, addressObj])).toJSON();
968 }968 }
969969
970 /**970 /**
971 * Get token data971 * Get token data
972 * 972 *
973 * @param collectionId ID of collection973 * @param collectionId ID of collection
974 * @param tokenId ID of token974 * @param tokenId ID of token
975 * @param blockHashAt 975 * @param propertyKeys optionally filter the token properties to only these keys
976 * @param propertyKeys976 * @param blockHashAt optionally query the data at some block with this hash
977 * @example getToken(10, 5);977 * @example getToken(10, 5);
978 * @returns human readable token data 978 * @returns human readable token data
979 */979 */
980 async getToken(collectionId: number, tokenId: number, blockHashAt?: string, propertyKeys?: string[]): Promise<{980 async getToken(collectionId: number, tokenId: number, propertyKeys: string[] = [], blockHashAt?: string): Promise<{
981 properties: IProperty[];981 properties: IProperty[];
982 owner: ICrossAccountId;982 owner: ICrossAccountId;
983 normalizedOwner: ICrossAccountId;983 normalizedOwner: ICrossAccountId;
987 tokenData = await this.helper.callRpc('api.rpc.unique.tokenData', [collectionId, tokenId]);987 tokenData = await this.helper.callRpc('api.rpc.unique.tokenData', [collectionId, tokenId]);
988 }988 }
989 else {989 else {
990 if(typeof propertyKeys === 'undefined') {990 if(propertyKeys.length == 0) {
991 const collection = (await this.helper.callRpc('api.rpc.unique.collectionById', [collectionId])).toHuman();991 const collection = (await this.helper.callRpc('api.rpc.unique.collectionById', [collectionId])).toHuman();
992 if(!collection) return null;992 if(!collection) return null;
993 propertyKeys = collection.tokenPropertyPermissions.map((x: ITokenPropertyPermission) => x.key);993 propertyKeys = collection.tokenPropertyPermissions.map((x: ITokenPropertyPermission) => x.key);
1025 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'common', 'PropertyPermissionSet');1025 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'common', 'PropertyPermissionSet');
1026 }1026 }
10271027
1028 /**1028 /**
1029 * Set token properties1029 * Set token properties
1030 * 1030 *
1031 * @param signer keyring of signer1031 * @param signer keyring of signer
1032 * @param collectionId ID of collection1032 * @param collectionId ID of collection
1033 * @param tokenId ID of token1033 * @param tokenId ID of token
1034 * @param properties 1034 * @param properties key-value pairs of metadata which to add to a token. Keys must be permitted in the collection
1035 * @example setTokenProperties(aliceKeyring, 10, 5, [{key: "gender", value: "female"}, {key: "age", value: "23"}])1035 * @example setTokenProperties(aliceKeyring, 10, 5, [{key: "gender", value: "female"}, {key: "age", value: "23"}])
1036 * @returns ```true``` if extrinsic success, otherwise ```false```1036 * @returns ```true``` if extrinsic success, otherwise ```false```
1037 */1037 */
1038 async setTokenProperties(signer: TSigner, collectionId: number, tokenId: number, properties: IProperty[]): Promise<boolean> {1038 async setTokenProperties(signer: TSigner, collectionId: number, tokenId: number, properties: IProperty[]): Promise<boolean> {
1039 const result = await this.helper.executeExtrinsic(1039 const result = await this.helper.executeExtrinsic(
1040 signer,1040 signer,
1119 return new UniqueNFTToken(tokenId, this.getCollectionObject(collectionId));1119 return new UniqueNFTToken(tokenId, this.getCollectionObject(collectionId));
1120 }1120 }
11211121
1122 /**1122 /**
1123 * Get token's owner1123 * Get token's owner
1124 * @param collectionId ID of collection1124 * @param collectionId ID of collection
1125 * @param tokenId ID of token1125 * @param tokenId ID of token
1126 * @param blockHashAt 1126 * @param blockHashAt optionally query the data at the block with this hash
1127 * @example getTokenOwner(10, 5);1127 * @example getTokenOwner(10, 5);
1128 * @returns Address in CrossAccountId format, e.g. {Substrate: "5DnSF6RRjwteE3BrCj..."}1128 * @returns Address in CrossAccountId format, e.g. {Substrate: "5DnSF6RRjwteE3BrCj..."}
1129 */1129 */
1130 async getTokenOwner(collectionId: number, tokenId: number, blockHashAt?: string): Promise<ICrossAccountId> {1130 async getTokenOwner(collectionId: number, tokenId: number, blockHashAt?: string): Promise<ICrossAccountId> {
1131 let owner;1131 let owner;
1132 if (typeof blockHashAt === 'undefined') {1132 if (typeof blockHashAt === 'undefined') {
1201 return owner.Substrate ? {Substrate: this.helper.address.normalizeSubstrate(owner.Substrate)} : owner;1201 return owner.Substrate ? {Substrate: this.helper.address.normalizeSubstrate(owner.Substrate)} : owner;
1202 }1202 }
12031203
1204 /**1204 /**
1205 * Get tokens nested in the provided token1205 * Get tokens nested in the provided token
1206 * @param collectionId ID of collection1206 * @param collectionId ID of collection
1207 * @param tokenId ID of token1207 * @param tokenId ID of token
1208 * @param blockHashAt 1208 * @param blockHashAt optionally query the data at the block with this hash
1209 * @example getTokenChildren(10, 5);1209 * @example getTokenChildren(10, 5);
1210 * @returns tokens whose depth of nesting is <= 5 1210 * @returns tokens whose depth of nesting is <= 5
1211 */1211 */
1212 async getTokenChildren(collectionId: number, tokenId: number, blockHashAt?: string): Promise<IToken[]> {1212 async getTokenChildren(collectionId: number, tokenId: number, blockHashAt?: string): Promise<IToken[]> {
1213 let children;1213 let children;
1214 if(typeof blockHashAt === 'undefined') {1214 if(typeof blockHashAt === 'undefined') {
1695 return (await this.helper.callRpc('api.rpc.unique.balance', [collectionId, addressObj, 0])).toBigInt();1695 return (await this.helper.callRpc('api.rpc.unique.balance', [collectionId, addressObj, 0])).toBigInt();
1696 }1696 }
16971697
1698 /**1698 /**
1699 * Transfer tokens to address1699 * Transfer tokens to address
1700 * @param signer keyring of signer1700 * @param signer keyring of signer
1701 * @param collectionId ID of collection1701 * @param collectionId ID of collection
1702 * @param toAddressObj address recepient1702 * @param toAddressObj address recipient
1703 * @param amount amount of tokens to be sent1703 * @param amount amount of tokens to be sent
1704 * @example transfer(aliceKeyring, 10, {Substrate: "5GHoZe9c73RYbVzq..."}, 1000n);1704 * @example transfer(aliceKeyring, 10, {Substrate: "5GHoZe9c73RYbVzq..."}, 1000n);
1705 * @returns ```true``` if extrinsic success, otherwise ```false``` 1705 * @returns ```true``` if extrinsic success, otherwise ```false```
1706 */1706 */
1707 async transfer(signer: TSigner, collectionId: number, toAddressObj: ICrossAccountId, amount=1n) {1707 async transfer(signer: TSigner, collectionId: number, toAddressObj: ICrossAccountId, amount=1n) {
1708 return await super.transferToken(signer, collectionId, 0, toAddressObj, amount);1708 return await super.transferToken(signer, collectionId, 0, toAddressObj, amount);
1709 }1709 }
1862 return (await this.helper.callRpc('api.rpc.eth.getBalance', [address])).toBigInt();1862 return (await this.helper.callRpc('api.rpc.eth.getBalance', [address])).toBigInt();
1863 }1863 }
18641864
1865 /**1865 /**
1866 * Transfer tokens to substrate address1866 * Transfer tokens to substrate address
1867 * @param signer keyring of signer1867 * @param signer keyring of signer
1868 * @param address substrate address of a recepient1868 * @param address substrate address of a recipient
1869 * @param amount amount of tokens to be transfered1869 * @param amount amount of tokens to be transfered
1870 * @example transferToSubstrate(aliceKeyring, "5GrwvaEF5zXb26Fz...", 100_000_000_000n);1870 * @example transferToSubstrate(aliceKeyring, "5GrwvaEF5zXb26Fz...", 100_000_000_000n);
1871 * @returns ```true``` if extrinsic success, otherwise ```false```1871 * @returns ```true``` if extrinsic success, otherwise ```false```
1872 */1872 */
1873 async transferToSubstrate(signer: TSigner, address: TSubstrateAccount, amount: bigint | string): Promise<boolean> {1873 async transferToSubstrate(signer: TSigner, address: TSubstrateAccount, amount: bigint | string): Promise<boolean> {
1874 const result = await this.helper.executeExtrinsic(signer, 'api.tx.balances.transfer', [address, amount], true/*, `Unable to transfer balance from ${this.helper.getSignerAddress(signer)} to ${address}`*/);1874 const result = await this.helper.executeExtrinsic(signer, 'api.tx.balances.transfer', [address, amount], true/*, `Unable to transfer balance from ${this.helper.getSignerAddress(signer)} to ${address}`*/);
18751875
2070 }2070 }
20712071
2072 async getToken(tokenId: number, blockHashAt?: string) {2072 async getToken(tokenId: number, blockHashAt?: string) {
2073 return await this.helper.nft.getToken(this.collectionId, tokenId, blockHashAt);2073 return await this.helper.nft.getToken(this.collectionId, tokenId, [], blockHashAt);
2074 }2074 }
20752075
2076 async getTokenOwner(tokenId: number, blockHashAt?: string) {2076 async getTokenOwner(tokenId: number, blockHashAt?: string) {