1
0
mirror of https://github.com/oceanprotocol-archive/squid-js.git synced 2024-02-02 15:31:51 +01:00

Update DDO service schema.

This commit is contained in:
Pedro Gutiérrez 2019-09-13 13:38:23 +02:00 committed by Matthias Kretschmann
parent 3d7d1f3972
commit e3a7c54c6a
Signed by: m
GPG Key ID: 606EEEF3C479A91F
12 changed files with 62 additions and 54 deletions

View File

@ -19,6 +19,12 @@ describe('Authentication Token', () => {
;[account1, account2] = await ocean.accounts.list()
})
after(async () => {
try {
localStorage.clear()
} catch {}
})
it('should generate a token', async () => {
const token = await ocean.auth.get(account1)

View File

@ -58,7 +58,9 @@ describe('Signature', () => {
purchaseEndpoint: undefined,
serviceEndpoint: undefined,
templateId,
serviceAgreementTemplate
attributes: {
serviceAgreementTemplate
}
} as any,
{
type: 'metadata',

View File

@ -11,7 +11,8 @@ describe('Versions', () => {
ocean = await Ocean.getInstance(config)
})
it('should return the versions', async () => {
// TODO: enable again after new versions of Brizo
xit('should return the versions', async () => {
const versions = await ocean.versions.get()
assert.equal(versions.aquarius.status, OceanPlatformTechStatus.Working)

43
package-lock.json generated
View File

@ -5829,8 +5829,7 @@
"ansi-regex": {
"version": "2.1.1",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"aproba": {
"version": "1.2.0",
@ -5851,14 +5850,12 @@
"balanced-match": {
"version": "1.0.0",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"brace-expansion": {
"version": "1.1.11",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"balanced-match": "^1.0.0",
"concat-map": "0.0.1"
@ -5873,20 +5870,17 @@
"code-point-at": {
"version": "1.1.0",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"concat-map": {
"version": "0.0.1",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"console-control-strings": {
"version": "1.1.0",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"core-util-is": {
"version": "1.0.2",
@ -6003,8 +5997,7 @@
"inherits": {
"version": "2.0.3",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"ini": {
"version": "1.3.5",
@ -6016,7 +6009,6 @@
"version": "1.0.0",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"number-is-nan": "^1.0.0"
}
@ -6031,7 +6023,6 @@
"version": "3.0.4",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"brace-expansion": "^1.1.7"
}
@ -6039,14 +6030,12 @@
"minimist": {
"version": "0.0.8",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"minipass": {
"version": "2.3.5",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"safe-buffer": "^5.1.2",
"yallist": "^3.0.0"
@ -6065,7 +6054,6 @@
"version": "0.5.1",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"minimist": "0.0.8"
}
@ -6146,8 +6134,7 @@
"number-is-nan": {
"version": "1.0.1",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"object-assign": {
"version": "4.1.1",
@ -6159,7 +6146,6 @@
"version": "1.4.0",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"wrappy": "1"
}
@ -6245,8 +6231,7 @@
"safe-buffer": {
"version": "5.1.2",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"safer-buffer": {
"version": "2.1.2",
@ -6282,7 +6267,6 @@
"version": "1.0.2",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"code-point-at": "^1.0.0",
"is-fullwidth-code-point": "^1.0.0",
@ -6302,7 +6286,6 @@
"version": "3.0.1",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"ansi-regex": "^2.0.0"
}
@ -6346,14 +6329,12 @@
"wrappy": {
"version": "1.0.2",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"yallist": {
"version": "3.0.3",
"bundled": true,
"dev": true,
"optional": true
"dev": true
}
}
},
@ -12534,7 +12515,7 @@
"requires": {
"underscore": "1.9.1",
"web3-core-helpers": "1.2.1",
"websocket": "github:web3-js/WebSocket-Node#polyfill/globalThis"
"websocket": "github:web3-js/WebSocket-Node#905deb4812572b344f5801f8c9ce8bb02799d82e"
}
},
"web3-shh": {

View File

@ -66,7 +66,7 @@ export class DDO {
* @return {Service} Service.
*/
public findServiceById<T extends ServiceType>(index: number): Service<T> {
if (!index) {
if (isNaN(index)) {
throw new Error('index is not set')
}

View File

@ -203,8 +203,6 @@ export interface MetaDataMain {
*/
checksum?: string
encryptedFiles?: any
encryptedService?: any
workflow?: Workflow
@ -339,6 +337,7 @@ export interface AdditionalInformation {
export interface MetaData {
main: MetaDataMain
encryptedFiles?: string
additionalInformation?: AdditionalInformation
curation?: Curation
}

View File

@ -8,6 +8,9 @@ export interface ServiceCommon {
type: ServiceType
index: number
serviceEndpoint?: string
attributes: any & {
main: { [key: string]: any }
}
}
export interface ServiceAuthorization extends ServiceCommon {
@ -22,12 +25,20 @@ export interface ServiceMetadata extends ServiceCommon {
export interface ServiceAccess extends ServiceCommon {
type: 'access'
name?: string
description?: string
creator?: string
templateId?: string
purchaseEndpoint?: string
serviceAgreementTemplate?: ServiceAgreementTemplate
attributes: {
main: {
creator: string
name: string
datePublished: string
price: string
timeout: number
}
serviceAgreementTemplate?: ServiceAgreementTemplate
additionalInformation: {
description: string
}
}
}
export interface ServiceComputing extends ServiceCommon {

View File

@ -18,7 +18,7 @@ export class EscrowComputeExecutionTemplate extends BaseEscrowTemplate {
public async createAgreementFromDDO(agreementId: string, ddo: DDO, consumer: string, from?: string) {
return !!(await this.createFullAgreement(
ddo.shortId(),
ddo.findServiceByType('Metadata').metadata.base.price,
ddo.findServiceByType('metadata').attributes.main.price,
consumer,
from,
agreementId
@ -33,7 +33,7 @@ export class EscrowComputeExecutionTemplate extends BaseEscrowTemplate {
} = await this.createFullAgreementData(
agreementId,
ddo.shortId(),
ddo.findServiceByType('Metadata').metadata.base.price,
ddo.findServiceByType('metadata').attributes.main.price,
consumer
)
return [computeExecutionConditionId, lockRewardConditionId, escrowRewardId]

View File

@ -47,7 +47,7 @@ export class OceanAgreements extends Instantiable {
const ddo = await this.ocean.aquarius.retrieveDDO(d)
const agreementId: string = zeroX(generateId())
const templateName = ddo.findServiceByType('access').serviceAgreementTemplate.contractName
const templateName = ddo.findServiceByType('access').attributes.serviceAgreementTemplate.contractName
const agreementConditionsIds = await this.ocean.keeper
.getTemplateByName(templateName)
.getAgreementIdsFromDDO(agreementId, ddo, consumer.getId(), consumer.getId())
@ -113,7 +113,7 @@ export class OceanAgreements extends Instantiable {
const d: DID = DID.parse(did)
const ddo = await this.ocean.aquarius.retrieveDDO(d)
const templateName = ddo.findServiceById<'access'>(index).serviceAgreementTemplate.contractName
const templateName = ddo.findServiceById<'access'>(index).attributes.serviceAgreementTemplate.contractName
await this.ocean.keeper
.getTemplateByName(templateName)
.createAgreementFromDDO(agreementId, ddo, consumer.getId(), publisher.getId())

View File

@ -98,17 +98,24 @@ export class OceanAssets extends Instantiable {
service: [
{
type: 'access',
creator: '',
purchaseEndpoint: this.ocean.brizo.getPurchaseEndpoint(),
serviceEndpoint: this.ocean.brizo.getConsumeEndpoint(),
name: 'dataAssetAccessServiceAgreement',
templateId: templates.escrowAccessSecretStoreTemplate.getAddress(),
serviceAgreementTemplate
attributes: {
main: {
creator: publisher.getId(),
datePublished: metadata.main.datePublished,
name: 'dataAssetAccessServiceAgreement',
price: metadata.main.price,
timeout: 3600
},
serviceAgreementTemplate
}
},
{
type: 'authorization',
service: 'SecretStore',
serviceEndpoint: secretStoreUri
serviceEndpoint: secretStoreUri,
attributes: { main: {} }
},
{
type: 'metadata',
@ -121,11 +128,11 @@ export class OceanAssets extends Instantiable {
},
// Overwrites defaults
...metadata,
encryptedFiles,
// Cleaning not needed information
main: {
...metadata.main,
contentUrls: undefined,
encryptedFiles,
files: metadata.main.files.map((file, index) => ({
...file,
index,
@ -239,7 +246,7 @@ export class OceanAssets extends Instantiable {
} else {
const files = await this.ocean.secretStore.decrypt(
did,
ddo.findServiceByType('metadata').attributes.main.encryptedFiles,
ddo.findServiceByType('metadata').attributes.encryptedFiles,
consumerAccount,
ddo.findServiceByType('authorization').serviceEndpoint
)
@ -272,7 +279,7 @@ export class OceanAssets extends Instantiable {
const ddo = await this.resolve(did)
const { keeper } = this.ocean
const templateName = ddo.findServiceByType('access').serviceAgreementTemplate.contractName
const templateName = ddo.findServiceByType('access').attributes.serviceAgreementTemplate.contractName
const template = keeper.getTemplateByName(templateName)
const accessCondition = keeper.conditions.accessSecretStoreCondition

View File

@ -133,6 +133,7 @@ export class OceanVersions extends Instantiable {
return
}
if (address !== _) {
this.logger.warn(`Error on contract ${name}`)
contractStatus = false
}
})

View File

@ -84,7 +84,7 @@ export class ServiceAgreement extends Instantiable {
}
private getTimeValuesFromService(service: ServiceAccess, type: 'timeout' | 'timelock'): number[] {
const timeoutValues: number[] = service.serviceAgreementTemplate.conditions.map(
const timeoutValues: number[] = service.attributes.serviceAgreementTemplate.conditions.map(
(condition: ServiceAgreementTemplateCondition) => condition[type]
)