difftreelog
Merge pull request #104 from usetech-llc/feature/NFTPAR-301_transfer_event
in: master
Add Transfer event
2 files changed
pallets/nft/src/lib.rsdiffbeforeafterboth508 /// item_id: Identifier of burned NFT.508 /// item_id: Identifier of burned NFT.509 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),510 }523 }511);524);512525155815711559 match target_collection.mode1572 match target_collection.mode1560 {1573 {1561 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())?,1562 CollectionMode::Fungible(_) => Self::transfer_fungible(collection_id, value, &sender, &recipient)?,1575 CollectionMode::Fungible(_) => Self::transfer_fungible(collection_id, value, &sender, &recipient)?,1563 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())?,1564 _ => ()1577 _ => ()1565 };1578 };15791580 Self::deposit_event(RawEvent::Transfer(collection_id, item_id, sender, recipient, value));156615811567 Ok(())1582 Ok(())1568 }1583 }tests/src/util/helpers.tsdiffbeforeafterboth39 recipient: string;39 recipient: string;40}40}4142interface TransferResult {43 success: boolean;44 collectionId: number;45 itemId: number;46 sender: string;47 recipient: string;48 value: bigint;49}415042interface IReFungibleOwner {51interface IReFungibleOwner {43 Fraction: BN;52 Fraction: BN;115 return result;124 return result;116}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}117151118interface Invalid {152interface Invalid {119 type: 'Invalid';153 type: 'Invalid';624 }658 }625 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);626 const events = await submitTransactionAsync(sender, transferTx);660 const events = await submitTransactionAsync(sender, transferTx);627 const result = getCreateItemResult(events);661 const result = getTransferResult(events);628 // tslint:disable-next-line:no-unused-expression662 // tslint:disable-next-line:no-unused-expression629 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());630 if (type === 'NFT') {669 if (type === 'NFT') {631 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;632 expect(nftItemData.Owner.toString()).to.be.equal(recipient.address);671 expect(nftItemData.Owner.toString()).to.be.equal(recipient.address);