2018-10-29 17:28:40 +01:00
|
|
|
import {Receipt} from "web3-utils"
|
2018-11-01 08:31:21 +01:00
|
|
|
import MethodReflection from "../../models/MethodReflection"
|
2018-10-29 10:53:22 +01:00
|
|
|
import ContractBase from "./ContractBase"
|
|
|
|
|
|
|
|
export default class ServiceAgreement extends ContractBase {
|
|
|
|
|
|
|
|
public static async getInstance(): Promise<ServiceAgreement> {
|
|
|
|
const serviceAgreement: ServiceAgreement = new ServiceAgreement("ServiceAgreement")
|
|
|
|
await serviceAgreement.init()
|
|
|
|
return serviceAgreement
|
|
|
|
}
|
2018-10-29 17:28:40 +01:00
|
|
|
|
2018-11-22 09:22:27 +01:00
|
|
|
public async setupAgreementTemplate(templateId: string,
|
|
|
|
methodReflections: MethodReflection[],
|
|
|
|
dependencyMatrix: number[],
|
|
|
|
name: any,
|
|
|
|
fulfillmentIndices: number[],
|
2018-11-21 15:58:59 +01:00
|
|
|
fulfillmentOperator: number,
|
2018-11-22 13:14:38 +01:00
|
|
|
ownerAddress: string): Promise<Receipt> {
|
2018-10-29 17:28:40 +01:00
|
|
|
|
|
|
|
return this.send("setupAgreementTemplate", ownerAddress, [
|
2018-11-07 09:35:47 +01:00
|
|
|
templateId, methodReflections.map((r) => r.address),
|
2018-11-22 13:14:38 +01:00
|
|
|
methodReflections.map((r) => r.signature), dependencyMatrix, name, fulfillmentIndices,
|
|
|
|
fulfillmentOperator,
|
2018-10-29 17:28:40 +01:00
|
|
|
])
|
|
|
|
}
|
|
|
|
|
2018-12-07 15:19:16 +01:00
|
|
|
// todo get service agreement consumer
|
|
|
|
|
2018-11-01 08:31:21 +01:00
|
|
|
public async getTemplateStatus(templateId: string) {
|
2018-10-29 17:28:40 +01:00
|
|
|
|
2018-11-01 08:31:21 +01:00
|
|
|
return this.call("getTemplateStatus", [templateId])
|
2018-10-29 17:28:40 +01:00
|
|
|
}
|
|
|
|
|
2018-11-06 16:13:12 +01:00
|
|
|
public async getTemplateOwner(templateId: string) {
|
|
|
|
|
|
|
|
return this.call("getTemplateOwner", [templateId])
|
|
|
|
}
|
|
|
|
|
2018-11-05 10:01:58 +01:00
|
|
|
public async getAgreementStatus(serviceDefinitionId: string) {
|
2018-11-01 08:31:21 +01:00
|
|
|
|
2018-11-05 10:01:58 +01:00
|
|
|
return this.call("getAgreementStatus", [serviceDefinitionId])
|
2018-11-01 08:31:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public async executeAgreement(serviceAgreementTemplateId: string, serviceAgreementSignatureHash: string,
|
|
|
|
consumerAddress: string, valueHashes: string[], timeoutValues: number[],
|
2018-11-05 10:01:58 +01:00
|
|
|
serviceAgreementId: string, did: string, publisherAddress: string):
|
|
|
|
Promise<Receipt> {
|
2018-10-29 17:28:40 +01:00
|
|
|
|
|
|
|
return this.send("executeAgreement", publisherAddress, [
|
2018-11-01 08:31:21 +01:00
|
|
|
serviceAgreementTemplateId, serviceAgreementSignatureHash, consumerAddress, valueHashes,
|
2018-11-23 16:01:42 +01:00
|
|
|
timeoutValues, serviceAgreementId, "0x" + did.replace("did:op:", ""),
|
2018-10-29 17:28:40 +01:00
|
|
|
])
|
|
|
|
}
|
2018-10-29 10:53:22 +01:00
|
|
|
}
|