Skip to content

Commit

Permalink
namings refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcos20 committed Jan 15, 2021
1 parent 7a6abdb commit 2ed4cb4
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 67 deletions.
1 change: 0 additions & 1 deletion src/ddo/interfaces/EditableMetadata.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { EditableMetadataLinks } from './EditableMetadataLinks'
import { ServicePrices } from './ServicePrices'

export interface EditableMetadata {
description?: string
Expand Down
67 changes: 11 additions & 56 deletions src/ocean/Assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,82 +246,37 @@ export class Assets extends Instantiable {

/**
* Edit Metadata for a DID.
* @param {did} string DID. You can leave this empty if you already have the DDO
* @param {ddo} DDO if empty, will trigger a retrieve
* @param {newMetadata} EditableMetadata Metadata fields & new values.
* @param {Account} account Ethereum account of owner to sign and prove the ownership.
* @return {Promise<DDO>} the new DDO
*/
public async editMetadata(
did: string,
ddo: DDO,
newMetadata: EditableMetadata
): Promise<DDO> {
if (!ddo) ddo = await this.ocean.metadatacache.retrieveDDO(did)
public async editMetadata(ddo: DDO, newMetadata: EditableMetadata): Promise<DDO> {
if (!ddo) return null
for (let i = 0; i < ddo.service.length; i++) {
if (ddo.service[i].type === 'metadata') {
if (newMetadata.title) ddo.service[i].attributes.main.name = newMetadata.title
if (!ddo.service[i].attributes.additionalInformation)
ddo.service[i].attributes.additionalInformation = Object()
if (newMetadata.description)
ddo.service[i].attributes.additionalInformation.description =
newMetadata.description
if (newMetadata.links)
ddo.service[i].attributes.additionalInformation.links = newMetadata.links
}
if (ddo.service[i].type !== 'metadata') continue
if (newMetadata.title) ddo.service[i].attributes.main.name = newMetadata.title
if (!ddo.service[i].attributes.additionalInformation)
ddo.service[i].attributes.additionalInformation = Object()
if (newMetadata.description)
ddo.service[i].attributes.additionalInformation.description = newMetadata.description
if (newMetadata.links)
ddo.service[i].attributes.additionalInformation.links = newMetadata.links
}
return ddo
}

/**
* Update Compute Privacy
* @param {did} string DID. You can leave this empty if you already have the DDO
* @param {ddo} DDO if empty, will trigger a retrieve
* @param {number} serviceIndex Index of the compute service in the DDO. If -1, will try to find it
* @param {ServiceComputePrivacy} computePrivacy ComputePrivacy fields & new values.
* @param {Account} account Ethereum account of owner to sign and prove the ownership.
* @return {Promise<DDO>}
*/
public async updateComputePrivacy(
did: string,
ddo: DDO,
serviceIndex: number,
computePrivacy: ServiceComputePrivacy
): Promise<DDO> {
if (!ddo) ddo = await this.ocean.metadatacache.retrieveDDO(did)
if (!ddo) return null
if (serviceIndex === -1) {
const service = ddo.findServiceByType('compute')
if (!service) return null
serviceIndex = service.index
}
if (typeof ddo.service[serviceIndex] === 'undefined') return null
if (ddo.service[serviceIndex].type !== 'compute') return null
ddo.service[serviceIndex].attributes.main.privacy.allowRawAlgorithm =
computePrivacy.allowRawAlgorithm
ddo.service[serviceIndex].attributes.main.privacy.allowNetworkAccess =
computePrivacy.allowNetworkAccess
ddo.service[serviceIndex].attributes.main.privacy.trustedAlgorithms =
computePrivacy.trustedAlgorithms
return ddo
}

/**
* Update Service Timeouts
* @param {did} string DID. You can leave this empty if you already have the DDO
* Edit Service Timeouts
* @param {ddo} DDO if empty, will trigger a retrieve
* @param {number} serviceIndex Index of the compute service in the DDO.
* @param {number} timeout New timeout setting
* @return {Promise<DDO>}
*/
public async updateServiceTimeout(
did: string,
public async editServiceTimeout(
ddo: DDO,
serviceIndex: number,
timeout: number
): Promise<DDO> {
if (!ddo) ddo = await this.ocean.metadatacache.retrieveDDO(did)
if (!ddo) return null
if (typeof ddo.service[serviceIndex] === 'undefined') return null
if (timeout < 0) return null
Expand Down
31 changes: 31 additions & 0 deletions src/ocean/Compute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -433,4 +433,35 @@ export class Compute extends Instantiable {
return order
})
}

/**
* Edit Compute Privacy
* @param {did} string DID. You can leave this empty if you already have the DDO
* @param {ddo} DDO if empty, will trigger a retrieve
* @param {number} serviceIndex Index of the compute service in the DDO. If -1, will try to find it
* @param {ServiceComputePrivacy} computePrivacy ComputePrivacy fields & new values.
* @param {Account} account Ethereum account of owner to sign and prove the ownership.
* @return {Promise<DDO>}
*/
public async editComputePrivacy(
ddo: DDO,
serviceIndex: number,
computePrivacy: ServiceComputePrivacy
): Promise<DDO> {
if (!ddo) return null
if (serviceIndex === -1) {
const service = ddo.findServiceByType('compute')
if (!service) return null
serviceIndex = service.index
}
if (typeof ddo.service[serviceIndex] === 'undefined') return null
if (ddo.service[serviceIndex].type !== 'compute') return null
ddo.service[serviceIndex].attributes.main.privacy.allowRawAlgorithm =
computePrivacy.allowRawAlgorithm
ddo.service[serviceIndex].attributes.main.privacy.allowNetworkAccess =
computePrivacy.allowNetworkAccess
ddo.service[serviceIndex].attributes.main.privacy.trustedAlgorithms =
computePrivacy.trustedAlgorithms
return ddo
}
}
5 changes: 2 additions & 3 deletions test/integration/ComputeFlow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -468,9 +468,8 @@ describe('Compute flow', () => {
}
}
assert(computeIndex > 0)
const newDdo = await ocean.assets.updateComputePrivacy(
ddo.id,
null,
const newDdo = await ocean.compute.editComputePrivacy(
ddo,
computeIndex,
newComputePrivacy
)
Expand Down
9 changes: 2 additions & 7 deletions test/integration/Marketplaceflow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ describe('Marketplace flow', () => {
title: 'new title',
links: [{ name: 'link1', type: 'sample', url: 'http://example.net' }]
}
const newDdo = await ocean.assets.editMetadata(ddo.id, null, newMetaData)
const newDdo = await ocean.assets.editMetadata(ddo, newMetaData)
assert(newDdo !== null)
const txid = await ocean.OnChainMetadataCache.update(newDdo.id, newDdo, alice.getId())
assert(txid !== null)
Expand All @@ -231,12 +231,7 @@ describe('Marketplace flow', () => {
assert(service !== null)
const serviceIndex = service.index
const newTimeout = 123
const newDdo = await ocean.assets.updateServiceTimeout(
ddo.id,
ddo,
serviceIndex,
newTimeout
)
const newDdo = await ocean.assets.editServiceTimeout(ddo, serviceIndex, newTimeout)
assert(newDdo !== null)
const txid = await ocean.OnChainMetadataCache.update(newDdo.id, newDdo, alice.getId())
assert(txid !== null)
Expand Down

0 comments on commit 2ed4cb4

Please sign in to comment.