diff --git a/src/keeper/Keeper.ts b/src/keeper/Keeper.ts index a8f4fad..f8b6aef 100644 --- a/src/keeper/Keeper.ts +++ b/src/keeper/Keeper.ts @@ -3,7 +3,7 @@ import AccessConditions from "./contracts/conditions/AccessConditions" import PaymentConditions from "./contracts/conditions/PaymentConditions" import DIDRegistry from "./contracts/DIDRegistry" import OceanMarket from "./contracts/Market" -import ServiceAgreement from "./contracts/ServiceAgreement" +import ServiceExecutionAgreement from "./contracts/ServiceExecutionAgreement" import OceanToken from "./contracts/Token" import Web3Provider from "./Web3Provider" @@ -29,7 +29,7 @@ export default class Keeper { Keeper.instance.market = await OceanMarket.getInstance() Keeper.instance.auth = await OceanAuth.getInstance() Keeper.instance.token = await OceanToken.getInstance() - Keeper.instance.serviceAgreement = await ServiceAgreement.getInstance() + Keeper.instance.serviceAgreement = await ServiceExecutionAgreement.getInstance() Keeper.instance.accessConditions = await AccessConditions.getInstance() Keeper.instance.paymentConditions = await PaymentConditions.getInstance() Keeper.instance.didRegistry = await DIDRegistry.getInstance() @@ -63,9 +63,9 @@ export default class Keeper { /** * Service agreement smart contract instance. - * @type {ServiceAgreement} + * @type {ServiceExecutionAgreement} */ - public serviceAgreement: ServiceAgreement + public serviceAgreement: ServiceExecutionAgreement /** * Access conditions smart contract instance. diff --git a/src/keeper/contracts/ServiceAgreement.ts b/src/keeper/contracts/ServiceExecutionAgreement.ts similarity index 69% rename from src/keeper/contracts/ServiceAgreement.ts rename to src/keeper/contracts/ServiceExecutionAgreement.ts index caea20b..467a03b 100644 --- a/src/keeper/contracts/ServiceAgreement.ts +++ b/src/keeper/contracts/ServiceExecutionAgreement.ts @@ -3,10 +3,10 @@ import MethodReflection from "../../models/MethodReflection" import DID from "../../ocean/DID" import ContractBase from "./ContractBase" -export default class ServiceAgreement extends ContractBase { +export default class ServiceExecutionAgreement extends ContractBase { - public static async getInstance(): Promise { - const serviceAgreement: ServiceAgreement = new ServiceAgreement("ServiceAgreement") + public static async getInstance(): Promise { + const serviceAgreement: ServiceExecutionAgreement = new ServiceExecutionAgreement("ServiceExecutionAgreement") await serviceAgreement.init() return serviceAgreement } @@ -43,11 +43,17 @@ export default class ServiceAgreement extends ContractBase { return this.call("getAgreementStatus", [serviceDefinitionId]) } - public async executeAgreement(serviceAgreementTemplateId: string, serviceAgreementSignatureHash: string, - consumerAddress: string, valueHashes: string[], timeoutValues: number[], - serviceAgreementId: string, did: DID, publisherAddress: string): - Promise { - + public async executeAgreement( + serviceAgreementTemplateId: string, + serviceAgreementSignatureHash: string, + consumerAddress: string, + valueHashes: string[], + timeoutValues: number[], + serviceAgreementId: string, + did: DID, + publisherAddress: string, + ): Promise { +console.log({serviceAgreementTemplateId, serviceAgreementSignatureHash, consumerAddress, valueHashes, timeoutValues, serviceAgreementId, did, publisherAddress}) return this.send("executeAgreement", publisherAddress, [ serviceAgreementTemplateId, serviceAgreementSignatureHash, consumerAddress, valueHashes, timeoutValues, "0x" + serviceAgreementId, "0x" + did.getId(), diff --git a/src/ocean/ServiceAgreements/ServiceAgreement.ts b/src/ocean/ServiceAgreements/ServiceAgreement.ts index 59e7ed9..c4ceed1 100644 --- a/src/ocean/ServiceAgreements/ServiceAgreement.ts +++ b/src/ocean/ServiceAgreements/ServiceAgreement.ts @@ -48,6 +48,7 @@ export default class ServiceAgreement extends OceanBase { Logger.log("Executing SA with serviceAgreementId", serviceAgreementId) } + const service: Service = ddo.findServiceById(serviceDefinitionId) const values: ValuePair[][] = ServiceAgreement.getValuesFromService(service, serviceAgreementId) const valueHashes: string[] = ServiceAgreement.createValueHashes(values) @@ -98,30 +99,35 @@ export default class ServiceAgreement extends OceanBase { return serviceAgreementHashSignature } - private static async executeAgreement(did: DID, - ddo: DDO, - serviceDefinitionId: string, - serviceAgreementId: string, - valueHashes: string[], - timeoutValues: number[], - serviceAgreementHashSignature: string, - consumerAddress: string, - publisher: Account): Promise { + private static async executeAgreement( + did: DID, + ddo: DDO, + serviceDefinitionId: string, + serviceAgreementId: string, + valueHashes: string[], + timeoutValues: number[], + serviceAgreementHashSignature: string, + consumerAddress: string, + publisher: Account, + ): Promise { const {serviceAgreement} = await Keeper.getInstance() + console.log(1) const service: Service = ddo.findServiceById(serviceDefinitionId) if (!service.templateId) { throw new Error(`TemplateId not found in service "${service.type}" ddo.`) } + console.log(2) const templateActive = await serviceAgreement.getTemplateStatus(service.templateId) if (!templateActive) { throw new Error(`Template with id ${service.templateId} is not active.`) } + console.log(3) const executeAgreementReceipt = await serviceAgreement .executeAgreement( service.templateId, @@ -131,8 +137,10 @@ export default class ServiceAgreement extends OceanBase { timeoutValues, serviceAgreementId, did, - publisher.getId()) + publisher.getId(), + ) + console.log(4) if (executeAgreementReceipt.events.ExecuteAgreement.returnValues.state === false) { throw new Error("executing service agreement failed.") }