mirror of
https://github.com/oceanprotocol/ocean-subgraph.git
synced 2024-12-02 05:57:29 +01:00
Tracking nft transferHistory
This commit is contained in:
parent
1bf645541f
commit
0e0bdff980
@ -582,7 +582,7 @@ type NftTransferHistory @entity {
|
||||
oldOwner: User!
|
||||
newOwner: User!
|
||||
txId: String
|
||||
timestamp: BigInt!
|
||||
timestamp: Int!
|
||||
block: Int!
|
||||
}
|
||||
|
||||
|
@ -26,6 +26,7 @@ export function handleNftCreated(event: NFTCreated): void {
|
||||
nft.tx = event.transaction.hash.toHex()
|
||||
nft.block = event.block.number.toI32()
|
||||
nft.transferable = event.params.transferable
|
||||
nft.transferHistory = []
|
||||
|
||||
nft.save()
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Nft, NftUpdate, NftData } from '../@types/schema'
|
||||
import { Nft, NftUpdate, NftData, NftTransferHistory } from '../@types/schema'
|
||||
import {
|
||||
MetadataCreated,
|
||||
MetadataState,
|
||||
@ -256,8 +256,21 @@ export function handleCleanedPermissions(event: CleanedPermissions): void {
|
||||
export function handleNftTransferred(event: Transfer): void {
|
||||
const id = event.address.toHex()
|
||||
const nft = getNftTokenWithID(id)
|
||||
const oldOwner = nft.owner
|
||||
const newOwner = getUser(event.params.to.toHexString())
|
||||
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()
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user