Refactored code.
This commit is contained in:
parent
f33c3dff1a
commit
bd41613f19
|
@ -123,7 +123,7 @@ export function handlerOrderReused(event: OrderReused): void {
|
|||
event.transaction.from.toHex(),
|
||||
event.logIndex.toI32()
|
||||
)
|
||||
log.info('searched order id: {}', [order.id])
|
||||
// log.info('searched order id: {}', [order.id])
|
||||
|
||||
if (!order) return
|
||||
|
||||
|
@ -270,43 +270,22 @@ export function handleProviderFee(event: ProviderFee): void {
|
|||
event.transaction.from.toHex(),
|
||||
event.logIndex.toI32()
|
||||
)
|
||||
const orderId = order.id
|
||||
|
||||
if (order) {
|
||||
order.providerFee = providerFee
|
||||
order.providerFeeValidUntil = event.params.validUntil
|
||||
order.save()
|
||||
return
|
||||
}
|
||||
log.info('order id in provider fee handler: {}', [orderId])
|
||||
|
||||
let orderReuse = searchOrderReusedForEvent(
|
||||
const orderReuse = searchOrderReusedForEvent(
|
||||
event.transaction.hash.toHex(),
|
||||
event.address.toHex(),
|
||||
event.logIndex.toI32()
|
||||
)
|
||||
log.info('order reuse id in provider fee handler: {}', [orderReuse.id])
|
||||
if (orderReuse) {
|
||||
|
||||
if (order) {
|
||||
log.info('order id in provider fee handler: {}', [order.id])
|
||||
order.providerFee = providerFee
|
||||
order.providerFeeValidUntil = event.params.validUntil
|
||||
order.save()
|
||||
} else if (orderReuse) {
|
||||
log.info('order reuse id in provider fee handler: {}', [orderReuse.id])
|
||||
orderReuse.providerFee = providerFee
|
||||
orderReuse.providerFeeValidUntil = event.params.validUntil
|
||||
log.info('order reused id: {}', [orderReuse.id])
|
||||
orderReuse.save()
|
||||
} else {
|
||||
orderReuse = new OrderReuse(event.transaction.hash.toHex())
|
||||
log.info('create a new order reuse: {}', [orderReuse.id])
|
||||
orderReuse.providerFee = providerFee
|
||||
orderReuse.providerFeeValidUntil = event.params.validUntil
|
||||
orderReuse.order = orderId
|
||||
orderReuse.createdTimestamp = event.block.timestamp.toI32()
|
||||
orderReuse.tx = event.transaction.hash.toHex()
|
||||
orderReuse.block = event.block.number.toI32()
|
||||
orderReuse.caller = event.transaction.from.toHex()
|
||||
if (event.transaction.gasPrice)
|
||||
orderReuse.gasPrice = event.transaction.gasPrice
|
||||
else orderReuse.gasPrice = BigInt.zero()
|
||||
if (event.receipt !== null && event.receipt!.gasUsed) {
|
||||
orderReuse.gasUsed = event.receipt!.gasUsed.toBigDecimal()
|
||||
} else orderReuse.gasUsed = BigDecimal.zero()
|
||||
orderReuse.save()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,12 +39,20 @@ export function searchOrderForEvent(
|
|||
address: string,
|
||||
transactionFrom: string,
|
||||
eventIndex: number
|
||||
): Order {
|
||||
): Order | null {
|
||||
for (let i = eventIndex - 1; i >= 0; i--) {
|
||||
log.info('i for order started: {}', [i.toString()])
|
||||
const orderId = getOrderId(transactionHash, address, transactionFrom, i)
|
||||
log.info('trying with this orderId: {}', [orderId])
|
||||
const order = Order.load(orderId)
|
||||
log.info('loaded order with this orderId: {}', [orderId])
|
||||
if (order) {
|
||||
log.info('order with this orderId: {}', [order.id])
|
||||
log.info('found order datatoken: {} and event address: {}', [
|
||||
order.datatoken,
|
||||
address
|
||||
])
|
||||
}
|
||||
if (order && order.datatoken == address) {
|
||||
log.info('found order datatoken: {} and event address: {}', [
|
||||
order.datatoken,
|
||||
|
@ -57,14 +65,14 @@ export function searchOrderForEvent(
|
|||
}
|
||||
}
|
||||
// return an Order just for compilation schema
|
||||
return getOrder(transactionHash, address, transactionFrom, eventIndex)
|
||||
return null
|
||||
}
|
||||
|
||||
export function searchOrderReusedForEvent(
|
||||
transactionHash: string,
|
||||
eventAddress: string,
|
||||
eventIndex: number
|
||||
): OrderReuse {
|
||||
): OrderReuse | null {
|
||||
for (let i = eventIndex - 1; i >= 0; i--) {
|
||||
log.info('i in order reused: {}', [i.toString()])
|
||||
const orderReused = OrderReuse.load(`${transactionHash}-${i}`)
|
||||
|
@ -85,5 +93,5 @@ export function searchOrderReusedForEvent(
|
|||
}
|
||||
}
|
||||
// return an OrderReuse just for compilation schema
|
||||
return new OrderReuse(`${transactionHash}-${eventIndex}`)
|
||||
return null
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue