This commit is contained in:
trizin 2024-07-22 16:50:26 +03:00 committed by GitHub
parent 5c588deed6
commit 37882645c4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -27,7 +27,10 @@ import {
searchOrderReusedForEvent searchOrderReusedForEvent
} from './utils/orderUtils' } from './utils/orderUtils'
const ADDRESS_ZERO = "0x0000000000000000000000000000000000000000"
export function handleOrderStarted(event: OrderStarted): void { export function handleOrderStarted(event: OrderStarted): void {
log.info("handleOrderStarted")
const order = new Order( const order = new Order(
getOrderId( getOrderId(
event.transaction.hash.toHex(), event.transaction.hash.toHex(),
@ -36,41 +39,59 @@ export function handleOrderStarted(event: OrderStarted): void {
event.logIndex.toI32() event.logIndex.toI32()
) )
) )
log.info("Created order object")
const token = getToken(event.address, true) const token = getToken(event.address, true)
log.info("Got the token")
order.datatoken = token.id order.datatoken = token.id
token.orderCount = token.orderCount.plus(integer.ONE) token.orderCount = token.orderCount.plus(integer.ONE)
log.info("set data token and order count")
const consumer = getUser(event.params.consumer.toHex()) const consumer = getUser(event.params.consumer.toHex())
order.consumer = consumer.id order.consumer = consumer.id
log.info("got consumer id")
if (token.nft) { if (token.nft) {
const nft = Nft.load(token.nft as string) as Nft const nft = Nft.load(token.nft as string) as Nft
if (nft) {
log.info("nft loaded and set")
const nftOwner = getUser(nft.owner) const nftOwner = getUser(nft.owner)
order.nftOwner = nftOwner.id order.nftOwner = nftOwner.id
} else {
log.info("nft couldnt load")
order.nftOwner = ADDRESS_ZERO
}
} else {
log.info("nft not found")
} }
const payer = getUser(event.params.payer.toHex()) const payer = getUser(event.params.payer.toHex())
payer.totalOrders = payer.totalOrders.plus(integer.ONE) payer.totalOrders = payer.totalOrders.plus(integer.ONE)
payer.save() payer.save()
log.info("payer saved")
order.payer = payer.id order.payer = payer.id
order.amount = weiToDecimal( order.amount = weiToDecimal(
event.params.amount.toBigDecimal(), event.params.amount.toBigDecimal(),
token.decimals token.decimals
) )
log.info("set order amount")
order.serviceIndex = event.params.serviceIndex.toI32() order.serviceIndex = event.params.serviceIndex.toI32()
log.info("set order service index")
const publishMarket = getUser(event.params.publishMarketAddress.toHex()) const publishMarket = getUser(event.params.publishMarketAddress.toHex())
order.publishingMarket = publishMarket.id order.publishingMarket = publishMarket.id
log.info("set order publish market")
order.createdTimestamp = event.block.timestamp.toI32() order.createdTimestamp = event.block.timestamp.toI32()
order.tx = event.transaction.hash.toHex() order.tx = event.transaction.hash.toHex()
order.eventIndex = event.logIndex.toI32() order.eventIndex = event.logIndex.toI32()
order.block = event.block.number.toI32() order.block = event.block.number.toI32()
log.info("set created ts tx eventindex and block")
const tokenId = token.lastPriceToken const tokenId = token.lastPriceToken
log.info("got token id")
if (tokenId) { if (tokenId) {
log.info("token id setting")
const priceToken = getToken(Address.fromString(tokenId), false) const priceToken = getToken(Address.fromString(tokenId), false)
order.lastPriceToken = priceToken.id order.lastPriceToken = priceToken.id
order.lastPriceValue = token.lastPriceValue order.lastPriceValue = token.lastPriceValue
@ -79,21 +100,28 @@ export function handleOrderStarted(event: OrderStarted): void {
order.lastPriceValue, order.lastPriceValue,
order.createdTimestamp order.createdTimestamp
) )
log.info("token id is set")
} }
if (event.receipt !== null && event.receipt!.gasUsed) { if (event.receipt !== null && event.receipt!.gasUsed) {
order.gasUsed = event.receipt!.gasUsed.toBigDecimal() order.gasUsed = event.receipt!.gasUsed.toBigDecimal()
log.info("LOG1")
} else { } else {
order.gasUsed = BigDecimal.zero() order.gasUsed = BigDecimal.zero()
log.info("LOG2")
} }
if (event.transaction.gasPrice) { if (event.transaction.gasPrice) {
order.gasPrice = event.transaction.gasPrice order.gasPrice = event.transaction.gasPrice
log.info("LOG3")
} else { } else {
order.gasPrice = BigInt.zero() order.gasPrice = BigInt.zero()
log.info("LOG4")
} }
log.info("order save start")
order.save() order.save()
token.save() token.save()
addOrder() addOrder()
log.info("order save done")
if (token.nft) { if (token.nft) {
const nft = Nft.load(token.nft as string) as Nft const nft = Nft.load(token.nft as string) as Nft
if (nft) { if (nft) {
@ -103,6 +131,7 @@ export function handleOrderStarted(event: OrderStarted): void {
const owner = getUser(nft.owner) const owner = getUser(nft.owner)
owner.totalSales = owner.totalSales.plus(integer.ONE) owner.totalSales = owner.totalSales.plus(integer.ONE)
owner.save() owner.save()
log.info("owner data updated")
} }
} }