Tracking nft transferHistory

This commit is contained in:
Jamie Hewitt 2022-11-21 14:05:38 +03:00
parent 1bf645541f
commit 0e0bdff980
3 changed files with 16 additions and 2 deletions

View File

@ -582,7 +582,7 @@ type NftTransferHistory @entity {
oldOwner: User! oldOwner: User!
newOwner: User! newOwner: User!
txId: String txId: String
timestamp: BigInt! timestamp: Int!
block: Int! block: Int!
} }

View File

@ -26,6 +26,7 @@ export function handleNftCreated(event: NFTCreated): void {
nft.tx = event.transaction.hash.toHex() nft.tx = event.transaction.hash.toHex()
nft.block = event.block.number.toI32() nft.block = event.block.number.toI32()
nft.transferable = event.params.transferable nft.transferable = event.params.transferable
nft.transferHistory = []
nft.save() nft.save()
} }

View File

@ -1,4 +1,4 @@
import { Nft, NftUpdate, NftData } from '../@types/schema' import { Nft, NftUpdate, NftData, NftTransferHistory } from '../@types/schema'
import { import {
MetadataCreated, MetadataCreated,
MetadataState, MetadataState,
@ -256,8 +256,21 @@ export function handleCleanedPermissions(event: CleanedPermissions): void {
export function handleNftTransferred(event: Transfer): void { export function handleNftTransferred(event: Transfer): void {
const id = event.address.toHex() const id = event.address.toHex()
const nft = getNftTokenWithID(id) const nft = getNftTokenWithID(id)
const oldOwner = nft.owner
const newOwner = getUser(event.params.to.toHexString()) const newOwner = getUser(event.params.to.toHexString())
nft.owner = newOwner.id nft.owner = newOwner.id
const transferId = `${nft.address}-${id}-${event.logIndex}`
const newTransfer = new NftTransferHistory(transferId)
newTransfer.nft = nft.id
newTransfer.oldOwner = oldOwner
newTransfer.newOwner = newOwner.id
newTransfer.txId = id
newTransfer.timestamp = event.block.timestamp.toI32()
newTransfer.block = event.block.number.toI32()
newTransfer.save()
if (nft.transferHistory && typeof newTransfer.id === 'string') {
nft.transferHistory!.push(newTransfer.id)
}
nft.save() nft.save()
} }