From e22b63cc8032d2ccb2b203b97a340c3d2a5b7116 Mon Sep 17 00:00:00 2001 From: ssallam Date: Thu, 16 Jan 2020 15:47:29 +0100 Subject: [PATCH] More updates. --- .../managers/TemplateStoreManager.ts | 17 ++++++++++---- .../templates/AgreementTemplateBase.ts | 23 ++++++++++++++++--- src/ocean/OceanAssets.ts | 5 ++-- 3 files changed, 36 insertions(+), 9 deletions(-) diff --git a/src/keeper/contracts/managers/TemplateStoreManager.ts b/src/keeper/contracts/managers/TemplateStoreManager.ts index a6092b0..3bd82f2 100644 --- a/src/keeper/contracts/managers/TemplateStoreManager.ts +++ b/src/keeper/contracts/managers/TemplateStoreManager.ts @@ -30,10 +30,11 @@ export class TemplateStoreManager extends ContractBase { } public generateId(templateName: string) { - return this.call( - "generateId", - [templateName] - ) + const args: any = [ + { type: 'string', value: templateName }, + ] + + return this.web3.utils.soliditySha3(...args) } public getOwner(): Promise { @@ -83,6 +84,14 @@ export class TemplateStoreManager extends ContractBase { ) } + public async getActorTypeValue(actorTypeId: string) { + const typeValue = await this.call( + "getTemplateActorTypeValue", + [actorTypeId] + ) + return typeValue + } + public async getTemplate(templateId: string) { const { state, diff --git a/src/keeper/contracts/templates/AgreementTemplateBase.ts b/src/keeper/contracts/templates/AgreementTemplateBase.ts index a5c3962..2d8d32e 100644 --- a/src/keeper/contracts/templates/AgreementTemplateBase.ts +++ b/src/keeper/contracts/templates/AgreementTemplateBase.ts @@ -87,7 +87,7 @@ export class AgreementTemplateBase { } public getId() { - return '' + return this.templateManager.generateId(this.templateName) } /** @@ -143,8 +143,8 @@ export class AgreementTemplateBase { * Conditions address list. * @return {Promise} Conditions address. */ - public getConditionTypes(): Promise { - return this.templateManager.getConditionTypes(this.getId()) + public async getConditionTypes(): Promise { + return await this.templateManager.getConditionTypes(this.getId()) } /** @@ -276,4 +276,21 @@ export class AgreementTemplateBase { return this.agreementStoreManager.getAgreementCreatedEvent(agreementId) } + /** + * Return actor type ids for this template (specified by subclass) + * + */ + public async getActorTypeIds() { + const { actorTypeIds } = await this.templateManager.getTemplate(this.getId()) + return actorTypeIds + } + + /** + * Return actor types (strings) for this template (specified by subclass) + * + */ + public async getActorTypes() { + const actorTypeIds = await this.getActorTypeIds() + return actorTypeIds.map(typeId => this.templateManager.getActorTypeValue(typeId)) + } } diff --git a/src/ocean/OceanAssets.ts b/src/ocean/OceanAssets.ts index e983fc7..8f558eb 100644 --- a/src/ocean/OceanAssets.ts +++ b/src/ocean/OceanAssets.ts @@ -56,7 +56,8 @@ export class OceanAssets extends Instantiable { /** * Creates a new DDO. * @param {MetaData} metadata DDO metadata. - * @param {Account} publisher Publisher account. + * @param {Account} publisher Publisher account. + * @param {list} services list of Service description documents * @return {Promise} */ public create( @@ -106,7 +107,7 @@ export class OceanAssets extends Instantiable { { type: 'access', serviceEndpoint: this.ocean.brizo.getConsumeEndpoint(), - templateId: templates.escrowAccessSecretStoreTemplate.getAddress(), + templateId: templates.escrowAccessSecretStoreTemplate.getId(), attributes: { main: { creator: publisher.getId(),