Creating order utils

This commit is contained in:
Jamie Hewitt 2022-06-29 17:38:56 +03:00
parent 71839ad67e
commit ec2b925c30

View File

@ -0,0 +1,27 @@
import { Order } from '../../@types/schema'
export function getOrderId(
tx: string,
tokenAddress: string,
fromAddress: string
): string {
return `${tx}-${tokenAddress}-${fromAddress}`
}
export function createOrder(orderId: string): Order {
const order = new Order(orderId)
return order
}
export function getOrder(
transactionHash: string,
address: string,
transactionFrom: string
): Order {
const orderId = getOrderId(transactionHash, address, transactionFrom)
let newOrder = Order.load(orderId)
if (newOrder === null) {
newOrder = createOrder(orderId)
}
return newOrder
}