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

changed name of ServiceExecutionAgreement

This commit is contained in:
Pedro Gutiérrez 2019-01-28 15:36:58 +01:00 committed by Pedro Gutiérrez
parent 95a98daa38
commit 64921829f9
3 changed files with 36 additions and 22 deletions

View File

@ -3,7 +3,7 @@ import AccessConditions from "./contracts/conditions/AccessConditions"
import PaymentConditions from "./contracts/conditions/PaymentConditions" import PaymentConditions from "./contracts/conditions/PaymentConditions"
import DIDRegistry from "./contracts/DIDRegistry" import DIDRegistry from "./contracts/DIDRegistry"
import OceanMarket from "./contracts/Market" import OceanMarket from "./contracts/Market"
import ServiceAgreement from "./contracts/ServiceAgreement" import ServiceExecutionAgreement from "./contracts/ServiceExecutionAgreement"
import OceanToken from "./contracts/Token" import OceanToken from "./contracts/Token"
import Web3Provider from "./Web3Provider" import Web3Provider from "./Web3Provider"
@ -29,7 +29,7 @@ export default class Keeper {
Keeper.instance.market = await OceanMarket.getInstance() Keeper.instance.market = await OceanMarket.getInstance()
Keeper.instance.auth = await OceanAuth.getInstance() Keeper.instance.auth = await OceanAuth.getInstance()
Keeper.instance.token = await OceanToken.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.accessConditions = await AccessConditions.getInstance()
Keeper.instance.paymentConditions = await PaymentConditions.getInstance() Keeper.instance.paymentConditions = await PaymentConditions.getInstance()
Keeper.instance.didRegistry = await DIDRegistry.getInstance() Keeper.instance.didRegistry = await DIDRegistry.getInstance()
@ -63,9 +63,9 @@ export default class Keeper {
/** /**
* Service agreement smart contract instance. * Service agreement smart contract instance.
* @type {ServiceAgreement} * @type {ServiceExecutionAgreement}
*/ */
public serviceAgreement: ServiceAgreement public serviceAgreement: ServiceExecutionAgreement
/** /**
* Access conditions smart contract instance. * Access conditions smart contract instance.

View File

@ -3,10 +3,10 @@ import MethodReflection from "../../models/MethodReflection"
import DID from "../../ocean/DID" import DID from "../../ocean/DID"
import ContractBase from "./ContractBase" import ContractBase from "./ContractBase"
export default class ServiceAgreement extends ContractBase { export default class ServiceExecutionAgreement extends ContractBase {
public static async getInstance(): Promise<ServiceAgreement> { public static async getInstance(): Promise<ServiceExecutionAgreement> {
const serviceAgreement: ServiceAgreement = new ServiceAgreement("ServiceAgreement") const serviceAgreement: ServiceExecutionAgreement = new ServiceExecutionAgreement("ServiceExecutionAgreement")
await serviceAgreement.init() await serviceAgreement.init()
return serviceAgreement return serviceAgreement
} }
@ -43,11 +43,17 @@ export default class ServiceAgreement extends ContractBase {
return this.call("getAgreementStatus", [serviceDefinitionId]) return this.call("getAgreementStatus", [serviceDefinitionId])
} }
public async executeAgreement(serviceAgreementTemplateId: string, serviceAgreementSignatureHash: string, public async executeAgreement(
consumerAddress: string, valueHashes: string[], timeoutValues: number[], serviceAgreementTemplateId: string,
serviceAgreementId: string, did: DID, publisherAddress: string): serviceAgreementSignatureHash: string,
Promise<Receipt> { consumerAddress: string,
valueHashes: string[],
timeoutValues: number[],
serviceAgreementId: string,
did: DID,
publisherAddress: string,
): Promise<Receipt> {
console.log({serviceAgreementTemplateId, serviceAgreementSignatureHash, consumerAddress, valueHashes, timeoutValues, serviceAgreementId, did, publisherAddress})
return this.send("executeAgreement", publisherAddress, [ return this.send("executeAgreement", publisherAddress, [
serviceAgreementTemplateId, serviceAgreementSignatureHash, consumerAddress, valueHashes, serviceAgreementTemplateId, serviceAgreementSignatureHash, consumerAddress, valueHashes,
timeoutValues, "0x" + serviceAgreementId, "0x" + did.getId(), timeoutValues, "0x" + serviceAgreementId, "0x" + did.getId(),

View File

@ -48,6 +48,7 @@ export default class ServiceAgreement extends OceanBase {
Logger.log("Executing SA with serviceAgreementId", serviceAgreementId) Logger.log("Executing SA with serviceAgreementId", serviceAgreementId)
} }
const service: Service = ddo.findServiceById(serviceDefinitionId) const service: Service = ddo.findServiceById(serviceDefinitionId)
const values: ValuePair[][] = ServiceAgreement.getValuesFromService(service, serviceAgreementId) const values: ValuePair[][] = ServiceAgreement.getValuesFromService(service, serviceAgreementId)
const valueHashes: string[] = ServiceAgreement.createValueHashes(values) const valueHashes: string[] = ServiceAgreement.createValueHashes(values)
@ -98,30 +99,35 @@ export default class ServiceAgreement extends OceanBase {
return serviceAgreementHashSignature return serviceAgreementHashSignature
} }
private static async executeAgreement(did: DID, private static async executeAgreement(
ddo: DDO, did: DID,
serviceDefinitionId: string, ddo: DDO,
serviceAgreementId: string, serviceDefinitionId: string,
valueHashes: string[], serviceAgreementId: string,
timeoutValues: number[], valueHashes: string[],
serviceAgreementHashSignature: string, timeoutValues: number[],
consumerAddress: string, serviceAgreementHashSignature: string,
publisher: Account): Promise<ServiceAgreement> { consumerAddress: string,
publisher: Account,
): Promise<ServiceAgreement> {
const {serviceAgreement} = await Keeper.getInstance() const {serviceAgreement} = await Keeper.getInstance()
console.log(1)
const service: Service = ddo.findServiceById(serviceDefinitionId) const service: Service = ddo.findServiceById(serviceDefinitionId)
if (!service.templateId) { if (!service.templateId) {
throw new Error(`TemplateId not found in service "${service.type}" ddo.`) throw new Error(`TemplateId not found in service "${service.type}" ddo.`)
} }
console.log(2)
const templateActive = await serviceAgreement.getTemplateStatus(service.templateId) const templateActive = await serviceAgreement.getTemplateStatus(service.templateId)
if (!templateActive) { if (!templateActive) {
throw new Error(`Template with id ${service.templateId} is not active.`) throw new Error(`Template with id ${service.templateId} is not active.`)
} }
console.log(3)
const executeAgreementReceipt = await serviceAgreement const executeAgreementReceipt = await serviceAgreement
.executeAgreement( .executeAgreement(
service.templateId, service.templateId,
@ -131,8 +137,10 @@ export default class ServiceAgreement extends OceanBase {
timeoutValues, timeoutValues,
serviceAgreementId, serviceAgreementId,
did, did,
publisher.getId()) publisher.getId(),
)
console.log(4)
if (executeAgreementReceipt.events.ExecuteAgreement.returnValues.state === false) { if (executeAgreementReceipt.events.ExecuteAgreement.returnValues.state === false) {
throw new Error("executing service agreement failed.") throw new Error("executing service agreement failed.")
} }