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:
parent
95a98daa38
commit
64921829f9
@ -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.
|
||||
|
@ -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<ServiceAgreement> {
|
||||
const serviceAgreement: ServiceAgreement = new ServiceAgreement("ServiceAgreement")
|
||||
public static async getInstance(): Promise<ServiceExecutionAgreement> {
|
||||
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<Receipt> {
|
||||
|
||||
public async executeAgreement(
|
||||
serviceAgreementTemplateId: string,
|
||||
serviceAgreementSignatureHash: string,
|
||||
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, [
|
||||
serviceAgreementTemplateId, serviceAgreementSignatureHash, consumerAddress, valueHashes,
|
||||
timeoutValues, "0x" + serviceAgreementId, "0x" + did.getId(),
|
@ -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,7 +99,8 @@ export default class ServiceAgreement extends OceanBase {
|
||||
return serviceAgreementHashSignature
|
||||
}
|
||||
|
||||
private static async executeAgreement(did: DID,
|
||||
private static async executeAgreement(
|
||||
did: DID,
|
||||
ddo: DDO,
|
||||
serviceDefinitionId: string,
|
||||
serviceAgreementId: string,
|
||||
@ -106,22 +108,26 @@ export default class ServiceAgreement extends OceanBase {
|
||||
timeoutValues: number[],
|
||||
serviceAgreementHashSignature: string,
|
||||
consumerAddress: string,
|
||||
publisher: Account): Promise<ServiceAgreement> {
|
||||
publisher: Account,
|
||||
): Promise<ServiceAgreement> {
|
||||
|
||||
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.")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user