git.delta.rocks / unique-network / refs/commits / 9df3a53c8a16

difftreelog

test(util) replace label with native error message + shift default amounts in functions to 1

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

1 file changed

modifiedtests/src/util/playgrounds/unique.tsdiffbeforeafterboth
91 return encodeAddress(decodeAddress(address), ss58Format);91 return encodeAddress(decodeAddress(address), ss58Format);
92 }92 }
9393
94 static extractCollectionIdFromCreationResult(creationResult: ITransactionResult, label = 'new collection') {94 static extractCollectionIdFromCreationResult(creationResult: ITransactionResult) {
95 if (creationResult.status !== this.transactionStatus.SUCCESS) {95 if (creationResult.status !== this.transactionStatus.SUCCESS) {
96 throw Error(`Unable to create collection for ${label}`);96 throw Error('Unable to create collection!');
97 }97 }
9898
99 let collectionId = null;99 let collectionId = null;
104 });104 });
105105
106 if (collectionId === null) {106 if (collectionId === null) {
107 throw Error(`No CollectionCreated event for ${label}`);107 throw Error('No CollectionCreated event was found!');
108 }108 }
109109
110 return collectionId;110 return collectionId;
111 }111 }
112112
113 static extractTokensFromCreationResult(creationResult: ITransactionResult, label = 'new tokens') {113 static extractTokensFromCreationResult(creationResult: ITransactionResult) {
114 if (creationResult.status !== this.transactionStatus.SUCCESS) {114 if (creationResult.status !== this.transactionStatus.SUCCESS) {
115 throw Error(`Unable to create tokens for ${label}`);115 throw Error('Unable to create tokens!');
116 }116 }
117 let success = false;117 let success = false;
118 const tokens = [] as any;118 const tokens = [] as any;
130 return {success, tokens};130 return {success, tokens};
131 }131 }
132132
133 static extractTokensFromBurnResult(burnResult: ITransactionResult, label = 'burned tokens') {133 static extractTokensFromBurnResult(burnResult: ITransactionResult) {
134 if (burnResult.status !== this.transactionStatus.SUCCESS) {134 if (burnResult.status !== this.transactionStatus.SUCCESS) {
135 throw Error(`Unable to burn tokens for ${label}`);135 throw Error('Unable to burn tokens!');
136 }136 }
137 let success = false;137 let success = false;
138 const tokens = [] as any;138 const tokens = [] as any;
150 return {success, tokens};150 return {success, tokens};
151 }151 }
152152
153 static findCollectionInEvents(events: {event: IChainEvent}[], collectionId: number, expectedSection: string, expectedMethod: string, label?: string) {153 static findCollectionInEvents(events: {event: IChainEvent}[], collectionId: number, expectedSection: string, expectedMethod: string) {
154 let eventId = null;154 let eventId = null;
155 events.forEach(({event: {data, method, section}}) => {155 events.forEach(({event: {data, method, section}}) => {
156 if ((section === expectedSection) && (method === expectedMethod)) {156 if ((section === expectedSection) && (method === expectedMethod)) {
159 });159 });
160160
161 if (eventId === null) {161 if (eventId === null) {
162 throw Error(`No ${expectedMethod} event for ${label}`);162 throw Error(`No ${expectedMethod} event was found!`);
163 }163 }
164 return eventId === collectionId;164 return eventId === collectionId;
165 }165 }
364 return call(...params);364 return call(...params);
365 }365 }
366366
367 async executeExtrinsic(sender: TSigner, extrinsic: string, params: any[], expectSuccess=false, failureMessage='expected success') {367 async executeExtrinsic(sender: TSigner, extrinsic: string, params: any[], expectSuccess=false/*, failureMessage='expected success'*/) {
368 if(this.api === null) throw Error('API not initialized');368 if(this.api === null) throw Error('API not initialized');
369 if(!extrinsic.startsWith('api.tx.')) throw Error(`${extrinsic} is not transaction`);369 if(!extrinsic.startsWith('api.tx.')) throw Error(`${extrinsic} is not transaction`);
370370
396396
397 this.chainLog.push(log);397 this.chainLog.push(log);
398398
399 if(expectSuccess && result.status !== this.transactionStatus.SUCCESS) throw Error(failureMessage);399 if(expectSuccess && result.status !== this.transactionStatus.SUCCESS) throw Error(`${result.moduleError}`);
400 return result;400 return result;
401 }401 }
402402
556 * 556 *
557 * @param signer keyring of signer557 * @param signer keyring of signer
558 * @param collectionId ID of collection558 * @param collectionId ID of collection
559 * @param label extra label for log
560 * @example await helper.collection.burn(aliceKeyring, 3);559 * @example await helper.collection.burn(aliceKeyring, 3);
561 * @returns ```true``` if extrinsic success, otherwise ```false```560 * @returns ```true``` if extrinsic success, otherwise ```false```
562 */561 */
563 async burn(signer: TSigner, collectionId: number, label?: string): Promise<boolean> {562 async burn(signer: TSigner, collectionId: number): Promise<boolean> {
564 if(typeof label === 'undefined') label = `collection #${collectionId}`;
565 const result = await this.helper.executeExtrinsic(563 const result = await this.helper.executeExtrinsic(
566 signer,564 signer,
567 'api.tx.unique.destroyCollection', [collectionId],565 'api.tx.unique.destroyCollection', [collectionId],
568 true, `Unable to burn collection for ${label}`,566 true,
569 );567 );
570568
571 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'common', 'CollectionDestroyed', label);569 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'common', 'CollectionDestroyed');
572 }570 }
573571
574 /**572 /**
577 * @param signer keyring of signer575 * @param signer keyring of signer
578 * @param collectionId ID of collection576 * @param collectionId ID of collection
579 * @param sponsorAddress Sponsor substrate address577 * @param sponsorAddress Sponsor substrate address
580 * @param label extra label for log
581 * @example setSponsor(aliceKeyring, 10, "5DyN4Y92vZCjv38fg...")578 * @example setSponsor(aliceKeyring, 10, "5DyN4Y92vZCjv38fg...")
582 * @returns ```true``` if extrinsic success, otherwise ```false```579 * @returns ```true``` if extrinsic success, otherwise ```false```
583 */580 */
584 async setSponsor(signer: TSigner, collectionId: number, sponsorAddress: TSubstrateAccount, label?: string): Promise<boolean> {581 async setSponsor(signer: TSigner, collectionId: number, sponsorAddress: TSubstrateAccount): Promise<boolean> {
585 if(typeof label === 'undefined') label = `collection #${collectionId}`;
586 const result = await this.helper.executeExtrinsic(582 const result = await this.helper.executeExtrinsic(
587 signer,583 signer,
588 'api.tx.unique.setCollectionSponsor', [collectionId, sponsorAddress],584 'api.tx.unique.setCollectionSponsor', [collectionId, sponsorAddress],
589 true, `Unable to set collection sponsor for ${label}`,585 true,
590 );586 );
591587
592 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'unique', 'CollectionSponsorSet', label);588 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'unique', 'CollectionSponsorSet');
593 }589 }
594590
595 /**591 /**
596 * Confirms consent to sponsor the collection on behalf of the signer.592 * Confirms consent to sponsor the collection on behalf of the signer.
597 * 593 *
598 * @param signer keyring of signer594 * @param signer keyring of signer
599 * @param collectionId ID of collection595 * @param collectionId ID of collection
600 * @param label extra label for log
601 * @example confirmSponsorship(aliceKeyring, 10)596 * @example confirmSponsorship(aliceKeyring, 10)
602 * @returns ```true``` if extrinsic success, otherwise ```false```597 * @returns ```true``` if extrinsic success, otherwise ```false```
603 */598 */
604 async confirmSponsorship(signer: TSigner, collectionId: number, label?: string): Promise<boolean> {599 async confirmSponsorship(signer: TSigner, collectionId: number): Promise<boolean> {
605 if(typeof label === 'undefined') label = `collection #${collectionId}`;
606 const result = await this.helper.executeExtrinsic(600 const result = await this.helper.executeExtrinsic(
607 signer,601 signer,
608 'api.tx.unique.confirmSponsorship', [collectionId],602 'api.tx.unique.confirmSponsorship', [collectionId],
609 true, `Unable to confirm collection sponsorship for ${label}`,603 true,
610 );604 );
611605
612 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'unique', 'SponsorshipConfirmed', label);606 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'unique', 'SponsorshipConfirmed');
613 }607 }
614608
615 /**609 /**
618 * @param signer keyring of signer612 * @param signer keyring of signer
619 * @param collectionId ID of collection613 * @param collectionId ID of collection
620 * @param limits collection limits object614 * @param limits collection limits object
621 * @param label extra label for log
622 * @example615 * @example
623 * await setLimits(616 * await setLimits(
624 * aliceKeyring,617 * aliceKeyring,
630 * )623 * )
631 * @returns ```true``` if extrinsic success, otherwise ```false```624 * @returns ```true``` if extrinsic success, otherwise ```false```
632 */625 */
633 async setLimits(signer: TSigner, collectionId: number, limits: ICollectionLimits, label?: string): Promise<boolean> {626 async setLimits(signer: TSigner, collectionId: number, limits: ICollectionLimits): Promise<boolean> {
634 if(typeof label === 'undefined') label = `collection #${collectionId}`;
635 const result = await this.helper.executeExtrinsic(627 const result = await this.helper.executeExtrinsic(
636 signer,628 signer,
637 'api.tx.unique.setCollectionLimits', [collectionId, limits],629 'api.tx.unique.setCollectionLimits', [collectionId, limits],
638 true, `Unable to set collection limits for ${label}`,630 true,
639 );631 );
640632
641 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'unique', 'CollectionLimitSet', label);633 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'unique', 'CollectionLimitSet');
642 }634 }
643635
644 /**636 /**
647 * @param signer keyring of signer639 * @param signer keyring of signer
648 * @param collectionId ID of collection640 * @param collectionId ID of collection
649 * @param ownerAddress substrate address of new owner641 * @param ownerAddress substrate address of new owner
650 * @param label extra label for log
651 * @example changeOwner(aliceKeyring, 10, "5DyN4Y92vZCjv38fg...")642 * @example changeOwner(aliceKeyring, 10, "5DyN4Y92vZCjv38fg...")
652 * @returns ```true``` if extrinsic success, otherwise ```false```643 * @returns ```true``` if extrinsic success, otherwise ```false```
653 */644 */
654 async changeOwner(signer: TSigner, collectionId: number, ownerAddress: TSubstrateAccount, label?: string): Promise<boolean> {645 async changeOwner(signer: TSigner, collectionId: number, ownerAddress: TSubstrateAccount): Promise<boolean> {
655 if(typeof label === 'undefined') label = `collection #${collectionId}`;
656 const result = await this.helper.executeExtrinsic(646 const result = await this.helper.executeExtrinsic(
657 signer,647 signer,
658 'api.tx.unique.changeCollectionOwner', [collectionId, ownerAddress],648 'api.tx.unique.changeCollectionOwner', [collectionId, ownerAddress],
659 true, `Unable to change collection owner for ${label}`,649 true,
660 );650 );
661651
662 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'unique', 'CollectionOwnedChanged', label);652 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'unique', 'CollectionOwnedChanged');
663 }653 }
664654
665 /**655 /**
668 * @param signer keyring of signer658 * @param signer keyring of signer
669 * @param collectionId ID of collection659 * @param collectionId ID of collection
670 * @param adminAddressObj Administrator address (substrate or ethereum)660 * @param adminAddressObj Administrator address (substrate or ethereum)
671 * @param label extra label for log
672 * @example addAdmin(aliceKeyring, 10, {Substrate: "5DyN4Y92vZCjv38fg..."})661 * @example addAdmin(aliceKeyring, 10, {Substrate: "5DyN4Y92vZCjv38fg..."})
673 * @returns ```true``` if extrinsic success, otherwise ```false```662 * @returns ```true``` if extrinsic success, otherwise ```false```
674 */663 */
675 async addAdmin(signer: TSigner, collectionId: number, adminAddressObj: ICrossAccountId, label?: string): Promise<boolean> {664 async addAdmin(signer: TSigner, collectionId: number, adminAddressObj: ICrossAccountId): Promise<boolean> {
676 if(typeof label === 'undefined') label = `collection #${collectionId}`;
677 const result = await this.helper.executeExtrinsic(665 const result = await this.helper.executeExtrinsic(
678 signer,666 signer,
679 'api.tx.unique.addCollectionAdmin', [collectionId, adminAddressObj],667 'api.tx.unique.addCollectionAdmin', [collectionId, adminAddressObj],
680 true, `Unable to add collection admin for ${label}`,668 true,
681 );669 );
682670
683 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'unique', 'CollectionAdminAdded', label);671 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'unique', 'CollectionAdminAdded');
684 }672 }
685673
686 /**674 /**
675 * Removes a collection administrator.
676 *
677 * @param signer keyring of signer
678 * @param collectionId ID of collection
679 * @param adminAddressObj Administrator address (substrate or ethereum)
680 * @example removeAdmin(aliceKeyring, 10, {Substrate: "5DyN4Y92vZCjv38fg..."})
681 * @returns ```true``` if extrinsic success, otherwise ```false```
682 */
683 async removeAdmin(signer: TSigner, collectionId: number, adminAddressObj: ICrossAccountId): Promise<boolean> {
684 const result = await this.helper.executeExtrinsic(
685 signer,
686 'api.tx.unique.removeCollectionAdmin', [collectionId, adminAddressObj],
687 true,
688 );
689
690 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'unique', 'CollectionAdminRemoved');
691 }
692
693 /**
687 * Adds an address to allow list 694 * Adds an address to allow list
688 * @param signer keyring of signer695 * @param signer keyring of signer
689 * @param collectionId ID of collection696 * @param collectionId ID of collection
690 * @param addressObj address to add to the allow list697 * @param addressObj address to add to the allow list
691 * @param label extra label for log
692 * @returns ```true``` if extrinsic success, otherwise ```false```698 * @returns ```true``` if extrinsic success, otherwise ```false```
693 */699 */
694 async addToAllowList(signer: TSigner, collectionId: number, addressObj: ICrossAccountId, label?: string): Promise<boolean> {700 async addToAllowList(signer: TSigner, collectionId: number, addressObj: ICrossAccountId): Promise<boolean> {
695 if(typeof label === 'undefined') label = `collection #${collectionId}`;
696 const result = await this.helper.executeExtrinsic(701 const result = await this.helper.executeExtrinsic(
697 signer,702 signer,
698 'api.tx.unique.addToAllowList', [collectionId, addressObj],703 'api.tx.unique.addToAllowList', [collectionId, addressObj],
699 true, `Unable to add address to allow list for ${label}`,704 true,
700 );705 );
701706
702 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'unique', 'AllowListAddressAdded');707 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'unique', 'AllowListAddressAdded');
703 }708 }
704709
705 /**710 /**
706 * Removes a collection administrator.711 * Removes an address from allow list
707 * 712 *
708 * @param signer keyring of signer713 * @param signer keyring of signer
709 * @param collectionId ID of collection714 * @param collectionId ID of collection
710 * @param adminAddressObj Administrator address (substrate or ethereum)715 * @param addressObj address to remove from the allow list
711 * @param label extra label for log
712 * @example removeAdmin(aliceKeyring, 10, {Substrate: "5DyN4Y92vZCjv38fg..."})
713 * @returns ```true``` if extrinsic success, otherwise ```false```716 * @returns ```true``` if extrinsic success, otherwise ```false```
714 */717 */
715 async removeAdmin(signer: TSigner, collectionId: number, adminAddressObj: ICrossAccountId, label?: string): Promise<boolean> {718 async removeFromAllowList(signer: TSigner, collectionId: number, addressObj: ICrossAccountId): Promise<boolean> {
716 if(typeof label === 'undefined') label = `collection #${collectionId}`;
717 const result = await this.helper.executeExtrinsic(719 const result = await this.helper.executeExtrinsic(
718 signer,720 signer,
719 'api.tx.unique.removeCollectionAdmin', [collectionId, adminAddressObj],721 'api.tx.unique.removeFromAllowList', [collectionId, addressObj],
720 true, `Unable to remove collection admin for ${label}`,722 true,
721 );723 );
722724
723 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'unique', 'CollectionAdminRemoved', label);725 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'unique', 'AllowListAddressRemoved');
724 }726 }
725727
726 /**728 /**
729 * @param signer keyring of signer731 * @param signer keyring of signer
730 * @param collectionId ID of collection732 * @param collectionId ID of collection
731 * @param permissions collection permissions object733 * @param permissions collection permissions object
732 * @param label extra label for log
733 * @example setPermissions(aliceKeyring, 10, {access:'AllowList', mintMode: true, nesting: {collectionAdmin: true, tokenOwner: true}});734 * @example setPermissions(aliceKeyring, 10, {access:'AllowList', mintMode: true, nesting: {collectionAdmin: true, tokenOwner: true}});
734 * @returns ```true``` if extrinsic success, otherwise ```false```735 * @returns ```true``` if extrinsic success, otherwise ```false```
735 */736 */
736 async setPermissions(signer: TSigner, collectionId: number, permissions: ICollectionPermissions, label?: string): Promise<boolean> {737 async setPermissions(signer: TSigner, collectionId: number, permissions: ICollectionPermissions): Promise<boolean> {
737 if(typeof label === 'undefined') label = `collection #${collectionId}`;
738 const result = await this.helper.executeExtrinsic(738 const result = await this.helper.executeExtrinsic(
739 signer,739 signer,
740 'api.tx.unique.setCollectionPermissions', [collectionId, permissions],740 'api.tx.unique.setCollectionPermissions', [collectionId, permissions],
741 true, `Unable to set collection permissions for ${label}`,741 true,
742 );742 );
743743
744 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'unique', 'CollectionPermissionSet', label);744 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'unique', 'CollectionPermissionSet');
745 }745 }
746746
747 /**747 /**
750 * @param signer keyring of signer750 * @param signer keyring of signer
751 * @param collectionId ID of collection751 * @param collectionId ID of collection
752 * @param permissions nesting permissions object752 * @param permissions nesting permissions object
753 * @param label extra label for log
754 * @example enableNesting(aliceKeyring, 10, {collectionAdmin: true, tokenOwner: true});753 * @example enableNesting(aliceKeyring, 10, {collectionAdmin: true, tokenOwner: true});
755 * @returns ```true``` if extrinsic success, otherwise ```false```754 * @returns ```true``` if extrinsic success, otherwise ```false```
756 */755 */
757 async enableNesting(signer: TSigner, collectionId: number, permissions: INestingPermissions, label?: string): Promise<boolean> {756 async enableNesting(signer: TSigner, collectionId: number, permissions: INestingPermissions): Promise<boolean> {
758 return await this.setPermissions(signer, collectionId, {nesting: permissions}, label);757 return await this.setPermissions(signer, collectionId, {nesting: permissions});
759 }758 }
760759
761 /**760 /**
762 * Disables nesting for selected collection.761 * Disables nesting for selected collection.
763 * 762 *
764 * @param signer keyring of signer763 * @param signer keyring of signer
765 * @param collectionId ID of collection764 * @param collectionId ID of collection
766 * @param label extra label for log
767 * @example disableNesting(aliceKeyring, 10);765 * @example disableNesting(aliceKeyring, 10);
768 * @returns ```true``` if extrinsic success, otherwise ```false```766 * @returns ```true``` if extrinsic success, otherwise ```false```
769 */767 */
770 async disableNesting(signer: TSigner, collectionId: number, label?: string): Promise<boolean> {768 async disableNesting(signer: TSigner, collectionId: number): Promise<boolean> {
771 return await this.setPermissions(signer, collectionId, {nesting: {tokenOwner: false, collectionAdmin: false}}, label);769 return await this.setPermissions(signer, collectionId, {nesting: {tokenOwner: false, collectionAdmin: false}});
772 }770 }
773771
774 /**772 /**
777 * @param signer keyring of signer775 * @param signer keyring of signer
778 * @param collectionId ID of collection776 * @param collectionId ID of collection
779 * @param properties array of property objects777 * @param properties array of property objects
780 * @param label extra label for log
781 * @example setProperties(aliceKeyring, 10, [{key: "gender", value: "male"}]);778 * @example setProperties(aliceKeyring, 10, [{key: "gender", value: "male"}]);
782 * @returns ```true``` if extrinsic success, otherwise ```false```779 * @returns ```true``` if extrinsic success, otherwise ```false```
783 */780 */
784 async setProperties(signer: TSigner, collectionId: number, properties: IProperty[], label?: string): Promise<boolean> {781 async setProperties(signer: TSigner, collectionId: number, properties: IProperty[]): Promise<boolean> {
785 if(typeof label === 'undefined') label = `collection #${collectionId}`;
786 const result = await this.helper.executeExtrinsic(782 const result = await this.helper.executeExtrinsic(
787 signer,783 signer,
788 'api.tx.unique.setCollectionProperties', [collectionId, properties],784 'api.tx.unique.setCollectionProperties', [collectionId, properties],
789 true, `Unable to set collection properties for ${label}`,785 true,
790 );786 );
791787
792 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'common', 'CollectionPropertySet', label);788 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'common', 'CollectionPropertySet');
793 }789 }
794790
795 /**791 /**
798 * @param signer keyring of signer794 * @param signer keyring of signer
799 * @param collectionId ID of collection795 * @param collectionId ID of collection
800 * @param propertyKeys array of property keys to delete796 * @param propertyKeys array of property keys to delete
801 * @param label
802 * @example deleteProperties(aliceKeyring, 10, ["gender", "age"]);797 * @example deleteProperties(aliceKeyring, 10, ["gender", "age"]);
803 * @returns ```true``` if extrinsic success, otherwise ```false```798 * @returns ```true``` if extrinsic success, otherwise ```false```
804 */799 */
805 async deleteProperties(signer: TSigner, collectionId: number, propertyKeys: string[], label?: string): Promise<boolean> {800 async deleteProperties(signer: TSigner, collectionId: number, propertyKeys: string[]): Promise<boolean> {
806 if(typeof label === 'undefined') label = `collection #${collectionId}`;
807 const result = await this.helper.executeExtrinsic(801 const result = await this.helper.executeExtrinsic(
808 signer,802 signer,
809 'api.tx.unique.deleteCollectionProperties', [collectionId, propertyKeys],803 'api.tx.unique.deleteCollectionProperties', [collectionId, propertyKeys],
810 true, `Unable to delete collection properties for ${label}`,804 true,
811 );805 );
812806
813 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'common', 'CollectionPropertyDeleted', label);807 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'common', 'CollectionPropertyDeleted');
814 }808 }
815809
816 /**810 /**
828 const result = await this.helper.executeExtrinsic(822 const result = await this.helper.executeExtrinsic(
829 signer,823 signer,
830 'api.tx.unique.transfer', [addressObj, collectionId, tokenId, amount],824 'api.tx.unique.transfer', [addressObj, collectionId, tokenId, amount],
831 true, `Unable to transfer token #${tokenId} from collection #${collectionId}`,825 true, // `Unable to transfer token #${tokenId} from collection #${collectionId}`,
832 );826 );
833827
834 return this.helper.util.isTokenTransferSuccess(result.result.events, collectionId, tokenId, {Substrate: typeof signer === 'string' ? signer : signer.address}, addressObj, amount);828 return this.helper.util.isTokenTransferSuccess(result.result.events, collectionId, tokenId, {Substrate: typeof signer === 'string' ? signer : signer.address}, addressObj, amount);
851 const result = await this.helper.executeExtrinsic(845 const result = await this.helper.executeExtrinsic(
852 signer,846 signer,
853 'api.tx.unique.transferFrom', [fromAddressObj, toAddressObj, collectionId, tokenId, amount],847 'api.tx.unique.transferFrom', [fromAddressObj, toAddressObj, collectionId, tokenId, amount],
854 true, `Unable to transfer token #${tokenId} from collection #${collectionId}`,848 true, // `Unable to transfer token #${tokenId} from collection #${collectionId}`,
855 );849 );
856 return this.helper.util.isTokenTransferSuccess(result.result.events, collectionId, tokenId, fromAddressObj, toAddressObj, amount);850 return this.helper.util.isTokenTransferSuccess(result.result.events, collectionId, tokenId, fromAddressObj, toAddressObj, amount);
857 }851 }
863 * @param signer keyring of signer857 * @param signer keyring of signer
864 * @param collectionId ID of collection858 * @param collectionId ID of collection
865 * @param tokenId ID of token859 * @param tokenId ID of token
866 * @param label
867 * @param amount amount of tokens to be burned. For NFT must be set to 1n860 * @param amount amount of tokens to be burned. For NFT must be set to 1n
868 * @example burnToken(aliceKeyring, 10, 5);861 * @example burnToken(aliceKeyring, 10, 5);
869 * @returns ```true``` and burnt token number is extrinsic success. Otherwise ```false``` and ```null```862 * @returns ```true``` and burnt token number is extrinsic success. Otherwise ```false``` and ```null```
870 */863 */
871 async burnToken(signer: TSigner, collectionId: number, tokenId: number, label?: string, amount=1n): Promise<{864 async burnToken(signer: TSigner, collectionId: number, tokenId: number, amount=1n): Promise<{
872 success: boolean,865 success: boolean,
873 token: number | null866 token: number | null
874 }> {867 }> {
875 if(typeof label === 'undefined') label = `collection #${collectionId}`;
876 const burnResult = await this.helper.executeExtrinsic(868 const burnResult = await this.helper.executeExtrinsic(
877 signer,869 signer,
878 'api.tx.unique.burnItem', [collectionId, tokenId, amount],870 'api.tx.unique.burnItem', [collectionId, tokenId, amount],
879 true, `Unable to burn token for ${label}`,871 true, // `Unable to burn token for ${label}`,
880 );872 );
881 const burnedTokens = this.helper.util.extractTokensFromBurnResult(burnResult, label);873 const burnedTokens = this.helper.util.extractTokensFromBurnResult(burnResult);
882 if (burnedTokens.tokens.length > 1) throw Error('Burned multiple tokens');874 if (burnedTokens.tokens.length > 1) throw Error('Burned multiple tokens');
883 return {success: burnedTokens.success, token: burnedTokens.tokens.length > 0 ? burnedTokens.tokens[0] : null};875 return {success: burnedTokens.success, token: burnedTokens.tokens.length > 0 ? burnedTokens.tokens[0] : null};
884 }876 }
890 * @param collectionId ID of collection882 * @param collectionId ID of collection
891 * @param fromAddressObj address on behalf of which the token will be burnt883 * @param fromAddressObj address on behalf of which the token will be burnt
892 * @param tokenId ID of token884 * @param tokenId ID of token
893 * @param label
894 * @param amount amount of tokens to be burned. For NFT must be set to 1n885 * @param amount amount of tokens to be burned. For NFT must be set to 1n
895 * @example burnTokenFrom(aliceKeyring, 10, {Substrate: "5DyN4Y92vZCjv38fg..."}, 5, {Ethereum: "0x9F0583DbB85..."})886 * @example burnTokenFrom(aliceKeyring, 10, {Substrate: "5DyN4Y92vZCjv38fg..."}, 5, {Ethereum: "0x9F0583DbB85..."})
896 * @returns ```true``` if extrinsic success, otherwise ```false```887 * @returns ```true``` if extrinsic success, otherwise ```false```
897 */888 */
898 async burnTokenFrom(signer: TSigner, collectionId: number, fromAddressObj: ICrossAccountId, tokenId: number, label?: string, amount=1n): Promise<boolean> {889 async burnTokenFrom(signer: TSigner, collectionId: number, fromAddressObj: ICrossAccountId, tokenId: number, amount=1n): Promise<boolean> {
899 if(typeof label === 'undefined') label = `collection #${collectionId}`;
900 const burnResult = await this.helper.executeExtrinsic(890 const burnResult = await this.helper.executeExtrinsic(
901 signer,891 signer,
902 'api.tx.unique.burnFrom', [collectionId, fromAddressObj, tokenId, amount],892 'api.tx.unique.burnFrom', [collectionId, fromAddressObj, tokenId, amount],
903 true, `Unable to burn token from for ${label}`,893 true, // `Unable to burn token from for ${label}`,
904 );894 );
905 const burnedTokens = this.helper.util.extractTokensFromBurnResult(burnResult, label);895 const burnedTokens = this.helper.util.extractTokensFromBurnResult(burnResult);
906 return burnedTokens.success && burnedTokens.tokens.length > 0;896 return burnedTokens.success && burnedTokens.tokens.length > 0;
907 }897 }
908898
912 * @param signer keyring of signer902 * @param signer keyring of signer
913 * @param collectionId ID of collection903 * @param collectionId ID of collection
914 * @param tokenId ID of token904 * @param tokenId ID of token
915 * @param toAddressObj 905 * @param toAddressObj Substrate or Ethereum address which gets approved use of the signer's tokens
916 * @param label
917 * @param amount amount of token to be approved. For NFT must be set to 1n906 * @param amount amount of token to be approved. For NFT must be set to 1n
918 * @returns ```true``` if extrinsic success, otherwise ```false```907 * @returns ```true``` if extrinsic success, otherwise ```false```
919 */908 */
920 async approveToken(signer: IKeyringPair, collectionId: number, tokenId: number, toAddressObj: ICrossAccountId, label?: string, amount=1n) {909 async approveToken(signer: IKeyringPair, collectionId: number, tokenId: number, toAddressObj: ICrossAccountId, amount=1n) {
921 if(typeof label === 'undefined') label = `collection #${collectionId}`;
922 const approveResult = await this.helper.executeExtrinsic(910 const approveResult = await this.helper.executeExtrinsic(
923 signer, 911 signer,
924 'api.tx.unique.approve', [toAddressObj, collectionId, tokenId, amount],912 'api.tx.unique.approve', [toAddressObj, collectionId, tokenId, amount],
925 true, `Unable to approve token for ${label}`,913 true, // `Unable to approve token for ${label}`,
926 );914 );
927915
928 return this.helper.util.findCollectionInEvents(approveResult.result.events, collectionId, 'common', 'Approved', label);916 return this.helper.util.findCollectionInEvents(approveResult.result.events, collectionId, 'common', 'Approved');
929 }917 }
930918
931 /**919 /**
932 * Get the amount of token pieces approved to transfer920 * Get the amount of token pieces approved to transfer or burn. Normally 0.
921 *
933 * @param collectionId ID of collection922 * @param collectionId ID of collection
934 * @param tokenId ID of token923 * @param tokenId ID of token
935 * @param toAccountObj 924 * @param toAccountObj address which is approved to use token pieces
936 * @param fromAccountObj925 * @param fromAccountObj address which may have allowed the use of its owned tokens
937 * @example getTokenApprovedPieces(10, 5, {Substrate: "5DyN4Y92vZCjv38fg..."}, {Substrate: "5ERZNF88Mm7UGfPP3mdG..."})926 * @example getTokenApprovedPieces(10, 5, {Substrate: "5DyN4Y92vZCjv38fg..."}, {Substrate: "5ERZNF88Mm7UGfPP3mdG..."})
938 * @returns number of approved to transfer pieces927 * @returns number of approved to transfer pieces
939 */928 */
942 }931 }
943932
944 /**933 /**
945 * Get the last created token id934 * Get the last created token ID in a collection
935 *
946 * @param collectionId ID of collection936 * @param collectionId ID of collection
947 * @example getLastTokenId(10);937 * @example getLastTokenId(10);
948 * @returns id of the last created token938 * @returns id of the last created token
953943
954 /**944 /**
955 * Check if token exists945 * Check if token exists
946 *
956 * @param collectionId ID of collection947 * @param collectionId ID of collection
957 * @param tokenId ID of token948 * @param tokenId ID of token
958 * @example isTokenExists(10, 20);949 * @example isTokenExists(10, 20);
978969
979 /**970 /**
980 * Get token data971 * Get token data
972 *
981 * @param collectionId ID of collection973 * @param collectionId ID of collection
982 * @param tokenId ID of token974 * @param tokenId ID of token
983 * @param blockHashAt 975 * @param blockHashAt
10141006
1015 /**1007 /**
1016 * Set permissions to change token properties1008 * Set permissions to change token properties
1009 *
1017 * @param signer keyring of signer1010 * @param signer keyring of signer
1018 * @param collectionId ID of collection1011 * @param collectionId ID of collection
1019 * @param permissions permissions to change a property by the collection owner or admin1012 * @param permissions permissions to change a property by the collection owner or admin
1020 * @param label
1021 * @example setTokenPropertyPermissions(1013 * @example setTokenPropertyPermissions(
1022 * aliceKeyring, 10, [{key: "gender", permission: {tokenOwner: true, mutable: true, collectionAdmin: true}}]1014 * aliceKeyring, 10, [{key: "gender", permission: {tokenOwner: true, mutable: true, collectionAdmin: true}}]
1023 * )1015 * )
1024 * @returns true if extrinsic success otherwise false1016 * @returns true if extrinsic success otherwise false
1025 */1017 */
1026 async setTokenPropertyPermissions(signer: TSigner, collectionId: number, permissions: ITokenPropertyPermission[], label?: string): Promise<boolean> {1018 async setTokenPropertyPermissions(signer: TSigner, collectionId: number, permissions: ITokenPropertyPermission[]): Promise<boolean> {
1027 if(typeof label === 'undefined') label = `collection #${collectionId}`;
1028 const result = await this.helper.executeExtrinsic(1019 const result = await this.helper.executeExtrinsic(
1029 signer,1020 signer,
1030 'api.tx.unique.setTokenPropertyPermissions', [collectionId, permissions],1021 'api.tx.unique.setTokenPropertyPermissions', [collectionId, permissions],
1031 true, `Unable to set token property permissions for ${label}`,1022 true,
1032 );1023 );
10331024
1034 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'common', 'PropertyPermissionSet', label);1025 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'common', 'PropertyPermissionSet');
1035 }1026 }
10361027
1037 /**1028 /**
1038 * Set token properties1029 * Set token properties
1030 *
1039 * @param signer keyring of signer1031 * @param signer keyring of signer
1040 * @param collectionId ID of collection1032 * @param collectionId ID of collection
1041 * @param tokenId ID of token1033 * @param tokenId ID of token
1042 * @param properties 1034 * @param properties
1043 * @param label
1044 * @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"}])
1045 * @returns ```true``` if extrinsic success, otherwise ```false```1036 * @returns ```true``` if extrinsic success, otherwise ```false```
1046 */1037 */
1047 async setTokenProperties(signer: TSigner, collectionId: number, tokenId: number, properties: IProperty[], label?: string): Promise<boolean> {1038 async setTokenProperties(signer: TSigner, collectionId: number, tokenId: number, properties: IProperty[]): Promise<boolean> {
1048 if(typeof label === 'undefined') label = `token #${tokenId} from collection #${collectionId}`;
1049 const result = await this.helper.executeExtrinsic(1039 const result = await this.helper.executeExtrinsic(
1050 signer,1040 signer,
1051 'api.tx.unique.setTokenProperties', [collectionId, tokenId, properties],1041 'api.tx.unique.setTokenProperties', [collectionId, tokenId, properties],
1052 true, `Unable to set token properties for ${label}`,1042 true,
1053 );1043 );
10541044
1055 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'common', 'TokenPropertySet', label);1045 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'common', 'TokenPropertySet');
1056 }1046 }
10571047
1058 /**1048 /**
1061 * @param collectionId ID of collection1051 * @param collectionId ID of collection
1062 * @param tokenId ID of token1052 * @param tokenId ID of token
1063 * @param propertyKeys property keys to be deleted 1053 * @param propertyKeys property keys to be deleted
1064 * @param label
1065 * @example deleteTokenProperties(aliceKeyring, 10, 5, ["gender", "age"])1054 * @example deleteTokenProperties(aliceKeyring, 10, 5, ["gender", "age"])
1066 * @returns ```true``` if extrinsic success, otherwise ```false```1055 * @returns ```true``` if extrinsic success, otherwise ```false```
1067 */1056 */
1068 async deleteTokenProperties(signer: TSigner, collectionId: number, tokenId: number, propertyKeys: string[], label?: string): Promise<boolean> {1057 async deleteTokenProperties(signer: TSigner, collectionId: number, tokenId: number, propertyKeys: string[]): Promise<boolean> {
1069 if(typeof label === 'undefined') label = `token #${tokenId} from collection #${collectionId}`;
1070 const result = await this.helper.executeExtrinsic(1058 const result = await this.helper.executeExtrinsic(
1071 signer,1059 signer,
1072 'api.tx.unique.deleteTokenProperties', [collectionId, tokenId, propertyKeys],1060 'api.tx.unique.deleteTokenProperties', [collectionId, tokenId, propertyKeys],
1073 true, `Unable to delete token properties for ${label}`,1061 true,
1074 );1062 );
10751063
1076 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'common', 'TokenPropertyDeleted', label);1064 return this.helper.util.findCollectionInEvents(result.result.events, collectionId, 'common', 'TokenPropertyDeleted');
1077 }1065 }
10781066
1079 /**1067 /**
1080 * Mint new collection1068 * Mint new collection
1069 *
1081 * @param signer keyring of signer1070 * @param signer keyring of signer
1082 * @param collectionOptions basic collection options and properties 1071 * @param collectionOptions basic collection options and properties
1083 * @param mode NFT or RFT type of a collection1072 * @param mode NFT or RFT type of a collection
1084 * @param errorLabel
1085 * @example mintCollection(aliceKeyring, {name: 'New', description: "New collection", tokenPrefix: "NEW"}, "NFT")1073 * @example mintCollection(aliceKeyring, {name: 'New', description: "New collection", tokenPrefix: "NEW"}, "NFT")
1086 * @returns object of the created collection1074 * @returns object of the created collection
1087 */1075 */
1088 async mintCollection(signer: TSigner, collectionOptions: ICollectionCreationOptions, mode: 'NFT' | 'RFT', errorLabel = 'Unable to mint collection'): Promise<UniqueCollectionBase> {1076 async mintCollection(signer: TSigner, collectionOptions: ICollectionCreationOptions, mode: 'NFT' | 'RFT'): Promise<UniqueCollectionBase> {
1089 collectionOptions = JSON.parse(JSON.stringify(collectionOptions)) as ICollectionCreationOptions; // Clone object1077 collectionOptions = JSON.parse(JSON.stringify(collectionOptions)) as ICollectionCreationOptions; // Clone object
1090 collectionOptions.mode = (mode === 'NFT') ? {nft: null} : {refungible: null};1078 collectionOptions.mode = (mode === 'NFT') ? {nft: null} : {refungible: null};
1091 for (const key of ['name', 'description', 'tokenPrefix']) {1079 for (const key of ['name', 'description', 'tokenPrefix']) {
1094 const creationResult = await this.helper.executeExtrinsic(1082 const creationResult = await this.helper.executeExtrinsic(
1095 signer,1083 signer,
1096 'api.tx.unique.createCollectionEx', [collectionOptions],1084 'api.tx.unique.createCollectionEx', [collectionOptions],
1097 true, errorLabel,1085 true, // errorLabel,
1098 );1086 );
1099 return this.getCollectionObject(this.helper.util.extractCollectionIdFromCreationResult(creationResult, errorLabel));1087 return this.getCollectionObject(this.helper.util.extractCollectionIdFromCreationResult(creationResult));
1100 }1088 }
11011089
1102 getCollectionObject(collectionId: number): any {1090 getCollectionObject(collectionId: number): any {
1239 * @param signer keyring of signer1227 * @param signer keyring of signer
1240 * @param tokenObj token to be nested1228 * @param tokenObj token to be nested
1241 * @param rootTokenObj token to be parent1229 * @param rootTokenObj token to be parent
1242 * @param label
1243 * @example nestToken(aliceKeyring, {collectionId: 10, tokenId: 5}, {collectionId: 10, tokenId: 4});1230 * @example nestToken(aliceKeyring, {collectionId: 10, tokenId: 5}, {collectionId: 10, tokenId: 4});
1244 * @returns ```true``` if extrinsic success, otherwise ```false```1231 * @returns ```true``` if extrinsic success, otherwise ```false```
1245 */1232 */
1246 async nestToken(signer: TSigner, tokenObj: IToken, rootTokenObj: IToken, label='nest token'): Promise<boolean> {1233 async nestToken(signer: TSigner, tokenObj: IToken, rootTokenObj: IToken): Promise<boolean> {
1247 const rootTokenAddress = {Ethereum: this.helper.util.getNestingTokenAddress(rootTokenObj.collectionId, rootTokenObj.tokenId)};1234 const rootTokenAddress = {Ethereum: this.helper.util.getNestingTokenAddress(rootTokenObj.collectionId, rootTokenObj.tokenId)};
1248 const result = await this.transferToken(signer, tokenObj.collectionId, tokenObj.tokenId, rootTokenAddress);1235 const result = await this.transferToken(signer, tokenObj.collectionId, tokenObj.tokenId, rootTokenAddress);
1249 if(!result) {1236 if(!result) {
1250 throw Error(`Unable to nest token for ${label}`);1237 throw Error('Unable to nest token!');
1251 }1238 }
1252 return result;1239 return result;
1253 }1240 }
1258 * @param tokenObj token to unnest1245 * @param tokenObj token to unnest
1259 * @param rootTokenObj parent of a token1246 * @param rootTokenObj parent of a token
1260 * @param toAddressObj address of a new token owner 1247 * @param toAddressObj address of a new token owner
1261 * @param label
1262 * @example unnestToken(aliceKeyring, {collectionId: 10, tokenId: 5}, {collectionId: 10, tokenId: 4}, {Substrate: "5DyN4Y92vZCjv38fg..."});1248 * @example unnestToken(aliceKeyring, {collectionId: 10, tokenId: 5}, {collectionId: 10, tokenId: 4}, {Substrate: "5DyN4Y92vZCjv38fg..."});
1263 * @returns ```true``` if extrinsic success, otherwise ```false```1249 * @returns ```true``` if extrinsic success, otherwise ```false```
1264 */1250 */
1265 async unnestToken(signer: TSigner, tokenObj: IToken, rootTokenObj: IToken, toAddressObj: ICrossAccountId, label='unnest token'): Promise<boolean> {1251 async unnestToken(signer: TSigner, tokenObj: IToken, rootTokenObj: IToken, toAddressObj: ICrossAccountId): Promise<boolean> {
1266 const rootTokenAddress = {Ethereum: this.helper.util.getNestingTokenAddress(rootTokenObj.collectionId, rootTokenObj.tokenId)};1252 const rootTokenAddress = {Ethereum: this.helper.util.getNestingTokenAddress(rootTokenObj.collectionId, rootTokenObj.tokenId)};
1267 const result = await this.transferTokenFrom(signer, tokenObj.collectionId, tokenObj.tokenId, rootTokenAddress, toAddressObj);1253 const result = await this.transferTokenFrom(signer, tokenObj.collectionId, tokenObj.tokenId, rootTokenAddress, toAddressObj);
1268 if(!result) {1254 if(!result) {
1269 throw Error(`Unable to unnest token for ${label}`);1255 throw Error('Unable to unnest token!');
1270 }1256 }
1271 return result;1257 return result;
1272 }1258 }
1275 * Mint new collection1261 * Mint new collection
1276 * @param signer keyring of signer1262 * @param signer keyring of signer
1277 * @param collectionOptions Collection options1263 * @param collectionOptions Collection options
1278 * @param label
1279 * @example 1264 * @example
1280 * mintCollection(aliceKeyring, {1265 * mintCollection(aliceKeyring, {
1281 * name: 'New',1266 * name: 'New',
1284 * })1269 * })
1285 * @returns object of the created collection1270 * @returns object of the created collection
1286 */1271 */
1287 async mintCollection(signer: TSigner, collectionOptions: ICollectionCreationOptions, label = 'new collection'): Promise<UniqueNFTCollection> {1272 async mintCollection(signer: TSigner, collectionOptions: ICollectionCreationOptions): Promise<UniqueNFTCollection> {
1288 return await super.mintCollection(signer, collectionOptions, 'NFT', `Unable to mint NFT collection for ${label}`) as UniqueNFTCollection;1273 return await super.mintCollection(signer, collectionOptions, 'NFT') as UniqueNFTCollection;
1289 }1274 }
12901275
1291 /**1276 /**
1292 * Mint new token1277 * Mint new token
1293 * @param signer keyring of signer1278 * @param signer keyring of signer
1294 * @param data token data1279 * @param data token data
1295 * @param label
1296 * @returns created token object1280 * @returns created token object
1297 */1281 */
1298 async mintToken(signer: TSigner, data: { collectionId: number; owner: ICrossAccountId | string; properties?: IProperty[]; }, label?: string): Promise<UniqueNFTToken> {1282 async mintToken(signer: TSigner, data: { collectionId: number; owner: ICrossAccountId | string; properties?: IProperty[]; }): Promise<UniqueNFTToken> {
1299 if(typeof label === 'undefined') label = `collection #${data.collectionId}`;
1300 const creationResult = await this.helper.executeExtrinsic(1283 const creationResult = await this.helper.executeExtrinsic(
1301 signer,1284 signer,
1302 'api.tx.unique.createItem', [data.collectionId, (typeof data.owner === 'string') ? {Substrate: data.owner} : data.owner, {1285 'api.tx.unique.createItem', [data.collectionId, (typeof data.owner === 'string') ? {Substrate: data.owner} : data.owner, {
1303 nft: {1286 nft: {
1304 properties: data.properties,1287 properties: data.properties,
1305 },1288 },
1306 }],1289 }],
1307 true, `Unable to mint NFT token for ${label}`,1290 true,
1308 );1291 );
1309 const createdTokens = this.helper.util.extractTokensFromCreationResult(creationResult, label);1292 const createdTokens = this.helper.util.extractTokensFromCreationResult(creationResult);
1310 if (createdTokens.tokens.length > 1) throw Error('Minted multiple tokens');1293 if (createdTokens.tokens.length > 1) throw Error('Minted multiple tokens');
1311 if (createdTokens.tokens.length < 1) throw Error('No tokens minted');1294 if (createdTokens.tokens.length < 1) throw Error('No tokens minted');
1312 return this.getTokenObject(data.collectionId, createdTokens.tokens[0].tokenId);1295 return this.getTokenObject(data.collectionId, createdTokens.tokens[0].tokenId);
1317 * @param signer keyring of signer1300 * @param signer keyring of signer
1318 * @param collectionId ID of collection1301 * @param collectionId ID of collection
1319 * @param tokens array of tokens with owner and properties1302 * @param tokens array of tokens with owner and properties
1320 * @param label
1321 * @example 1303 * @example
1322 * mintMultipleTokens(aliceKeyring, 10, [{1304 * mintMultipleTokens(aliceKeyring, 10, [{
1323 * owner: {Substrate: "5DyN4Y92vZCjv38fg..."},1305 * owner: {Substrate: "5DyN4Y92vZCjv38fg..."},
1328 * }]);1310 * }]);
1329 * @returns ```true``` if extrinsic success, otherwise ```false```1311 * @returns ```true``` if extrinsic success, otherwise ```false```
1330 */1312 */
1331 async mintMultipleTokens(signer: TSigner, collectionId: number, tokens: {owner: ICrossAccountId, properties?: IProperty[]}[], label?: string): Promise<UniqueNFTToken[]> {1313 async mintMultipleTokens(signer: TSigner, collectionId: number, tokens: {owner: ICrossAccountId, properties?: IProperty[]}[]): Promise<UniqueNFTToken[]> {
1332 if(typeof label === 'undefined') label = `collection #${collectionId}`;
1333 const creationResult = await this.helper.executeExtrinsic(1314 const creationResult = await this.helper.executeExtrinsic(
1334 signer,1315 signer,
1335 'api.tx.unique.createMultipleItemsEx', [collectionId, {NFT: tokens}],1316 'api.tx.unique.createMultipleItemsEx', [collectionId, {NFT: tokens}],
1336 true, `Unable to mint NFT tokens for ${label}`,1317 true,
1337 );1318 );
1338 const collection = this.getCollectionObject(collectionId);1319 const collection = this.getCollectionObject(collectionId);
1339 return this.helper.util.extractTokensFromCreationResult(creationResult, label).tokens.map((x: IToken) => collection.getTokenObject(x.tokenId));1320 return this.helper.util.extractTokensFromCreationResult(creationResult).tokens.map((x: IToken) => collection.getTokenObject(x.tokenId));
1340 }1321 }
13411322
1342 /**1323 /**
1345 * @param collectionId ID of collection1326 * @param collectionId ID of collection
1346 * @param owner tokens owner1327 * @param owner tokens owner
1347 * @param tokens array of tokens with owner and properties1328 * @param tokens array of tokens with owner and properties
1348 * @param label
1349 * @example1329 * @example
1350 * mintMultipleTokensWithOneOwner(aliceKeyring, 10, "5DyN4Y92vZCjv38fg...", [{1330 * mintMultipleTokensWithOneOwner(aliceKeyring, 10, "5DyN4Y92vZCjv38fg...", [{
1351 * properties: [{1331 * properties: [{
1358 * }]);1338 * }]);
1359 * @returns array of newly created tokens1339 * @returns array of newly created tokens
1360 */1340 */
1361 async mintMultipleTokensWithOneOwner(signer: TSigner, collectionId: number, owner: ICrossAccountId, tokens: {properties?: IProperty[]}[], label?: string): Promise<UniqueNFTToken[]> {1341 async mintMultipleTokensWithOneOwner(signer: TSigner, collectionId: number, owner: ICrossAccountId, tokens: {properties?: IProperty[]}[]): Promise<UniqueNFTToken[]> {
1362 if(typeof label === 'undefined') label = `collection #${collectionId}`;
1363 const rawTokens = [];1342 const rawTokens = [];
1364 for (const token of tokens) {1343 for (const token of tokens) {
1365 const raw = {NFT: {properties: token.properties}};1344 const raw = {NFT: {properties: token.properties}};
1368 const creationResult = await this.helper.executeExtrinsic(1347 const creationResult = await this.helper.executeExtrinsic(
1369 signer,1348 signer,
1370 'api.tx.unique.createMultipleItems', [collectionId, owner, rawTokens],1349 'api.tx.unique.createMultipleItems', [collectionId, owner, rawTokens],
1371 true, `Unable to mint NFT tokens for ${label}`,1350 true,
1372 );1351 );
1373 const collection = this.getCollectionObject(collectionId);1352 const collection = this.getCollectionObject(collectionId);
1374 return this.helper.util.extractTokensFromCreationResult(creationResult, label).tokens.map((x: IToken) => collection.getTokenObject(x.tokenId));1353 return this.helper.util.extractTokensFromCreationResult(creationResult).tokens.map((x: IToken) => collection.getTokenObject(x.tokenId));
1375 }1354 }
13761355
1377 /**1356 /**
1378 * Destroys a concrete instance of NFT.1357 * Destroys a concrete instance of NFT.
1379 * @param signer keyring of signer1358 * @param signer keyring of signer
1380 * @param collectionId ID of collection1359 * @param collectionId ID of collection
1381 * @param tokenId ID of token1360 * @param tokenId ID of token
1382 * @param label
1383 * @example burnToken(aliceKeyring, 10, 5);1361 * @example burnToken(aliceKeyring, 10, 5);
1384 * @returns ```true``` and burnt token number is extrinsic success. Otherwise ```false``` and ```null```1362 * @returns ```true``` and burnt token number is extrinsic success. Otherwise ```false``` and ```null```
1385 */1363 */
1386 async burnToken(signer: IKeyringPair, collectionId: number, tokenId: number, label?: string): Promise<{ success: boolean; token: number | null; }> {1364 async burnToken(signer: IKeyringPair, collectionId: number, tokenId: number): Promise<{ success: boolean; token: number | null; }> {
1387 return await super.burnToken(signer, collectionId, tokenId, label, 1n);1365 return await super.burnToken(signer, collectionId, tokenId, 1n);
1388 }1366 }
13891367
1390 /**1368 /**
1394 * @param collectionId ID of collection1372 * @param collectionId ID of collection
1395 * @param tokenId ID of token1373 * @param tokenId ID of token
1396 * @param toAddressObj address to approve1374 * @param toAddressObj address to approve
1397 * @param label
1398 * @example approveToken(aliceKeyring, 10, 5, {Substrate: "5DyN4Y92vZCjv38fg..."})1375 * @example approveToken(aliceKeyring, 10, 5, {Substrate: "5DyN4Y92vZCjv38fg..."})
1399 * @returns ```true``` if extrinsic success, otherwise ```false```1376 * @returns ```true``` if extrinsic success, otherwise ```false```
1400 */1377 */
1401 async approveToken(signer: IKeyringPair, collectionId: number, tokenId: number, toAddressObj: ICrossAccountId, label?: string) {1378 async approveToken(signer: IKeyringPair, collectionId: number, tokenId: number, toAddressObj: ICrossAccountId) {
1402 return super.approveToken(signer, collectionId, tokenId, toAddressObj, label, 1n);1379 return super.approveToken(signer, collectionId, tokenId, toAddressObj, 1n);
1403 }1380 }
1404}1381}
14051382
1459 * @example transferTokenFrom(aliceKeyring, 10, 5, {Substrate: "5DyN4Y92vZCjv38fg..."}, 2000n)1436 * @example transferTokenFrom(aliceKeyring, 10, 5, {Substrate: "5DyN4Y92vZCjv38fg..."}, 2000n)
1460 * @returns ```true``` if extrinsic success, otherwise ```false```1437 * @returns ```true``` if extrinsic success, otherwise ```false```
1461 */1438 */
1462 async transferToken(signer: TSigner, collectionId: number, tokenId: number, addressObj: ICrossAccountId, amount=100n): Promise<boolean> {1439 async transferToken(signer: TSigner, collectionId: number, tokenId: number, addressObj: ICrossAccountId, amount=1n): Promise<boolean> {
1463 return await super.transferToken(signer, collectionId, tokenId, addressObj, amount);1440 return await super.transferToken(signer, collectionId, tokenId, addressObj, amount);
1464 }1441 }
14651442
1474 * @example transferTokenFrom(aliceKeyring, 10, 5, {Substrate: "5DyN4Y92vZCjv38fg..."}, {Substrate: "5DfhbVfww7ThF8q6f3i..."}, 2000n)1451 * @example transferTokenFrom(aliceKeyring, 10, 5, {Substrate: "5DyN4Y92vZCjv38fg..."}, {Substrate: "5DfhbVfww7ThF8q6f3i..."}, 2000n)
1475 * @returns ```true``` if extrinsic success, otherwise ```false```1452 * @returns ```true``` if extrinsic success, otherwise ```false```
1476 */1453 */
1477 async transferTokenFrom(signer: TSigner, collectionId: number, tokenId: number, fromAddressObj: ICrossAccountId, toAddressObj: ICrossAccountId, amount=100n): Promise<boolean> {1454 async transferTokenFrom(signer: TSigner, collectionId: number, tokenId: number, fromAddressObj: ICrossAccountId, toAddressObj: ICrossAccountId, amount=1n): Promise<boolean> {
1478 return await super.transferTokenFrom(signer, collectionId, tokenId, fromAddressObj, toAddressObj, amount);1455 return await super.transferTokenFrom(signer, collectionId, tokenId, fromAddressObj, toAddressObj, amount);
1479 }1456 }
14801457
1481 /**1458 /**
1482 * Mint new collection1459 * Mint new collection
1483 * @param signer keyring of signer1460 * @param signer keyring of signer
1484 * @param collectionOptions Collection options1461 * @param collectionOptions Collection options
1485 * @param label
1486 * @example1462 * @example
1487 * mintCollection(aliceKeyring, {1463 * mintCollection(aliceKeyring, {
1488 * name: 'New',1464 * name: 'New',
1491 * })1467 * })
1492 * @returns object of the created collection1468 * @returns object of the created collection
1493 */1469 */
1494 async mintCollection(signer: TSigner, collectionOptions: ICollectionCreationOptions, label = 'new collection'): Promise<UniqueRFTCollection> {1470 async mintCollection(signer: TSigner, collectionOptions: ICollectionCreationOptions): Promise<UniqueRFTCollection> {
1495 return await super.mintCollection(signer, collectionOptions, 'RFT', `Unable to mint RFT collection for ${label}`) as UniqueRFTCollection;1471 return await super.mintCollection(signer, collectionOptions, 'RFT') as UniqueRFTCollection;
1496 }1472 }
14971473
1498 /**1474 /**
1499 * Mint new token1475 * Mint new token
1500 * @param signer keyring of signer1476 * @param signer keyring of signer
1501 * @param data token data1477 * @param data token data
1502 * @param label
1503 * @example mintToken(aliceKeyring, {collectionId: 10, owner: {Substrate: '5GHoZe9c73RYbVzq...'}, pieces: 10000n});1478 * @example mintToken(aliceKeyring, {collectionId: 10, owner: {Substrate: '5GHoZe9c73RYbVzq...'}, pieces: 10000n});
1504 * @returns created token object1479 * @returns created token object
1505 */1480 */
1506 async mintToken(signer: TSigner, data: { collectionId: number; owner: ICrossAccountId | string; pieces: bigint; properties?: IProperty[]; }, label?: string): Promise<UniqueRFTToken> {1481 async mintToken(signer: TSigner, data: { collectionId: number; owner: ICrossAccountId | string; pieces: bigint; properties?: IProperty[]; }): Promise<UniqueRFTToken> {
1507 if(typeof label === 'undefined') label = `collection #${data.collectionId}`;
1508 const creationResult = await this.helper.executeExtrinsic(1482 const creationResult = await this.helper.executeExtrinsic(
1509 signer,1483 signer,
1510 'api.tx.unique.createItem', [data.collectionId, (typeof data.owner === 'string') ? {Substrate: data.owner} : data.owner, {1484 'api.tx.unique.createItem', [data.collectionId, (typeof data.owner === 'string') ? {Substrate: data.owner} : data.owner, {
1513 properties: data.properties,1487 properties: data.properties,
1514 },1488 },
1515 }],1489 }],
1516 true, `Unable to mint RFT token for ${label}`,1490 true,
1517 );1491 );
1518 const createdTokens = this.helper.util.extractTokensFromCreationResult(creationResult, label);1492 const createdTokens = this.helper.util.extractTokensFromCreationResult(creationResult);
1519 if (createdTokens.tokens.length > 1) throw Error('Minted multiple tokens');1493 if (createdTokens.tokens.length > 1) throw Error('Minted multiple tokens');
1520 if (createdTokens.tokens.length < 1) throw Error('No tokens minted');1494 if (createdTokens.tokens.length < 1) throw Error('No tokens minted');
1521 return this.getTokenObject(data.collectionId, createdTokens.tokens[0].tokenId);1495 return this.getTokenObject(data.collectionId, createdTokens.tokens[0].tokenId);
1522 }1496 }
15231497
1524 async mintMultipleTokens(signer: TSigner, collectionId: number, tokens: {owner: ICrossAccountId, pieces: bigint, properties?: IProperty[]}[], label?: string): Promise<UniqueRFTToken[]> {1498 async mintMultipleTokens(signer: TSigner, collectionId: number, tokens: {owner: ICrossAccountId, pieces: bigint, properties?: IProperty[]}[]): Promise<UniqueRFTToken[]> {
1525 throw Error('Not implemented');1499 throw Error('Not implemented');
1526 if(typeof label === 'undefined') label = `collection #${collectionId}`;
1527 const creationResult = await this.helper.executeExtrinsic(1500 const creationResult = await this.helper.executeExtrinsic(
1528 signer,1501 signer,
1529 'api.tx.unique.createMultipleItemsEx', [collectionId, {RefungibleMultipleOwners: tokens}],1502 'api.tx.unique.createMultipleItemsEx', [collectionId, {RefungibleMultipleOwners: tokens}],
1530 true, `Unable to mint RFT tokens for ${label}`,1503 true, // `Unable to mint RFT tokens for ${label}`,
1531 );1504 );
1532 const collection = this.getCollectionObject(collectionId);1505 const collection = this.getCollectionObject(collectionId);
1533 return this.helper.util.extractTokensFromCreationResult(creationResult, label).tokens.map((x: IToken) => collection.getTokenObject(x.tokenId));1506 return this.helper.util.extractTokensFromCreationResult(creationResult).tokens.map((x: IToken) => collection.getTokenObject(x.tokenId));
1534 }1507 }
15351508
1536 /**1509 /**
1539 * @param collectionId ID of collection1512 * @param collectionId ID of collection
1540 * @param owner tokens owner1513 * @param owner tokens owner
1541 * @param tokens array of tokens with properties and pieces1514 * @param tokens array of tokens with properties and pieces
1542 * @param label
1543 * @example mintMultipleTokensWithOneOwner(aliceKeyring, 10, {Substrate: "5GHoZe9c73RYbVzq..."}, [{pieces: 100000n, properties: [{key: "gender", value: "male"}]}]);1515 * @example mintMultipleTokensWithOneOwner(aliceKeyring, 10, {Substrate: "5GHoZe9c73RYbVzq..."}, [{pieces: 100000n, properties: [{key: "gender", value: "male"}]}]);
1544 * @returns array of newly created RFT tokens1516 * @returns array of newly created RFT tokens
1545 */1517 */
1546 async mintMultipleTokensWithOneOwner(signer: TSigner, collectionId: number, owner: ICrossAccountId, tokens: {pieces: bigint, properties?: IProperty[]}[], label?: string): Promise<UniqueRFTToken[]> {1518 async mintMultipleTokensWithOneOwner(signer: TSigner, collectionId: number, owner: ICrossAccountId, tokens: {pieces: bigint, properties?: IProperty[]}[]): Promise<UniqueRFTToken[]> {
1547 if(typeof label === 'undefined') label = `collection #${collectionId}`;
1548 const rawTokens = [];1519 const rawTokens = [];
1549 for (const token of tokens) {1520 for (const token of tokens) {
1550 const raw = {ReFungible: {pieces: token.pieces, properties: token.properties}};1521 const raw = {ReFungible: {pieces: token.pieces, properties: token.properties}};
1553 const creationResult = await this.helper.executeExtrinsic(1524 const creationResult = await this.helper.executeExtrinsic(
1554 signer,1525 signer,
1555 'api.tx.unique.createMultipleItems', [collectionId, owner, rawTokens],1526 'api.tx.unique.createMultipleItems', [collectionId, owner, rawTokens],
1556 true, `Unable to mint RFT tokens for ${label}`,1527 true,
1557 );1528 );
1558 const collection = this.getCollectionObject(collectionId);1529 const collection = this.getCollectionObject(collectionId);
1559 return this.helper.util.extractTokensFromCreationResult(creationResult, label).tokens.map((x: IToken) => collection.getTokenObject(x.tokenId));1530 return this.helper.util.extractTokensFromCreationResult(creationResult).tokens.map((x: IToken) => collection.getTokenObject(x.tokenId));
1560 }1531 }
15611532
1562 /**1533 /**
1563 * Destroys a concrete instance of RFT.1534 * Destroys a concrete instance of RFT.
1564 * @param signer keyring of signer1535 * @param signer keyring of signer
1565 * @param collectionId ID of collection1536 * @param collectionId ID of collection
1566 * @param tokenId ID of token1537 * @param tokenId ID of token
1567 * @param label
1568 * @param amount number of pieces to be burnt1538 * @param amount number of pieces to be burnt
1569 * @example burnToken(aliceKeyring, 10, 5);1539 * @example burnToken(aliceKeyring, 10, 5);
1570 * @returns ```true``` and burnt token number is extrinsic success. Otherwise ```false``` and ```null```1540 * @returns ```true``` and burnt token number is extrinsic success. Otherwise ```false``` and ```null```
1571 */1541 */
1572 async burnToken(signer: IKeyringPair, collectionId: number, tokenId: number, label?: string, amount=100n): Promise<{ success: boolean; token: number | null; }> {1542 async burnToken(signer: IKeyringPair, collectionId: number, tokenId: number, amount=1n): Promise<{ success: boolean; token: number | null; }> {
1573 return await super.burnToken(signer, collectionId, tokenId, label, amount);1543 return await super.burnToken(signer, collectionId, tokenId, amount);
1574 }1544 }
15751545
1576 /**1546 /**
1580 * @param collectionId ID of collection1550 * @param collectionId ID of collection
1581 * @param tokenId ID of token1551 * @param tokenId ID of token
1582 * @param toAddressObj address to approve1552 * @param toAddressObj address to approve
1583 * @param label
1584 * @param amount number of pieces to be approved1553 * @param amount number of pieces to be approved
1585 * @example approveToken(aliceKeyring, 10, 5, {Substrate: "5GHoZe9c73RYbVzq..."}, "", 10000n);1554 * @example approveToken(aliceKeyring, 10, 5, {Substrate: "5GHoZe9c73RYbVzq..."}, "", 10000n);
1586 * @returns true if the token success, otherwise false1555 * @returns true if the token success, otherwise false
1587 */1556 */
1588 async approveToken(signer: IKeyringPair, collectionId: number, tokenId: number, toAddressObj: ICrossAccountId, label?: string, amount=100n) {1557 async approveToken(signer: IKeyringPair, collectionId: number, tokenId: number, toAddressObj: ICrossAccountId, amount=1n) {
1589 return super.approveToken(signer, collectionId, tokenId, toAddressObj, label, amount);1558 return super.approveToken(signer, collectionId, tokenId, toAddressObj, amount);
1590 }1559 }
15911560
1592 /**1561 /**
1606 * @param collectionId ID of collection1575 * @param collectionId ID of collection
1607 * @param tokenId ID of token1576 * @param tokenId ID of token
1608 * @param amount new number of pieces1577 * @param amount new number of pieces
1609 * @param label
1610 * @example repartitionToken(aliceKeyring, 10, 5, 12345n);1578 * @example repartitionToken(aliceKeyring, 10, 5, 12345n);
1611 * @returns true if the repartion was success, otherwise false1579 * @returns true if the repartion was success, otherwise false
1612 */1580 */
1613 async repartitionToken(signer: TSigner, collectionId: number, tokenId: number, amount: bigint, label?: string): Promise<boolean> {1581 async repartitionToken(signer: TSigner, collectionId: number, tokenId: number, amount: bigint): Promise<boolean> {
1614 if(typeof label === 'undefined') label = `collection #${collectionId}`;
1615 const currentAmount = await this.getTokenTotalPieces(collectionId, tokenId);1582 const currentAmount = await this.getTokenTotalPieces(collectionId, tokenId);
1616 const repartitionResult = await this.helper.executeExtrinsic(1583 const repartitionResult = await this.helper.executeExtrinsic(
1617 signer,1584 signer,
1618 'api.tx.unique.repartition', [collectionId, tokenId, amount],1585 'api.tx.unique.repartition', [collectionId, tokenId, amount],
1619 true, `Unable to repartition RFT token for ${label}`,1586 true,
1620 );1587 );
1621 if(currentAmount < amount) return this.helper.util.findCollectionInEvents(repartitionResult.result.events, collectionId, 'common', 'ItemCreated', label);1588 if(currentAmount < amount) return this.helper.util.findCollectionInEvents(repartitionResult.result.events, collectionId, 'common', 'ItemCreated');
1622 return this.helper.util.findCollectionInEvents(repartitionResult.result.events, collectionId, 'common', 'ItemDestroyed', label);1589 return this.helper.util.findCollectionInEvents(repartitionResult.result.events, collectionId, 'common', 'ItemDestroyed');
1623 }1590 }
1624}1591}
16251592
1640 * @param signer keyring of signer1607 * @param signer keyring of signer
1641 * @param collectionOptions Collection options1608 * @param collectionOptions Collection options
1642 * @param decimalPoints number of token decimals 1609 * @param decimalPoints number of token decimals
1643 * @param errorLabel
1644 * @example1610 * @example
1645 * mintCollection(aliceKeyring, {1611 * mintCollection(aliceKeyring, {
1646 * name: 'New',1612 * name: 'New',
1649 * }, 18)1615 * }, 18)
1650 * @returns newly created fungible collection1616 * @returns newly created fungible collection
1651 */1617 */
1652 async mintCollection(signer: TSigner, collectionOptions: ICollectionCreationOptions, decimalPoints = 0, errorLabel = 'Unable to mint collection'): Promise<UniqueFTCollection> {1618 async mintCollection(signer: TSigner, collectionOptions: ICollectionCreationOptions, decimalPoints = 0): Promise<UniqueFTCollection> {
1653 collectionOptions = JSON.parse(JSON.stringify(collectionOptions)) as ICollectionCreationOptions; // Clone object1619 collectionOptions = JSON.parse(JSON.stringify(collectionOptions)) as ICollectionCreationOptions; // Clone object
1654 if(collectionOptions.tokenPropertyPermissions) throw Error('Fungible collections has no tokenPropertyPermissions');1620 if(collectionOptions.tokenPropertyPermissions) throw Error('Fungible collections has no tokenPropertyPermissions');
1655 collectionOptions.mode = {fungible: decimalPoints};1621 collectionOptions.mode = {fungible: decimalPoints};
1659 const creationResult = await this.helper.executeExtrinsic(1625 const creationResult = await this.helper.executeExtrinsic(
1660 signer,1626 signer,
1661 'api.tx.unique.createCollectionEx', [collectionOptions],1627 'api.tx.unique.createCollectionEx', [collectionOptions],
1662 true, errorLabel,1628 true,
1663 );1629 );
1664 return this.getCollectionObject(this.helper.util.extractCollectionIdFromCreationResult(creationResult, errorLabel));1630 return this.getCollectionObject(this.helper.util.extractCollectionIdFromCreationResult(creationResult));
1665 }1631 }
16661632
1667 /**1633 /**
1670 * @param collectionId ID of collection1636 * @param collectionId ID of collection
1671 * @param owner address owner of new tokens1637 * @param owner address owner of new tokens
1672 * @param amount amount of tokens to be meanted1638 * @param amount amount of tokens to be meanted
1673 * @param label
1674 * @example mintTokens(aliceKeyring, 10, {Substrate: "5GHoZe9c73RYbVzq"}, 1000n);1639 * @example mintTokens(aliceKeyring, 10, {Substrate: "5GHoZe9c73RYbVzq"}, 1000n);
1675 * @returns ```true``` if extrinsic success, otherwise ```false``` 1640 * @returns ```true``` if extrinsic success, otherwise ```false```
1676 */1641 */
1677 async mintTokens(signer: TSigner, collectionId: number, owner: ICrossAccountId | string, amount: bigint, label?: string): Promise<boolean> {1642 async mintTokens(signer: TSigner, collectionId: number, owner: ICrossAccountId | string, amount: bigint): Promise<boolean> {
1678 if(typeof label === 'undefined') label = `collection #${collectionId}`;
1679 const creationResult = await this.helper.executeExtrinsic(1643 const creationResult = await this.helper.executeExtrinsic(
1680 signer,1644 signer,
1681 'api.tx.unique.createItem', [collectionId, (typeof owner === 'string') ? {Substrate: owner} : owner, {1645 'api.tx.unique.createItem', [collectionId, (typeof owner === 'string') ? {Substrate: owner} : owner, {
1682 fungible: {1646 fungible: {
1683 value: amount,1647 value: amount,
1684 },1648 },
1685 }],1649 }],
1686 true, `Unable to mint fungible tokens for ${label}`,1650 true, // `Unable to mint fungible tokens for ${label}`,
1687 );1651 );
1688 return this.helper.util.findCollectionInEvents(creationResult.result.events, collectionId, 'common', 'ItemCreated', label);1652 return this.helper.util.findCollectionInEvents(creationResult.result.events, collectionId, 'common', 'ItemCreated');
1689 }1653 }
16901654
1691 /**1655 /**
1694 * @param collectionId ID of collection1658 * @param collectionId ID of collection
1695 * @param owner tokens owner1659 * @param owner tokens owner
1696 * @param tokens array of tokens with properties and pieces1660 * @param tokens array of tokens with properties and pieces
1697 * @param label
1698 * @returns ```true``` if extrinsic success, otherwise ```false``` 1661 * @returns ```true``` if extrinsic success, otherwise ```false```
1699 */1662 */
1700 async mintMultipleTokensWithOneOwner(signer: TSigner, collectionId: number, owner: ICrossAccountId, tokens: {value: bigint}[], label?: string): Promise<boolean> {1663 async mintMultipleTokensWithOneOwner(signer: TSigner, collectionId: number, owner: ICrossAccountId, tokens: {value: bigint}[]): Promise<boolean> {
1701 if(typeof label === 'undefined') label = `collection #${collectionId}`;
1702 const rawTokens = [];1664 const rawTokens = [];
1703 for (const token of tokens) {1665 for (const token of tokens) {
1704 const raw = {Fungible: {Value: token.value}};1666 const raw = {Fungible: {Value: token.value}};
1707 const creationResult = await this.helper.executeExtrinsic(1669 const creationResult = await this.helper.executeExtrinsic(
1708 signer,1670 signer,
1709 'api.tx.unique.createMultipleItems', [collectionId, owner, rawTokens],1671 'api.tx.unique.createMultipleItems', [collectionId, owner, rawTokens],
1710 true, `Unable to mint RFT tokens for ${label}`,1672 true,
1711 );1673 );
1712 return this.helper.util.findCollectionInEvents(creationResult.result.events, collectionId, 'common', 'ItemCreated', label);1674 return this.helper.util.findCollectionInEvents(creationResult.result.events, collectionId, 'common', 'ItemCreated');
1713 }1675 }
17141676
1715 /**1677 /**
1742 * @example transfer(aliceKeyring, 10, {Substrate: "5GHoZe9c73RYbVzq..."}, 1000n);1704 * @example transfer(aliceKeyring, 10, {Substrate: "5GHoZe9c73RYbVzq..."}, 1000n);
1743 * @returns ```true``` if extrinsic success, otherwise ```false``` 1705 * @returns ```true``` if extrinsic success, otherwise ```false```
1744 */1706 */
1745 async transfer(signer: TSigner, collectionId: number, toAddressObj: ICrossAccountId, amount: bigint) {1707 async transfer(signer: TSigner, collectionId: number, toAddressObj: ICrossAccountId, amount=1n) {
1746 return await super.transferToken(signer, collectionId, 0, toAddressObj, amount);1708 return await super.transferToken(signer, collectionId, 0, toAddressObj, amount);
1747 }1709 }
17481710
1756 * @example transferFrom(aliceKeyring, 10, {Substrate: "5GHoZe9c73RYbVzq..."}, {Substrate: "5DfhbVfww7ThF8q6f3ij..."}, 10000n);1718 * @example transferFrom(aliceKeyring, 10, {Substrate: "5GHoZe9c73RYbVzq..."}, {Substrate: "5DfhbVfww7ThF8q6f3ij..."}, 10000n);
1757 * @returns ```true``` if extrinsic success, otherwise ```false``` 1719 * @returns ```true``` if extrinsic success, otherwise ```false```
1758 */1720 */
1759 async transferFrom(signer: TSigner, collectionId: number, fromAddressObj: ICrossAccountId, toAddressObj: ICrossAccountId, amount: bigint) {1721 async transferFrom(signer: TSigner, collectionId: number, fromAddressObj: ICrossAccountId, toAddressObj: ICrossAccountId, amount=1n) {
1760 return await super.transferTokenFrom(signer, collectionId, 0, fromAddressObj, toAddressObj, amount);1722 return await super.transferTokenFrom(signer, collectionId, 0, fromAddressObj, toAddressObj, amount);
1761 }1723 }
17621724
1765 * @param signer keyring of signer1727 * @param signer keyring of signer
1766 * @param collectionId ID of collection1728 * @param collectionId ID of collection
1767 * @param amount amount of tokens to be destroyed1729 * @param amount amount of tokens to be destroyed
1768 * @param label
1769 * @example burnTokens(aliceKeyring, 10, 1000n);1730 * @example burnTokens(aliceKeyring, 10, 1000n);
1770 * @returns ```true``` if extrinsic success, otherwise ```false``` 1731 * @returns ```true``` if extrinsic success, otherwise ```false```
1771 */1732 */
1772 async burnTokens(signer: IKeyringPair, collectionId: number, amount=100n, label?: string): Promise<boolean> {1733 async burnTokens(signer: IKeyringPair, collectionId: number, amount=1n): Promise<boolean> {
1773 return (await super.burnToken(signer, collectionId, 0, label, amount)).success;1734 return (await super.burnToken(signer, collectionId, 0, amount)).success;
1774 }1735 }
17751736
1776 /**1737 /**
1779 * @param collectionId ID of collection1740 * @param collectionId ID of collection
1780 * @param fromAddressObj address on behalf of which tokens will be burnt1741 * @param fromAddressObj address on behalf of which tokens will be burnt
1781 * @param amount amount of tokens to be burnt1742 * @param amount amount of tokens to be burnt
1782 * @param label
1783 * @example burnTokensFrom(aliceKeyring, 10, {Substrate: "5GHoZe9c73RYbVzq..."}, 1000n);1743 * @example burnTokensFrom(aliceKeyring, 10, {Substrate: "5GHoZe9c73RYbVzq..."}, 1000n);
1784 * @returns ```true``` if extrinsic success, otherwise ```false``` 1744 * @returns ```true``` if extrinsic success, otherwise ```false```
1785 */1745 */
1786 async burnTokensFrom(signer: IKeyringPair, collectionId: number, fromAddressObj: ICrossAccountId, amount=100n, label?: string): Promise<boolean> {1746 async burnTokensFrom(signer: IKeyringPair, collectionId: number, fromAddressObj: ICrossAccountId, amount=1n): Promise<boolean> {
1787 return await super.burnTokenFrom(signer, collectionId, fromAddressObj, 0, label, amount);1747 return await super.burnTokenFrom(signer, collectionId, fromAddressObj, 0, amount);
1788 }1748 }
17891749
1790 /**1750 /**
1803 * @param collectionId ID of collection1763 * @param collectionId ID of collection
1804 * @param toAddressObj address to be approved1764 * @param toAddressObj address to be approved
1805 * @param amount amount of tokens to be approved1765 * @param amount amount of tokens to be approved
1806 * @param label
1807 * @example approveTokens(aliceKeyring, 10, {Substrate: "5GHoZe9c73RYbVzq..."}, 1000n)1766 * @example approveTokens(aliceKeyring, 10, {Substrate: "5GHoZe9c73RYbVzq..."}, 1000n)
1808 * @returns ```true``` if extrinsic success, otherwise ```false``` 1767 * @returns ```true``` if extrinsic success, otherwise ```false```
1809 */1768 */
1810 async approveTokens(signer: IKeyringPair, collectionId: number, toAddressObj: ICrossAccountId, amount=100n, label?: string) {1769 async approveTokens(signer: IKeyringPair, collectionId: number, toAddressObj: ICrossAccountId, amount=1n) {
1811 return super.approveToken(signer, collectionId, 0, toAddressObj, label, amount);1770 return super.approveToken(signer, collectionId, 0, toAddressObj, amount);
1812 }1771 }
18131772
1814 /**1773 /**
1912 * @returns ```true``` if extrinsic success, otherwise ```false```1871 * @returns ```true``` if extrinsic success, otherwise ```false```
1913 */1872 */
1914 async transferToSubstrate(signer: TSigner, address: TSubstrateAccount, amount: bigint | string): Promise<boolean> {1873 async transferToSubstrate(signer: TSigner, address: TSubstrateAccount, amount: bigint | string): Promise<boolean> {
1915 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}`*/);
19161875
1917 let transfer = {from: null, to: null, amount: 0n} as any;1876 let transfer = {from: null, to: null, amount: 0n} as any;
1918 result.result.events.forEach(({event: {data, method, section}}) => {1877 result.result.events.forEach(({event: {data, method, section}}) => {
20331992
2034 async getEffectiveLimits() {1993 async getEffectiveLimits() {
2035 return await this.helper.collection.getEffectiveLimits(this.collectionId);1994 return await this.helper.collection.getEffectiveLimits(this.collectionId);
1995 }
1996
1997 async setSponsor(signer: TSigner, sponsorAddress: TSubstrateAccount) {
1998 return await this.helper.collection.setSponsor(signer, this.collectionId, sponsorAddress);
1999 }
2000
2001 async confirmSponsorship(signer: TSigner) {
2002 return await this.helper.collection.confirmSponsorship(signer, this.collectionId);
2036 }2003 }
20372004
2038 async setSponsor(signer: TSigner, sponsorAddress: TSubstrateAccount, label?: string) {2005 async setLimits(signer: TSigner, limits: ICollectionLimits) {
2039 return await this.helper.collection.setSponsor(signer, this.collectionId, sponsorAddress, label);2006 return await this.helper.collection.setLimits(signer, this.collectionId, limits);
2040 }2007 }
20412008
2042 async confirmSponsorship(signer: TSigner, label?: string) {2009 async changeOwner(signer: TSigner, ownerAddress: TSubstrateAccount) {
2043 return await this.helper.collection.confirmSponsorship(signer, this.collectionId, label);2010 return await this.helper.collection.changeOwner(signer, this.collectionId, ownerAddress);
2044 }2011 }
20452012
2046 async setLimits(signer: TSigner, limits: ICollectionLimits, label?: string) {2013 async addAdmin(signer: TSigner, adminAddressObj: ICrossAccountId) {
2047 return await this.helper.collection.setLimits(signer, this.collectionId, limits, label);2014 return await this.helper.collection.addAdmin(signer, this.collectionId, adminAddressObj);
2048 }2015 }
20492016
2050 async changeOwner(signer: TSigner, ownerAddress: TSubstrateAccount, label?: string) {2017 async enableAllowList(signer: TSigner, value = true/*: 'Normal' | 'AllowList' = 'AllowList'*/) {
2051 return await this.helper.collection.changeOwner(signer, this.collectionId, ownerAddress, label);2018 return await this.setPermissions(signer, value ? {access: 'AllowList', mintMode: true} : {access: 'Normal'});
2052 }2019 }
20532020
2054 async addAdmin(signer: TSigner, adminAddressObj: ICrossAccountId, label?: string) {2021 async addToAllowList(signer: TSigner, addressObj: ICrossAccountId) {
2055 return await this.helper.collection.addAdmin(signer, this.collectionId, adminAddressObj, label);2022 return await this.helper.collection.addToAllowList(signer, this.collectionId, addressObj);
2056 }2023 }
20572024
2058 async addToAllowList(signer: TSigner, addressObj: ICrossAccountId, label?: string) {2025 async removeFromAllowList(signer: TSigner, addressObj: ICrossAccountId) {
2059 return await this.helper.collection.addToAllowList(signer, this.collectionId, addressObj, label);2026 return await this.helper.collection.removeFromAllowList(signer, this.collectionId, addressObj);
2060 }2027 }
20612028
2062 async removeAdmin(signer: TSigner, adminAddressObj: ICrossAccountId, label?: string) {2029 async removeAdmin(signer: TSigner, adminAddressObj: ICrossAccountId) {
2063 return await this.helper.collection.removeAdmin(signer, this.collectionId, adminAddressObj, label);2030 return await this.helper.collection.removeAdmin(signer, this.collectionId, adminAddressObj);
2064 }2031 }
20652032
2066 async setProperties(signer: TSigner, properties: IProperty[], label?: string) {2033 async setProperties(signer: TSigner, properties: IProperty[]) {
2067 return await this.helper.collection.setProperties(signer, this.collectionId, properties, label);2034 return await this.helper.collection.setProperties(signer, this.collectionId, properties);
2068 }2035 }
20692036
2070 async deleteProperties(signer: TSigner, propertyKeys: string[], label?: string) {2037 async deleteProperties(signer: TSigner, propertyKeys: string[]) {
2071 return await this.helper.collection.deleteProperties(signer, this.collectionId, propertyKeys, label);2038 return await this.helper.collection.deleteProperties(signer, this.collectionId, propertyKeys);
2072 }2039 }
20732040
2074 async getTokenNextSponsored(tokenId: number, addressObj: ICrossAccountId) {2041 async getTokenNextSponsored(tokenId: number, addressObj: ICrossAccountId) {
2075 return await this.helper.collection.getTokenNextSponsored(this.collectionId, tokenId, addressObj);2042 return await this.helper.collection.getTokenNextSponsored(this.collectionId, tokenId, addressObj);
2076 }2043 }
20772044
2078 async setPermissions(signer: TSigner, permissions: ICollectionPermissions, label?: string) {2045 async setPermissions(signer: TSigner, permissions: ICollectionPermissions) {
2079 return await this.helper.collection.setPermissions(signer, this.collectionId, permissions, label);2046 return await this.helper.collection.setPermissions(signer, this.collectionId, permissions);
2080 }2047 }
20812048
2082 async enableNesting(signer: TSigner, permissions: INestingPermissions, label?: string) {2049 async enableNesting(signer: TSigner, permissions: INestingPermissions) {
2083 return await this.helper.collection.enableNesting(signer, this.collectionId, permissions, label);2050 return await this.helper.collection.enableNesting(signer, this.collectionId, permissions);
2084 }2051 }
20852052
2086 async disableNesting(signer: TSigner, label?: string) {2053 async disableNesting(signer: TSigner) {
2087 return await this.helper.collection.disableNesting(signer, this.collectionId, label);2054 return await this.helper.collection.disableNesting(signer, this.collectionId);
2088 }2055 }
20892056
2090 async burn(signer: TSigner, label?: string) {2057 async burn(signer: TSigner) {
2091 return await this.helper.collection.burn(signer, this.collectionId, label);2058 return await this.helper.collection.burn(signer, this.collectionId);
2092 }2059 }
2093}2060}
20942061
2126 return await this.helper.nft.transferTokenFrom(signer, this.collectionId, tokenId, fromAddressObj, toAddressObj);2093 return await this.helper.nft.transferTokenFrom(signer, this.collectionId, tokenId, fromAddressObj, toAddressObj);
2127 }2094 }
21282095
2129 async approveToken(signer: TSigner, tokenId: number, toAddressObj: ICrossAccountId, label?: string) {2096 async approveToken(signer: TSigner, tokenId: number, toAddressObj: ICrossAccountId) {
2130 return await this.helper.nft.approveToken(signer, this.collectionId, tokenId, toAddressObj, label);2097 return await this.helper.nft.approveToken(signer, this.collectionId, tokenId, toAddressObj);
2131 }2098 }
21322099
2133 async isTokenApproved(tokenId: number, toAddressObj: ICrossAccountId) {2100 async isTokenApproved(tokenId: number, toAddressObj: ICrossAccountId) {
2134 return await this.helper.nft.isTokenApproved(this.collectionId, tokenId, toAddressObj);2101 return await this.helper.nft.isTokenApproved(this.collectionId, tokenId, toAddressObj);
2135 }2102 }
21362103
2137 async mintToken(signer: TSigner, owner: ICrossAccountId, properties?: IProperty[], label?: string) {2104 async mintToken(signer: TSigner, owner: ICrossAccountId, properties?: IProperty[]) {
2138 return await this.helper.nft.mintToken(signer, {collectionId: this.collectionId, owner, properties}, label);2105 return await this.helper.nft.mintToken(signer, {collectionId: this.collectionId, owner, properties});
2139 }2106 }
21402107
2141 async mintMultipleTokens(signer: TSigner, tokens: {owner: ICrossAccountId, properties?: IProperty[]}[], label?: string) {2108 async mintMultipleTokens(signer: TSigner, tokens: {owner: ICrossAccountId, properties?: IProperty[]}[]) {
2142 return await this.helper.nft.mintMultipleTokens(signer, this.collectionId, tokens, label);2109 return await this.helper.nft.mintMultipleTokens(signer, this.collectionId, tokens);
2143 }2110 }
21442111
2145 async burnToken(signer: TSigner, tokenId: number, label?: string) {2112 async burnToken(signer: TSigner, tokenId: number) {
2146 return await this.helper.nft.burnToken(signer, this.collectionId, tokenId, label);2113 return await this.helper.nft.burnToken(signer, this.collectionId, tokenId);
2147 }2114 }
21482115
2149 async setTokenProperties(signer: TSigner, tokenId: number, properties: IProperty[], label?: string) {2116 async setTokenProperties(signer: TSigner, tokenId: number, properties: IProperty[]) {
2150 return await this.helper.nft.setTokenProperties(signer, this.collectionId, tokenId, properties, label);2117 return await this.helper.nft.setTokenProperties(signer, this.collectionId, tokenId, properties);
2151 }2118 }
21522119
2153 async deleteTokenProperties(signer: TSigner, tokenId: number, propertyKeys: string[], label?: string) {2120 async deleteTokenProperties(signer: TSigner, tokenId: number, propertyKeys: string[]) {
2154 return await this.helper.nft.deleteTokenProperties(signer, this.collectionId, tokenId, propertyKeys, label);2121 return await this.helper.nft.deleteTokenProperties(signer, this.collectionId, tokenId, propertyKeys);
2155 }2122 }
21562123
2157 async setTokenPropertyPermissions(signer: TSigner, permissions: ITokenPropertyPermission[], label?: string) {2124 async setTokenPropertyPermissions(signer: TSigner, permissions: ITokenPropertyPermission[]) {
2158 return await this.helper.nft.setTokenPropertyPermissions(signer, this.collectionId, permissions, label);2125 return await this.helper.nft.setTokenPropertyPermissions(signer, this.collectionId, permissions);
2159 }2126 }
21602127
2161 async nestToken(signer: TSigner, tokenId: number, toTokenObj: IToken, label?: string) {2128 async nestToken(signer: TSigner, tokenId: number, toTokenObj: IToken) {
2162 return await this.helper.nft.nestToken(signer, {collectionId: this.collectionId, tokenId}, toTokenObj, label);2129 return await this.helper.nft.nestToken(signer, {collectionId: this.collectionId, tokenId}, toTokenObj);
2163 }2130 }
21642131
2165 async unnestToken(signer: TSigner, tokenId: number, fromTokenObj: IToken, toAddressObj: ICrossAccountId, label?: string) {2132 async unnestToken(signer: TSigner, tokenId: number, fromTokenObj: IToken, toAddressObj: ICrossAccountId) {
2166 return await this.helper.nft.unnestToken(signer, {collectionId: this.collectionId, tokenId}, fromTokenObj, toAddressObj, label);2133 return await this.helper.nft.unnestToken(signer, {collectionId: this.collectionId, tokenId}, fromTokenObj, toAddressObj);
2167 }2134 }
2168}2135}
21692136
2189 return await this.helper.rft.getTokenTotalPieces(this.collectionId, tokenId);2156 return await this.helper.rft.getTokenTotalPieces(this.collectionId, tokenId);
2190 }2157 }
21912158
2192 async transferToken(signer: TSigner, tokenId: number, addressObj: ICrossAccountId, amount=100n) {2159 async transferToken(signer: TSigner, tokenId: number, addressObj: ICrossAccountId, amount=1n) {
2193 return await this.helper.rft.transferToken(signer, this.collectionId, tokenId, addressObj, amount);2160 return await this.helper.rft.transferToken(signer, this.collectionId, tokenId, addressObj, amount);
2194 }2161 }
21952162
2196 async transferTokenFrom(signer: TSigner, tokenId: number, fromAddressObj: ICrossAccountId, toAddressObj: ICrossAccountId, amount=100n) {2163 async transferTokenFrom(signer: TSigner, tokenId: number, fromAddressObj: ICrossAccountId, toAddressObj: ICrossAccountId, amount=1n) {
2197 return await this.helper.rft.transferTokenFrom(signer, this.collectionId, tokenId, fromAddressObj, toAddressObj, amount);2164 return await this.helper.rft.transferTokenFrom(signer, this.collectionId, tokenId, fromAddressObj, toAddressObj, amount);
2198 }2165 }
21992166
2200 async approveToken(signer: TSigner, tokenId: number, toAddressObj: ICrossAccountId, amount=100n, label?: string) {2167 async approveToken(signer: TSigner, tokenId: number, toAddressObj: ICrossAccountId, amount=1n) {
2201 return await this.helper.rft.approveToken(signer, this.collectionId, tokenId, toAddressObj, label, amount);2168 return await this.helper.rft.approveToken(signer, this.collectionId, tokenId, toAddressObj, amount);
2202 }2169 }
22032170
2204 async getTokenApprovedPieces(tokenId: number, fromAddressObj: ICrossAccountId, toAddressObj: ICrossAccountId) {2171 async getTokenApprovedPieces(tokenId: number, fromAddressObj: ICrossAccountId, toAddressObj: ICrossAccountId) {
2205 return await this.helper.rft.getTokenApprovedPieces(this.collectionId, tokenId, toAddressObj, fromAddressObj);2172 return await this.helper.rft.getTokenApprovedPieces(this.collectionId, tokenId, toAddressObj, fromAddressObj);
2206 }2173 }
22072174
2208 async repartitionToken(signer: TSigner, tokenId: number, amount: bigint, label?: string) {2175 async repartitionToken(signer: TSigner, tokenId: number, amount: bigint) {
2209 return await this.helper.rft.repartitionToken(signer, this.collectionId, tokenId, amount, label);2176 return await this.helper.rft.repartitionToken(signer, this.collectionId, tokenId, amount);
2210 }2177 }
22112178
2212 async mintToken(signer: TSigner, owner: ICrossAccountId, pieces=100n, properties?: IProperty[], label?: string) {2179 async mintToken(signer: TSigner, owner: ICrossAccountId, pieces=100n, properties?: IProperty[]) {
2213 return await this.helper.rft.mintToken(signer, {collectionId: this.collectionId, owner, pieces, properties}, label);2180 return await this.helper.rft.mintToken(signer, {collectionId: this.collectionId, owner, pieces, properties});
2214 }2181 }
22152182
2216 async mintMultipleTokens(signer: TSigner, tokens: {owner: ICrossAccountId, pieces: bigint, properties?: IProperty[]}[], label?: string) {2183 async mintMultipleTokens(signer: TSigner, tokens: {owner: ICrossAccountId, pieces: bigint, properties?: IProperty[]}[]) {
2217 return await this.helper.rft.mintMultipleTokens(signer, this.collectionId, tokens, label);2184 return await this.helper.rft.mintMultipleTokens(signer, this.collectionId, tokens);
2218 }2185 }
22192186
2220 async burnToken(signer: TSigner, tokenId: number, amount=100n, label?: string) {2187 async burnToken(signer: TSigner, tokenId: number, amount=1n) {
2221 return await this.helper.rft.burnToken(signer, this.collectionId, tokenId, label, amount);2188 return await this.helper.rft.burnToken(signer, this.collectionId, tokenId, amount);
2222 }2189 }
22232190
2224 async setTokenProperties(signer: TSigner, tokenId: number, properties: IProperty[], label?: string) {2191 async setTokenProperties(signer: TSigner, tokenId: number, properties: IProperty[]) {
2225 return await this.helper.rft.setTokenProperties(signer, this.collectionId, tokenId, properties, label);2192 return await this.helper.rft.setTokenProperties(signer, this.collectionId, tokenId, properties);
2226 }2193 }
22272194
2228 async deleteTokenProperties(signer: TSigner, tokenId: number, propertyKeys: string[], label?: string) {2195 async deleteTokenProperties(signer: TSigner, tokenId: number, propertyKeys: string[]) {
2229 return await this.helper.rft.deleteTokenProperties(signer, this.collectionId, tokenId, propertyKeys, label);2196 return await this.helper.rft.deleteTokenProperties(signer, this.collectionId, tokenId, propertyKeys);
2230 }2197 }
22312198
2232 async setTokenPropertyPermissions(signer: TSigner, permissions: ITokenPropertyPermission[], label?: string) {2199 async setTokenPropertyPermissions(signer: TSigner, permissions: ITokenPropertyPermission[]) {
2233 return await this.helper.rft.setTokenPropertyPermissions(signer, this.collectionId, permissions, label);2200 return await this.helper.rft.setTokenPropertyPermissions(signer, this.collectionId, permissions);
2234 }2201 }
2235}2202}
22362203
22372204
2238class UniqueFTCollection extends UniqueCollectionBase {2205class UniqueFTCollection extends UniqueCollectionBase {
2239 async mint(signer: TSigner, owner: ICrossAccountId, amount: bigint, label?: string) {2206 async mint(signer: TSigner, owner: ICrossAccountId, amount: bigint) {
2240 return await this.helper.ft.mintTokens(signer, this.collectionId, owner, amount, label);2207 return await this.helper.ft.mintTokens(signer, this.collectionId, owner, amount);
2241 }2208 }
22422209
2243 async mintWithOneOwner(signer: TSigner, owner: ICrossAccountId, tokens: {value: bigint}[], label?: string) {2210 async mintWithOneOwner(signer: TSigner, owner: ICrossAccountId, tokens: {value: bigint}[]) {
2244 return await this.helper.ft.mintMultipleTokensWithOneOwner(signer, this.collectionId, owner, tokens, label);2211 return await this.helper.ft.mintMultipleTokensWithOneOwner(signer, this.collectionId, owner, tokens);
2245 }2212 }
22462213
2247 async getBalance(addressObj: ICrossAccountId) {2214 async getBalance(addressObj: ICrossAccountId) {
2252 return await this.helper.ft.getTop10Owners(this.collectionId);2219 return await this.helper.ft.getTop10Owners(this.collectionId);
2253 }2220 }
22542221
2255 async transfer(signer: TSigner, toAddressObj: ICrossAccountId, amount: bigint) {2222 async transfer(signer: TSigner, toAddressObj: ICrossAccountId, amount=1n) {
2256 return await this.helper.ft.transfer(signer, this.collectionId, toAddressObj, amount);2223 return await this.helper.ft.transfer(signer, this.collectionId, toAddressObj, amount);
2257 }2224 }
22582225
2259 async transferFrom(signer: TSigner, fromAddressObj: ICrossAccountId, toAddressObj: ICrossAccountId, amount: bigint) {2226 async transferFrom(signer: TSigner, fromAddressObj: ICrossAccountId, toAddressObj: ICrossAccountId, amount=1n) {
2260 return await this.helper.ft.transferFrom(signer, this.collectionId, fromAddressObj, toAddressObj, amount);2227 return await this.helper.ft.transferFrom(signer, this.collectionId, fromAddressObj, toAddressObj, amount);
2261 }2228 }
22622229
2263 async burnTokens(signer: TSigner, amount: bigint, label?: string) {2230 async burnTokens(signer: TSigner, amount=1n) {
2264 return await this.helper.ft.burnTokens(signer, this.collectionId, amount, label);2231 return await this.helper.ft.burnTokens(signer, this.collectionId, amount);
2265 }2232 }
22662233
2267 async burnTokensFrom(signer: TSigner, fromAddressObj: ICrossAccountId, amount: bigint, label?: string) {2234 async burnTokensFrom(signer: TSigner, fromAddressObj: ICrossAccountId, amount=1n) {
2268 return await this.helper.ft.burnTokensFrom(signer, this.collectionId, fromAddressObj, amount, label);2235 return await this.helper.ft.burnTokensFrom(signer, this.collectionId, fromAddressObj, amount);
2269 }2236 }
22702237
2271 async getTotalPieces() {2238 async getTotalPieces() {
2272 return await this.helper.ft.getTotalPieces(this.collectionId);2239 return await this.helper.ft.getTotalPieces(this.collectionId);
2273 }2240 }
22742241
2275 async approveTokens(signer: TSigner, toAddressObj: ICrossAccountId, amount=100n, label?: string) {2242 async approveTokens(signer: TSigner, toAddressObj: ICrossAccountId, amount=1n) {
2276 return await this.helper.ft.approveTokens(signer, this.collectionId, toAddressObj, amount, label);2243 return await this.helper.ft.approveTokens(signer, this.collectionId, toAddressObj, amount);
2277 }2244 }
22782245
2279 async getApprovedTokens(fromAddressObj: ICrossAccountId, toAddressObj: ICrossAccountId) {2246 async getApprovedTokens(fromAddressObj: ICrossAccountId, toAddressObj: ICrossAccountId) {
2297 return await this.collection.getTokenNextSponsored(this.tokenId, addressObj);2264 return await this.collection.getTokenNextSponsored(this.tokenId, addressObj);
2298 }2265 }
22992266
2300 async setProperties(signer: TSigner, properties: IProperty[], label?: string) {2267 async setProperties(signer: TSigner, properties: IProperty[]) {
2301 return await this.collection.setTokenProperties(signer, this.tokenId, properties, label);2268 return await this.collection.setTokenProperties(signer, this.tokenId, properties);
2302 }2269 }
23032270
2304 async deleteProperties(signer: TSigner, propertyKeys: string[], label?: string) {2271 async deleteProperties(signer: TSigner, propertyKeys: string[]) {
2305 return await this.collection.deleteTokenProperties(signer, this.tokenId, propertyKeys, label);2272 return await this.collection.deleteTokenProperties(signer, this.tokenId, propertyKeys);
2306 }2273 }
2307}2274}
23082275
2331 return await this.collection.getTokenChildren(this.tokenId, blockHashAt);2298 return await this.collection.getTokenChildren(this.tokenId, blockHashAt);
2332 }2299 }
23332300
2334 async nest(signer: TSigner, toTokenObj: IToken, label?: string) {2301 async nest(signer: TSigner, toTokenObj: IToken) {
2335 return await this.collection.nestToken(signer, this.tokenId, toTokenObj, label);2302 return await this.collection.nestToken(signer, this.tokenId, toTokenObj);
2336 }2303 }
23372304
2338 async unnest(signer: TSigner, fromTokenObj: IToken, toAddressObj: ICrossAccountId, label?: string) {2305 async unnest(signer: TSigner, fromTokenObj: IToken, toAddressObj: ICrossAccountId) {
2339 return await this.collection.unnestToken(signer, this.tokenId, fromTokenObj, toAddressObj, label);2306 return await this.collection.unnestToken(signer, this.tokenId, fromTokenObj, toAddressObj);
2340 }2307 }
23412308
2342 async transfer(signer: TSigner, addressObj: ICrossAccountId) {2309 async transfer(signer: TSigner, addressObj: ICrossAccountId) {
2347 return await this.collection.transferTokenFrom(signer, this.tokenId, fromAddressObj, toAddressObj);2314 return await this.collection.transferTokenFrom(signer, this.tokenId, fromAddressObj, toAddressObj);
2348 }2315 }
23492316
2350 async approve(signer: TSigner, toAddressObj: ICrossAccountId, label?: string) {2317 async approve(signer: TSigner, toAddressObj: ICrossAccountId) {
2351 return await this.collection.approveToken(signer, this.tokenId, toAddressObj, label);2318 return await this.collection.approveToken(signer, this.tokenId, toAddressObj);
2352 }2319 }
23532320
2354 async isApproved(toAddressObj: ICrossAccountId) {2321 async isApproved(toAddressObj: ICrossAccountId) {
2355 return await this.collection.isTokenApproved(this.tokenId, toAddressObj);2322 return await this.collection.isTokenApproved(this.tokenId, toAddressObj);
2356 }2323 }
23572324
2358 async burn(signer: TSigner, label?: string) {2325 async burn(signer: TSigner) {
2359 return await this.collection.burnToken(signer, this.tokenId, label);2326 return await this.collection.burnToken(signer, this.tokenId);
2360 }2327 }
2361}2328}
23622329
2380 return await this.collection.getTokenTotalPieces(this.tokenId);2347 return await this.collection.getTokenTotalPieces(this.tokenId);
2381 }2348 }
23822349
2383 async transfer(signer: TSigner, addressObj: ICrossAccountId, amount=100n) {2350 async transfer(signer: TSigner, addressObj: ICrossAccountId, amount=1n) {
2384 return await this.collection.transferToken(signer, this.tokenId, addressObj, amount);2351 return await this.collection.transferToken(signer, this.tokenId, addressObj, amount);
2385 }2352 }
23862353
2387 async transferFrom(signer: TSigner, fromAddressObj: ICrossAccountId, toAddressObj: ICrossAccountId, amount=100n) {2354 async transferFrom(signer: TSigner, fromAddressObj: ICrossAccountId, toAddressObj: ICrossAccountId, amount=1n) {
2388 return await this.collection.transferTokenFrom(signer, this.tokenId, fromAddressObj, toAddressObj, amount);2355 return await this.collection.transferTokenFrom(signer, this.tokenId, fromAddressObj, toAddressObj, amount);
2389 }2356 }
23902357
2391 async approve(signer: TSigner, toAddressObj: ICrossAccountId, amount=100n, label?: string) {2358 async approve(signer: TSigner, toAddressObj: ICrossAccountId, amount=1n) {
2392 return await this.collection.approveToken(signer, this.tokenId, toAddressObj, amount, label);2359 return await this.collection.approveToken(signer, this.tokenId, toAddressObj, amount);
2393 }2360 }
23942361
2395 async getApprovedPieces(fromAddressObj: ICrossAccountId, toAccountObj: ICrossAccountId) {2362 async getApprovedPieces(fromAddressObj: ICrossAccountId, toAccountObj: ICrossAccountId) {
2396 return await this.collection.getTokenApprovedPieces(this.tokenId, fromAddressObj, toAccountObj);2363 return await this.collection.getTokenApprovedPieces(this.tokenId, fromAddressObj, toAccountObj);
2397 }2364 }
23982365
2399 async repartition(signer: TSigner, amount: bigint, label?: string) {2366 async repartition(signer: TSigner, amount: bigint) {
2400 return await this.collection.repartitionToken(signer, this.tokenId, amount, label);2367 return await this.collection.repartitionToken(signer, this.tokenId, amount);
2401 }2368 }
24022369
2403 async burn(signer: TSigner, amount=100n, label?: string) {2370 async burn(signer: TSigner, amount=1n) {
2404 return await this.collection.burnToken(signer, this.tokenId, amount, label);2371 return await this.collection.burnToken(signer, this.tokenId, amount);
2405 }2372 }
2406}2373}