mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
add order history
This commit is contained in:
parent
50e2f8de61
commit
eadaa7abb5
@ -11,7 +11,7 @@ import {
|
||||
import { EditableMetadata } from '../ddo/interfaces/EditableMetadata'
|
||||
import Account from './Account'
|
||||
import DID from './DID'
|
||||
import { SubscribablePromise } from '../utils'
|
||||
import { SubscribablePromise, didNoZeroX, didPrefixed } from '../utils'
|
||||
import { Instantiable, InstantiableConfig } from '../Instantiable.abstract'
|
||||
import { WebServiceConnector } from './utils/WebServiceConnector'
|
||||
import BigNumber from 'bignumber.js'
|
||||
@ -33,6 +33,15 @@ export enum OrderProgressStep {
|
||||
TransferDataToken
|
||||
}
|
||||
|
||||
export interface OrderHistory {
|
||||
dtAddress: string
|
||||
timestamp: number
|
||||
transactionHash: string
|
||||
did?: string
|
||||
serviceId?: number
|
||||
serviceType?: string
|
||||
}
|
||||
|
||||
/**
|
||||
* Assets submodule of Ocean Protocol.
|
||||
*/
|
||||
@ -581,4 +590,38 @@ export class Assets extends Instantiable {
|
||||
|
||||
return serviceEndpoint
|
||||
}
|
||||
|
||||
/**
|
||||
* get Order History
|
||||
* @param {Account} account
|
||||
* @return {Promise<OrderHistory[]>} transactionHash of the payment
|
||||
*/
|
||||
public async getOrderHistory(account: Account): Promise<OrderHistory[]> {
|
||||
const results: OrderHistory[] = []
|
||||
const address = this.web3.utils.toChecksumAddress(account.getId())
|
||||
const events = await this.web3.eth.getPastLogs({
|
||||
topics: [
|
||||
['0x24c95b9bea47f62df4b9eea32c98c597eccfc5cac47f8477647be875ad925eee', address]
|
||||
],
|
||||
fromBlock: 0
|
||||
})
|
||||
for (let i = 0; i < events.length; i++) {
|
||||
const blockDetails = await this.web3.eth.getBlock(events[i].blockNumber)
|
||||
const order: OrderHistory = {
|
||||
dtAddress: events[i].address,
|
||||
timestamp: parseInt(String(blockDetails.timestamp)),
|
||||
transactionHash: events[i].transactionHash
|
||||
}
|
||||
const params = this.web3.eth.abi.decodeParameters(
|
||||
['uint256', 'uint256', 'uint256', 'uint256'],
|
||||
events[i].data
|
||||
)
|
||||
order.serviceId = parseInt(params[1])
|
||||
order.did = didPrefixed(didNoZeroX(order.dtAddress))
|
||||
const service = await this.getServiceByIndex(order.did, order.serviceId)
|
||||
order.serviceType = service.type
|
||||
results.push(order)
|
||||
}
|
||||
return results
|
||||
}
|
||||
}
|
||||
|
@ -460,7 +460,10 @@ describe('Compute flow', () => {
|
||||
newComputePrivacy.trustedAlgorithms
|
||||
)
|
||||
})
|
||||
|
||||
it('Bob gets his order History', async () => {
|
||||
const history = await ocean.assets.getOrderHistory(bob)
|
||||
assert(history.length > 0)
|
||||
})
|
||||
// it('Bob restarts compute job', async () => {})
|
||||
// it('Bob gets outputs', async () => {})
|
||||
})
|
||||
|
@ -252,4 +252,8 @@ describe('Marketplace flow', () => {
|
||||
ddo = await ocean.assets.create(asset, alice, [service1])
|
||||
assert.equal(ddo, null)
|
||||
})
|
||||
it('Alice gets hers order History', async () => {
|
||||
const history = await ocean.assets.getOrderHistory(alice)
|
||||
assert(history.length > 0)
|
||||
})
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user