ocean-subgraph/src/mappings/utils/orderUtils.ts
Jamie Hewitt 3ebc29a74d
Issue 471 provider fees (#474)
* Adding providerFee to Order in the schema

* Adding ProviderFee to subgraph.template.yaml

* Creating order utils

* Saving providerFee as a string

* Saving providerFee as an array of all previous provider fees

* Creating test for providerFee

* Removing arrary from providerFee

* Updating or Creating OrderResue provider fee

* lint:fix

* Creating additional tests for testing providerFees on Order and reuseOrder

* lint:fix

* Updating JSON string notation

* Fixing first test

* fixing second test: testing provider fees after calling reuseOrder on a using a previous txId

* added providerFeeValidUntil

Co-authored-by: mihaisc <mihai@oceanprotocol.com>
2022-07-12 11:11:43 +03:00

28 lines
608 B
TypeScript

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
}