From 75a0ef05d9789a9358180707b28bad95a84d6499 Mon Sep 17 00:00:00 2001 From: ssallam Date: Thu, 5 Mar 2020 11:56:58 +0100 Subject: [PATCH] Fix publishing compute service (fill in parameters value in agreement conditions). Update agreement template events and conditions in the sample json. --- src/ddo/Service.ts | 1 + src/keeper/Keeper.ts | 11 ++----- .../EscrowAccess.serviceAgreementTemplate.ts | 14 ++++----- .../EscrowCompute.serviceAgreementTemplate.ts | 30 +++++++++---------- src/ocean/OceanAssets.ts | 11 +++++-- .../utils/ddo-metadata-generator.ts | 6 ++-- 6 files changed, 38 insertions(+), 35 deletions(-) diff --git a/src/ddo/Service.ts b/src/ddo/Service.ts index 6ee5b8f..42a7497 100644 --- a/src/ddo/Service.ts +++ b/src/ddo/Service.ts @@ -33,6 +33,7 @@ export interface ServiceComputeAttributes extends ServiceCommonAttributes { price: string timeout: number provider?: ServiceComputeProvider + name: string } } diff --git a/src/keeper/Keeper.ts b/src/keeper/Keeper.ts index f85757d..75f26d3 100644 --- a/src/keeper/Keeper.ts +++ b/src/keeper/Keeper.ts @@ -95,24 +95,19 @@ export class Keeper extends Instantiable { computeExecutionCondition: keeper.instances.computeExecutionCondition } // Templates - keeper.instances.escrowAccessSecretStoreTemplate = new EscrowAccessSecretStoreTemplate( + keeper.templates = Object() + keeper.templates.escrowAccessSecretStoreTemplate = new EscrowAccessSecretStoreTemplate( keeper.templateStoreManager, keeper.agreementStoreManager, keeper.didRegistry, keeper.conditions ) - keeper.instances.escrowComputeExecutionTemplate = new EscrowComputeExecutionTemplate( + keeper.templates.escrowComputeExecutionTemplate = new EscrowComputeExecutionTemplate( keeper.templateStoreManager, keeper.agreementStoreManager, keeper.didRegistry, keeper.conditions ) - keeper.templates = { - escrowAccessSecretStoreTemplate: - keeper.instances.escrowAccessSecretStoreTemplate, - escrowComputeExecutionTemplate: - keeper.instances.escrowComputeExecutionTemplate - } // Utils keeper.utils = { eventHandler: new EventHandler(config) diff --git a/src/keeper/contracts/templates/EscrowAccess.serviceAgreementTemplate.ts b/src/keeper/contracts/templates/EscrowAccess.serviceAgreementTemplate.ts index 651ec6e..cf1b361 100644 --- a/src/keeper/contracts/templates/EscrowAccess.serviceAgreementTemplate.ts +++ b/src/keeper/contracts/templates/EscrowAccess.serviceAgreementTemplate.ts @@ -4,10 +4,10 @@ export const escrowAccessServiceAgreementTemplate: ServiceAgreementTemplate = { contractName: 'EscrowAccessSecretStoreTemplate', events: [ { - name: 'AgreementCreated', - actorType: 'consumer', + name: 'AgreementActorAdded', + actorType: 'provider', handler: { - moduleName: 'escrowAccessSecretStoreTemplate', + moduleName: '', functionName: 'fulfillLockRewardCondition', version: '0.1' } @@ -45,7 +45,7 @@ export const escrowAccessServiceAgreementTemplate: ServiceAgreementTemplate = { events: [ { name: 'Fulfilled', - actorType: 'publisher', + actorType: 'provider', handler: { moduleName: 'lockRewardCondition', functionName: 'fulfillAccessSecretStoreCondition', @@ -75,7 +75,7 @@ export const escrowAccessServiceAgreementTemplate: ServiceAgreementTemplate = { events: [ { name: 'Fulfilled', - actorType: 'publisher', + actorType: 'provider', handler: { moduleName: 'accessSecretStore', functionName: 'fulfillEscrowRewardCondition', @@ -87,7 +87,7 @@ export const escrowAccessServiceAgreementTemplate: ServiceAgreementTemplate = { actorType: 'consumer', handler: { moduleName: 'accessSecretStore', - functionName: 'fulfillEscrowRewardCondition', + functionName: 'refundReward', version: '0.1' } } @@ -129,7 +129,7 @@ export const escrowAccessServiceAgreementTemplate: ServiceAgreementTemplate = { events: [ { name: 'Fulfilled', - actorType: 'publisher', + actorType: 'provider', handler: { moduleName: 'escrowRewardCondition', functionName: 'verifyRewardTokens', diff --git a/src/keeper/contracts/templates/EscrowCompute.serviceAgreementTemplate.ts b/src/keeper/contracts/templates/EscrowCompute.serviceAgreementTemplate.ts index 732c20d..5c35f85 100644 --- a/src/keeper/contracts/templates/EscrowCompute.serviceAgreementTemplate.ts +++ b/src/keeper/contracts/templates/EscrowCompute.serviceAgreementTemplate.ts @@ -4,10 +4,10 @@ export const escrowComputeServiceAgreementTemplate: ServiceAgreementTemplate = { contractName: 'EscrowComputeExecutionTemplate', events: [ { - name: 'AgreementCreated', - actorType: 'consumer', + name: 'AgreementActorAdded', + actorType: 'provider', handler: { - moduleName: 'serviceExecutionTemplate', + moduleName: '', functionName: 'fulfillLockRewardCondition', version: '0.1' } @@ -15,13 +15,13 @@ export const escrowComputeServiceAgreementTemplate: ServiceAgreementTemplate = { ], fulfillmentOrder: [ 'lockReward.fulfill', - 'serviceExecution.fulfill', + 'computeExecution.fulfill', 'escrowReward.fulfill' ], conditionDependency: { lockReward: [], serviceExecution: [], - escrowReward: ['lockReward', 'serviceExecution'] + escrowReward: ['lockReward', 'computeExecution'] }, conditions: [ { @@ -45,17 +45,17 @@ export const escrowComputeServiceAgreementTemplate: ServiceAgreementTemplate = { events: [ { name: 'Fulfilled', - actorType: 'publisher', + actorType: 'provider', handler: { - moduleName: 'lockRewardCondition', - functionName: 'fulfillServiceExecutionCondition', + moduleName: 'lockRewardExecutionCondition', + functionName: 'fulfillComputeExecutionCondition', version: '0.1' } } ] }, { - name: 'serviceExecution', + name: 'computeExecution', timelock: 0, timeout: 0, contractName: 'ComputeExecutionCondition', @@ -75,10 +75,10 @@ export const escrowComputeServiceAgreementTemplate: ServiceAgreementTemplate = { events: [ { name: 'Fulfilled', - actorType: 'publisher', + actorType: 'provider', handler: { - moduleName: 'serviceExecution', - functionName: 'fulfillServiceExecutionCondition', + moduleName: 'accessSecretStore', + functionName: 'fulfillEscrowRewardCondition', version: '0.1' } }, @@ -86,8 +86,8 @@ export const escrowComputeServiceAgreementTemplate: ServiceAgreementTemplate = { name: 'TimedOut', actorType: 'consumer', handler: { - moduleName: 'serviceExec', - functionName: 'fulfillServiceExecutionCondition', + moduleName: 'accessSecretStore', + functionName: 'refundReward', version: '0.1' } } @@ -129,7 +129,7 @@ export const escrowComputeServiceAgreementTemplate: ServiceAgreementTemplate = { events: [ { name: 'Fulfilled', - actorType: 'publisher', + actorType: 'provider', handler: { moduleName: 'escrowRewardCondition', functionName: 'verifyRewardTokens', diff --git a/src/ocean/OceanAssets.ts b/src/ocean/OceanAssets.ts index e8d2723..82e5ef0 100644 --- a/src/ocean/OceanAssets.ts +++ b/src/ocean/OceanAssets.ts @@ -159,9 +159,14 @@ export class OceanAssets extends Instantiable { }) // Overwrite initial service agreement conditions - const rawConditions = await templates.escrowAccessSecretStoreTemplate.getServiceAgreementTemplateConditions() - const conditions = fillConditionsWithDDO(rawConditions, ddo) - serviceAgreementTemplate.conditions = conditions + let rawConditions = await templates.escrowAccessSecretStoreTemplate.getServiceAgreementTemplateConditions() + serviceAgreementTemplate.conditions = fillConditionsWithDDO(rawConditions, ddo) + for (let service of services) { + if (service.type === 'compute') { + const rawConditions = await templates.escrowComputeExecutionTemplate.getServiceAgreementTemplateConditions() + service.attributes.serviceAgreementTemplate.conditions = fillConditionsWithDDO(rawConditions, ddo) + } + } this.logger.log('Generating proof') observer.next(CreateProgressStep.GeneratingProof) diff --git a/test/integration/utils/ddo-metadata-generator.ts b/test/integration/utils/ddo-metadata-generator.ts index 75f6238..d79a4dd 100644 --- a/test/integration/utils/ddo-metadata-generator.ts +++ b/test/integration/utils/ddo-metadata-generator.ts @@ -87,17 +87,19 @@ export const createComputeService = async ( const { templates } = ocean.keeper const serviceAgreementTemplate = await templates.escrowComputeExecutionTemplate.getServiceAgreementTemplate() + const name = 'dataAssetComputingServiceAgreement' return { type: 'compute', index: 3, serviceEndpoint: ocean.brizo.getComputeEndpoint(), - templateId: templates.escrowAccessSecretStoreTemplate.getId(), + templateId: templates.escrowComputeExecutionTemplate.getId(), attributes: { main: { creator: publisher.getId(), datePublished, price, - timeout: 3600 + timeout: 3600, + name }, serviceAgreementTemplate }