diff --git a/src/mappings/erc20Templates.ts b/src/mappings/erc20Templates.ts index cd2faaa..3234034 100644 --- a/src/mappings/erc20Templates.ts +++ b/src/mappings/erc20Templates.ts @@ -23,7 +23,7 @@ import { getUser } from './utils/userUtils' import { getOrderId, searchOrderForEvent, - searchOrderResusedForEvent + searchOrderReusedForEvent } from './utils/orderUtils' export function handleOrderStarted(event: OrderStarted): void { @@ -270,16 +270,32 @@ export function handleProviderFee(event: ProviderFee): void { order.providerFee = providerFee order.providerFeeValidUntil = event.params.validUntil order.save() + return + } + let orderReuse = searchOrderReusedForEvent( + event.transaction.hash.toHex(), + event.address.toHex(), + event.logIndex.toI32() + ) + if (orderReuse) { + orderReuse.providerFee = providerFee + orderReuse.providerFeeValidUntil = event.params.validUntil + orderReuse.save() } else { - const orderReuse = searchOrderResusedForEvent( - event.transaction.hash.toHex(), - event.address.toHex(), - event.logIndex.toI32() - ) - if (orderReuse) { - orderReuse.providerFee = providerFee - orderReuse.providerFeeValidUntil = event.params.validUntil - orderReuse.save() - } + orderReuse = new OrderReuse(event.transaction.hash.toHex()) + orderReuse.providerFee = providerFee + orderReuse.providerFeeValidUntil = event.params.validUntil + orderReuse.order = order.id + 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() } } diff --git a/src/mappings/utils/orderUtils.ts b/src/mappings/utils/orderUtils.ts index 47f25d3..c26c646 100644 --- a/src/mappings/utils/orderUtils.ts +++ b/src/mappings/utils/orderUtils.ts @@ -63,7 +63,7 @@ export function searchOrderForEvent( return getOrder(transactionHash, address, transactionFrom, firstEventIndex) } -export function searchOrderResusedForEvent( +export function searchOrderReusedForEvent( transactionHash: string, eventAddress: string, eventIndex: number @@ -81,6 +81,8 @@ export function searchOrderResusedForEvent( ]) return orderReused } + firstEventIndex-- + continue } firstEventIndex--