Skip to content

Commit

Permalink
feat: updated at when bid/order changes (decentraland#238)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicosantangelo authored Nov 27, 2020
1 parent 447da2b commit 9779ddb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
17 changes: 17 additions & 0 deletions indexer/src/handlers/bid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ export function handleBidCreated(event: BidCreated): void {
bid.seller = Address.fromString(nft.owner)

bid.save()

nft.updatedAt = event.block.timestamp
nft.save()
}
}

Expand All @@ -57,12 +60,19 @@ export function handleBidAccepted(event: BidAccepted): void {
if (bid == null) {
return
}
let nft = NFT.load(bid.nft)
if (nft == null) {
return
}

bid.status = status.SOLD
bid.seller = event.params._seller
bid.blockNumber = event.block.number
bid.updatedAt = event.block.timestamp
bid.save()

nft.updatedAt = event.block.timestamp
nft.save()
}

export function handleBidCancelled(event: BidCancelled): void {
Expand All @@ -76,9 +86,16 @@ export function handleBidCancelled(event: BidCancelled): void {
if (bid == null) {
return
}
let nft = NFT.load(bid.nft)
if (nft == null) {
return
}

bid.status = status.CANCELLED
bid.blockNumber = event.block.number
bid.updatedAt = event.block.timestamp
bid.save()

nft.updatedAt = event.block.timestamp
nft.save()
}
3 changes: 3 additions & 0 deletions indexer/src/handlers/marketplace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export function handleOrderCreated(event: OrderCreated): void {

cancelActiveOrder(nft!, event.block.timestamp)

nft.updatedAt = event.block.timestamp
nft = updateNFTOrderProperties(nft!, order)
nft.save()

Expand Down Expand Up @@ -73,6 +74,7 @@ export function handleOrderSuccessful(event: OrderSuccessful): void {
order.save()

nft.owner = event.params.buyer.toHex()
nft.updatedAt = event.block.timestamp
nft = updateNFTOrderProperties(nft!, order!)
nft.save()
}
Expand All @@ -97,6 +99,7 @@ export function handleOrderCancelled(event: OrderCancelled): void {
order.updatedAt = event.block.timestamp
order.save()

nft.updatedAt = event.block.timestamp
nft = updateNFTOrderProperties(nft!, order!)
nft.save()
}
Expand Down

0 comments on commit 9779ddb

Please sign in to comment.