1
0
mirror of https://github.com/oceanprotocol/ocean.js.git synced 2024-11-26 20:39:05 +01:00

fix initialize

This commit is contained in:
Ahmed Ali 2020-06-30 11:37:03 +02:00
parent 2219d183f6
commit f9c5b7bd49
3 changed files with 11 additions and 24 deletions

View File

@ -386,10 +386,8 @@ export class Assets extends Instantiable {
public async order( public async order(
did: string, did: string,
serviceType: string, serviceType: string,
tokenAddress,
consumerAddress: string consumerAddress: string
): Promise<void> { ): Promise<string> {
// provider.initialize
const service = await this.getService(did, serviceType) const service = await this.getService(did, serviceType)
return await this.ocean.provider.initialize( return await this.ocean.provider.initialize(
did, did,

View File

@ -69,7 +69,7 @@ export class Provider extends Instantiable {
serviceIndex: number, serviceIndex: number,
serviceType: string, serviceType: string,
consumerAddress: string consumerAddress: string
): Promise<any> { ): Promise<string> {
let DDO let DDO
try { try {
DDO = await this.ocean.assets.resolve(did) DDO = await this.ocean.assets.resolve(did)
@ -78,20 +78,16 @@ export class Provider extends Instantiable {
throw new Error('Failed to resolve DID') throw new Error('Failed to resolve DID')
} }
const args = { let initializeUrl = this.getInitializeEndpoint()
documentId: did, initializeUrl += `?documentId=${did}`
serviceId: serviceIndex, initializeUrl += `&serviceId=${serviceIndex}`
serviceType: serviceType, initializeUrl += `&serviceType=${serviceType}`
tokenAddress: DDO.dataToken, initializeUrl += `&tokenAddress=${DDO.dataToken}`
consumerAddress: consumerAddress initializeUrl += `&consumerAddress=${consumerAddress}`
}
console.log(args)
try { try {
return await this.ocean.utils.fetch.post( const response = await this.ocean.utils.fetch.get(initializeUrl)
this.getInitializeEndpoint(), return await response.text()
decodeURI(JSON.stringify(args))
)
} catch (e) { } catch (e) {
this.logger.error(e) this.logger.error(e)
throw new Error('HTTP request failed') throw new Error('HTTP request failed')

View File

@ -159,14 +159,7 @@ describe('Marketplace flow', () => {
}) })
it('Bob consumes asset 1', async () => { it('Bob consumes asset 1', async () => {
console.log( console.log(await ocean.assets.order(ddo.id, accessService.type, bob.getId()))
await ocean.assets.order(
ddo.id,
accessService.type,
ddo.dataToken,
bob.getId()
)
)
// await ocean.assets.download(tokenAddress, accessService.serviceEndpoint, accessService.index, bob.getId(), '~/my-datasets') // await ocean.assets.download(tokenAddress, accessService.serviceEndpoint, accessService.index, bob.getId(), '~/my-datasets')
}) })
}) })