difftreelog
Merge branch 'develop' into release/v2.0.0
in: master
4 files changed
doc/application_development.mddiffbeforeafterboth101- Owner: Address, initial owner of the NFT101- Owner: Address, initial owner of the NFT102102103##### Events103##### Events104ItemCreated105ItemId: Identifier of newly created NFT, which is unique within the Collection, so the NFT is uniquely identified with a pair of values: CollectionId and ItemId.106Recipient: Address, owner of newly created item104107105- ItemCreated106 - ItemId: Identifier of newly created NFT, which is unique within the Collection, so the NFT is uniquely107 identified with a pair of values: CollectionId and ItemId.108109#### BurnItem108#### BurnItem110109111##### Description110##### Descriptionpallets/nft/src/lib.rsdiffbeforeafterboth495 /// * collection_id: Id of the collection where item was created.495 /// * collection_id: Id of the collection where item was created.496 /// 496 /// 497 /// * item_id: Id of an item. Unique within the collection.497 /// * item_id: Id of an item. Unique within the collection.498 ///499 /// * recipient: Owner of newly created item 498 ItemCreated(CollectionId, TokenId),500 ItemCreated(CollectionId, TokenId, AccountId),499501500 /// Collection item was burned.502 /// Collection item was burned.501 /// 503 /// 506 /// item_id: Identifier of burned NFT.508 /// item_id: Identifier of burned NFT.507 ItemDestroyed(CollectionId, TokenId),509 ItemDestroyed(CollectionId, TokenId),510511 /// Item was transferred512 ///513 /// * collection_id: Id of collection to which item is belong514 ///515 /// * item_id: Id of an item516 ///517 /// * sender: Original owner of item518 ///519 /// * recipient: New owner of item520 ///521 /// * amount: Always 1 for NFT522 Transfer(CollectionId, TokenId, AccountId, AccountId, u128),508 }523 }509);524);510525155615711557 match target_collection.mode1572 match target_collection.mode1558 {1573 {1559 CollectionMode::NFT => Self::transfer_nft(collection_id, item_id, sender.clone(), recipient)?,1574 CollectionMode::NFT => Self::transfer_nft(collection_id, item_id, sender.clone(), recipient.clone())?,1560 CollectionMode::Fungible(_) => Self::transfer_fungible(collection_id, value, &sender, &recipient)?,1575 CollectionMode::Fungible(_) => Self::transfer_fungible(collection_id, value, &sender, &recipient)?,1561 CollectionMode::ReFungible => Self::transfer_refungible(collection_id, item_id, value, sender.clone(), recipient)?,1576 CollectionMode::ReFungible => Self::transfer_refungible(collection_id, item_id, value, sender.clone(), recipient.clone())?,1562 _ => ()1577 _ => ()1563 };1578 };15791580 Self::deposit_event(RawEvent::Transfer(collection_id, item_id, sender, recipient, value));156415811565 Ok(())1582 Ok(())1566 }1583 }1635 {1652 {1636 CreateItemData::NFT(data) => {1653 CreateItemData::NFT(data) => {1637 let item = NftItemType {1654 let item = NftItemType {1638 owner,1655 owner: owner.clone(),1639 const_data: data.const_data,1656 const_data: data.const_data,1640 variable_data: data.variable_data1657 variable_data: data.variable_data1641 };1658 };1660 };1677 };166116781662 // call event1679 // call event1663 Self::deposit_event(RawEvent::ItemCreated(collection_id, <ItemListIndex>::get(collection_id)));1680 Self::deposit_event(RawEvent::ItemCreated(collection_id, <ItemListIndex>::get(collection_id), owner));166416811665 Ok(())1682 Ok(())1666 }1683 }tests/package.jsondiffbeforeafterboth29 "testRemoveFromWhiteList": "mocha --timeout 9999999 -r ts-node/register ./**/removeFromWhiteList.test.ts",29 "testRemoveFromWhiteList": "mocha --timeout 9999999 -r ts-node/register ./**/removeFromWhiteList.test.ts",30 "testConnection": "mocha --timeout 9999999 -r ts-node/register ./**/connection.test.ts",30 "testConnection": "mocha --timeout 9999999 -r ts-node/register ./**/connection.test.ts",31 "testCollection": "mocha --timeout 9999999 -r ts-node/register ./**/createCollection.test.ts",31 "testCollection": "mocha --timeout 9999999 -r ts-node/register ./**/createCollection.test.ts",32 "testCreateItem": "mocha --timeout 9999999 -r ts-node/register ./**/createItem.test.ts",32 "testCreateMultipleItems": "mocha --timeout 9999999 -r ts-node/register ./**/createMultipleItems.test.ts",33 "testCreateMultipleItems": "mocha --timeout 9999999 -r ts-node/register ./**/createMultipleItems.test.ts",33 "testApprove": "mocha --timeout 9999999 -r ts-node/register ./**/approve.test.ts",34 "testApprove": "mocha --timeout 9999999 -r ts-node/register ./**/approve.test.ts",34 "testTransferFrom": "mocha --timeout 9999999 -r ts-node/register ./**/transferFrom.test.ts",35 "testTransferFrom": "mocha --timeout 9999999 -r ts-node/register ./**/transferFrom.test.ts",tests/src/util/helpers.tsdiffbeforeafterboth36 success: boolean;36 success: boolean;37 collectionId: number;37 collectionId: number;38 itemId: number;38 itemId: number;39 recipient: string;39}40}4142interface TransferResult {43 success: boolean;44 collectionId: number;45 itemId: number;46 sender: string;47 recipient: string;48 value: bigint;49}405041interface IReFungibleOwner {51interface IReFungibleOwner {42 Fraction: BN;52 Fraction: BN;94 let success = false;104 let success = false;95 let collectionId: number = 0;105 let collectionId: number = 0;96 let itemId: number = 0;106 let itemId: number = 0;107 let recipient: string = '';97 events.forEach(({ phase, event: { data, method, section } }) => {108 events.forEach(({ phase, event: { data, method, section } }) => {98 // console.log(` ${phase}: ${section}.${method}:: ${data}`);109 // console.log(` ${phase}: ${section}.${method}:: ${data}`);99 if (method == 'ExtrinsicSuccess') {110 if (method == 'ExtrinsicSuccess') {100 success = true;111 success = true;101 } else if ((section == 'nft') && (method == 'ItemCreated')) {112 } else if ((section == 'nft') && (method == 'ItemCreated')) {102 collectionId = parseInt(data[0].toString());113 collectionId = parseInt(data[0].toString());103 itemId = parseInt(data[1].toString());114 itemId = parseInt(data[1].toString());115 recipient = data[2].toString();104 }116 }105 });117 });106 const result: CreateItemResult = {118 const result: CreateItemResult = {107 success,119 success,108 collectionId,120 collectionId,109 itemId,121 itemId,122 recipient,110 };123 };111 return result;124 return result;112}125}126127export function getTransferResult(events: EventRecord[]): TransferResult {128 const result: TransferResult = {129 success: false,130 collectionId: 0,131 itemId: 0,132 sender: '',133 recipient: '',134 value: 0n,135 };136137 events.forEach(({event: {data, method, section}}) => {138 if (method === 'ExtrinsicSuccess') {139 result.success = true;140 } else if (section === 'nft' && method === 'Transfer') {141 result.collectionId = +data[0].toString();142 result.itemId = +data[1].toString();143 result.sender = data[2].toString();144 result.recipient = data[3].toString();145 result.value = BigInt(data[4].toString());146 }147 });148149 return result;150}113151114interface Invalid {152interface Invalid {115 type: 'Invalid';153 type: 'Invalid';620 }658 }621 const transferTx = await api.tx.nft.transfer(recipient.address, collectionId, tokenId, value);659 const transferTx = await api.tx.nft.transfer(recipient.address, collectionId, tokenId, value);622 const events = await submitTransactionAsync(sender, transferTx);660 const events = await submitTransactionAsync(sender, transferTx);623 const result = getCreateItemResult(events);661 const result = getTransferResult(events);624 // tslint:disable-next-line:no-unused-expression662 // tslint:disable-next-line:no-unused-expression625 expect(result.success).to.be.true;663 expect(result.success).to.be.true;664 expect(result.collectionId).to.be.equal(collectionId);665 expect(result.itemId).to.be.equal(tokenId);666 expect(result.sender).to.be.equal(sender.address);667 expect(result.recipient).to.be.equal(recipient.address);668 expect(result.value.toString()).to.be.equal(value.toString());626 if (type === 'NFT') {669 if (type === 'NFT') {627 const nftItemData = await api.query.nft.nftItemList(collectionId, tokenId) as unknown as ITokenDataType;670 const nftItemData = await api.query.nft.nftItemList(collectionId, tokenId) as unknown as ITokenDataType;628 expect(nftItemData.Owner.toString()).to.be.equal(recipient.address);671 expect(nftItemData.Owner.toString()).to.be.equal(recipient.address);736 }779 }737 expect(collectionId).to.be.equal(result.collectionId);780 expect(collectionId).to.be.equal(result.collectionId);738 expect(BItemCount).to.be.equal(result.itemId);781 expect(BItemCount).to.be.equal(result.itemId);782 expect(owner).to.be.equal(result.recipient);739 newItemId = result.itemId;783 newItemId = result.itemId;740 });784 });741 return newItemId;785 return newItemId;