Skip to content

Commit

Permalink
add getService
Browse files Browse the repository at this point in the history
  • Loading branch information
0x3bfc committed Jun 29, 2020
1 parent 2f5025a commit d5b6bb3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
18 changes: 17 additions & 1 deletion src/ocean/Assets.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { SearchQuery } from '../metadatastore/MetadataStore'
import { DDO } from '../ddo/DDO'
import { Metadata } from '../ddo/interfaces/Metadata'
import { Service, ServiceAccess, ServiceComputePrivacy } from '../ddo/interfaces/Service'
import {
Service,
ServiceAccess,
ServiceComputePrivacy,
ServiceCommon
} from '../ddo/interfaces/Service'
import { EditableMetadata } from '../ddo/interfaces/EditableMetadata'
import Account from './Account'
import DID from './DID'
Expand Down Expand Up @@ -352,6 +357,17 @@ export class Assets extends Instantiable {
} as SearchQuery)
}

public async getService(did: string, serviceType: string): Promise<ServiceCommon> {
const services: ServiceCommon[] = (await this.resolve(did)).service
let service
services.forEach((serv) => {
if (serv.type.toString() === serviceType) {
service = serv
}
})
return service
}

public async createAccessServiceAttributes(
creator: Account,
dtCost: number,
Expand Down
4 changes: 3 additions & 1 deletion test/integration/Marketplaceflow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ describe('Marketplace flow', () => {
})

it('Marketplace posts asset for sale', async () => {
// const downloadService = await ocean.assets.getService(ddo.id, 'download')
const accessService = await ocean.assets.getService(ddo.id, 'access')
const price = 20
assert(accessService.attributes.main.dtCost * price === 200)
})

it('Bob gets datatokens', async () => {
Expand Down

0 comments on commit d5b6bb3

Please sign in to comment.