mirror of
https://github.com/oceanprotocol/ocean-subgraph.git
synced 2024-12-02 05:57:29 +01:00
Creating order utils
This commit is contained in:
parent
71839ad67e
commit
ec2b925c30
27
src/mappings/utils/orderUtils.ts
Normal file
27
src/mappings/utils/orderUtils.ts
Normal 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
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user