diff --git a/src/ddo/interfaces/ServicePrices.ts b/src/ddo/interfaces/ServicePrices.ts index 1e632198..0c85ccaa 100644 --- a/src/ddo/interfaces/ServicePrices.ts +++ b/src/ddo/interfaces/ServicePrices.ts @@ -1,4 +1,4 @@ export interface ServicePrices { serviceIndex: number - price: string + cost: string } diff --git a/src/metadatastore/OnChainMetaData.ts b/src/metadatastore/OnChainMetaData.ts index bc9d8ec3..93e711ec 100644 --- a/src/metadatastore/OnChainMetaData.ts +++ b/src/metadatastore/OnChainMetaData.ts @@ -99,7 +99,6 @@ export class OnChainMetadataStore { return null } try { - // const data = this.web3.utils.bytesToHex(ddo) const estGas = await this.DDOContract.methods .create(did, flags, data) .estimateGas(function (err, estGas) { @@ -127,7 +126,7 @@ export class OnChainMetadataStore { public async updateRaw( did: string, flags: any, - ddo: any, + data: any, consumerAccount: string ): Promise { if (!this.DDOContract) { @@ -135,16 +134,9 @@ export class OnChainMetadataStore { return null } try { - const data = this.web3.utils.bytesToHex(ddo) - const estGas = await this.DDOContract.methods - .update(did, flags, data) - .estimateGas(function (err, estGas) { - if (err) console.log('OnChainMetadataStore: ' + err) - return estGas - }) const trxReceipt = await this.DDOContract.methods .update(did, flags, data) - .send({ from: consumerAccount, gas: estGas + 1 }) + .send({ from: consumerAccount }) return trxReceipt } catch (e) { console.error(e) diff --git a/src/ocean/Assets.ts b/src/ocean/Assets.ts index 41fbb789..345f7fc7 100644 --- a/src/ocean/Assets.ts +++ b/src/ocean/Assets.ts @@ -223,23 +223,39 @@ export class Assets extends Instantiable { did: string, newMetadata: EditableMetadata, account: Account - ): Promise { + ): Promise { const oldDdo = await this.ocean.metadatastore.retrieveDDO(did) - // get a signature - const signature = await this.ocean.utils.signature.signForAquarius( - oldDdo.updated, - account + let i + for (i = 0; i < oldDdo.service.length; i++) { + if (oldDdo.service[i].type === 'metadata') { + if (newMetadata.title) oldDdo.service[i].attributes.main.name = newMetadata.title + if (!oldDdo.service[i].attributes.additionalInformation) + oldDdo.service[i].attributes.additionalInformation = Object() + if (newMetadata.description) + oldDdo.service[i].attributes.additionalInformation.description = + newMetadata.description + if (newMetadata.links) + oldDdo.service[i].attributes.additionalInformation.links = newMetadata.links + } + } + if (newMetadata.servicePrices) { + for (i = 0; i < newMetadata.servicePrices.length; i++) { + if ( + newMetadata.servicePrices[i].cost && + newMetadata.servicePrices[i].serviceIndex + ) { + oldDdo.service[newMetadata.servicePrices[i].serviceIndex].attributes.main.cost = + newMetadata.servicePrices[i].cost + } + } + } + const storeTx = await this.ocean.OnChainMetadataStore.update( + oldDdo.id, + oldDdo, + account.getId() ) - let result = null - if (signature != null) - result = await this.ocean.metadatastore.editMetadata( - did, - newMetadata, - oldDdo.updated, - signature - ) - - return result + if (storeTx) return oldDdo + else return null } /** @@ -255,45 +271,22 @@ export class Assets extends Instantiable { serviceIndex: number, computePrivacy: ServiceComputePrivacy, account: Account - ): Promise { + ): Promise { const oldDdo = await this.ocean.metadatastore.retrieveDDO(did) - // get a signature - const signature = await this.ocean.utils.signature.signForAquarius( - oldDdo.updated, - account + if (oldDdo.service[serviceIndex].type !== 'compute') return null + oldDdo.service[serviceIndex].attributes.main.privacy.allowRawAlgorithm = + computePrivacy.allowRawAlgorithm + oldDdo.service[serviceIndex].attributes.main.privacy.allowNetworkAccess = + computePrivacy.allowNetworkAccess + oldDdo.service[serviceIndex].attributes.main.privacy.trustedAlgorithms = + computePrivacy.trustedAlgorithms + const storeTx = await this.ocean.OnChainMetadataStore.update( + oldDdo.id, + oldDdo, + account.getId() ) - let result = null - if (signature != null) - result = await this.ocean.metadatastore.updateComputePrivacy( - did, - serviceIndex, - computePrivacy.allowRawAlgorithm, - computePrivacy.allowNetworkAccess, - computePrivacy.trustedAlgorithms, - oldDdo.updated, - signature - ) - - return result - } - - /** - * Retire a DDO (Delete) - * @param {did} string DID. - * @param {Account} account Ethereum account of owner to sign and prove the ownership. - * @return {Promise} - */ - public async retire(did: string, account: Account): Promise { - const oldDdo = await this.ocean.metadatastore.retrieveDDO(did) - // get a signature - const signature = await this.ocean.utils.signature.signForAquarius( - oldDdo.updated, - account - ) - let result = null - if (signature != null) - result = await this.ocean.metadatastore.retire(did, oldDdo.updated, signature) - return result + if (storeTx) return oldDdo + else return null } /** diff --git a/test/integration/ComputeFlow.test.ts b/test/integration/ComputeFlow.test.ts index 41d51f3f..b20759da 100644 --- a/test/integration/ComputeFlow.test.ts +++ b/test/integration/ComputeFlow.test.ts @@ -388,6 +388,42 @@ describe('Compute flow', () => { jobId = response.jobId assert(response.status >= 10) }) + it('Alice updates Compute Privacy', async () => { + const newComputePrivacy = { + allowRawAlgorithm: false, + allowNetworkAccess: true, + trustedAlgorithms: ['did:op:1234', 'did:op:1235'] + } + let computeIndex = 0 + for (let i = 0; i < ddo.service.length; i++) { + if (ddo.service[i].type === 'compute') { + computeIndex = i + break + } + } + assert(computeIndex > 0) + const newDdo = await ocean.assets.updateComputePrivacy( + ddo.id, + computeIndex, + newComputePrivacy, + alice + ) + assert(newDdo !== null) + await sleep(6000) + const metaData = await ocean.assets.getServiceByType(ddo.id, 'compute') + assert( + metaData.attributes.main.privacy.allowRawAlgorithm === + newComputePrivacy.allowRawAlgorithm + ) + assert( + metaData.attributes.main.privacy.allowNetworkAccess === + newComputePrivacy.allowNetworkAccess + ) + assert( + metaData.attributes.main.privacy.trustedAlgorithms === + newComputePrivacy.trustedAlgorithms + ) + }) // it('Bob restarts compute job', async () => {}) // it('Bob gets outputs', async () => {}) diff --git a/test/integration/Marketplaceflow.test.ts b/test/integration/Marketplaceflow.test.ts index 302b46af..972f6505 100644 --- a/test/integration/Marketplaceflow.test.ts +++ b/test/integration/Marketplaceflow.test.ts @@ -3,12 +3,14 @@ import { TestContractHandler } from '../TestContractHandler' import { DataTokens } from '../../src/datatokens/Datatokens' import { Ocean } from '../../src/ocean/Ocean' import { ConfigHelper } from '../../src/utils/ConfigHelper' + // import config from './config' import { assert } from 'console' import Web3 from 'web3' import factory from '@oceanprotocol/contracts/artifacts/DTFactory.json' import datatokensTemplate from '@oceanprotocol/contracts/artifacts/DataTokenTemplate.json' +import { EditableMetadata } from '../../src/lib' const web3 = new Web3('http://127.0.0.1:8545') function sleep(ms) { @@ -193,4 +195,20 @@ describe('Marketplace flow', () => { const assets = await ocean.assets.ownerAssets(alice.getId()) assert(assets.length > 0) }) + it('Alice updates metadata', async () => { + const newMetaData: EditableMetadata = { + description: 'new description', + title: 'new title', + links: [{ name: 'link1', type: 'sample', url: 'http://example.net' }] + } + const newDdo = await ocean.assets.editMetadata(ddo.id, newMetaData, alice) + assert(newDdo !== null) + await sleep(6000) + const metaData = await ocean.assets.getServiceByType(ddo.id, 'metadata') + assert(metaData.attributes.main.name === newMetaData.title) + assert( + metaData.attributes.additionalInformation.description === newMetaData.description + ) + assert(metaData.attributes.additionalInformation.links === newMetaData.links) + }) })