mirror of
https://github.com/oceanprotocol-archive/squid-js.git
synced 2024-02-02 15:31:51 +01:00
added search by text, added templates for fitchain and access
This commit is contained in:
parent
1874e24b61
commit
86be0cc6d5
@ -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<any[]> {
|
||||
return AquariusProvider.getAquarius().queryMetadataByText(query)
|
||||
public async searchAssetsByText(text: string): Promise<any[]> {
|
||||
return AquariusProvider.getAquarius().queryMetadataByText({
|
||||
text,
|
||||
page: 1,
|
||||
offset: 100,
|
||||
query: {
|
||||
value: 1
|
||||
},
|
||||
sort: {
|
||||
value: 1
|
||||
}
|
||||
} as SearchQuery)
|
||||
}
|
||||
}
|
||||
|
@ -2,5 +2,6 @@ import MethodReflection from "../../models/MethodReflection"
|
||||
|
||||
export default class Condition {
|
||||
public methodReflection: MethodReflection
|
||||
public condtionKey
|
||||
public condtionKey: string
|
||||
public timeout: number
|
||||
}
|
||||
|
@ -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
|
||||
})
|
||||
|
||||
|
@ -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
|
||||
|
30
src/ocean/ServiceAgreements/Templates/Access.ts
Normal file
30
src/ocean/ServiceAgreements/Templates/Access.ts
Normal file
@ -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,
|
||||
]
|
||||
}
|
@ -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}
|
30
src/ocean/ServiceAgreements/Templates/FitchainCompute.ts
Normal file
30
src/ocean/ServiceAgreements/Templates/FitchainCompute.ts
Normal file
@ -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,
|
||||
]
|
||||
}
|
6
src/ocean/ServiceAgreements/Templates/TemplateBase.ts
Normal file
6
src/ocean/ServiceAgreements/Templates/TemplateBase.ts
Normal file
@ -0,0 +1,6 @@
|
||||
export default class TemplateBase {
|
||||
|
||||
protected static templateName: string
|
||||
protected static id: string = "0x00000000000000000000000000000000000000000000000000000000000000"
|
||||
|
||||
}
|
@ -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)
|
||||
})
|
||||
|
||||
})
|
||||
})
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user