diff --git a/src/ocean/Ocean.ts b/src/ocean/Ocean.ts index 46d1357..f07a422 100644 --- a/src/ocean/Ocean.ts +++ b/src/ocean/Ocean.ts @@ -14,7 +14,7 @@ import Asset from "./Asset" import IdGenerator from "./IdGenerator" import Condition from "./ServiceAgreements/Condition" import ServiceAgreementTemplate from "./ServiceAgreements/ServiceAgreementTemplate" -import DefaultTemplate from "./ServiceAgreements/Templates/Default" +import Access from "./ServiceAgreements/Templates/Access" export default class Ocean { @@ -50,9 +50,8 @@ export default class Ocean { const assetId: string = IdGenerator.generateId() const did: string = `did:op:${assetId}` - const serviceName = "Access" const serviceAgreementTemplate: ServiceAgreementTemplate = - await ServiceAgreementTemplate.registerServiceAgreementsTemplate(serviceName, DefaultTemplate.methods, + await ServiceAgreementTemplate.registerServiceAgreementsTemplate(Access.templateName, Access.Methods, asset.publisher) // get condition keys from template @@ -62,7 +61,7 @@ export default class Ocean { const ddoConditions: DDOCondition[] = conditions.map((condition: Condition): DDOCondition => { return { name: condition.methodReflection.methodName, - timeout: 100, + timeout: condition.timeout, conditionKey: condition.condtionKey, parameters: condition.methodReflection.inputs.map((input: ValuePair) => { return { @@ -79,7 +78,7 @@ export default class Ocean { id: did, service: [ { - type: serviceName, + type: Access.templateName, // tslint:disable serviceEndpoint: "http://mybrizo.org/api/v1/brizo/services/consume?pubKey=${pubKey}&serviceId={serviceId}&url={url}", purchaseEndpoint: "http://mybrizo.org/api/v1/brizo/services/access/purchase?", @@ -103,7 +102,17 @@ export default class Ocean { return AquariusProvider.getAquarius().queryMetadata(query) } - public async searchAssetsByText(query: SearchQuery): Promise { - return AquariusProvider.getAquarius().queryMetadataByText(query) + public async searchAssetsByText(text: string): Promise { + return AquariusProvider.getAquarius().queryMetadataByText({ + text, + page: 1, + offset: 100, + query: { + value: 1 + }, + sort: { + value: 1 + } + } as SearchQuery) } } diff --git a/src/ocean/ServiceAgreements/Condition.ts b/src/ocean/ServiceAgreements/Condition.ts index 68885c2..9b78cb1 100644 --- a/src/ocean/ServiceAgreements/Condition.ts +++ b/src/ocean/ServiceAgreements/Condition.ts @@ -2,5 +2,6 @@ import MethodReflection from "../../models/MethodReflection" export default class Condition { public methodReflection: MethodReflection - public condtionKey + public condtionKey: string + public timeout: number } diff --git a/src/ocean/ServiceAgreements/ServiceAgreement.ts b/src/ocean/ServiceAgreements/ServiceAgreement.ts index 90cec13..1049e16 100644 --- a/src/ocean/ServiceAgreements/ServiceAgreement.ts +++ b/src/ocean/ServiceAgreements/ServiceAgreement.ts @@ -1,3 +1,4 @@ +import Condition from "../../ddo/Condition" import DDO from "../../ddo/DDO" import AccessConditions from "../../keeper/contracts/conditions/AccessConditions" import ServiceAgreementContract from "../../keeper/contracts/ServiceAgreement" @@ -91,7 +92,7 @@ export default class ServiceAgreement extends OceanBase { } private static getTimeoutValuesFromDDO(ddo: DDO): number[] { - const timeoutValues: number[] = ddo.service[0].conditions.map((condition) => { + const timeoutValues: number[] = ddo.service[0].conditions.map((condition: Condition) => { return condition.timeout }) diff --git a/src/ocean/ServiceAgreements/ServiceAgreementTemplate.ts b/src/ocean/ServiceAgreements/ServiceAgreementTemplate.ts index de95849..d86b269 100644 --- a/src/ocean/ServiceAgreements/ServiceAgreementTemplate.ts +++ b/src/ocean/ServiceAgreements/ServiceAgreementTemplate.ts @@ -37,9 +37,10 @@ export default class ServiceAgreementTemplate extends OceanBase { const serviceAgreementTemplateId = receipt.events.SetupAgreementTemplate.returnValues.serviceTemplateId - const conditions: Condition[] = methodReflections.map((methodReflection) => { + const conditions: Condition[] = methodReflections.map((methodReflection, i) => { return { methodReflection, + timeout: methods[i].timeout, condtionKey: ServiceAgreementTemplate.generateConditionsKey(serviceAgreementTemplateId, methodReflection), } as Condition diff --git a/src/ocean/ServiceAgreements/Templates/Access.ts b/src/ocean/ServiceAgreements/Templates/Access.ts new file mode 100644 index 0000000..2b15758 --- /dev/null +++ b/src/ocean/ServiceAgreements/Templates/Access.ts @@ -0,0 +1,30 @@ +import Method from "../Method" +import TemplateBase from "./TemplateBase" + +export default class Access extends TemplateBase { + + public static templateName: string = "Access" + public static id: string = "0x00000000000000000000000000000000000000000000000000000000000001" + public static Methods: Method[] = [ + { + path: "PaymentConditions.lockPayment", + dependency: 0, + timeout: 10, + } as Method, + { + path: "AccessConditions.grantAccess", + dependency: 1, + timeout: 500, + } as Method, + { + path: "PaymentConditions.releasePayment", + dependency: 4, + timeout: 17, + } as Method, + { + path: "PaymentConditions.refundPayment", + dependency: 1, + timeout: 40, + } as Method, + ] +} diff --git a/src/ocean/ServiceAgreements/Templates/Default.ts b/src/ocean/ServiceAgreements/Templates/Default.ts deleted file mode 100644 index 71043c9..0000000 --- a/src/ocean/ServiceAgreements/Templates/Default.ts +++ /dev/null @@ -1,26 +0,0 @@ -import Method from "../Method" - -const methods: Method[] = [ - { - path: "PaymentConditions.lockPayment", - dependency: 0, - timeout: 10, - } as Method, - { - path: "AccessConditions.grantAccess", - dependency: 1, - timeout: 500, - } as Method, - { - path: "PaymentConditions.releasePayment", - dependency: 4, - timeout: 17, - } as Method, - { - path: "PaymentConditions.refundPayment", - dependency: 1, - timeout: 40, - } as Method, -] - -export default {methods} diff --git a/src/ocean/ServiceAgreements/Templates/FitchainCompute.ts b/src/ocean/ServiceAgreements/Templates/FitchainCompute.ts new file mode 100644 index 0000000..951a8e8 --- /dev/null +++ b/src/ocean/ServiceAgreements/Templates/FitchainCompute.ts @@ -0,0 +1,30 @@ +import Method from "../Method" +import TemplateBase from "./TemplateBase" + +export default class Access extends TemplateBase { + + public static templateName: string = "FitchainCompute" + public static id: string = "0x00000000000000000000000000000000000000000000000000000000000002" + public static Methods: Method[] = [ + { + path: "PaymentConditions.lockPayment", + dependency: 0, + timeout: 10, + } as Method, + { + path: "AccessConditions.grantAccess", + dependency: 1, + timeout: 500, + } as Method, + { + path: "PaymentConditions.releasePayment", + dependency: 4, + timeout: 17, + } as Method, + { + path: "PaymentConditions.refundPayment", + dependency: 1, + timeout: 40, + } as Method, + ] +} diff --git a/src/ocean/ServiceAgreements/Templates/TemplateBase.ts b/src/ocean/ServiceAgreements/Templates/TemplateBase.ts new file mode 100644 index 0000000..657b457 --- /dev/null +++ b/src/ocean/ServiceAgreements/Templates/TemplateBase.ts @@ -0,0 +1,6 @@ +export default class TemplateBase { + + protected static templateName: string + protected static id: string = "0x00000000000000000000000000000000000000000000000000000000000000" + +} diff --git a/test/ocean/Ocean.test.ts b/test/ocean/Ocean.test.ts index 8f20298..5f1523b 100644 --- a/test/ocean/Ocean.test.ts +++ b/test/ocean/Ocean.test.ts @@ -89,4 +89,15 @@ describe("Ocean", () => { }) }) + + describe("#searchAssetsByText()", () => { + + it("should search for assets", async () => { + const text = "office" + const assets: any[] = await ocean.searchAssetsByText(text) + + assert(assets) + }) + + }) }) diff --git a/test/ocean/ServiceAgreement.test.ts b/test/ocean/ServiceAgreement.test.ts index de12aec..5fd24dd 100644 --- a/test/ocean/ServiceAgreement.test.ts +++ b/test/ocean/ServiceAgreement.test.ts @@ -12,7 +12,7 @@ import Ocean from "../../src/ocean/Ocean" import Condition from "../../src/ocean/ServiceAgreements/Condition" import ServiceAgreement from "../../src/ocean/ServiceAgreements/ServiceAgreement" import ServiceAgreementTemplate from "../../src/ocean/ServiceAgreements/ServiceAgreementTemplate" -import DefaultTemplate from "../../src/ocean/ServiceAgreements/Templates/Default" +import Access from "../../src/ocean/ServiceAgreements/Templates/Access" import config from "../config" import AquariusConnectorMock from "../mocks/AquariusConnector.mock" @@ -37,10 +37,8 @@ describe("ServiceAgreement", () => { publisherAccount = accounts[1] consumerAccount = accounts[2] - const resourceName = "superb car data" - testServiceAgreementTemplate = - await ServiceAgreementTemplate.registerServiceAgreementsTemplate(resourceName, DefaultTemplate.methods, + await ServiceAgreementTemplate.registerServiceAgreementsTemplate(Access.templateName, Access.Methods, templateOwnerAccount) // get condition keys from template diff --git a/test/ocean/ServiceAgreementTemplate.test.ts b/test/ocean/ServiceAgreementTemplate.test.ts index f8914f9..ebdd7e4 100644 --- a/test/ocean/ServiceAgreementTemplate.test.ts +++ b/test/ocean/ServiceAgreementTemplate.test.ts @@ -4,7 +4,7 @@ import ContractHandler from "../../src/keeper/ContractHandler" import Account from "../../src/ocean/Account" import Ocean from "../../src/ocean/Ocean" import ServiceAgreementTemplate from "../../src/ocean/ServiceAgreements/ServiceAgreementTemplate" -import DefaultTemplate from "../../src/ocean/ServiceAgreements/Templates/Default" +import Access from "../../src/ocean/ServiceAgreements/Templates/Access" import config from "../config" let ocean: Ocean @@ -23,9 +23,8 @@ describe("ServiceAgreementTemplate", () => { it("should setup an agreement template", async () => { const templateOwner = accounts[0] - const resourceName = "consume" const serviceAgreementTemplate: ServiceAgreementTemplate = - await ServiceAgreementTemplate.registerServiceAgreementsTemplate(resourceName, DefaultTemplate.methods, + await ServiceAgreementTemplate.registerServiceAgreementsTemplate(Access.templateName, Access.Methods, templateOwner) assert(serviceAgreementTemplate) @@ -38,10 +37,8 @@ describe("ServiceAgreementTemplate", () => { it("should get the status of a newly deployed agreement template", async () => { const publisherAccount = accounts[0] - const resourceName = "consume" - const serviceAgreementTemplate: ServiceAgreementTemplate = - await ServiceAgreementTemplate.registerServiceAgreementsTemplate(resourceName, DefaultTemplate.methods, + await ServiceAgreementTemplate.registerServiceAgreementsTemplate(Access.templateName, Access.Methods, publisherAccount) assert(serviceAgreementTemplate)