Updating order id with event index.

This commit is contained in:
Maria Carmina 2023-03-22 14:53:42 +02:00
parent 00e804c683
commit 67066df45f
4 changed files with 20 additions and 9 deletions

View File

@ -143,7 +143,7 @@ type OrderReuse @entity {
}
type Order @entity {
"transaction hash - token address - from address"
"transaction hash - token address - from address - eventIndex"
id: ID!
datatoken: Token!

View File

@ -27,7 +27,8 @@ export function handleOrderStarted(event: OrderStarted): void {
getOrderId(
event.transaction.hash.toHex(),
event.address.toHex(),
event.transaction.from.toHex()
event.transaction.from.toHex(),
event.logIndex.toI32().toString()
)
)
@ -107,7 +108,8 @@ export function handlerOrderReused(event: OrderReused): void {
const orderId = getOrderId(
event.params.orderTxId.toHexString(),
event.address.toHex(),
event.params.caller.toHex()
event.params.caller.toHex(),
event.logIndex.toI32().toString()
)
const order = Order.load(orderId)
@ -247,7 +249,8 @@ export function handleProviderFee(event: ProviderFee): void {
const orderId = getOrderId(
event.transaction.hash.toHex(),
event.address.toHex(),
event.transaction.from.toHex()
event.transaction.from.toHex(),
event.logIndex.toI32().toString()
)
const order = Order.load(orderId)

View File

@ -3,9 +3,10 @@ import { Order } from '../../@types/schema'
export function getOrderId(
tx: string,
tokenAddress: string,
fromAddress: string
fromAddress: string,
eventIndex: string
): string {
return `${tx}-${tokenAddress}-${fromAddress}`
return `${tx}-${tokenAddress}-${fromAddress}-${eventIndex}`
}
export function createOrder(orderId: string): Order {
@ -16,9 +17,15 @@ export function createOrder(orderId: string): Order {
export function getOrder(
transactionHash: string,
address: string,
transactionFrom: string
transactionFrom: string,
eventIndex: string
): Order {
const orderId = getOrderId(transactionHash, address, transactionFrom)
const orderId = getOrderId(
transactionHash,
address,
transactionFrom,
eventIndex
)
let newOrder = Order.load(orderId)
if (newOrder === null) {
newOrder = createOrder(orderId)

View File

@ -419,7 +419,8 @@ describe('Datatoken tests', async () => {
setProviderFee
)
assert(orderTx, 'Invalid orderTx')
const orderId = `${orderTx.transactionHash.toLowerCase()}-${newDtAddress.toLowerCase()}-${user1.toLowerCase()}`
console.log('event: ', orderTx.events.OrderStarted.logIndex)
const orderId = `${orderTx.transactionHash.toLowerCase()}-${newDtAddress.toLowerCase()}-${user1.toLowerCase()}-${orderTx.events.OrderStarted.logIndex.toString()}`
await sleep(3000)
response = await fetch(subgraphUrl, {