From 8d018633a997629f2df4094e25768e57dba7999f Mon Sep 17 00:00:00 2001 From: Sebastian Gerske Date: Fri, 23 Nov 2018 09:17:30 +0100 Subject: [PATCH 01/53] added buy asset and grant access samples, prepare for consumption --- src/examples/BuyAsset.ts | 78 ++++++++++++++++++ src/examples/GrantAccess.ts | 81 +++++++++++++++++++ src/examples/fire_lazers.sh | 2 + src/ocean/Ocean.ts | 12 +-- .../ServiceAgreements/ServiceAgreement.ts | 1 + 5 files changed, 168 insertions(+), 6 deletions(-) create mode 100644 src/examples/BuyAsset.ts create mode 100644 src/examples/GrantAccess.ts diff --git a/src/examples/BuyAsset.ts b/src/examples/BuyAsset.ts new file mode 100644 index 0000000..643985f --- /dev/null +++ b/src/examples/BuyAsset.ts @@ -0,0 +1,78 @@ +import DDO from "../ddo/DDO" +import MetaData from "../ddo/MetaData" +import MetaDataBase from "../ddo/MetaDataBase" +import Service from "../ddo/Service" +import {Account, Logger, Ocean, ServiceAgreement} from "../squid" + +(async () => { + const ocean: Ocean = await Ocean.getInstance({ + nodeUri: "http://localhost:8545", + aquariusUri: "http://localhost:5000", + brizoUri: "http://localhost:8030", + parityUri: "http://localhost:9545", + secretStoreUri: "http://localhost:12001", + threshold: 0, + password: "unittest", + address: "0xed243adfb84a6626eba46178ccb567481c6e655d", + }) + + const publisher: Account = (await ocean.getAccounts())[0] + const consumer: Account = (await ocean.getAccounts())[1] + + const metaData = new MetaData({ + base: { + name: "Office Humidity", + type: "dataset", + description: "Weather information of UK including temperature and humidity", + size: "3.1gb", + dateCreated: "2012-02-01T10:55:11+00:00", + author: "Met Office", + license: "CC-BY", + copyrightHolder: "Met Office", + encoding: "UTF-8", + compression: "zip", + contentType: "text/csv", + // tslint:disable-next-line + workExample: "stationId,latitude,longitude,datetime,temperature,humidity423432fsd,51.509865,-0.118092,2011-01-01T10:55:11+00:00,7.2,68", + contentUrls: [ + "https://testocnfiles.blob.core.windows.net/testfiles/testzkp.zip", + "https://testocnfiles.blob.core.windows.net/testfiles/testzkp.zip", + ], + links: [ + {sample1: "http://data.ceda.ac.uk/badc/ukcp09/data/gridded-land-obs/gridded-land-obs-daily/"}, + {sample2: "http://data.ceda.ac.uk/badc/ukcp09/data/gridded-land-obs/gridded-land-obs-averages-25km/"}, + {fieldsDescription: "http://data.ceda.ac.uk/badc/ukcp09/"}, + ], + inLanguage: "en", + tags: "weather, uk, 2011, temperature, humidity", + price: 10, + } as MetaDataBase, + } as MetaData) + + const ddo: DDO = await ocean.registerAsset(metaData, publisher) + Logger.log("did", ddo.id) + const assetId = ddo.id.replace("did:op:", "") + + const accessService = ddo.findServiceByType("Access") + + const serviceAgreementSignatureResult: any = await ocean.signServiceAgreement(ddo.id, + accessService.serviceDefinitionId, consumer) + Logger.log("ServiceAgreement Id:", serviceAgreementSignatureResult.serviceAgreementId) + Logger.log("ServiceAgreement Signature:", serviceAgreementSignatureResult.serviceAgreementSignature) + + const service: Service = ddo.findServiceByType("Access") + + const serviceAgreement: ServiceAgreement = await ocean.executeServiceAgreement( + ddo.id, + service.serviceDefinitionId, + serviceAgreementSignatureResult.serviceAgreementId, + serviceAgreementSignatureResult.serviceAgreementSignature, + consumer, + publisher) + Logger.log("ServiceAgreement Id:", serviceAgreement.getId()) + + await consumer.requestTokens(metaData.base.price) + + const paid = await serviceAgreement.buyAsset(assetId, metaData.base.price, consumer) + Logger.log(`Asset paid: ${paid}`) +})() diff --git a/src/examples/GrantAccess.ts b/src/examples/GrantAccess.ts new file mode 100644 index 0000000..269fa2d --- /dev/null +++ b/src/examples/GrantAccess.ts @@ -0,0 +1,81 @@ +import DDO from "../ddo/DDO" +import MetaData from "../ddo/MetaData" +import MetaDataBase from "../ddo/MetaDataBase" +import Service from "../ddo/Service" +import {Account, Logger, Ocean, ServiceAgreement} from "../squid" + +(async () => { + const ocean: Ocean = await Ocean.getInstance({ + nodeUri: "http://localhost:8545", + aquariusUri: "http://localhost:5000", + brizoUri: "http://localhost:8030", + parityUri: "http://localhost:9545", + secretStoreUri: "http://localhost:12001", + threshold: 0, + password: "unittest", + address: "0xed243adfb84a6626eba46178ccb567481c6e655d", + }) + + const publisher: Account = (await ocean.getAccounts())[0] + const consumer: Account = (await ocean.getAccounts())[1] + + const metaData = new MetaData({ + base: { + name: "Office Humidity", + type: "dataset", + description: "Weather information of UK including temperature and humidity", + size: "3.1gb", + dateCreated: "2012-02-01T10:55:11+00:00", + author: "Met Office", + license: "CC-BY", + copyrightHolder: "Met Office", + encoding: "UTF-8", + compression: "zip", + contentType: "text/csv", + // tslint:disable-next-line + workExample: "stationId,latitude,longitude,datetime,temperature,humidity423432fsd,51.509865,-0.118092,2011-01-01T10:55:11+00:00,7.2,68", + contentUrls: [ + "https://testocnfiles.blob.core.windows.net/testfiles/testzkp.zip", + "https://testocnfiles.blob.core.windows.net/testfiles/testzkp.zip", + ], + links: [ + {sample1: "http://data.ceda.ac.uk/badc/ukcp09/data/gridded-land-obs/gridded-land-obs-daily/"}, + {sample2: "http://data.ceda.ac.uk/badc/ukcp09/data/gridded-land-obs/gridded-land-obs-averages-25km/"}, + {fieldsDescription: "http://data.ceda.ac.uk/badc/ukcp09/"}, + ], + inLanguage: "en", + tags: "weather, uk, 2011, temperature, humidity", + price: 10, + } as MetaDataBase, + } as MetaData) + + const ddo: DDO = await ocean.registerAsset(metaData, publisher) + Logger.log("did", ddo.id) + const assetId = ddo.id.replace("did:op:", "") + + const accessService = ddo.findServiceByType("Access") + + const serviceAgreementSignatureResult: any = await ocean.signServiceAgreement(ddo.id, + accessService.serviceDefinitionId, consumer) + Logger.log("ServiceAgreement Id:", serviceAgreementSignatureResult.serviceAgreementId) + Logger.log("ServiceAgreement Signature:", serviceAgreementSignatureResult.serviceAgreementSignature) + + const service: Service = ddo.findServiceByType("Access") + + const serviceAgreement: ServiceAgreement = await ocean.executeServiceAgreement( + ddo.id, + service.serviceDefinitionId, + serviceAgreementSignatureResult.serviceAgreementId, + serviceAgreementSignatureResult.serviceAgreementSignature, + consumer, + publisher) + Logger.log("ServiceAgreement Id:", serviceAgreement.getId()) + + await consumer.requestTokens(metaData.base.price) + + const paid = await serviceAgreement.buyAsset(assetId, metaData.base.price, consumer) + Logger.log(`Asset paid: ${paid}`) + + const accessGranted = await serviceAgreement.grantAccess(assetId, assetId) + Logger.log(`Asset access granted: ${accessGranted}`) +})() diff --git a/src/examples/fire_lazers.sh b/src/examples/fire_lazers.sh index f521131..2ace01f 100755 --- a/src/examples/fire_lazers.sh +++ b/src/examples/fire_lazers.sh @@ -7,3 +7,5 @@ npm run run src/examples/RegisterAsset.ts npm run run src/examples/Search.ts npm run run src/examples/SignAgreement.ts npm run run src/examples/ExecuteAgreement.ts +npm run run src/examples/BuyAsset.ts +npm run run src/examples/GrantAccess.ts diff --git a/src/ocean/Ocean.ts b/src/ocean/Ocean.ts index 4784da7..924e882 100644 --- a/src/ocean/Ocean.ts +++ b/src/ocean/Ocean.ts @@ -62,12 +62,12 @@ export default class Ocean { const aquarius = AquariusProvider.getAquarius() const brizo = BrizoProvider.getBrizo() - const id: string = IdGenerator.generateId() - const did: string = `did:op:${id}` + const assetId: string = IdGenerator.generateId() + const did: string = `did:op:${assetId}` const serviceDefinitionId: string = IdGenerator.generatePrefixedId() metadata.base.contentUrls = - await SecretStoreProvider.getSecretStore().encryptDocument(id, metadata.base.contentUrls) + await SecretStoreProvider.getSecretStore().encryptDocument(assetId, metadata.base.contentUrls) const template = new Access() const serviceAgreementTemplate = new ServiceAgreementTemplate(template) @@ -98,9 +98,9 @@ export default class Ocean { case "price": return metadata.base.price case "assetId": - return "0x" + id + return "0x" + assetId case "documentKeyId": - return "0x1234" + return "0x" + assetId } return null @@ -182,7 +182,7 @@ export default class Ocean { const storedDdo = await aquarius.storeDDO(ddo) await didRegistry.registerAttribute( - id, + assetId, ValueType.DID, "Metadata", serviceEndpoint, diff --git a/src/ocean/ServiceAgreements/ServiceAgreement.ts b/src/ocean/ServiceAgreements/ServiceAgreement.ts index 0f0302b..dba4bc6 100644 --- a/src/ocean/ServiceAgreements/ServiceAgreement.ts +++ b/src/ocean/ServiceAgreements/ServiceAgreement.ts @@ -205,6 +205,7 @@ export default class ServiceAgreement extends OceanBase { super(serviceAgreementId) } + // todo: sync with samer public async buyAsset(assetId: string, price: number, consumer: Account): Promise { const {paymentConditions, token} = await Keeper.getInstance() From 43db4412ee50e2fc3a88b7698a73349470438805 Mon Sep 17 00:00:00 2001 From: Sebastian Gerske Date: Fri, 23 Nov 2018 09:57:26 +0100 Subject: [PATCH 02/53] add events to template --- src/ocean/ServiceAgreements/Event.ts | 7 ++ src/ocean/ServiceAgreements/EventHandler.ts | 5 ++ src/ocean/ServiceAgreements/Method.ts | 2 + .../ServiceAgreements/Templates/Access.ts | 72 ++++++++++++++++--- 4 files changed, 78 insertions(+), 8 deletions(-) create mode 100644 src/ocean/ServiceAgreements/Event.ts create mode 100644 src/ocean/ServiceAgreements/EventHandler.ts diff --git a/src/ocean/ServiceAgreements/Event.ts b/src/ocean/ServiceAgreements/Event.ts new file mode 100644 index 0000000..4ba5249 --- /dev/null +++ b/src/ocean/ServiceAgreements/Event.ts @@ -0,0 +1,7 @@ +import EventHandler from "./EventHandler" + +export default class Event { + public name: string = "PaymentLocked" + public actorType: string = "publisher" + public handler: EventHandler +} diff --git a/src/ocean/ServiceAgreements/EventHandler.ts b/src/ocean/ServiceAgreements/EventHandler.ts new file mode 100644 index 0000000..978b855 --- /dev/null +++ b/src/ocean/ServiceAgreements/EventHandler.ts @@ -0,0 +1,5 @@ +export default class EventHandler { + public moduleName: string = "accessControl" + public functionName: string = "grantAccess" + public version: string = "0.1" +} diff --git a/src/ocean/ServiceAgreements/Method.ts b/src/ocean/ServiceAgreements/Method.ts index 1e31f46..9f4e169 100644 --- a/src/ocean/ServiceAgreements/Method.ts +++ b/src/ocean/ServiceAgreements/Method.ts @@ -1,3 +1,4 @@ +import Event from "./Event" import Parameter from "./Parameter" export default class Method { @@ -6,6 +7,7 @@ export default class Method { public methodName: string public timeout: number public parameters: Parameter[] + public events: Event[] public dependencies: string[] public dependencyTimeoutFlags: number[] public isTerminalCondition: boolean diff --git a/src/ocean/ServiceAgreements/Templates/Access.ts b/src/ocean/ServiceAgreements/Templates/Access.ts index 8c41126..0f92da5 100644 --- a/src/ocean/ServiceAgreements/Templates/Access.ts +++ b/src/ocean/ServiceAgreements/Templates/Access.ts @@ -1,4 +1,7 @@ +import Event from "../Event" +import EventHandler from "../EventHandler" import Method from "../Method" +import Parameter from "../Parameter" import TemplateBase from "./TemplateBase" export default class Access extends TemplateBase { @@ -15,11 +18,22 @@ export default class Access extends TemplateBase { { name: "assetId", type: "bytes32", - }, + } as Parameter, { name: "price", type: "uint256", - }, + } as Parameter, + ], + events: [ + { + name: "PaymentLocked", + actorType: "publisher", + handler: { + moduleName: "accessControl", + functionName: "grantAccess", + version: "0.1", + } as EventHandler, + } as Event, ], dependencies: [], dependencyTimeoutFlags: [], @@ -34,11 +48,31 @@ export default class Access extends TemplateBase { { name: "assetId", type: "bytes32", - }, + } as Parameter, { name: "documentKeyId", type: "bytes32", - }, + } as Parameter, + ], + events: [ + { + name: "AccessGranted", + actorType: "consumer", + handler: { + moduleName: "asset", + functionName: "consumeService", + version: "0.1", + } as EventHandler, + } as Event, + { + name: "AccessGranted", + actorType: "publisher", + handler: { + moduleName: "payment", + functionName: "releasePayment", + version: "0.1", + } as EventHandler, + } as Event, ], dependencies: ["lockPayment"], dependencyTimeoutFlags: [0], @@ -53,11 +87,22 @@ export default class Access extends TemplateBase { { name: "assetId", type: "bytes32", - }, + } as Parameter, { name: "price", type: "uint256", - }, + } as Parameter, + ], + events: [ + { + name: "PaymentReleased", + actorType: "publisher", + handler: { + moduleName: "serviceAgreement", + functionName: "fulfillAgreement", + version: "0.1", + } as EventHandler, + } as Event, ], dependencies: ["grantAccess"], dependencyTimeoutFlags: [0], @@ -72,11 +117,22 @@ export default class Access extends TemplateBase { { name: "assetId", type: "bytes32", - }, + } as Parameter, { name: "price", type: "uint256", - }, + } as Parameter, + ], + events: [ + { + name: "PaymentRefund", + actorType: "consumer", + handler: { + moduleName: "serviceAgreement", + functionName: "fulfillAgreement", + version: "0.1", + } as EventHandler, + } as Event, ], dependencies: ["lockPayment", "grantAccess"], dependencyTimeoutFlags: [0, 1], From 375f153b93aeb21e39692b162a63e4264d006af7 Mon Sep 17 00:00:00 2001 From: Sebastian Gerske Date: Fri, 23 Nov 2018 09:57:37 +0100 Subject: [PATCH 03/53] add detection for local poa --- src/keeper/Keeper.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/keeper/Keeper.ts b/src/keeper/Keeper.ts index e278cdb..621041a 100644 --- a/src/keeper/Keeper.ts +++ b/src/keeper/Keeper.ts @@ -56,6 +56,9 @@ export default class Keeper { case 42: network = "Kovan" break + case 8996: + network = "Ocean_POA_net_local" + break case 8995: network = "Ocean_POA_AWS" break From dccd58802a94435b99f800d33b5abae3e301976a Mon Sep 17 00:00:00 2001 From: Sebastian Gerske Date: Fri, 23 Nov 2018 11:39:08 +0100 Subject: [PATCH 04/53] added error messages --- test/ocean/Account.test.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/test/ocean/Account.test.ts b/test/ocean/Account.test.ts index 209d76a..b07b10e 100644 --- a/test/ocean/Account.test.ts +++ b/test/ocean/Account.test.ts @@ -47,7 +47,8 @@ describe("Account", () => { const balance = await account.getEtherBalance() const web3 = Web3Provider.getWeb3() - assert(Number(web3.utils.toWei("100", "ether")) === balance) + assert(Number(web3.utils.toWei("100", "ether")) === balance, + `ether did not match ${balance}`) }) }) @@ -59,8 +60,9 @@ describe("Account", () => { const balance = await account.getBalance() const web3 = Web3Provider.getWeb3() - assert(Number(web3.utils.toWei("100", "ether")) === balance.eth) - assert(0 === balance.ocn) + assert(Number(web3.utils.toWei("100", "ether")) === balance.eth, + `ether did not match ${balance.eth}`) + assert(0 === balance.ocn, `tokens did not match ${balance.ocn}`) }) }) From df475b69582b6477ae9c2f07f64d2c1f18dfe11e Mon Sep 17 00:00:00 2001 From: Sebastian Gerske Date: Fri, 23 Nov 2018 11:39:16 +0100 Subject: [PATCH 05/53] added event listener --- src/keeper/Event.ts | 35 +++++++++++++++ src/keeper/EventListener.ts | 25 +++++++++++ test/keeper/EventListener.test.ts | 71 +++++++++++++++++++++++++++++++ 3 files changed, 131 insertions(+) create mode 100644 src/keeper/Event.ts create mode 100644 src/keeper/EventListener.ts create mode 100644 test/keeper/EventListener.test.ts diff --git a/src/keeper/Event.ts b/src/keeper/Event.ts new file mode 100644 index 0000000..e1d8b97 --- /dev/null +++ b/src/keeper/Event.ts @@ -0,0 +1,35 @@ +import GenericContract from "./contracts/GenericContract" + +export default class Event { + + private poller + private lastBlock: number = 0 + + constructor(private contractName: string, + private eventName: string, + private filter: any) { + + } + + public stopListen() { + clearTimeout(this.poller) + } + + public listen(callback: any) { + this.poller = setTimeout(() => this.handler(callback), 200) + } + + private async handler(callback: any) { + const contract = await + GenericContract.getInstance(this.contractName) + const events = await + contract.getEventData(this.eventName, { + filter: this.filter, + fromBlock: this.lastBlock, + toBlock: "latest", + }) + + this.lastBlock = events[events.length - 1].blockNumber + callback(events) + } +} diff --git a/src/keeper/EventListener.ts b/src/keeper/EventListener.ts new file mode 100644 index 0000000..58035e5 --- /dev/null +++ b/src/keeper/EventListener.ts @@ -0,0 +1,25 @@ +import Event from "./Event" + +export default class EventListener { + + private static events: Event[] = [] + + public subscribe(contractName: string, + eventName: string, + filter: any): Event { + + const event = new Event(contractName, eventName, filter) + EventListener.events.push(event) + + return event + } + + public unsubscribe(event): boolean { + + EventListener.events = EventListener.events.splice( + EventListener.events.findIndex((e) => e === event), + 1) + + return true + } +} diff --git a/test/keeper/EventListener.test.ts b/test/keeper/EventListener.test.ts new file mode 100644 index 0000000..46bd18c --- /dev/null +++ b/test/keeper/EventListener.test.ts @@ -0,0 +1,71 @@ +import {assert} from "chai" +import ConfigProvider from "../../src/ConfigProvider" +import EventListener from "../../src/keeper/EventListener" +import Keeper from "../../src/keeper/Keeper" +import Account from "../../src/ocean/Account" +import Ocean from "../../src/ocean/Ocean" +import config from "../config" +import TestContractHandler from "./TestContractHandler" + +let keeper: Keeper +let ocean: Ocean +let accounts: Account[] + +describe("EventListener", () => { + + before(async () => { + ConfigProvider.setConfig(config) + await TestContractHandler.prepareContracts() + keeper = await Keeper.getInstance() + assert(keeper) + ocean = await Ocean.getInstance(config) + assert(ocean) + accounts = await ocean.getAccounts() + assert(accounts) + }) + + describe("#subscribe()", () => { + + it("should subscribe to an event", (done) => { + + const eventListener = new EventListener() + const acc = accounts[1] + + const event = eventListener.subscribe("OceanToken", + "Transfer", + { + to: acc.getId(), + }) + + event.listen((events) => { + + assert(events) + assert(events.length === 2) + done() + }) + + const {market} = keeper + + market.requestTokens(400, acc.getId()) + market.requestTokens(400, acc.getId()) + }) + }) + + describe("#unsubscribe()", () => { + + it("should subscribe to an event", (done) => { + + const eventListener = new EventListener() + + const event = eventListener.subscribe("OceanToken", + "Transfer", + {}) + + const unsubscribed = eventListener.unsubscribe(event) + assert(unsubscribed) + + done() + }) + }) + +}) From f37a1cc1c63cea9e96e0e8cea24f3fabec8ec9db Mon Sep 17 00:00:00 2001 From: Sebastian Gerske Date: Fri, 23 Nov 2018 11:47:39 +0100 Subject: [PATCH 06/53] make event listener static --- src/keeper/EventListener.ts | 12 ++++++------ test/keeper/EventListener.test.ts | 9 +++------ 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/keeper/EventListener.ts b/src/keeper/EventListener.ts index 58035e5..00fe7c2 100644 --- a/src/keeper/EventListener.ts +++ b/src/keeper/EventListener.ts @@ -2,11 +2,9 @@ import Event from "./Event" export default class EventListener { - private static events: Event[] = [] - - public subscribe(contractName: string, - eventName: string, - filter: any): Event { + public static subscribe(contractName: string, + eventName: string, + filter: any): Event { const event = new Event(contractName, eventName, filter) EventListener.events.push(event) @@ -14,7 +12,7 @@ export default class EventListener { return event } - public unsubscribe(event): boolean { + public static unsubscribe(event): boolean { EventListener.events = EventListener.events.splice( EventListener.events.findIndex((e) => e === event), @@ -22,4 +20,6 @@ export default class EventListener { return true } + + private static events: Event[] = [] } diff --git a/test/keeper/EventListener.test.ts b/test/keeper/EventListener.test.ts index 46bd18c..9b40c35 100644 --- a/test/keeper/EventListener.test.ts +++ b/test/keeper/EventListener.test.ts @@ -28,10 +28,9 @@ describe("EventListener", () => { it("should subscribe to an event", (done) => { - const eventListener = new EventListener() const acc = accounts[1] - const event = eventListener.subscribe("OceanToken", + const event = EventListener.subscribe("OceanToken", "Transfer", { to: acc.getId(), @@ -55,13 +54,11 @@ describe("EventListener", () => { it("should subscribe to an event", (done) => { - const eventListener = new EventListener() - - const event = eventListener.subscribe("OceanToken", + const event = EventListener.subscribe("OceanToken", "Transfer", {}) - const unsubscribed = eventListener.unsubscribe(event) + const unsubscribed = EventListener.unsubscribe(event) assert(unsubscribed) done() From 1b967896dfdd9248d67e04228e5b1b88c4060c99 Mon Sep 17 00:00:00 2001 From: Sebastian Gerske Date: Fri, 23 Nov 2018 12:40:18 +0100 Subject: [PATCH 07/53] small ddo adoptions --- src/ocean/Ocean.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/ocean/Ocean.ts b/src/ocean/Ocean.ts index 924e882..af19138 100644 --- a/src/ocean/Ocean.ts +++ b/src/ocean/Ocean.ts @@ -64,10 +64,12 @@ export default class Ocean { const assetId: string = IdGenerator.generateId() const did: string = `did:op:${assetId}` - const serviceDefinitionId: string = IdGenerator.generatePrefixedId() + const accessServiceDefinitionId: string = "0" + const computeServiceDefintionId: string = "1" + const metadataServiceDefinitionId: string = "2" metadata.base.contentUrls = - await SecretStoreProvider.getSecretStore().encryptDocument(assetId, metadata.base.contentUrls) + [await SecretStoreProvider.getSecretStore().encryptDocument(assetId, metadata.base.contentUrls)] const template = new Access() const serviceAgreementTemplate = new ServiceAgreementTemplate(template) @@ -159,9 +161,9 @@ export default class Ocean { type: template.templateName, purchaseEndpoint: brizo.getPurchaseEndpoint(), serviceEndpoint: brizo.getConsumeEndpoint(publisher.getId(), - serviceDefinitionId, metadata.base.contentUrls[0]), + accessServiceDefinitionId, metadata.base.contentUrls[0]), // the id of the service agreement? - serviceDefinitionId, + serviceDefinitionId: accessServiceDefinitionId, // the id of the service agreement template templateId: serviceAgreementTemplate.getId(), conditions: ddoConditions, @@ -169,11 +171,13 @@ export default class Ocean { { type: "Compute", serviceEndpoint: brizo.getComputeEndpoint(publisher.getId(), - serviceDefinitionId, "xxx", "xxx"), + computeServiceDefintionId, "xxx", "xxx"), + serviceDefinitionId: computeServiceDefintionId, } as Service, { type: "Metadata", serviceEndpoint, + serviceDefinitionId: metadataServiceDefinitionId, metadata, } as Service, ], From 9503419b0e1d102e732ebfdcd2fb65975e3e8840 Mon Sep 17 00:00:00 2001 From: Sebastian Gerske Date: Fri, 23 Nov 2018 12:40:49 +0100 Subject: [PATCH 08/53] added more functionality to event listener --- src/keeper/Event.ts | 13 +++++- src/keeper/EventListener.ts | 14 +++--- test/keeper/Event.test.ts | 75 +++++++++++++++++++++++++++++++ test/keeper/EventListener.test.ts | 48 ++++++++++---------- 4 files changed, 120 insertions(+), 30 deletions(-) create mode 100644 test/keeper/Event.test.ts diff --git a/src/keeper/Event.ts b/src/keeper/Event.ts index e1d8b97..8bb5b8f 100644 --- a/src/keeper/Event.ts +++ b/src/keeper/Event.ts @@ -1,9 +1,11 @@ import GenericContract from "./contracts/GenericContract" +import EventListener from "./EventListener" export default class Event { private poller private lastBlock: number = 0 + private interval: number = 200 constructor(private contractName: string, private eventName: string, @@ -16,7 +18,16 @@ export default class Event { } public listen(callback: any) { - this.poller = setTimeout(() => this.handler(callback), 200) + this.poller = setTimeout( + () => this.handler(callback), + this.interval) + } + + public async listenOnce() { + this.listen((events: any[]) => { + EventListener.unsubscribe(this) + return events + }) } private async handler(callback: any) { diff --git a/src/keeper/EventListener.ts b/src/keeper/EventListener.ts index 00fe7c2..d150c58 100644 --- a/src/keeper/EventListener.ts +++ b/src/keeper/EventListener.ts @@ -13,13 +13,17 @@ export default class EventListener { } public static unsubscribe(event): boolean { - - EventListener.events = EventListener.events.splice( - EventListener.events.findIndex((e) => e === event), - 1) - + event.stopListen() + const i = EventListener.events.indexOf(event) + if (i > -1) { + EventListener.events.splice(i, 1) + } return true } + public static count() { + return EventListener.events.length + } + private static events: Event[] = [] } diff --git a/test/keeper/Event.test.ts b/test/keeper/Event.test.ts new file mode 100644 index 0000000..4dc51a5 --- /dev/null +++ b/test/keeper/Event.test.ts @@ -0,0 +1,75 @@ +import {assert} from "chai" +import ConfigProvider from "../../src/ConfigProvider" +import EventListener from "../../src/keeper/EventListener" +import Keeper from "../../src/keeper/Keeper" +import Account from "../../src/ocean/Account" +import Ocean from "../../src/ocean/Ocean" +import config from "../config" +import TestContractHandler from "./TestContractHandler" + +let keeper: Keeper +let ocean: Ocean +let accounts: Account[] + +describe("EventListener", () => { + + before(async () => { + ConfigProvider.setConfig(config) + await TestContractHandler.prepareContracts() + keeper = await Keeper.getInstance() + assert(keeper) + ocean = await Ocean.getInstance(config) + assert(ocean) + accounts = await ocean.getAccounts() + assert(accounts) + }) + + describe("#listen()", () => { + + it("should listen to an event", (done) => { + + const acc = accounts[1] + + const event = EventListener.subscribe("OceanToken", + "Transfer", + { + to: acc.getId(), + }) + + event.listen((events) => { + + assert(events) + assert(events.length === 2) + done() + }) + + const {market} = keeper + + market.requestTokens(400, acc.getId()) + market.requestTokens(400, acc.getId()) + }) + }) + + describe("#listenOnce()", () => { + + xit("should listen once", async () => { + + const acc = accounts[1] + + const event = EventListener.subscribe("OceanToken", + "Transfer", + { + to: acc.getId(), + }) + + const events = await event.listenOnce() + + assert(events, "no events") + + const {market} = keeper + + market.requestTokens(400, acc.getId()) + }) + }) + +}) diff --git a/test/keeper/EventListener.test.ts b/test/keeper/EventListener.test.ts index 9b40c35..3634595 100644 --- a/test/keeper/EventListener.test.ts +++ b/test/keeper/EventListener.test.ts @@ -29,40 +29,40 @@ describe("EventListener", () => { it("should subscribe to an event", (done) => { const acc = accounts[1] + const countBefore = EventListener.count() const event = EventListener.subscribe("OceanToken", "Transfer", { to: acc.getId(), }) + assert(event) - event.listen((events) => { - - assert(events) - assert(events.length === 2) - done() - }) - - const {market} = keeper - - market.requestTokens(400, acc.getId()) - market.requestTokens(400, acc.getId()) - }) - }) - - describe("#unsubscribe()", () => { - - it("should subscribe to an event", (done) => { - - const event = EventListener.subscribe("OceanToken", - "Transfer", - {}) - - const unsubscribed = EventListener.unsubscribe(event) - assert(unsubscribed) + const countAfter = EventListener.count() + assert(countBefore + 1 === countAfter, `${countBefore}${countAfter}`) done() }) }) + describe("#unsubscribe()", () => { + + it("should unsubscribe from an event", (done) => { + + const countBefore = EventListener.count() + const event = EventListener.subscribe("OceanToken", + "Transfer", + {}) + const count = EventListener.count() + + const unsubscribed = EventListener.unsubscribe(event) + assert(unsubscribed) + + const countAfter = EventListener.count() + assert(count > countBefore, `${count}${countAfter}`) + assert(countBefore === countAfter, `${countBefore}${countAfter}`) + done() + }) + }) + }) From 0c3c21b4c58278ba6a86a2697a3279c0df163950 Mon Sep 17 00:00:00 2001 From: Sebastian Gerske Date: Fri, 23 Nov 2018 14:14:35 +0100 Subject: [PATCH 09/53] fix listener, add eventing, moved generation of conditions to template structure --- src/ddo/Condition.ts | 7 +- src/ddo/Dependency.ts | 4 ++ src/examples/Listener.ts | 28 ++++++++ src/keeper/Event.ts | 28 ++++---- src/ocean/Ocean.ts | 69 ++---------------- .../ServiceAgreementTemplate.ts | 72 ++++++++++++++++++- test/ocean/ServiceAgreement.test.ts | 67 +---------------- test/ocean/ServiceAgreementTemplate.test.ts | 3 +- 8 files changed, 133 insertions(+), 145 deletions(-) create mode 100644 src/ddo/Dependency.ts create mode 100644 src/examples/Listener.ts diff --git a/src/ddo/Condition.ts b/src/ddo/Condition.ts index 80609d2..ff88d89 100644 --- a/src/ddo/Condition.ts +++ b/src/ddo/Condition.ts @@ -1,14 +1,15 @@ +import Dependency from "./Dependency" import Event from "./Event" import Parameter from "./Parameter" export default class Condition { + public name: string public contractName: string = "AccessCondition" - public methodName: string = "lockPayment" + public functionName: string = "lockPayment" public timeout: number = 0 public conditionKey: string = "0x12122434" public parameters: Parameter[] public events: Event[] - public dependencies: string[] = [] - public dependencyTimeoutFlags: number[] = [] + public dependencies: Dependency[] = [] public isTerminalCondition: boolean = false } diff --git a/src/ddo/Dependency.ts b/src/ddo/Dependency.ts new file mode 100644 index 0000000..2a824f6 --- /dev/null +++ b/src/ddo/Dependency.ts @@ -0,0 +1,4 @@ +export default class Dependency { + public name: string = "lockPayment" + public timeout: number = 0 +} diff --git a/src/examples/Listener.ts b/src/examples/Listener.ts new file mode 100644 index 0000000..a4c5b76 --- /dev/null +++ b/src/examples/Listener.ts @@ -0,0 +1,28 @@ +import {Logger, Ocean} from "../squid" +// tslint:disable-next-line +import EventListener from "../keeper/EventListener" + +(async () => { + Ocean.getInstance({ + nodeUri: "http://localhost:8545", + aquariusUri: "http://localhost:5000", + brizoUri: "http://localhost:8030", + parityUri: "http://localhost:9545", + secretStoreUri: "http://localhost:12001", + threshold: 0, + password: "unittest", + address: "0xed243adfb84a6626eba46178ccb567481c6e655d", + }) +})() + +const event = EventListener.subscribe("OceanToken", "Transfer", {}) + +Logger.log(`Listening to Transfer event of OceanToken`) + +event.listen((data: any[]) => { + + Logger.log(Date.now()) + Logger.log("From", data[0].returnValues.from) + Logger.log("To", data[0].returnValues.to) + Logger.log("Value", data[0].returnValues.value) +}) diff --git a/src/keeper/Event.ts b/src/keeper/Event.ts index 8bb5b8f..2138e5b 100644 --- a/src/keeper/Event.ts +++ b/src/keeper/Event.ts @@ -1,5 +1,6 @@ import GenericContract from "./contracts/GenericContract" import EventListener from "./EventListener" +import Web3Provider from "./Web3Provider" export default class Event { @@ -17,8 +18,10 @@ export default class Event { clearTimeout(this.poller) } - public listen(callback: any) { - this.poller = setTimeout( + public async listen(callback: any) { + this.lastBlock = await Web3Provider.getWeb3().eth.getBlockNumber() + 1 + + this.poller = setInterval( () => this.handler(callback), this.interval) } @@ -31,16 +34,17 @@ export default class Event { } private async handler(callback: any) { - const contract = await - GenericContract.getInstance(this.contractName) - const events = await - contract.getEventData(this.eventName, { - filter: this.filter, - fromBlock: this.lastBlock, - toBlock: "latest", - }) + const contract = await GenericContract.getInstance(this.contractName) - this.lastBlock = events[events.length - 1].blockNumber - callback(events) + const events = await contract.getEventData(this.eventName, { + filter: this.filter, + fromBlock: this.lastBlock, + toBlock: "latest", + }) + + if (events.length > 0) { + this.lastBlock = events[events.length - 1].blockNumber + 1 + callback(events) + } } } diff --git a/src/ocean/Ocean.ts b/src/ocean/Ocean.ts index af19138..c954633 100644 --- a/src/ocean/Ocean.ts +++ b/src/ocean/Ocean.ts @@ -3,12 +3,9 @@ import SearchQuery from "../aquarius/query/SearchQuery" import BrizoProvider from "../brizo/BrizoProvider" import ConfigProvider from "../ConfigProvider" import Authentication from "../ddo/Authentication" -import DDOCondition from "../ddo/Condition" +import Condition from "../ddo/Condition" import DDO from "../ddo/DDO" -import Event from "../ddo/Event" -import EventHandlers from "../ddo/EventHandlers" import MetaData from "../ddo/MetaData" -import Parameter from "../ddo/Parameter" import Service from "../ddo/Service" import Keeper from "../keeper/Keeper" import Web3Provider from "../keeper/Web3Provider" @@ -18,7 +15,6 @@ import SecretStoreProvider from "../secretstore/SecretStoreProvider" import Logger from "../utils/Logger" import Account from "./Account" import IdGenerator from "./IdGenerator" -import Condition from "./ServiceAgreements/Condition" import ServiceAgreement from "./ServiceAgreements/ServiceAgreement" import ServiceAgreementTemplate from "./ServiceAgreements/ServiceAgreementTemplate" import Access from "./ServiceAgreements/Templates/Access" @@ -74,64 +70,7 @@ export default class Ocean { const template = new Access() const serviceAgreementTemplate = new ServiceAgreementTemplate(template) - // get condition keys from template - const conditions: Condition[] = await serviceAgreementTemplate.getConditions() - - // create ddo conditions out of the keys - const ddoConditions: DDOCondition[] = conditions - .map((condition: Condition, index: number): DDOCondition => { - const events: Event[] = [ - { - name: "PaymentReleased", - actorType: [ - "consumer", - ], - handlers: { - moduleName: "serviceAgreement", - functionName: "fulfillAgreement", - version: "0.1", - } as EventHandlers, - } as Event, - ] - - const mapParameterValueToName = (name) => { - - switch (name) { - case "price": - return metadata.base.price - case "assetId": - return "0x" + assetId - case "documentKeyId": - return "0x" + assetId - } - - return null - } - - const parameters: Parameter[] = condition.parameters.map((parameter: Parameter) => { - return { - name: parameter.name, - type: parameter.type, - value: mapParameterValueToName(parameter.name), - } as Parameter - }) - - // Logger.log(`${condition.methodReflection.contractName}.${condition.methodReflection.methodName}`, - // JSON.stringify(parameters, null, 2)) - - return { - contractName: condition.methodReflection.contractName, - methodName: condition.methodReflection.methodName, - timeout: condition.timeout, - index, - conditionKey: condition.condtionKey, - parameters, - events, - dependencies: condition.dependencies, - dependencyTimeoutFlags: condition.dependencyTimeoutFlags, - isTerminalCondition: condition.isTerminalCondition, - } as DDOCondition - }) + const conditions: Condition[] = await serviceAgreementTemplate.getConditions(metadata, assetId) const serviceEndpoint = aquarius.getServiceEndpoint(did) @@ -166,7 +105,7 @@ export default class Ocean { serviceDefinitionId: accessServiceDefinitionId, // the id of the service agreement template templateId: serviceAgreementTemplate.getId(), - conditions: ddoConditions, + conditions, } as Service, { type: "Compute", @@ -185,6 +124,8 @@ export default class Ocean { const storedDdo = await aquarius.storeDDO(ddo) + Logger.log(JSON.stringify(storedDdo, null, 2)) + await didRegistry.registerAttribute( assetId, ValueType.DID, diff --git a/src/ocean/ServiceAgreements/ServiceAgreementTemplate.ts b/src/ocean/ServiceAgreements/ServiceAgreementTemplate.ts index 32317c5..6c8130b 100644 --- a/src/ocean/ServiceAgreements/ServiceAgreementTemplate.ts +++ b/src/ocean/ServiceAgreements/ServiceAgreementTemplate.ts @@ -1,3 +1,9 @@ +import DDOCondition from "../../ddo/Condition" +import Dependency from "../../ddo/Dependency" +import Event from "../../ddo/Event" +import EventHandlers from "../../ddo/EventHandlers" +import MetaData from "../../ddo/MetaData" +import Parameter from "../../ddo/Parameter" import ContractReflector from "../../keeper/ContractReflector" import Keeper from "../../keeper/Keeper" import Web3Provider from "../../keeper/Web3Provider" @@ -96,7 +102,71 @@ export default class ServiceAgreementTemplate extends OceanBase { return new Account(await serviceAgreement.getTemplateOwner(this.id)) } - public async getConditions(): Promise { + public async getConditions(metadata: MetaData, assetId: string): Promise { + const conditions = await this.blendConditions() + return conditions.map((condition: Condition, index: number): DDOCondition => { + const events: Event[] = [ + { + name: "PaymentReleased", + actorType: [ + "consumer", + ], + handlers: { + moduleName: "serviceAgreement", + functionName: "fulfillAgreement", + version: "0.1", + } as EventHandlers, + } as Event, + ] + + const mapParameterValueToName = (name) => { + + switch (name) { + case "price": + return metadata.base.price + case "assetId": + return "0x" + assetId + case "documentKeyId": + return "0x" + assetId + } + + return null + } + + const parameters: Parameter[] = condition.parameters.map((parameter: Parameter) => { + return { + name: parameter.name, + type: parameter.type, + value: mapParameterValueToName(parameter.name), + } as Parameter + }) + + // Logger.log(`${condition.methodReflection.contractName}.${condition.methodReflection.methodName}`, + // JSON.stringify(parameters, null, 2)) + + const dependencies: Dependency[] = condition.dependencies.map((dep, i) => { + return { + name: dep, + timeout: condition.dependencyTimeoutFlags[i], + } as Dependency + }) + + return { + name: condition.methodReflection.methodName, + dependencies, + timeout: condition.timeout, + isTerminalCondition: condition.isTerminalCondition, + conditionKey: condition.condtionKey, + contractName: condition.methodReflection.contractName, + functionName: condition.methodReflection.methodName, + index, + parameters, + events, + } as DDOCondition + }) + } + + private async blendConditions(): Promise { const methodReflections = await this.getMethodReflections() const conditions: Condition[] = methodReflections.map((methodReflection, i) => { diff --git a/test/ocean/ServiceAgreement.test.ts b/test/ocean/ServiceAgreement.test.ts index e944a8f..e4e5fb9 100644 --- a/test/ocean/ServiceAgreement.test.ts +++ b/test/ocean/ServiceAgreement.test.ts @@ -1,16 +1,12 @@ import {assert} from "chai" import ConfigProvider from "../../src/ConfigProvider" -import DDOCondition from "../../src/ddo/Condition" +import Condition from "../../src/ddo/Condition" import DDO from "../../src/ddo/DDO" -import Event from "../../src/ddo/Event" -import EventHandlers from "../../src/ddo/EventHandlers" import MetaData from "../../src/ddo/MetaData" -import Parameter from "../../src/ddo/Parameter" import Service from "../../src/ddo/Service" import Account from "../../src/ocean/Account" import IdGenerator from "../../src/ocean/IdGenerator" 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 Access from "../../src/ocean/ServiceAgreements/Templates/Access" @@ -44,70 +40,13 @@ describe("ServiceAgreement", () => { const serviceAgreementTemplate: ServiceAgreementTemplate = new ServiceAgreementTemplate(new Access()) - // get condition keys from template - const conditions: Condition[] = await serviceAgreementTemplate.getConditions() - - // create ddo conditions out of the keys - const ddoConditions: DDOCondition[] = conditions - .map((condition: Condition, index): DDOCondition => { - - const events: Event[] = [ - { - name: "PaymentReleased", - actorType: [ - "consumer", - ], - handlers: { - moduleName: "serviceAgreement", - functionName: "fulfillAgreement", - version: "0.1", - } as EventHandlers, - } as Event, - ] - - const mapParameterValueToName = (name) => { - - switch (name) { - case "price": - return metadata.base.price - case "assetId": - return "0x" + assetId - case "documentKeyId": - return "0x" + assetId - - } - - return null - } - - const parameters: Parameter[] = condition.parameters - .map((parameter: Parameter) => { - return { - name: parameter.name, - type: parameter.type, - value: mapParameterValueToName(parameter.name), - } as Parameter - }) - - return { - contractName: condition.methodReflection.contractName, - methodName: condition.methodReflection.methodName, - timeout: condition.timeout, - index, - conditionKey: condition.condtionKey, - parameters, - events, - dependencies: condition.dependencies, - dependencyTimeoutFlags: condition.dependencyTimeoutFlags, - isTerminalCondition: condition.isTerminalCondition, - } as DDOCondition - }) + const conditions: Condition[] = await serviceAgreementTemplate.getConditions(metadata, assetId) accessService = { type: "Access", serviceDefinitionId: IdGenerator.generateId(), templateId: serviceAgreementTemplate.getId(), - conditions: ddoConditions, + conditions, } as Service metaDataService = { diff --git a/test/ocean/ServiceAgreementTemplate.test.ts b/test/ocean/ServiceAgreementTemplate.test.ts index 2e906a4..8ea80f3 100644 --- a/test/ocean/ServiceAgreementTemplate.test.ts +++ b/test/ocean/ServiceAgreementTemplate.test.ts @@ -1,5 +1,6 @@ import {assert} from "chai" import ConfigProvider from "../../src/ConfigProvider" +import MetaData from "../../src/ddo/MetaData" import Account from "../../src/ocean/Account" import IdGenerator from "../../src/ocean/IdGenerator" import Ocean from "../../src/ocean/Ocean" @@ -48,7 +49,7 @@ describe("ServiceAgreementTemplate", () => { new ServiceAgreementTemplate(access) assert(serviceAgreementTemplate) - const conds = await serviceAgreementTemplate.getConditions() + const conds = await serviceAgreementTemplate.getConditions(new MetaData(), IdGenerator.generateId()) assert(conds) }) }) From 17f1b3e53e490dbff874a6a5695de4b8c016a801 Mon Sep 17 00:00:00 2001 From: Sebastian Gerske Date: Fri, 23 Nov 2018 14:28:41 +0100 Subject: [PATCH 10/53] fix listen once --- src/keeper/Event.ts | 8 +++++--- src/ocean/Ocean.ts | 2 +- test/keeper/Event.test.ts | 12 +++++++++--- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/keeper/Event.ts b/src/keeper/Event.ts index 2138e5b..f4c59ee 100644 --- a/src/keeper/Event.ts +++ b/src/keeper/Event.ts @@ -26,10 +26,12 @@ export default class Event { this.interval) } - public async listenOnce() { + public listenOnce(callback: any) { this.listen((events: any[]) => { - EventListener.unsubscribe(this) - return events + if (events) { + EventListener.unsubscribe(this) + callback(events[0]) + } }) } diff --git a/src/ocean/Ocean.ts b/src/ocean/Ocean.ts index c954633..2cb7e98 100644 --- a/src/ocean/Ocean.ts +++ b/src/ocean/Ocean.ts @@ -124,7 +124,7 @@ export default class Ocean { const storedDdo = await aquarius.storeDDO(ddo) - Logger.log(JSON.stringify(storedDdo, null, 2)) + // Logger.log(JSON.stringify(storedDdo, null, 2)) await didRegistry.registerAttribute( assetId, diff --git a/test/keeper/Event.test.ts b/test/keeper/Event.test.ts index 4dc51a5..eadbe19 100644 --- a/test/keeper/Event.test.ts +++ b/test/keeper/Event.test.ts @@ -52,19 +52,25 @@ describe("EventListener", () => { describe("#listenOnce()", () => { - xit("should listen once", async () => { + it("should listen once", (done) => { const acc = accounts[1] + const countBefore = EventListener.count() const event = EventListener.subscribe("OceanToken", "Transfer", { to: acc.getId(), }) - const events = await event.listenOnce() + event.listenOnce( + (data: any) => { - assert(events, "no events") + assert(data) + assert(data.blockNumber) + assert(EventListener.count() === countBefore) + done() + }) const {market} = keeper From 695825c50b9efa4aa13b2910f92282f2bb40cdfc Mon Sep 17 00:00:00 2001 From: Sebastian Gerske Date: Fri, 23 Nov 2018 14:54:22 +0100 Subject: [PATCH 11/53] fix unsubscribe --- src/keeper/Event.ts | 5 +++-- test/keeper/Event.test.ts | 1 + test/keeper/EventListener.test.ts | 1 + 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/keeper/Event.ts b/src/keeper/Event.ts index f4c59ee..39d9401 100644 --- a/src/keeper/Event.ts +++ b/src/keeper/Event.ts @@ -4,7 +4,7 @@ import Web3Provider from "./Web3Provider" export default class Event { - private poller + private poller = null private lastBlock: number = 0 private interval: number = 200 @@ -15,7 +15,8 @@ export default class Event { } public stopListen() { - clearTimeout(this.poller) + clearInterval(this.poller) + this.poller = null } public async listen(callback: any) { diff --git a/test/keeper/Event.test.ts b/test/keeper/Event.test.ts index eadbe19..a0f06a7 100644 --- a/test/keeper/Event.test.ts +++ b/test/keeper/Event.test.ts @@ -41,6 +41,7 @@ describe("EventListener", () => { assert(events) assert(events.length === 2) done() + EventListener.unsubscribe(event) }) const {market} = keeper diff --git a/test/keeper/EventListener.test.ts b/test/keeper/EventListener.test.ts index 3634595..bc3eb88 100644 --- a/test/keeper/EventListener.test.ts +++ b/test/keeper/EventListener.test.ts @@ -41,6 +41,7 @@ describe("EventListener", () => { const countAfter = EventListener.count() assert(countBefore + 1 === countAfter, `${countBefore}${countAfter}`) + EventListener.unsubscribe(event) done() }) }) From a904649c3305c23d09e39f179c9216336644edcd Mon Sep 17 00:00:00 2001 From: Sebastian Gerske Date: Fri, 23 Nov 2018 16:01:42 +0100 Subject: [PATCH 12/53] add event listener for lockPayment --- src/ddo/Contract.ts | 7 +++ src/ddo/Service.ts | 2 + src/examples/ExecuteAgreement.ts | 2 + src/keeper/contracts/ServiceAgreement.ts | 2 +- src/ocean/Ocean.ts | 47 ++++++++++++++++++- .../ServiceAgreements/ServiceAgreement.ts | 19 ++------ test/ocean/ServiceAgreement.test.ts | 16 +++---- 7 files changed, 70 insertions(+), 25 deletions(-) create mode 100644 src/ddo/Contract.ts diff --git a/src/ddo/Contract.ts b/src/ddo/Contract.ts new file mode 100644 index 0000000..0396a1a --- /dev/null +++ b/src/ddo/Contract.ts @@ -0,0 +1,7 @@ +import Event from "./Event" + +export default class Contract { + public contractName: string + public fulfillmentOperator: number + public events: Event[] +} diff --git a/src/ddo/Service.ts b/src/ddo/Service.ts index 7e910b5..4891d39 100644 --- a/src/ddo/Service.ts +++ b/src/ddo/Service.ts @@ -1,4 +1,5 @@ import Condition from "./Condition" +import Contract from "./Contract" import MetaData from "./MetaData" export default class Service { @@ -9,5 +10,6 @@ export default class Service { public purchaseEndpoint?: string public description?: string = "My public social inbox" public metadata?: MetaData = {} as MetaData + public serviceAgreementContract?: Contract public conditions?: Condition[] = [] } diff --git a/src/examples/ExecuteAgreement.ts b/src/examples/ExecuteAgreement.ts index f9d68c8..dbbc508 100644 --- a/src/examples/ExecuteAgreement.ts +++ b/src/examples/ExecuteAgreement.ts @@ -54,6 +54,8 @@ import {Account, Logger, Ocean, ServiceAgreement} from "../squid" const accessService = ddo.findServiceByType("Access") + await consumer.requestTokens(metaData.base.price) + const serviceAgreementSignatureResult: any = await ocean.signServiceAgreement(ddo.id, accessService.serviceDefinitionId, consumer) Logger.log("ServiceAgreement Id:", serviceAgreementSignatureResult.serviceAgreementId) diff --git a/src/keeper/contracts/ServiceAgreement.ts b/src/keeper/contracts/ServiceAgreement.ts index db09194..ca2d4c7 100644 --- a/src/keeper/contracts/ServiceAgreement.ts +++ b/src/keeper/contracts/ServiceAgreement.ts @@ -47,7 +47,7 @@ export default class ServiceAgreement extends ContractBase { return this.send("executeAgreement", publisherAddress, [ serviceAgreementTemplateId, serviceAgreementSignatureHash, consumerAddress, valueHashes, - timeoutValues, "0x" + serviceAgreementId, "0x" + did.replace("did:op:", ""), + timeoutValues, serviceAgreementId, "0x" + did.replace("did:op:", ""), ]) } } diff --git a/src/ocean/Ocean.ts b/src/ocean/Ocean.ts index 2cb7e98..9df0849 100644 --- a/src/ocean/Ocean.ts +++ b/src/ocean/Ocean.ts @@ -4,9 +4,13 @@ import BrizoProvider from "../brizo/BrizoProvider" import ConfigProvider from "../ConfigProvider" import Authentication from "../ddo/Authentication" import Condition from "../ddo/Condition" +import Contract from "../ddo/Contract" import DDO from "../ddo/DDO" +import Event from "../ddo/Event" +import EventHandlers from "../ddo/EventHandlers" import MetaData from "../ddo/MetaData" import Service from "../ddo/Service" +import ContractEvent from "../keeper/Event" import Keeper from "../keeper/Keeper" import Web3Provider from "../keeper/Web3Provider" import Config from "../models/Config" @@ -19,6 +23,8 @@ import ServiceAgreement from "./ServiceAgreements/ServiceAgreement" import ServiceAgreementTemplate from "./ServiceAgreements/ServiceAgreementTemplate" import Access from "./ServiceAgreements/Templates/Access" +import EventListener from "../keeper/EventListener" + export default class Ocean { public static async getInstance(config: Config) { @@ -105,6 +111,21 @@ export default class Ocean { serviceDefinitionId: accessServiceDefinitionId, // the id of the service agreement template templateId: serviceAgreementTemplate.getId(), + serviceAgreementContract: { + contractName: "ServiceAgreement", + fulfillmentOperator: template.fulfillmentOperator, + events: [ + { + name: "ExecuteAgreement", + actorType: ["consumer"], + handlers: { + moduleName: "payment", + functionName: "lockPayment", + version: "0.1", + } as EventHandlers, + } as Event, + ], + } as Contract, conditions, } as Service, { @@ -142,11 +163,35 @@ export default class Ocean { const ddo = await AquariusProvider.getAquarius().retrieveDDO(did) const id = did.replace("did:op:", "") - const serviceAgreementId: string = IdGenerator.generateId() + const serviceAgreementId: string = IdGenerator.generatePrefixedId() try { const serviceAgreementSignature: string = await ServiceAgreement.signServiceAgreement(id, ddo, serviceDefinitionId, serviceAgreementId, consumer) + + const accessService: Service = ddo.findServiceByType("Access") + const metadataService: Service = ddo.findServiceByType("Metadata") + + const event: ContractEvent = EventListener.subscribe(accessService.serviceAgreementContract.contractName, + accessService.serviceAgreementContract.events[0].name, { + serviceAgreementId, + }) + + const price = metadataService.metadata.base.price + const balance = await consumer.getOceanBalance() + if (balance < price) { + throw new Error(`Not enough ocean tokens! Should have ${price} but has ${balance}`) + } + + event.listenOnce((data) => { + + new ServiceAgreement(serviceAgreementId) + .buyAsset(id, + metadataService.metadata.base.price, + consumer, + ) + }) + return { serviceAgreementId, serviceAgreementSignature, diff --git a/src/ocean/ServiceAgreements/ServiceAgreement.ts b/src/ocean/ServiceAgreements/ServiceAgreement.ts index dba4bc6..6c8faa5 100644 --- a/src/ocean/ServiceAgreements/ServiceAgreement.ts +++ b/src/ocean/ServiceAgreements/ServiceAgreement.ts @@ -117,11 +117,6 @@ export default class ServiceAgreement extends OceanBase { return new ServiceAgreement( executeAgreementReceipt.events.ExecuteAgreement.returnValues.serviceAgreementId, - ddo, - publisher, - new Account(consumerAddress), - executeAgreementReceipt.events.ExecuteAgreement.returnValues.state, - executeAgreementReceipt.events.ExecuteAgreement.returnValues.status, ) } @@ -186,7 +181,7 @@ export default class ServiceAgreement extends OceanBase { contionValues.push({ type: parameter.type, - value: parameter.name === "serviceId" ? "0x" + serviceAgreementId : parameter.value, + value: parameter.name === "serviceId" ? serviceAgreementId : parameter.value, } as ValuePair) }) @@ -196,12 +191,7 @@ export default class ServiceAgreement extends OceanBase { return values } - private constructor(serviceAgreementId: string, - ddo: DDO, - private publisher: Account, - consumer: Account, - state: boolean, - status: boolean) { + constructor(serviceAgreementId: string) { super(serviceAgreementId) } @@ -218,12 +208,11 @@ export default class ServiceAgreement extends OceanBase { return lockPaymentReceipt.status } - public async grantAccess(assetId: string, documentId: string): Promise { + public async grantAccess(assetId: string, documentId: string, publisher: Account): Promise { const {accessConditions} = await Keeper.getInstance() const grantAccessReceipt = - await accessConditions.grantAccess(this.getId(), assetId, documentId, - this.publisher.getId()) + await accessConditions.grantAccess(this.getId(), assetId, documentId, publisher.getId()) return !!grantAccessReceipt.events.AccessGranted } diff --git a/test/ocean/ServiceAgreement.test.ts b/test/ocean/ServiceAgreement.test.ts index e4e5fb9..1472dba 100644 --- a/test/ocean/ServiceAgreement.test.ts +++ b/test/ocean/ServiceAgreement.test.ts @@ -60,7 +60,7 @@ describe("ServiceAgreement", () => { const did: string = `did:op:${assetId}` const ddo = new DDO({id: did, service: [accessService]}) - const serviceAgreementId: string = IdGenerator.generateId() + const serviceAgreementId: string = IdGenerator.generatePrefixedId() // @ts-ignore WebServiceConnectorProvider.setConnector(new WebServiceConnectorMock(ddo)) @@ -79,7 +79,7 @@ describe("ServiceAgreement", () => { const did: string = `did:op:${assetId}` const ddo = new DDO({id: did, service: [accessService]}) - const serviceAgreementId: string = IdGenerator.generateId() + const serviceAgreementId: string = IdGenerator.generatePrefixedId() // @ts-ignore WebServiceConnectorProvider.setConnector(new WebServiceConnectorMock(ddo)) @@ -103,7 +103,7 @@ describe("ServiceAgreement", () => { const did: string = `did:op:${assetId}` const ddo = new DDO({id: did, service: [accessService]}) - const serviceAgreementId: string = IdGenerator.generateId() + const serviceAgreementId: string = IdGenerator.generatePrefixedId() // @ts-ignore WebServiceConnectorProvider.setConnector(new WebServiceConnectorMock(ddo)) @@ -127,7 +127,7 @@ describe("ServiceAgreement", () => { const did: string = `did:op:${assetId}` const ddo = new DDO({id: did, service: [accessService, metaDataService]}) - const serviceAgreementId: string = IdGenerator.generateId() + const serviceAgreementId: string = IdGenerator.generatePrefixedId() // @ts-ignore WebServiceConnectorProvider.setConnector(new WebServiceConnectorMock(ddo)) @@ -156,7 +156,7 @@ describe("ServiceAgreement", () => { const did: string = `did:op:${assetId}` const ddo = new DDO({id: did, service: [accessService]}) - const serviceAgreementId: string = IdGenerator.generateId() + const serviceAgreementId: string = IdGenerator.generatePrefixedId() // @ts-ignore WebServiceConnectorProvider.setConnector(new WebServiceConnectorMock(ddo)) @@ -178,7 +178,7 @@ describe("ServiceAgreement", () => { assert(paid) // todo: use document id - const accessGranted: boolean = await serviceAgreement.grantAccess(assetId, assetId) + const accessGranted: boolean = await serviceAgreement.grantAccess(assetId, assetId, publisherAccount) assert(accessGranted) }) @@ -186,7 +186,7 @@ describe("ServiceAgreement", () => { const did: string = `did:op:${assetId}` const ddo = new DDO({id: did, service: [accessService]}) - const serviceAgreementId: string = IdGenerator.generateId() + const serviceAgreementId: string = IdGenerator.generatePrefixedId() // @ts-ignore WebServiceConnectorProvider.setConnector(new WebServiceConnectorMock(ddo)) @@ -201,7 +201,7 @@ describe("ServiceAgreement", () => { assert(serviceAgreement) // todo: use document id - const accessGranted: boolean = await serviceAgreement.grantAccess(assetId, assetId) + const accessGranted: boolean = await serviceAgreement.grantAccess(assetId, assetId, publisherAccount) assert(!accessGranted) }) }) From 3bf09e63a1f8f9d575352d708751c327e994f043 Mon Sep 17 00:00:00 2001 From: Sebastian Gerske Date: Fri, 23 Nov 2018 16:09:31 +0100 Subject: [PATCH 13/53] added executeAgreement event listener --- src/ocean/Ocean.ts | 16 +++++++++------- src/ocean/ServiceAgreements/ServiceAgreement.ts | 3 +-- test/ocean/ServiceAgreement.test.ts | 6 +++--- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/ocean/Ocean.ts b/src/ocean/Ocean.ts index 9df0849..194bc7a 100644 --- a/src/ocean/Ocean.ts +++ b/src/ocean/Ocean.ts @@ -172,21 +172,23 @@ export default class Ocean { const accessService: Service = ddo.findServiceByType("Access") const metadataService: Service = ddo.findServiceByType("Metadata") - const event: ContractEvent = EventListener.subscribe(accessService.serviceAgreementContract.contractName, - accessService.serviceAgreementContract.events[0].name, { - serviceAgreementId, - }) - const price = metadataService.metadata.base.price const balance = await consumer.getOceanBalance() if (balance < price) { throw new Error(`Not enough ocean tokens! Should have ${price} but has ${balance}`) } + const event: ContractEvent = EventListener.subscribe( + accessService.serviceAgreementContract.contractName, + accessService.serviceAgreementContract.events[0].name, { + serviceAgreementId, + }) + event.listenOnce((data) => { - new ServiceAgreement(serviceAgreementId) - .buyAsset(id, + Logger.log("Paying asset") + new ServiceAgreement(data.returnValues.serviceAgreementId) + .payAsset(id, metadataService.metadata.base.price, consumer, ) diff --git a/src/ocean/ServiceAgreements/ServiceAgreement.ts b/src/ocean/ServiceAgreements/ServiceAgreement.ts index 6c8faa5..b7fe848 100644 --- a/src/ocean/ServiceAgreements/ServiceAgreement.ts +++ b/src/ocean/ServiceAgreements/ServiceAgreement.ts @@ -195,8 +195,7 @@ export default class ServiceAgreement extends OceanBase { super(serviceAgreementId) } - // todo: sync with samer - public async buyAsset(assetId: string, price: number, consumer: Account): Promise { + public async payAsset(assetId: string, price: number, consumer: Account): Promise { const {paymentConditions, token} = await Keeper.getInstance() await token.approve(paymentConditions.getAddress(), price, consumer.getId()) diff --git a/test/ocean/ServiceAgreement.test.ts b/test/ocean/ServiceAgreement.test.ts index 1472dba..c2b8385 100644 --- a/test/ocean/ServiceAgreement.test.ts +++ b/test/ocean/ServiceAgreement.test.ts @@ -122,7 +122,7 @@ describe("ServiceAgreement", () => { }) }) - describe("#buyAsset()", () => { + describe("#payAsset()", () => { it("should lock the payment in that service agreement", async () => { const did: string = `did:op:${assetId}` @@ -145,7 +145,7 @@ describe("ServiceAgreement", () => { // get funds await consumerAccount.requestTokens(metaDataService.metadata.base.price) - const paid: boolean = await serviceAgreement.buyAsset(assetId, metaDataService.metadata.base.price, + const paid: boolean = await serviceAgreement.payAsset(assetId, metaDataService.metadata.base.price, consumerAccount) assert(paid) }) @@ -173,7 +173,7 @@ describe("ServiceAgreement", () => { // get funds await consumerAccount.requestTokens(metaDataService.metadata.base.price) - const paid: boolean = await serviceAgreement.buyAsset(assetId, metaDataService.metadata.base.price, + const paid: boolean = await serviceAgreement.payAsset(assetId, metaDataService.metadata.base.price, consumerAccount) assert(paid) From 2201ebb9976360571dd30b1895fd784c2fd1d525 Mon Sep 17 00:00:00 2001 From: Sebastian Gerske Date: Fri, 23 Nov 2018 17:05:44 +0100 Subject: [PATCH 14/53] fix samples --- src/examples/BuyAsset.ts | 2 +- src/examples/GrantAccess.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/examples/BuyAsset.ts b/src/examples/BuyAsset.ts index 643985f..8aa1721 100644 --- a/src/examples/BuyAsset.ts +++ b/src/examples/BuyAsset.ts @@ -73,6 +73,6 @@ import {Account, Logger, Ocean, ServiceAgreement} from "../squid" await consumer.requestTokens(metaData.base.price) - const paid = await serviceAgreement.buyAsset(assetId, metaData.base.price, consumer) + const paid = await serviceAgreement.payAsset(assetId, metaData.base.price, consumer) Logger.log(`Asset paid: ${paid}`) })() diff --git a/src/examples/GrantAccess.ts b/src/examples/GrantAccess.ts index 269fa2d..6d8194a 100644 --- a/src/examples/GrantAccess.ts +++ b/src/examples/GrantAccess.ts @@ -73,9 +73,9 @@ import {Account, Logger, Ocean, ServiceAgreement} from "../squid" await consumer.requestTokens(metaData.base.price) - const paid = await serviceAgreement.buyAsset(assetId, metaData.base.price, consumer) + const paid = await serviceAgreement.payAsset(assetId, metaData.base.price, consumer) Logger.log(`Asset paid: ${paid}`) - const accessGranted = await serviceAgreement.grantAccess(assetId, assetId) + const accessGranted = await serviceAgreement.grantAccess(assetId, assetId, publisher) Logger.log(`Asset access granted: ${accessGranted}`) })() From 12bd56e5f951fed628fba702b3f909c5c4162bbe Mon Sep 17 00:00:00 2001 From: Sebastian Gerske Date: Mon, 26 Nov 2018 11:04:05 +0100 Subject: [PATCH 15/53] adapt unit tests --- test/ocean/Ocean.test.ts | 16 ++++++++++------ test/ocean/ServiceAgreement.test.ts | 1 + 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/test/ocean/Ocean.test.ts b/test/ocean/Ocean.test.ts index 39c0f17..f95898b 100644 --- a/test/ocean/Ocean.test.ts +++ b/test/ocean/Ocean.test.ts @@ -127,20 +127,24 @@ describe("Ocean", () => { const publisher = accounts[0] const consumer = accounts[1] - const ddo: DDO = await ocean.registerAsset(new MetaData(), publisher) + const metaData = new MetaData() + const ddo: DDO = await ocean.registerAsset(metaData, publisher) const service: Service = ddo.findServiceByType("Access") // @ts-ignore WebServiceConnectorProvider.setConnector(new WebServiceConnectorMock(ddo)) - const serviceAgreementSignature: any = await ocean.signServiceAgreement(ddo.id, + await consumer.requestTokens(metaData.base.price) + + const signServiceAgreementResult: any = await ocean.signServiceAgreement(ddo.id, service.serviceDefinitionId, consumer) - assert(serviceAgreementSignature) - assert(serviceAgreementSignature.serviceAgreementId) - assert(serviceAgreementSignature.serviceAgreementSignature) - assert(serviceAgreementSignature.serviceAgreementSignature.startsWith("0x")) + assert(signServiceAgreementResult) + assert(signServiceAgreementResult.serviceAgreementId, "no serviceAgreementId") + assert(signServiceAgreementResult.serviceAgreementSignature, "no serviceAgreementSignature") + assert(signServiceAgreementResult.serviceAgreementSignature.startsWith("0x")) + assert(signServiceAgreementResult.serviceAgreementSignature.length === 132) }) }) diff --git a/test/ocean/ServiceAgreement.test.ts b/test/ocean/ServiceAgreement.test.ts index c2b8385..a3aef06 100644 --- a/test/ocean/ServiceAgreement.test.ts +++ b/test/ocean/ServiceAgreement.test.ts @@ -71,6 +71,7 @@ describe("ServiceAgreement", () => { assert(serviceAgreementSignature) assert(serviceAgreementSignature.startsWith("0x")) + assert(serviceAgreementSignature.length === 132) }) }) From 1b3ec0f145281dddfb6dee2550856311880811b8 Mon Sep 17 00:00:00 2001 From: Sebastian Gerske Date: Mon, 26 Nov 2018 11:45:58 +0100 Subject: [PATCH 16/53] fix build --- package-lock.json | 2 +- package.json | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index ef07552..d5af121 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@oceanprotocol/squid", - "version": "0.1.24", + "version": "0.1.25", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 5ac30de..268d64c 100644 --- a/package.json +++ b/package.json @@ -2,10 +2,12 @@ "name": "@oceanprotocol/squid", "version": "0.1.25", "description": "JavaScript client library for Ocean Protocol", - "main": "dist/squid.js", + "main": "dist/cjs/squid.js", "module": "dist/esm/squid.js", "browser": "dist/umd/squid.min.js", - "files": ["dist/umd"], + "files": [ + "dist/umd" + ], "scripts": { "test": "mocha", "test:watch": "mocha -w --watch-extensions js,ts,json", @@ -13,7 +15,7 @@ "clean": "rm -rf ./dist/ ./doc/ ./coverage ./.nyc_output", "lint": "tslint -c tslint.json 'src/**/*.ts' 'test/**/*.ts'", "start": "npm link @oceanprotocol/keeper-contracts @oceanprotocol/secret-store-client && npm run build:watch", - "build": "npm run clean && npm run lint && tsc && npm run build:all && npm run doc", + "build": "npm run clean && npm run lint && npm run build:all && npm run doc", "build:all": "npm run build:es2015 && npm run build:esm && npm run build:cjs && npm run build:umd && npm run build:umd:min", "build:es2015": "tsc --module es2015 --target es2015 --outDir dist/es2015", "build:esm": "tsc --module es2015 --target es5 --outDir dist/esm", From ccf6bb42278655d18b39121c28eec874595fc1c3 Mon Sep 17 00:00:00 2001 From: Sebastian Gerske Date: Mon, 26 Nov 2018 12:14:13 +0100 Subject: [PATCH 17/53] removed warning --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 268d64c..d37f50f 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ "build:es2015": "tsc --module es2015 --target es2015 --outDir dist/es2015", "build:esm": "tsc --module es2015 --target es5 --outDir dist/esm", "build:cjs": "tsc --module commonjs --target es5 --outDir dist/cjs", - "build:umd": "rollup dist/esm/squid.js --format umd --name squid --sourceMap --file dist/umd/squid.js", + "build:umd": "rollup dist/esm/squid.js --format umd --name squid --sourcemap --file dist/umd/squid.js", "build:umd:min": "cd dist/umd && uglifyjs --compress --mangle --comments -o squid.min.js -- squid.js && gzip squid.min.js -c > squid.min.js.gz", "build:watch": "tsc -w", "doc": "typedoc --mode modules --out ./doc/ ./src/", From 43a5e53d57ae4813c6771ab4e37297a10046b956 Mon Sep 17 00:00:00 2001 From: Sebastian Gerske Date: Mon, 26 Nov 2018 15:24:59 +0100 Subject: [PATCH 18/53] fix brizo connection --- src/brizo/Brizo.ts | 31 ++++++++++++++++++------------- src/examples/SignAgreement.ts | 3 +++ src/ocean/Ocean.ts | 2 +- test.html | 28 ++++++++++++++++++++++++++++ 4 files changed, 50 insertions(+), 14 deletions(-) create mode 100644 test.html diff --git a/src/brizo/Brizo.ts b/src/brizo/Brizo.ts index e01f7e5..f28d969 100644 --- a/src/brizo/Brizo.ts +++ b/src/brizo/Brizo.ts @@ -1,6 +1,8 @@ import Config from "../models/Config" import WebServiceConnectorProvider from "../utils/WebServiceConnectorProvider" +const apiPath = "/api/v1/brizo/services" + export default class Brizo { private url: string @@ -10,16 +12,16 @@ export default class Brizo { } public getPurchaseEndpoint() { - return `${this.url}/api/v1/brizo/services/access/purchase?` + return `${this.url}${apiPath}/access/purchase?` } public getConsumeEndpoint(pubKey: string, serviceId: string, url: string) { - return `${this.url}/api/v1/brizo/services/consume?pubKey=${pubKey}&serviceId=${serviceId}&url=${url}` + return `${this.url}${apiPath}/consume?pubKey=${pubKey}&serviceId=${serviceId}&url=${url}` } public getComputeEndpoint(pubKey: string, serviceId: string, algo: string, container: string) { // tslint:disable-next-line - return `${this.url}/api/v1/brizo/services/compute?pubKey=${pubKey}&serviceId=${serviceId}&algo=${algo}&container=${container}"` + return `${this.url}${apiPath}/compute?pubKey=${pubKey}&serviceId=${serviceId}&algo=${algo}&container=${container}"` } public async initializeServiceAgreement( @@ -27,17 +29,20 @@ export default class Brizo { serviceAgreementId: string, serviceDefinitionId: string, signature: string, - consumerPublicKey: string): Promise { + consumerAddress: string): Promise { - return WebServiceConnectorProvider.getConnector().post( - `${this.url}/api/v1/brizo/services/access/initialize`, - { - did, - serviceAgreementId, - serviceDefinitionId, - signature, - consumerPublicKey, - }) + return WebServiceConnectorProvider + .getConnector() + .post( + `${this.url}${apiPath}/access/initialize`, + JSON.stringify({ + did, + serviceAgreementId, + serviceDefinitionId, + signature, + consumerAddress, + }), + ) } } diff --git a/src/examples/SignAgreement.ts b/src/examples/SignAgreement.ts index 47d2bb7..7a3b5c1 100644 --- a/src/examples/SignAgreement.ts +++ b/src/examples/SignAgreement.ts @@ -74,6 +74,9 @@ import {Account, Logger, Ocean} from "../squid" Logger.log("did", ddo.id) const accessService: Service = ddo.findServiceByType("Access") + + await consumer.requestTokens(metaData.base.price) + const serviceAgreementResult: any = await ocean .signServiceAgreement( ddo.id, diff --git a/src/ocean/Ocean.ts b/src/ocean/Ocean.ts index 194bc7a..b577503 100644 --- a/src/ocean/Ocean.ts +++ b/src/ocean/Ocean.ts @@ -216,7 +216,7 @@ export default class Ocean { serviceAgreementId, serviceDefinitionId, serviceAgreementSignature, - await consumer.getPublicKey()) + consumer.getId()) Logger.log(result) } diff --git a/test.html b/test.html new file mode 100644 index 0000000..2a76e0d --- /dev/null +++ b/test.html @@ -0,0 +1,28 @@ + + + + + Title + + + + + + \ No newline at end of file From 2a24529413d14be7dced3b09cf7d5260bb9c7a1d Mon Sep 17 00:00:00 2001 From: Sebastian Gerske Date: Tue, 27 Nov 2018 09:07:36 +0100 Subject: [PATCH 19/53] up, up it goes --- package-lock.json | 342 +++++++++++++++++++++++----------------------- package.json | 4 +- 2 files changed, 173 insertions(+), 173 deletions(-) diff --git a/package-lock.json b/package-lock.json index 805546e..8ed5545 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@oceanprotocol/squid", - "version": "0.1.25", + "version": "0.1.26", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -136,9 +136,9 @@ "dev": true }, "@oceanprotocol/keeper-contracts": { - "version": "0.3.25", - "resolved": "https://registry.npmjs.org/@oceanprotocol/keeper-contracts/-/keeper-contracts-0.3.25.tgz", - "integrity": "sha512-lW/36WYYCIHSX4OVnbk6KcKnnV7vsBbrEQPW+6cWUDokEWoBfxpdMIeTxCOyKZKavv7MrtFHDrb8BgjfTIIhsA==" + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/@oceanprotocol/keeper-contracts/-/keeper-contracts-0.4.0.tgz", + "integrity": "sha512-fDu8uuMBf0jf2GVAxJ814avE/2+KoMbvC9i/zZ3GN0whkt50/H1wyhDzgKw3ZpviWq3ZT9UvhNgI9s8ZgejaYQ==" }, "@oceanprotocol/secret-store-client": { "version": "0.0.12", @@ -170,7 +170,7 @@ }, "@types/events": { "version": "1.2.0", - "resolved": "https://registry.npmjs.org/@types/events/-/events-1.2.0.tgz", + "resolved": "http://registry.npmjs.org/@types/events/-/events-1.2.0.tgz", "integrity": "sha512-KEIlhXnIutzKwRbQkGWb/I4HFqBuUykAdHgDED6xqwXJfONCjF5VoE0cXEiurh3XauygxzeDzgtXUqvLkxFzzA==", "dev": true }, @@ -578,7 +578,7 @@ }, "util": { "version": "0.10.3", - "resolved": "https://registry.npmjs.org/util/-/util-0.10.3.tgz", + "resolved": "http://registry.npmjs.org/util/-/util-0.10.3.tgz", "integrity": "sha1-evsa/lCAUkZInj23/g7TeTNqwPk=", "requires": { "inherits": "2.0.1" @@ -1520,7 +1520,7 @@ "dependencies": { "pify": { "version": "2.3.0", - "resolved": "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz", + "resolved": "http://registry.npmjs.org/pify/-/pify-2.3.0.tgz", "integrity": "sha1-7RQaasBDqEnqWISY59yosVMw6Qw=" } } @@ -1585,7 +1585,7 @@ "dependencies": { "file-type": { "version": "3.9.0", - "resolved": "https://registry.npmjs.org/file-type/-/file-type-3.9.0.tgz", + "resolved": "http://registry.npmjs.org/file-type/-/file-type-3.9.0.tgz", "integrity": "sha1-JXoHg4TR24CHvESdEH1SpSZyuek=" }, "get-stream": { @@ -1599,7 +1599,7 @@ }, "pify": { "version": "2.3.0", - "resolved": "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz", + "resolved": "http://registry.npmjs.org/pify/-/pify-2.3.0.tgz", "integrity": "sha1-7RQaasBDqEnqWISY59yosVMw6Qw=" } } @@ -1753,7 +1753,7 @@ }, "eccrypto": { "version": "1.0.3", - "resolved": "https://registry.npmjs.org/eccrypto/-/eccrypto-1.0.3.tgz", + "resolved": "http://registry.npmjs.org/eccrypto/-/eccrypto-1.0.3.tgz", "integrity": "sha1-pBIObOmLAHLBzqr96tFW9ruLJOM=", "requires": { "elliptic": "^6.0.2", @@ -3965,7 +3965,7 @@ }, "media-typer": { "version": "0.3.0", - "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", + "resolved": "http://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", "integrity": "sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g=" }, "mem": { @@ -4409,7 +4409,7 @@ "dependencies": { "align-text": { "version": "0.1.4", - "resolved": false, + "resolved": "https://registry.npmjs.org/align-text/-/align-text-0.1.4.tgz", "integrity": "sha1-DNkKVhCT810KmSVsIrcGlDP60Rc=", "dev": true, "requires": { @@ -4420,19 +4420,19 @@ }, "amdefine": { "version": "1.0.1", - "resolved": false, + "resolved": "https://registry.npmjs.org/amdefine/-/amdefine-1.0.1.tgz", "integrity": "sha1-SlKCrBZHKek2Gbz9OtFR+BfOkfU=", "dev": true }, "ansi-regex": { "version": "3.0.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.0.tgz", "integrity": "sha1-7QMXwyIGT3lGbAKWa922Bas32Zg=", "dev": true }, "append-transform": { "version": "1.0.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/append-transform/-/append-transform-1.0.0.tgz", "integrity": "sha512-P009oYkeHyU742iSZJzZZywj4QRJdnTWffaKuJQLablCZ1uz6/cW4yaRgcDaoQ+uwOxxnt0gRUcwfsNP2ri0gw==", "dev": true, "requires": { @@ -4441,31 +4441,31 @@ }, "archy": { "version": "1.0.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/archy/-/archy-1.0.0.tgz", "integrity": "sha1-+cjBN1fMHde8N5rHeyxipcKGjEA=", "dev": true }, "arrify": { "version": "1.0.1", - "resolved": false, + "resolved": "https://registry.npmjs.org/arrify/-/arrify-1.0.1.tgz", "integrity": "sha1-iYUI2iIm84DfkEcoRWhJwVAaSw0=", "dev": true }, "async": { "version": "1.5.2", - "resolved": false, + "resolved": "https://registry.npmjs.org/async/-/async-1.5.2.tgz", "integrity": "sha1-7GphrlZIDAw8skHJVhjiCJL5Zyo=", "dev": true }, "balanced-match": { "version": "1.0.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", "dev": true }, "brace-expansion": { "version": "1.1.11", - "resolved": false, + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", "dev": true, "requires": { @@ -4475,13 +4475,13 @@ }, "builtin-modules": { "version": "1.1.1", - "resolved": false, + "resolved": "https://registry.npmjs.org/builtin-modules/-/builtin-modules-1.1.1.tgz", "integrity": "sha1-Jw8HbFpywC9bZaR9+Uxf46J4iS8=", "dev": true }, "caching-transform": { "version": "2.0.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/caching-transform/-/caching-transform-2.0.0.tgz", "integrity": "sha512-tTfemGmFWe7KZ3KN6VsSgQZbd9Bgo7A40wlp4PTsJJvFu4YAnEC5YnfdiKq6Vh2i9XJLnA9n8OXD46orVpnPMw==", "dev": true, "requires": { @@ -4493,14 +4493,14 @@ }, "camelcase": { "version": "1.2.1", - "resolved": false, + "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-1.2.1.tgz", "integrity": "sha1-m7UwTS4LVmmLLHWLCKPqqdqlijk=", "dev": true, "optional": true }, "center-align": { "version": "0.1.3", - "resolved": false, + "resolved": "https://registry.npmjs.org/center-align/-/center-align-0.1.3.tgz", "integrity": "sha1-qg0yYptu6XIgBBHL1EYckHvCt60=", "dev": true, "optional": true, @@ -4511,7 +4511,7 @@ }, "cliui": { "version": "2.1.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/cliui/-/cliui-2.1.0.tgz", "integrity": "sha1-S0dXYP+AJkx2LDoXGQMukcf+oNE=", "dev": true, "optional": true, @@ -4523,7 +4523,7 @@ "dependencies": { "wordwrap": { "version": "0.0.2", - "resolved": false, + "resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-0.0.2.tgz", "integrity": "sha1-t5Zpu0LstAn4PVg8rVLKF+qhZD8=", "dev": true, "optional": true @@ -4532,25 +4532,25 @@ }, "code-point-at": { "version": "1.1.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/code-point-at/-/code-point-at-1.1.0.tgz", "integrity": "sha1-DQcLTQQ6W+ozovGkDi7bPZpMz3c=", "dev": true }, "commondir": { "version": "1.0.1", - "resolved": false, + "resolved": "https://registry.npmjs.org/commondir/-/commondir-1.0.1.tgz", "integrity": "sha1-3dgA2gxmEnOTzKWVDqloo6rxJTs=", "dev": true }, "concat-map": { "version": "0.0.1", - "resolved": false, + "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", "dev": true }, "convert-source-map": { "version": "1.6.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-1.6.0.tgz", "integrity": "sha512-eFu7XigvxdZ1ETfbgPBohgyQ/Z++C0eEhTor0qRwBw9unw+L0/6V8wkSuGgzdThkiS5lSpdptOQPD8Ak40a+7A==", "dev": true, "requires": { @@ -4559,7 +4559,7 @@ }, "cross-spawn": { "version": "4.0.2", - "resolved": false, + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-4.0.2.tgz", "integrity": "sha1-e5JHYhwjrf3ThWAEqCPL45dCTUE=", "dev": true, "requires": { @@ -4569,7 +4569,7 @@ }, "debug": { "version": "3.1.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz", "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==", "dev": true, "requires": { @@ -4578,19 +4578,19 @@ }, "debug-log": { "version": "1.0.1", - "resolved": false, + "resolved": "https://registry.npmjs.org/debug-log/-/debug-log-1.0.1.tgz", "integrity": "sha1-IwdjLUwEOCuN+KMvcLiVBG1SdF8=", "dev": true }, "decamelize": { "version": "1.2.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-1.2.0.tgz", "integrity": "sha1-9lNNFRSCabIDUue+4m9QH5oZEpA=", "dev": true }, "default-require-extensions": { "version": "2.0.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/default-require-extensions/-/default-require-extensions-2.0.0.tgz", "integrity": "sha1-9fj7sYp9bVCyH2QfZJ67Uiz+JPc=", "dev": true, "requires": { @@ -4599,7 +4599,7 @@ }, "error-ex": { "version": "1.3.2", - "resolved": false, + "resolved": "https://registry.npmjs.org/error-ex/-/error-ex-1.3.2.tgz", "integrity": "sha512-7dFHNmqeFSEt2ZBsCriorKnn3Z2pj+fd9kmI6QoWw4//DL+icEBfc0U7qJCisqrTsKTjw4fNFy2pW9OqStD84g==", "dev": true, "requires": { @@ -4608,13 +4608,13 @@ }, "es6-error": { "version": "4.1.1", - "resolved": false, + "resolved": "https://registry.npmjs.org/es6-error/-/es6-error-4.1.1.tgz", "integrity": "sha512-Um/+FxMr9CISWh0bi5Zv0iOD+4cFh5qLeks1qhAopKVAJw3drgKbKySikp7wGhDL0HPeaja0P5ULZrxLkniUVg==", "dev": true }, "execa": { "version": "0.7.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/execa/-/execa-0.7.0.tgz", "integrity": "sha1-lEvs00zEHuMqY6n68nrVpl/Fl3c=", "dev": true, "requires": { @@ -4629,7 +4629,7 @@ "dependencies": { "cross-spawn": { "version": "5.1.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-5.1.0.tgz", "integrity": "sha1-6L0O/uWPz/b4+UUQoKVUu/ojVEk=", "dev": true, "requires": { @@ -4642,7 +4642,7 @@ }, "find-cache-dir": { "version": "2.0.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/find-cache-dir/-/find-cache-dir-2.0.0.tgz", "integrity": "sha512-LDUY6V1Xs5eFskUVYtIwatojt6+9xC9Chnlk/jYOOvn3FAFfSaWddxahDGyNHh0b2dMXa6YW2m0tk8TdVaXHlA==", "dev": true, "requires": { @@ -4653,7 +4653,7 @@ }, "find-up": { "version": "3.0.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/find-up/-/find-up-3.0.0.tgz", "integrity": "sha512-1yD6RmLI1XBfxugvORwlck6f75tYL+iR0jqwsOrOxMZyGYqUuDhJ0l4AXdO1iX/FTs9cBAMEk1gWSEx1kSbylg==", "dev": true, "requires": { @@ -4662,7 +4662,7 @@ }, "foreground-child": { "version": "1.5.6", - "resolved": false, + "resolved": "https://registry.npmjs.org/foreground-child/-/foreground-child-1.5.6.tgz", "integrity": "sha1-T9ca0t/elnibmApcCilZN8svXOk=", "dev": true, "requires": { @@ -4672,25 +4672,25 @@ }, "fs.realpath": { "version": "1.0.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", "dev": true }, "get-caller-file": { "version": "1.0.3", - "resolved": false, + "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-1.0.3.tgz", "integrity": "sha512-3t6rVToeoZfYSGd8YoLFR2DJkiQrIiUrGcjvFX2mDw3bn6k2OtwHN0TNCLbBO+w8qTvimhDkv+LSscbJY1vE6w==", "dev": true }, "get-stream": { "version": "3.0.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-3.0.0.tgz", "integrity": "sha1-jpQ9E1jcN1VQVOy+LtsFqhdO3hQ=", "dev": true }, "glob": { "version": "7.1.3", - "resolved": false, + "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.3.tgz", "integrity": "sha512-vcfuiIxogLV4DlGBHIUOwI0IbrJ8HWPc4MU7HzviGeNho/UJDfi6B5p3sHeWIQ0KGIU0Jpxi5ZHxemQfLkkAwQ==", "dev": true, "requires": { @@ -4704,13 +4704,13 @@ }, "graceful-fs": { "version": "4.1.11", - "resolved": false, + "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.1.11.tgz", "integrity": "sha1-Dovf5NHduIVNZOBOp8AOKgJuVlg=", "dev": true }, "handlebars": { "version": "4.0.11", - "resolved": false, + "resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.0.11.tgz", "integrity": "sha1-Ywo13+ApS8KB7a5v/F0yn8eYLcw=", "dev": true, "requires": { @@ -4722,7 +4722,7 @@ "dependencies": { "source-map": { "version": "0.4.4", - "resolved": false, + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.4.4.tgz", "integrity": "sha1-66T12pwNyZneaAMti092FzZSA2s=", "dev": true, "requires": { @@ -4733,25 +4733,25 @@ }, "has-flag": { "version": "3.0.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=", "dev": true }, "hosted-git-info": { "version": "2.7.1", - "resolved": false, + "resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.7.1.tgz", "integrity": "sha512-7T/BxH19zbcCTa8XkMlbK5lTo1WtgkFi3GvdWEyNuc4Vex7/9Dqbnpsf4JMydcfj9HCg4zUWFTL3Za6lapg5/w==", "dev": true }, "imurmurhash": { "version": "0.1.4", - "resolved": false, + "resolved": "https://registry.npmjs.org/imurmurhash/-/imurmurhash-0.1.4.tgz", "integrity": "sha1-khi5srkoojixPcT7a21XbyMUU+o=", "dev": true }, "inflight": { "version": "1.0.6", - "resolved": false, + "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", "dev": true, "requires": { @@ -4761,31 +4761,31 @@ }, "inherits": { "version": "2.0.3", - "resolved": false, + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=", "dev": true }, "invert-kv": { "version": "1.0.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/invert-kv/-/invert-kv-1.0.0.tgz", "integrity": "sha1-EEqOSqym09jNFXqO+L+rLXo//bY=", "dev": true }, "is-arrayish": { "version": "0.2.1", - "resolved": false, + "resolved": "https://registry.npmjs.org/is-arrayish/-/is-arrayish-0.2.1.tgz", "integrity": "sha1-d8mYQFJ6qOyxqLppe4BkWnqSap0=", "dev": true }, "is-buffer": { "version": "1.1.6", - "resolved": false, + "resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-1.1.6.tgz", "integrity": "sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w==", "dev": true }, "is-builtin-module": { "version": "1.0.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/is-builtin-module/-/is-builtin-module-1.0.0.tgz", "integrity": "sha1-VAVy0096wxGfj3bDDLwbHgN6/74=", "dev": true, "requires": { @@ -4794,31 +4794,31 @@ }, "is-fullwidth-code-point": { "version": "2.0.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz", "integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=", "dev": true }, "is-stream": { "version": "1.1.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz", "integrity": "sha1-EtSj3U5o4Lec6428hBc66A2RykQ=", "dev": true }, "isexe": { "version": "2.0.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", "integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=", "dev": true }, "istanbul-lib-coverage": { "version": "2.0.1", - "resolved": false, + "resolved": "https://registry.npmjs.org/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.1.tgz", "integrity": "sha512-nPvSZsVlbG9aLhZYaC3Oi1gT/tpyo3Yt5fNyf6NmcKIayz4VV/txxJFFKAK/gU4dcNn8ehsanBbVHVl0+amOLA==", "dev": true }, "istanbul-lib-hook": { "version": "2.0.1", - "resolved": false, + "resolved": "https://registry.npmjs.org/istanbul-lib-hook/-/istanbul-lib-hook-2.0.1.tgz", "integrity": "sha512-ufiZoiJ8CxY577JJWEeFuxXZoMqiKpq/RqZtOAYuQLvlkbJWscq9n3gc4xrCGH9n4pW0qnTxOz1oyMmVtk8E1w==", "dev": true, "requires": { @@ -4827,7 +4827,7 @@ }, "istanbul-lib-report": { "version": "2.0.2", - "resolved": false, + "resolved": "https://registry.npmjs.org/istanbul-lib-report/-/istanbul-lib-report-2.0.2.tgz", "integrity": "sha512-rJ8uR3peeIrwAxoDEbK4dJ7cqqtxBisZKCuwkMtMv0xYzaAnsAi3AHrHPAAtNXzG/bcCgZZ3OJVqm1DTi9ap2Q==", "dev": true, "requires": { @@ -4838,7 +4838,7 @@ }, "istanbul-lib-source-maps": { "version": "2.0.1", - "resolved": false, + "resolved": "https://registry.npmjs.org/istanbul-lib-source-maps/-/istanbul-lib-source-maps-2.0.1.tgz", "integrity": "sha512-30l40ySg+gvBLcxTrLzR4Z2XTRj3HgRCA/p2rnbs/3OiTaoj054gAbuP5DcLOtwqmy4XW8qXBHzrmP2/bQ9i3A==", "dev": true, "requires": { @@ -4851,7 +4851,7 @@ "dependencies": { "source-map": { "version": "0.6.1", - "resolved": false, + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", "dev": true } @@ -4859,7 +4859,7 @@ }, "istanbul-reports": { "version": "2.0.1", - "resolved": false, + "resolved": "https://registry.npmjs.org/istanbul-reports/-/istanbul-reports-2.0.1.tgz", "integrity": "sha512-CT0QgMBJqs6NJLF678ZHcquUAZIoBIUNzdJrRJfpkI9OnzG6MkUfHxbJC3ln981dMswC7/B1mfX3LNkhgJxsuw==", "dev": true, "requires": { @@ -4868,13 +4868,13 @@ }, "json-parse-better-errors": { "version": "1.0.2", - "resolved": false, + "resolved": "https://registry.npmjs.org/json-parse-better-errors/-/json-parse-better-errors-1.0.2.tgz", "integrity": "sha512-mrqyZKfX5EhL7hvqcV6WG1yYjnjeuYDzDhhcAAUrq8Po85NBQBJP+ZDUT75qZQ98IkUoBqdkExkukOU7Ts2wrw==", "dev": true }, "kind-of": { "version": "3.2.2", - "resolved": false, + "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-3.2.2.tgz", "integrity": "sha1-MeohpzS6ubuw8yRm2JOupR5KPGQ=", "dev": true, "requires": { @@ -4883,14 +4883,14 @@ }, "lazy-cache": { "version": "1.0.4", - "resolved": false, + "resolved": "https://registry.npmjs.org/lazy-cache/-/lazy-cache-1.0.4.tgz", "integrity": "sha1-odePw6UEdMuAhF07O24dpJpEbo4=", "dev": true, "optional": true }, "lcid": { "version": "1.0.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/lcid/-/lcid-1.0.0.tgz", "integrity": "sha1-MIrMr6C8SDo4Z7S28rlQYlHRuDU=", "dev": true, "requires": { @@ -4899,7 +4899,7 @@ }, "load-json-file": { "version": "4.0.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/load-json-file/-/load-json-file-4.0.0.tgz", "integrity": "sha1-L19Fq5HjMhYjT9U62rZo607AmTs=", "dev": true, "requires": { @@ -4911,7 +4911,7 @@ }, "locate-path": { "version": "3.0.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-3.0.0.tgz", "integrity": "sha512-7AO748wWnIhNqAuaty2ZWHkQHRSNfPVIsPIfwEOWO22AmaoVrWavlOcMR5nzTLNYvp36X220/maaRsrec1G65A==", "dev": true, "requires": { @@ -4921,19 +4921,19 @@ }, "lodash.flattendeep": { "version": "4.4.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/lodash.flattendeep/-/lodash.flattendeep-4.4.0.tgz", "integrity": "sha1-+wMJF/hqMTTlvJvsDWngAT3f7bI=", "dev": true }, "longest": { "version": "1.0.1", - "resolved": false, + "resolved": "https://registry.npmjs.org/longest/-/longest-1.0.1.tgz", "integrity": "sha1-MKCy2jj3N3DoKUoNIuZiXtd9AJc=", "dev": true }, "lru-cache": { "version": "4.1.3", - "resolved": false, + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-4.1.3.tgz", "integrity": "sha512-fFEhvcgzuIoJVUF8fYr5KR0YqxD238zgObTps31YdADwPPAp82a4M8TrckkWyx7ekNlf9aBcVn81cFwwXngrJA==", "dev": true, "requires": { @@ -4943,7 +4943,7 @@ }, "make-dir": { "version": "1.3.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-1.3.0.tgz", "integrity": "sha512-2w31R7SJtieJJnQtGc7RVL2StM2vGYVfqUOvUDxH6bC6aJTxPxTF0GnIgCyu7tjockiUWAYQRbxa7vKn34s5sQ==", "dev": true, "requires": { @@ -4952,7 +4952,7 @@ }, "md5-hex": { "version": "2.0.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/md5-hex/-/md5-hex-2.0.0.tgz", "integrity": "sha1-0FiOnxx0lUSS7NJKwKxs6ZfZLjM=", "dev": true, "requires": { @@ -4961,13 +4961,13 @@ }, "md5-o-matic": { "version": "0.1.1", - "resolved": false, + "resolved": "https://registry.npmjs.org/md5-o-matic/-/md5-o-matic-0.1.1.tgz", "integrity": "sha1-givM1l4RfFFPqxdrJZRdVBAKA8M=", "dev": true }, "mem": { "version": "1.1.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/mem/-/mem-1.1.0.tgz", "integrity": "sha1-Xt1StIXKHZAP5kiVUFOZoN+kX3Y=", "dev": true, "requires": { @@ -4976,7 +4976,7 @@ }, "merge-source-map": { "version": "1.1.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/merge-source-map/-/merge-source-map-1.1.0.tgz", "integrity": "sha512-Qkcp7P2ygktpMPh2mCQZaf3jhN6D3Z/qVZHSdWvQ+2Ef5HgRAPBO57A77+ENm0CPx2+1Ce/MYKi3ymqdfuqibw==", "dev": true, "requires": { @@ -4985,7 +4985,7 @@ "dependencies": { "source-map": { "version": "0.6.1", - "resolved": false, + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", "dev": true } @@ -4993,13 +4993,13 @@ }, "mimic-fn": { "version": "1.2.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-1.2.0.tgz", "integrity": "sha512-jf84uxzwiuiIVKiOLpfYk7N46TSy8ubTonmneY9vrpHNAnp0QBt2BxWV9dO3/j+BoVAb+a5G6YDPW3M5HOdMWQ==", "dev": true }, "minimatch": { "version": "3.0.4", - "resolved": false, + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", "dev": true, "requires": { @@ -5008,13 +5008,13 @@ }, "minimist": { "version": "0.0.10", - "resolved": false, + "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.10.tgz", "integrity": "sha1-3j+YVD2/lggr5IrRoMfNqDYwHc8=", "dev": true }, "mkdirp": { "version": "0.5.1", - "resolved": false, + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", "dev": true, "requires": { @@ -5023,7 +5023,7 @@ "dependencies": { "minimist": { "version": "0.0.8", - "resolved": false, + "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=", "dev": true } @@ -5031,13 +5031,13 @@ }, "ms": { "version": "2.0.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=", "dev": true }, "normalize-package-data": { "version": "2.4.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/normalize-package-data/-/normalize-package-data-2.4.0.tgz", "integrity": "sha512-9jjUFbTPfEy3R/ad/2oNbKtW9Hgovl5O1FvFWKkKblNXoN/Oou6+9+KKohPK13Yc3/TyunyWhJp6gvRNR/PPAw==", "dev": true, "requires": { @@ -5049,7 +5049,7 @@ }, "npm-run-path": { "version": "2.0.2", - "resolved": false, + "resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-2.0.2.tgz", "integrity": "sha1-NakjLfo11wZ7TLLd8jV7GHFTbF8=", "dev": true, "requires": { @@ -5058,13 +5058,13 @@ }, "number-is-nan": { "version": "1.0.1", - "resolved": false, + "resolved": "https://registry.npmjs.org/number-is-nan/-/number-is-nan-1.0.1.tgz", "integrity": "sha1-CXtgK1NCKlIsGvuHkDGDNpQaAR0=", "dev": true }, "once": { "version": "1.4.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", "dev": true, "requires": { @@ -5073,7 +5073,7 @@ }, "optimist": { "version": "0.6.1", - "resolved": false, + "resolved": "https://registry.npmjs.org/optimist/-/optimist-0.6.1.tgz", "integrity": "sha1-2j6nRob6IaGaERwybpDrFaAZZoY=", "dev": true, "requires": { @@ -5083,13 +5083,13 @@ }, "os-homedir": { "version": "1.0.2", - "resolved": false, + "resolved": "https://registry.npmjs.org/os-homedir/-/os-homedir-1.0.2.tgz", "integrity": "sha1-/7xJiDNuDoM94MFox+8VISGqf7M=", "dev": true }, "os-locale": { "version": "2.1.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/os-locale/-/os-locale-2.1.0.tgz", "integrity": "sha512-3sslG3zJbEYcaC4YVAvDorjGxc7tv6KVATnLPZONiljsUncvihe9BQoVCEs0RZ1kmf4Hk9OBqlZfJZWI4GanKA==", "dev": true, "requires": { @@ -5100,13 +5100,13 @@ }, "p-finally": { "version": "1.0.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/p-finally/-/p-finally-1.0.0.tgz", "integrity": "sha1-P7z7FbiZpEEjs0ttzBi3JDNqLK4=", "dev": true }, "p-limit": { "version": "2.0.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.0.0.tgz", "integrity": "sha512-fl5s52lI5ahKCernzzIyAP0QAZbGIovtVHGwpcu1Jr/EpzLVDI2myISHwGqK7m8uQFugVWSrbxH7XnhGtvEc+A==", "dev": true, "requires": { @@ -5115,7 +5115,7 @@ }, "p-locate": { "version": "3.0.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-3.0.0.tgz", "integrity": "sha512-x+12w/To+4GFfgJhBEpiDcLozRJGegY+Ei7/z0tSLkMmxGZNybVMSfWj9aJn8Z5Fc7dBUNJOOVgPv2H7IwulSQ==", "dev": true, "requires": { @@ -5124,13 +5124,13 @@ }, "p-try": { "version": "2.0.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/p-try/-/p-try-2.0.0.tgz", "integrity": "sha512-hMp0onDKIajHfIkdRk3P4CdCmErkYAxxDtP3Wx/4nZ3aGlau2VKh3mZpcuFkH27WQkL/3WBCPOktzA9ZOAnMQQ==", "dev": true }, "package-hash": { "version": "2.0.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/package-hash/-/package-hash-2.0.0.tgz", "integrity": "sha1-eK4ybIngWk2BO2hgGXevBcANKg0=", "dev": true, "requires": { @@ -5142,7 +5142,7 @@ }, "parse-json": { "version": "4.0.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/parse-json/-/parse-json-4.0.0.tgz", "integrity": "sha1-vjX1Qlvh9/bHRxhPmKeIy5lHfuA=", "dev": true, "requires": { @@ -5152,25 +5152,25 @@ }, "path-exists": { "version": "3.0.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-3.0.0.tgz", "integrity": "sha1-zg6+ql94yxiSXqfYENe1mwEP1RU=", "dev": true }, "path-is-absolute": { "version": "1.0.1", - "resolved": false, + "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", "dev": true }, "path-key": { "version": "2.0.1", - "resolved": false, + "resolved": "https://registry.npmjs.org/path-key/-/path-key-2.0.1.tgz", "integrity": "sha1-QRyttXTFoUDTpLGRDUDYDMn0C0A=", "dev": true }, "path-type": { "version": "3.0.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/path-type/-/path-type-3.0.0.tgz", "integrity": "sha512-T2ZUsdZFHgA3u4e5PfPbjd7HDDpxPnQb5jN0SrDsjNSuVXHJqtwTnWqG0B1jZrgmJ/7lj1EmVIByWt1gxGkWvg==", "dev": true, "requires": { @@ -5179,13 +5179,13 @@ }, "pify": { "version": "3.0.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/pify/-/pify-3.0.0.tgz", "integrity": "sha1-5aSs0sEB/fPZpNB/DbxNtJ3SgXY=", "dev": true }, "pkg-dir": { "version": "3.0.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/pkg-dir/-/pkg-dir-3.0.0.tgz", "integrity": "sha512-/E57AYkoeQ25qkxMj5PBOVgF8Kiu/h7cYS30Z5+R7WaiCCBfLq58ZI/dSeaEKb9WVJV5n/03QwrN3IeWIFllvw==", "dev": true, "requires": { @@ -5194,13 +5194,13 @@ }, "pseudomap": { "version": "1.0.2", - "resolved": false, + "resolved": "https://registry.npmjs.org/pseudomap/-/pseudomap-1.0.2.tgz", "integrity": "sha1-8FKijacOYYkX7wqKw0wa5aaChrM=", "dev": true }, "read-pkg": { "version": "3.0.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/read-pkg/-/read-pkg-3.0.0.tgz", "integrity": "sha1-nLxoaXj+5l0WwA4rGcI3/Pbjg4k=", "dev": true, "requires": { @@ -5211,7 +5211,7 @@ }, "read-pkg-up": { "version": "4.0.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/read-pkg-up/-/read-pkg-up-4.0.0.tgz", "integrity": "sha512-6etQSH7nJGsK0RbG/2TeDzZFa8shjQ1um+SwQQ5cwKy0dhSXdOncEhb1CPpvQG4h7FyOV6EB6YlV0yJvZQNAkA==", "dev": true, "requires": { @@ -5221,7 +5221,7 @@ }, "release-zalgo": { "version": "1.0.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/release-zalgo/-/release-zalgo-1.0.0.tgz", "integrity": "sha1-CXALflB0Mpc5Mw5TXFqQ+2eFFzA=", "dev": true, "requires": { @@ -5230,31 +5230,31 @@ }, "repeat-string": { "version": "1.6.1", - "resolved": false, + "resolved": "https://registry.npmjs.org/repeat-string/-/repeat-string-1.6.1.tgz", "integrity": "sha1-jcrkcOHIirwtYA//Sndihtp15jc=", "dev": true }, "require-directory": { "version": "2.1.1", - "resolved": false, + "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", "integrity": "sha1-jGStX9MNqxyXbiNE/+f3kqam30I=", "dev": true }, "require-main-filename": { "version": "1.0.1", - "resolved": false, + "resolved": "https://registry.npmjs.org/require-main-filename/-/require-main-filename-1.0.1.tgz", "integrity": "sha1-l/cXtp1IeE9fUmpsWqj/3aBVpNE=", "dev": true }, "resolve-from": { "version": "4.0.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-4.0.0.tgz", "integrity": "sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==", "dev": true }, "right-align": { "version": "0.1.3", - "resolved": false, + "resolved": "https://registry.npmjs.org/right-align/-/right-align-0.1.3.tgz", "integrity": "sha1-YTObci/mo1FWiSENJOFMlhSGE+8=", "dev": true, "optional": true, @@ -5264,7 +5264,7 @@ }, "rimraf": { "version": "2.6.2", - "resolved": false, + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.2.tgz", "integrity": "sha512-lreewLK/BlghmxtfH36YYVg1i8IAce4TI7oao75I1g245+6BctqTVQiBP3YUJ9C6DQOXJmkYR9X9fCLtCOJc5w==", "dev": true, "requires": { @@ -5273,25 +5273,25 @@ }, "safe-buffer": { "version": "5.1.2", - "resolved": false, + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==", "dev": true }, "semver": { "version": "5.5.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/semver/-/semver-5.5.0.tgz", "integrity": "sha512-4SJ3dm0WAwWy/NVeioZh5AntkdJoWKxHxcmyP622fOkgHa4z3R0TdBJICINyaSDE6uNwVc8gZr+ZinwZAH4xIA==", "dev": true }, "set-blocking": { "version": "2.0.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz", "integrity": "sha1-BF+XgtARrppoA93TgrJDkrPYkPc=", "dev": true }, "shebang-command": { "version": "1.2.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-1.2.0.tgz", "integrity": "sha1-RKrGW2lbAzmJaMOfNj/uXer98eo=", "dev": true, "requires": { @@ -5300,26 +5300,26 @@ }, "shebang-regex": { "version": "1.0.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-1.0.0.tgz", "integrity": "sha1-2kL0l0DAtC2yypcoVxyxkMmO/qM=", "dev": true }, "signal-exit": { "version": "3.0.2", - "resolved": false, + "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.2.tgz", "integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=", "dev": true }, "source-map": { "version": "0.5.7", - "resolved": false, + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.5.7.tgz", "integrity": "sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w=", "dev": true, "optional": true }, "spawn-wrap": { "version": "1.4.2", - "resolved": false, + "resolved": "https://registry.npmjs.org/spawn-wrap/-/spawn-wrap-1.4.2.tgz", "integrity": "sha512-vMwR3OmmDhnxCVxM8M+xO/FtIp6Ju/mNaDfCMMW7FDcLRTPFWUswec4LXJHTJE2hwTI9O0YBfygu4DalFl7Ylg==", "dev": true, "requires": { @@ -5333,7 +5333,7 @@ }, "spdx-correct": { "version": "3.0.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/spdx-correct/-/spdx-correct-3.0.0.tgz", "integrity": "sha512-N19o9z5cEyc8yQQPukRCZ9EUmb4HUpnrmaL/fxS2pBo2jbfcFRVuFZ/oFC+vZz0MNNk0h80iMn5/S6qGZOL5+g==", "dev": true, "requires": { @@ -5343,13 +5343,13 @@ }, "spdx-exceptions": { "version": "2.1.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/spdx-exceptions/-/spdx-exceptions-2.1.0.tgz", "integrity": "sha512-4K1NsmrlCU1JJgUrtgEeTVyfx8VaYea9J9LvARxhbHtVtohPs/gFGG5yy49beySjlIMhhXZ4QqujIZEfS4l6Cg==", "dev": true }, "spdx-expression-parse": { "version": "3.0.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/spdx-expression-parse/-/spdx-expression-parse-3.0.0.tgz", "integrity": "sha512-Yg6D3XpRD4kkOmTpdgbUiEJFKghJH03fiC1OPll5h/0sO6neh2jqRDVHOQ4o/LMea0tgCkbMgea5ip/e+MkWyg==", "dev": true, "requires": { @@ -5359,13 +5359,13 @@ }, "spdx-license-ids": { "version": "3.0.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/spdx-license-ids/-/spdx-license-ids-3.0.0.tgz", "integrity": "sha512-2+EPwgbnmOIl8HjGBXXMd9NAu02vLjOO1nWw4kmeRDFyHn+M/ETfHxQUK0oXg8ctgVnl9t3rosNVsZ1jG61nDA==", "dev": true }, "string-width": { "version": "2.1.1", - "resolved": false, + "resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz", "integrity": "sha512-nOqH59deCq9SRHlxq1Aw85Jnt4w6KvLKqWVik6oA9ZklXLNIOlqg4F2yrT1MVaTjAqvVwdfeZ7w7aCvJD7ugkw==", "dev": true, "requires": { @@ -5375,7 +5375,7 @@ }, "strip-ansi": { "version": "4.0.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz", "integrity": "sha1-qEeQIusaw2iocTibY1JixQXuNo8=", "dev": true, "requires": { @@ -5384,19 +5384,19 @@ }, "strip-bom": { "version": "3.0.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-3.0.0.tgz", "integrity": "sha1-IzTBjpx1n3vdVv3vfprj1YjmjtM=", "dev": true }, "strip-eof": { "version": "1.0.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/strip-eof/-/strip-eof-1.0.0.tgz", "integrity": "sha1-u0P/VZim6wXYm1n80SnJgzE2Br8=", "dev": true }, "supports-color": { "version": "5.4.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.4.0.tgz", "integrity": "sha512-zjaXglF5nnWpsq470jSv6P9DwPvgLkuapYmfDm3JWOm0vkNTVF2tI4UrN2r6jH1qM/uc/WtxYY1hYoA2dOKj5w==", "dev": true, "requires": { @@ -5405,7 +5405,7 @@ }, "test-exclude": { "version": "5.0.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/test-exclude/-/test-exclude-5.0.0.tgz", "integrity": "sha512-bO3Lj5+qFa9YLfYW2ZcXMOV1pmQvw+KS/DpjqhyX6Y6UZ8zstpZJ+mA2ERkXfpOqhxsJlQiLeVXD3Smsrs6oLw==", "dev": true, "requires": { @@ -5417,7 +5417,7 @@ }, "uglify-js": { "version": "2.8.29", - "resolved": false, + "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-2.8.29.tgz", "integrity": "sha1-KcVzMUgFe7Th913zW3qcty5qWd0=", "dev": true, "optional": true, @@ -5429,7 +5429,7 @@ "dependencies": { "yargs": { "version": "3.10.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/yargs/-/yargs-3.10.0.tgz", "integrity": "sha1-9+572FfdfB0tOMDnTvvWgdFDH9E=", "dev": true, "optional": true, @@ -5444,20 +5444,20 @@ }, "uglify-to-browserify": { "version": "1.0.2", - "resolved": false, + "resolved": "https://registry.npmjs.org/uglify-to-browserify/-/uglify-to-browserify-1.0.2.tgz", "integrity": "sha1-bgkk1r2mta/jSeOabWMoUKD4grc=", "dev": true, "optional": true }, "uuid": { "version": "3.3.2", - "resolved": false, + "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.3.2.tgz", "integrity": "sha512-yXJmeNaw3DnnKAOKJE51sL/ZaYfWJRl1pK9dr19YFCu0ObS231AB1/LbqTKRAQ5kw8A90rA6fr4riOUpTZvQZA==", "dev": true }, "validate-npm-package-license": { "version": "3.0.3", - "resolved": false, + "resolved": "https://registry.npmjs.org/validate-npm-package-license/-/validate-npm-package-license-3.0.3.tgz", "integrity": "sha512-63ZOUnL4SIXj4L0NixR3L1lcjO38crAbgrTpl28t8jjrfuiOBL5Iygm+60qPs/KsZGzPNg6Smnc/oY16QTjF0g==", "dev": true, "requires": { @@ -5467,7 +5467,7 @@ }, "which": { "version": "1.3.1", - "resolved": false, + "resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz", "integrity": "sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ==", "dev": true, "requires": { @@ -5476,26 +5476,26 @@ }, "which-module": { "version": "2.0.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/which-module/-/which-module-2.0.0.tgz", "integrity": "sha1-2e8H3Od7mQK4o6j6SzHD4/fm6Ho=", "dev": true }, "window-size": { "version": "0.1.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/window-size/-/window-size-0.1.0.tgz", "integrity": "sha1-VDjNLqk7IC76Ohn+iIeu58lPnJ0=", "dev": true, "optional": true }, "wordwrap": { "version": "0.0.3", - "resolved": false, + "resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-0.0.3.tgz", "integrity": "sha1-o9XabNXAvAAI03I0u68b7WMFkQc=", "dev": true }, "wrap-ansi": { "version": "2.1.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-2.1.0.tgz", "integrity": "sha1-2Pw9KE3QV5T+hJc8rs3Rz4JP3YU=", "dev": true, "requires": { @@ -5505,13 +5505,13 @@ "dependencies": { "ansi-regex": { "version": "2.1.1", - "resolved": false, + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz", "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=", "dev": true }, "is-fullwidth-code-point": { "version": "1.0.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-1.0.0.tgz", "integrity": "sha1-754xOG8DGn8NZDr4L95QxFfvAMs=", "dev": true, "requires": { @@ -5520,7 +5520,7 @@ }, "string-width": { "version": "1.0.2", - "resolved": false, + "resolved": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz", "integrity": "sha1-EYvfW4zcUaKn5w0hHgfisLmxB9M=", "dev": true, "requires": { @@ -5531,7 +5531,7 @@ }, "strip-ansi": { "version": "3.0.1", - "resolved": false, + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", "dev": true, "requires": { @@ -5542,13 +5542,13 @@ }, "wrappy": { "version": "1.0.2", - "resolved": false, + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", "dev": true }, "write-file-atomic": { "version": "2.3.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/write-file-atomic/-/write-file-atomic-2.3.0.tgz", "integrity": "sha512-xuPeK4OdjWqtfi59ylvVL0Yn35SF3zgcAcv7rBPFHVaEapaDr4GdGgm3j7ckTwH9wHL7fGmgfAnb0+THrHb8tA==", "dev": true, "requires": { @@ -5559,19 +5559,19 @@ }, "y18n": { "version": "3.2.1", - "resolved": false, + "resolved": "https://registry.npmjs.org/y18n/-/y18n-3.2.1.tgz", "integrity": "sha1-bRX7qITAhnnA136I53WegR4H+kE=", "dev": true }, "yallist": { "version": "2.1.2", - "resolved": false, + "resolved": "https://registry.npmjs.org/yallist/-/yallist-2.1.2.tgz", "integrity": "sha1-HBH5IY8HYImkfdUS+TxmmaaoHVI=", "dev": true }, "yargs": { "version": "11.1.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/yargs/-/yargs-11.1.0.tgz", "integrity": "sha512-NwW69J42EsCSanF8kyn5upxvjp5ds+t3+udGBeTbFnERA+lF541DDpMawzo4z6W/QrzNM18D+BPMiOBibnFV5A==", "dev": true, "requires": { @@ -5591,7 +5591,7 @@ "dependencies": { "cliui": { "version": "4.1.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/cliui/-/cliui-4.1.0.tgz", "integrity": "sha512-4FG+RSG9DL7uEwRUZXZn3SS34DiDPfzP0VOiEwtUWlE+AR2EIg+hSyvrIgUUfhdgR/UkAeW2QHgeP+hWrXs7jQ==", "dev": true, "requires": { @@ -5602,7 +5602,7 @@ }, "find-up": { "version": "2.1.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/find-up/-/find-up-2.1.0.tgz", "integrity": "sha1-RdG35QbHF93UgndaK3eSCjwMV6c=", "dev": true, "requires": { @@ -5611,7 +5611,7 @@ }, "locate-path": { "version": "2.0.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-2.0.0.tgz", "integrity": "sha1-K1aLJl7slExtnA3pw9u7ygNUzY4=", "dev": true, "requires": { @@ -5621,7 +5621,7 @@ }, "p-limit": { "version": "1.3.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-1.3.0.tgz", "integrity": "sha512-vvcXsLAJ9Dr5rQOPk7toZQZJApBl2K4J6dANSsEuh6QI41JYcsS/qhTGa9ErIUUgK3WNQoJYvylxvjqmiqEA9Q==", "dev": true, "requires": { @@ -5630,7 +5630,7 @@ }, "p-locate": { "version": "2.0.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-2.0.0.tgz", "integrity": "sha1-IKAQOyIqcMj9OcwuWAaA893l7EM=", "dev": true, "requires": { @@ -5639,7 +5639,7 @@ }, "p-try": { "version": "1.0.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/p-try/-/p-try-1.0.0.tgz", "integrity": "sha1-y8ec26+P1CKOE/Yh8rGiN8GyB7M=", "dev": true } @@ -5647,7 +5647,7 @@ }, "yargs-parser": { "version": "9.0.2", - "resolved": false, + "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-9.0.2.tgz", "integrity": "sha1-nM9qQ0YP5O1Aqbto9I1DuKaMwHc=", "dev": true, "requires": { @@ -5656,7 +5656,7 @@ "dependencies": { "camelcase": { "version": "4.1.0", - "resolved": false, + "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-4.1.0.tgz", "integrity": "sha1-1UVjW+HjPFQmScaRc+Xeas+uNN0=", "dev": true } @@ -5884,7 +5884,7 @@ }, "path-is-absolute": { "version": "1.0.1", - "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", + "resolved": "http://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=" }, "path-key": { @@ -6349,7 +6349,7 @@ }, "safe-regex": { "version": "1.1.0", - "resolved": "https://registry.npmjs.org/safe-regex/-/safe-regex-1.1.0.tgz", + "resolved": "http://registry.npmjs.org/safe-regex/-/safe-regex-1.1.0.tgz", "integrity": "sha1-QKNmnzsHfR6UPURinhV91IAjvy4=", "requires": { "ret": "~0.1.10" @@ -6830,7 +6830,7 @@ }, "stream-browserify": { "version": "2.0.1", - "resolved": "https://registry.npmjs.org/stream-browserify/-/stream-browserify-2.0.1.tgz", + "resolved": "http://registry.npmjs.org/stream-browserify/-/stream-browserify-2.0.1.tgz", "integrity": "sha1-ZiZu5fm9uZQKTkUUyvtDu3Hlyds=", "requires": { "inherits": "~2.0.1", @@ -6903,7 +6903,7 @@ }, "strip-eof": { "version": "1.0.0", - "resolved": "https://registry.npmjs.org/strip-eof/-/strip-eof-1.0.0.tgz", + "resolved": "http://registry.npmjs.org/strip-eof/-/strip-eof-1.0.0.tgz", "integrity": "sha1-u0P/VZim6wXYm1n80SnJgzE2Br8=" }, "strip-hex-prefix": { @@ -6989,7 +6989,7 @@ }, "tar": { "version": "2.2.1", - "resolved": "https://registry.npmjs.org/tar/-/tar-2.2.1.tgz", + "resolved": "http://registry.npmjs.org/tar/-/tar-2.2.1.tgz", "integrity": "sha1-jk0qJWwOIYXGsYrWlK7JaLg8sdE=", "requires": { "block-stream": "*", @@ -7228,9 +7228,9 @@ "integrity": "sha512-c3zayb8/kWWpycWYg87P71E1S1ZL6b6IJxfb5fvsUgsf0S2MVGaDhDXXjDMpdCpfWXqptc+4mXwmiy1ypXqRAA==" }, "ts-loader": { - "version": "5.3.0", - "resolved": "https://registry.npmjs.org/ts-loader/-/ts-loader-5.3.0.tgz", - "integrity": "sha512-lGSNs7szRFj/rK9T1EQuayE3QNLg6izDUxt5jpmq0RG1rU2bapAt7E7uLckLCUPeO1jwxCiet2oRaWovc53UAg==", + "version": "5.3.1", + "resolved": "https://registry.npmjs.org/ts-loader/-/ts-loader-5.3.1.tgz", + "integrity": "sha512-fDDgpBH3SR8xlt2MasLdz3Yy611PQ/UY/KGyo7TgXhTRU/6sS8uGG0nJYnU1OdFBNKcoYbId1UTNaAOUn+i41g==", "dev": true, "requires": { "chalk": "^2.3.0", @@ -7766,7 +7766,7 @@ }, "utf8": { "version": "2.1.1", - "resolved": "https://registry.npmjs.org/utf8/-/utf8-2.1.1.tgz", + "resolved": "http://registry.npmjs.org/utf8/-/utf8-2.1.1.tgz", "integrity": "sha1-LgHbAvfY0JRPdxBPFgnrDDBM92g=" }, "util": { diff --git a/package.json b/package.json index 250db18..d84d6b5 100644 --- a/package.json +++ b/package.json @@ -51,7 +51,7 @@ }, "homepage": "https://github.com/oceanprotocol/squid-js#readme", "dependencies": { - "@oceanprotocol/keeper-contracts": "0.3.25", + "@oceanprotocol/keeper-contracts": "0.4.0", "@oceanprotocol/secret-store-client": "0.0.12", "bignumber.js": "^8.0.1", "eth-crypto": "^1.2.7", @@ -74,7 +74,7 @@ "nyc": "^13.1.0", "rollup": "^0.67.3", "source-map-support": "^0.5.9", - "ts-loader": "^5.3.0", + "ts-loader": "^5.3.1", "ts-node": "^7.0.1", "tslint": "^5.11.0", "typedoc": "^0.13.0", From 09812897458192d3014fcf9b75c276d4abc7ee99 Mon Sep 17 00:00:00 2001 From: Sebastian Gerske Date: Tue, 27 Nov 2018 12:27:15 +0100 Subject: [PATCH 20/53] changed formatting --- src/ocean/Account.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/ocean/Account.ts b/src/ocean/Account.ts index ccafbf7..f85dcf1 100644 --- a/src/ocean/Account.ts +++ b/src/ocean/Account.ts @@ -14,7 +14,9 @@ export default class Account extends OceanBase { public async getEtherBalance(): Promise { // Logger.log("getting balance for", account); - return Web3Provider.getWeb3().eth + return Web3Provider + .getWeb3() + .eth .getBalance(this.id, "latest") .then((balance: string): number => { // Logger.log("balance", balance); @@ -35,7 +37,9 @@ export default class Account extends OceanBase { } public async requestTokens(amount: number): Promise { - await (await Keeper.getInstance()).market.requestTokens(amount, this.id) + await (await Keeper.getInstance()) + .market + .requestTokens(amount, this.id) return amount } From 8d2b9c62f2aa0288787ec02db84125fe3ad7132c Mon Sep 17 00:00:00 2001 From: Sebastian Gerske Date: Tue, 27 Nov 2018 13:38:18 +0100 Subject: [PATCH 21/53] fix fire lazers --- src/examples/BuyAsset.ts | 16 ++++------------ src/examples/ExecuteAgreement.ts | 12 ++---------- src/examples/GetAccounts.ts | 10 ++++++++++ src/examples/GetBalance.ts | 10 ++++++++++ src/examples/GrantAccess.ts | 12 ++---------- src/examples/InitializeAgreement.ts | 12 ++---------- src/examples/Listener.ts | 12 ++---------- src/examples/RegisterAsset.ts | 12 ++---------- .../RegisterServiceAgreementTemplates.ts | 12 ++---------- src/examples/Search.ts | 12 ++---------- src/examples/SignAgreement.ts | 12 ++---------- src/examples/config.json | 10 ++++++++++ src/examples/fire_lazers.sh | 11 +++++++---- 13 files changed, 57 insertions(+), 96 deletions(-) create mode 100644 src/examples/GetAccounts.ts create mode 100644 src/examples/GetBalance.ts create mode 100644 src/examples/config.json diff --git a/src/examples/BuyAsset.ts b/src/examples/BuyAsset.ts index 8aa1721..3c591d9 100644 --- a/src/examples/BuyAsset.ts +++ b/src/examples/BuyAsset.ts @@ -3,18 +3,10 @@ import MetaData from "../ddo/MetaData" import MetaDataBase from "../ddo/MetaDataBase" import Service from "../ddo/Service" import {Account, Logger, Ocean, ServiceAgreement} from "../squid" +import * as config from "./config.json" (async () => { - const ocean: Ocean = await Ocean.getInstance({ - nodeUri: "http://localhost:8545", - aquariusUri: "http://localhost:5000", - brizoUri: "http://localhost:8030", - parityUri: "http://localhost:9545", - secretStoreUri: "http://localhost:12001", - threshold: 0, - password: "unittest", - address: "0xed243adfb84a6626eba46178ccb567481c6e655d", - }) + const ocean: Ocean = await Ocean.getInstance(config) const publisher: Account = (await ocean.getAccounts())[0] const consumer: Account = (await ocean.getAccounts())[1] @@ -55,6 +47,8 @@ import {Account, Logger, Ocean, ServiceAgreement} from "../squid" const accessService = ddo.findServiceByType("Access") + await consumer.requestTokens(metaData.base.price) + const serviceAgreementSignatureResult: any = await ocean.signServiceAgreement(ddo.id, accessService.serviceDefinitionId, consumer) Logger.log("ServiceAgreement Id:", serviceAgreementSignatureResult.serviceAgreementId) @@ -71,8 +65,6 @@ import {Account, Logger, Ocean, ServiceAgreement} from "../squid" publisher) Logger.log("ServiceAgreement Id:", serviceAgreement.getId()) - await consumer.requestTokens(metaData.base.price) - const paid = await serviceAgreement.payAsset(assetId, metaData.base.price, consumer) Logger.log(`Asset paid: ${paid}`) })() diff --git a/src/examples/ExecuteAgreement.ts b/src/examples/ExecuteAgreement.ts index dbbc508..84e928f 100644 --- a/src/examples/ExecuteAgreement.ts +++ b/src/examples/ExecuteAgreement.ts @@ -3,18 +3,10 @@ import MetaData from "../ddo/MetaData" import MetaDataBase from "../ddo/MetaDataBase" import Service from "../ddo/Service" import {Account, Logger, Ocean, ServiceAgreement} from "../squid" +import * as config from "./config.json" (async () => { - const ocean: Ocean = await Ocean.getInstance({ - nodeUri: "http://localhost:8545", - aquariusUri: "http://localhost:5000", - brizoUri: "http://localhost:8030", - parityUri: "http://localhost:9545", - secretStoreUri: "http://localhost:12001", - threshold: 0, - password: "unittest", - address: "0xed243adfb84a6626eba46178ccb567481c6e655d", - }) + const ocean: Ocean = await Ocean.getInstance(config) const publisher: Account = (await ocean.getAccounts())[0] const consumer: Account = (await ocean.getAccounts())[1] diff --git a/src/examples/GetAccounts.ts b/src/examples/GetAccounts.ts new file mode 100644 index 0000000..8497c91 --- /dev/null +++ b/src/examples/GetAccounts.ts @@ -0,0 +1,10 @@ +import {Logger, Ocean} from "../squid" +import * as config from "./config.json" + +(async () => { + const ocean: Ocean = await Ocean.getInstance(config) + + const accounts = await ocean.getAccounts() + + Logger.log(JSON.stringify(accounts, null, 2)) +})() diff --git a/src/examples/GetBalance.ts b/src/examples/GetBalance.ts new file mode 100644 index 0000000..85f7811 --- /dev/null +++ b/src/examples/GetBalance.ts @@ -0,0 +1,10 @@ +import {Logger, Ocean} from "../squid" +import * as config from "./config.json" + +(async () => { + const ocean: Ocean = await Ocean.getInstance(config) + + const accounts = await ocean.getAccounts() + + Logger.log(await accounts[0].getBalance()) +})() diff --git a/src/examples/GrantAccess.ts b/src/examples/GrantAccess.ts index 6d8194a..57ece2b 100644 --- a/src/examples/GrantAccess.ts +++ b/src/examples/GrantAccess.ts @@ -3,18 +3,10 @@ import MetaData from "../ddo/MetaData" import MetaDataBase from "../ddo/MetaDataBase" import Service from "../ddo/Service" import {Account, Logger, Ocean, ServiceAgreement} from "../squid" +import * as config from "./config.json" (async () => { - const ocean: Ocean = await Ocean.getInstance({ - nodeUri: "http://localhost:8545", - aquariusUri: "http://localhost:5000", - brizoUri: "http://localhost:8030", - parityUri: "http://localhost:9545", - secretStoreUri: "http://localhost:12001", - threshold: 0, - password: "unittest", - address: "0xed243adfb84a6626eba46178ccb567481c6e655d", - }) + const ocean: Ocean = await Ocean.getInstance(config) const publisher: Account = (await ocean.getAccounts())[0] const consumer: Account = (await ocean.getAccounts())[1] diff --git a/src/examples/InitializeAgreement.ts b/src/examples/InitializeAgreement.ts index 5bf417f..c7207a4 100644 --- a/src/examples/InitializeAgreement.ts +++ b/src/examples/InitializeAgreement.ts @@ -3,18 +3,10 @@ import MetaData from "../ddo/MetaData" import MetaDataBase from "../ddo/MetaDataBase" import Service from "../ddo/Service" import {Account, Logger, Ocean} from "../squid" +import * as config from "./config.json" (async () => { - const ocean: Ocean = await Ocean.getInstance({ - nodeUri: "http://localhost:8545", - aquariusUri: "http://localhost:5000", - brizoUri: "http://localhost:8030", - parityUri: "http://localhost:9545", - secretStoreUri: "http://localhost:12001", - threshold: 0, - password: "unittest", - address: "0xed243adfb84a6626eba46178ccb567481c6e655d", - }) + const ocean: Ocean = await Ocean.getInstance(config) const publisher: Account = (await ocean.getAccounts())[0] const consumer: Account = (await ocean.getAccounts())[1] diff --git a/src/examples/Listener.ts b/src/examples/Listener.ts index a4c5b76..b23cbd3 100644 --- a/src/examples/Listener.ts +++ b/src/examples/Listener.ts @@ -1,18 +1,10 @@ import {Logger, Ocean} from "../squid" // tslint:disable-next-line import EventListener from "../keeper/EventListener" +import * as config from "./config.json" (async () => { - Ocean.getInstance({ - nodeUri: "http://localhost:8545", - aquariusUri: "http://localhost:5000", - brizoUri: "http://localhost:8030", - parityUri: "http://localhost:9545", - secretStoreUri: "http://localhost:12001", - threshold: 0, - password: "unittest", - address: "0xed243adfb84a6626eba46178ccb567481c6e655d", - }) + Ocean.getInstance(config) })() const event = EventListener.subscribe("OceanToken", "Transfer", {}) diff --git a/src/examples/RegisterAsset.ts b/src/examples/RegisterAsset.ts index 292fc6e..cdb6b1f 100644 --- a/src/examples/RegisterAsset.ts +++ b/src/examples/RegisterAsset.ts @@ -2,18 +2,10 @@ import DDO from "../ddo/DDO" import MetaData from "../ddo/MetaData" import MetaDataBase from "../ddo/MetaDataBase" import {Account, Logger, Ocean} from "../squid" +import * as config from "./config.json" (async () => { - const ocean: Ocean = await Ocean.getInstance({ - nodeUri: "http://localhost:8545", - aquariusUri: "http://localhost:5000", - brizoUri: "http://localhost:8030", - parityUri: "http://localhost:9545", - secretStoreUri: "http://localhost:12001", - threshold: 0, - password: "unittest", - address: "0xed243adfb84a6626eba46178ccb567481c6e655d", - }) + const ocean: Ocean = await Ocean.getInstance(config) const publisher: Account = (await ocean.getAccounts())[0] diff --git a/src/examples/RegisterServiceAgreementTemplates.ts b/src/examples/RegisterServiceAgreementTemplates.ts index 6ffb422..497c828 100644 --- a/src/examples/RegisterServiceAgreementTemplates.ts +++ b/src/examples/RegisterServiceAgreementTemplates.ts @@ -1,16 +1,8 @@ import {Account, Logger, Ocean, ServiceAgreementTemplate, Templates} from "../squid" +import * as config from "./config.json" (async () => { - const ocean: Ocean = await Ocean.getInstance({ - nodeUri: "http://localhost:8545", - aquariusUri: "http://localhost:5000", - brizoUri: "http://localhost:8030", - parityUri: "http://localhost:9545", - secretStoreUri: "http://localhost:12001", - threshold: 0, - password: "unittest", - address: "0xed243adfb84a6626eba46178ccb567481c6e655d", - }) + const ocean: Ocean = await Ocean.getInstance(config) const templateOwner: Account = (await ocean.getAccounts())[5] diff --git a/src/examples/Search.ts b/src/examples/Search.ts index d0f0b06..8b24ad1 100644 --- a/src/examples/Search.ts +++ b/src/examples/Search.ts @@ -1,17 +1,9 @@ import DDO from "../ddo/DDO" import {Logger, Ocean} from "../squid" +import * as config from "./config.json" (async () => { - const ocean: Ocean = await Ocean.getInstance({ - nodeUri: "http://localhost:8545", - aquariusUri: "http://localhost:5000", - brizoUri: "http://localhost:8030", - parityUri: "http://localhost:9545", - secretStoreUri: "http://localhost:12001", - threshold: 0, - password: "unittest", - address: "0xed243adfb84a6626eba46178ccb567481c6e655d", - }) + const ocean: Ocean = await Ocean.getInstance(config) const result: DDO[] = await ocean.searchAssetsByText("Office Humidity") const names: string[] = result.map((ddo: DDO): string => { diff --git a/src/examples/SignAgreement.ts b/src/examples/SignAgreement.ts index 7a3b5c1..9536f43 100644 --- a/src/examples/SignAgreement.ts +++ b/src/examples/SignAgreement.ts @@ -5,18 +5,10 @@ import MetaData from "../ddo/MetaData" import MetaDataBase from "../ddo/MetaDataBase" import Service from "../ddo/Service" import {Account, Logger, Ocean} from "../squid" +import * as config from "./config.json" (async () => { - const ocean: Ocean = await Ocean.getInstance({ - nodeUri: "http://localhost:8545", - aquariusUri: "http://localhost:5000", - brizoUri: "http://localhost:8030", - parityUri: "http://localhost:9545", - secretStoreUri: "http://localhost:12001", - threshold: 0, - password: "unittest", - address: "0xed243adfb84a6626eba46178ccb567481c6e655d", - }) + const ocean: Ocean = await Ocean.getInstance(config) const publisher: Account = (await ocean.getAccounts())[0] const consumer: Account = (await ocean.getAccounts())[1] diff --git a/src/examples/config.json b/src/examples/config.json new file mode 100644 index 0000000..f6efecd --- /dev/null +++ b/src/examples/config.json @@ -0,0 +1,10 @@ +{ + "nodeUri": "http://localhost:8545", + "aquariusUri": "http://localhost:5000", + "brizoUri": "http://localhost:8030", + "parityUri": "http://localhost:8545", + "secretStoreUri": "http://localhost:12001", + "threshold": 0, + "password": "secret", + "address": "0xa99d43d86a0758d5632313b8fa3972b6088a21bb" +} diff --git a/src/examples/fire_lazers.sh b/src/examples/fire_lazers.sh index 2ace01f..8080e59 100755 --- a/src/examples/fire_lazers.sh +++ b/src/examples/fire_lazers.sh @@ -2,10 +2,13 @@ set -e +# this has to go first npm run run src/examples/RegisterServiceAgreementTemplates.ts + +npm run run src/examples/BuyAsset.ts +npm run run src/examples/ExecuteAgreement.ts +npm run run src/examples/GetAccounts.ts +npm run run src/examples/GetBalance.ts +npm run run src/examples/GrantAccess.ts npm run run src/examples/RegisterAsset.ts npm run run src/examples/Search.ts -npm run run src/examples/SignAgreement.ts -npm run run src/examples/ExecuteAgreement.ts -npm run run src/examples/BuyAsset.ts -npm run run src/examples/GrantAccess.ts From 07f347cefc0e16f41f295cef12dd811d0701ba28 Mon Sep 17 00:00:00 2001 From: Sebastian Gerske Date: Tue, 27 Nov 2018 13:55:05 +0100 Subject: [PATCH 22/53] removed test page --- test.html | 28 ---------------------------- 1 file changed, 28 deletions(-) delete mode 100644 test.html diff --git a/test.html b/test.html deleted file mode 100644 index 2a76e0d..0000000 --- a/test.html +++ /dev/null @@ -1,28 +0,0 @@ - - - - - Title - - - - - - \ No newline at end of file From 4e3005648369809d6a9aa6883aa4e85ea5f91010 Mon Sep 17 00:00:00 2001 From: Sebastian Gerske Date: Tue, 27 Nov 2018 13:57:54 +0100 Subject: [PATCH 23/53] removed config of mocked service --- test/config.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/test/config.ts b/test/config.ts index 375016e..f18bfa2 100644 --- a/test/config.ts +++ b/test/config.ts @@ -6,8 +6,4 @@ export default { nodeUri: "http://localhost:8545", parityUri: "http://localhost:9545", secretStoreUri: "http://localhost:12001", - threshold: 0, - password: "unittest", - address: "0xed243adfb84a6626eba46178ccb567481c6e655d", - web3Provider: null, } as Config From 32c7cc1f1a9946e36e5e385f10d4e389848de05a Mon Sep 17 00:00:00 2001 From: Sebastian Gerske Date: Tue, 27 Nov 2018 13:58:06 +0100 Subject: [PATCH 24/53] remove old password from config --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e2295b0..07a0eef 100644 --- a/README.md +++ b/README.md @@ -64,7 +64,7 @@ const ocean: Ocean = await Ocean.getInstance({ // the threshold of nodes from the secre store that have to agree to the decrypt threshold: 0, // the password for the account (in the local parity node) used to sign messages for secret store - password: "unittest", + password: "you password", // the address of the account (in the local parity node) used to sign messages for secret store address: "0xed243adfb84a6626eba46178ccb567481c6e655d", }) From 7829b9642045e56ef79e15f3c0d13f080d5ef940 Mon Sep 17 00:00:00 2001 From: Sebastian Gerske Date: Tue, 27 Nov 2018 14:13:51 +0100 Subject: [PATCH 25/53] fix bump version merge --- .bumpversion.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.bumpversion.cfg b/.bumpversion.cfg index 5badcd1..3ba456c 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 0.1.25 +current_version = 0.1.26 [bumpversion:file:package.json] From 0a01d0e0e77d27503750e29c3b1b276e71cb9b4a Mon Sep 17 00:00:00 2001 From: Sebastian Gerske Date: Tue, 27 Nov 2018 14:14:32 +0100 Subject: [PATCH 26/53] v0.1.27 --- .bumpversion.cfg | 2 +- package-lock.json | 2 +- package.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.bumpversion.cfg b/.bumpversion.cfg index 3ba456c..008e41a 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 0.1.26 +current_version = 0.1.27 [bumpversion:file:package.json] diff --git a/package-lock.json b/package-lock.json index 8ed5545..d47ac5e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@oceanprotocol/squid", - "version": "0.1.26", + "version": "0.1.27", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index d84d6b5..8fc64af 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@oceanprotocol/squid", - "version": "0.1.26", + "version": "0.1.27", "description": "JavaScript client library for Ocean Protocol", "main": "./dist/node/squid.js", "browser": "./dist/browser/squid.cjs2.min.js", From 2b4d45349f0e31b964c38a80ccc51fd52211a37f Mon Sep 17 00:00:00 2001 From: Sebastian Gerske Date: Wed, 28 Nov 2018 12:12:58 +0100 Subject: [PATCH 27/53] use compiled typescript instead of ts-loader to generate minified versions --- package.json | 1 - webpack.common.js | 7 +------ webpack.parts.js | 2 +- 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 8fc64af..4154174 100644 --- a/package.json +++ b/package.json @@ -74,7 +74,6 @@ "nyc": "^13.1.0", "rollup": "^0.67.3", "source-map-support": "^0.5.9", - "ts-loader": "^5.3.1", "ts-node": "^7.0.1", "tslint": "^5.11.0", "typedoc": "^0.13.0", diff --git a/webpack.common.js b/webpack.common.js index fc00627..46f5b59 100644 --- a/webpack.common.js +++ b/webpack.common.js @@ -5,17 +5,12 @@ const { paths } = require('./webpack.parts.js') module.exports = { entry: paths.entry, mode: 'none', - module: { - rules: [ - { test: /\.tsx?$/, loader: "ts-loader" } - ] - }, optimization: { minimize: true, noEmitOnErrors: true }, resolve: { - extensions: ['.js','.ts'], + extensions: ['.js'], modules: ['node_modules'], }, } diff --git a/webpack.parts.js b/webpack.parts.js index dc94126..796a5e0 100644 --- a/webpack.parts.js +++ b/webpack.parts.js @@ -9,7 +9,7 @@ const production = require('./webpack.production.js') const AddVendorsPlugin = require('./plugins/add-vendors-plugin') const paths = { - entry: path.resolve(__dirname, './src/squid.ts'), + entry: path.resolve(__dirname, './dist/node/squid.js'), bundle: path.resolve(__dirname, 'dist/browser'), } From ee45cf96c90cd314079a6aaee03a7a95696cf1f0 Mon Sep 17 00:00:00 2001 From: Sebastian Gerske Date: Wed, 28 Nov 2018 12:13:44 +0100 Subject: [PATCH 28/53] v0.1.28 --- .bumpversion.cfg | 2 +- package-lock.json | 15 +-------------- package.json | 2 +- 3 files changed, 3 insertions(+), 16 deletions(-) diff --git a/.bumpversion.cfg b/.bumpversion.cfg index 008e41a..19b1e23 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 0.1.27 +current_version = 0.1.28 [bumpversion:file:package.json] diff --git a/package-lock.json b/package-lock.json index d47ac5e..b4fc634 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@oceanprotocol/squid", - "version": "0.1.27", + "version": "0.1.28", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -7227,19 +7227,6 @@ "resolved": "https://registry.npmjs.org/tryer/-/tryer-1.0.1.tgz", "integrity": "sha512-c3zayb8/kWWpycWYg87P71E1S1ZL6b6IJxfb5fvsUgsf0S2MVGaDhDXXjDMpdCpfWXqptc+4mXwmiy1ypXqRAA==" }, - "ts-loader": { - "version": "5.3.1", - "resolved": "https://registry.npmjs.org/ts-loader/-/ts-loader-5.3.1.tgz", - "integrity": "sha512-fDDgpBH3SR8xlt2MasLdz3Yy611PQ/UY/KGyo7TgXhTRU/6sS8uGG0nJYnU1OdFBNKcoYbId1UTNaAOUn+i41g==", - "dev": true, - "requires": { - "chalk": "^2.3.0", - "enhanced-resolve": "^4.0.0", - "loader-utils": "^1.0.2", - "micromatch": "^3.1.4", - "semver": "^5.0.1" - } - }, "ts-node": { "version": "7.0.1", "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-7.0.1.tgz", diff --git a/package.json b/package.json index 4154174..9d8fda1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@oceanprotocol/squid", - "version": "0.1.27", + "version": "0.1.28", "description": "JavaScript client library for Ocean Protocol", "main": "./dist/node/squid.js", "browser": "./dist/browser/squid.cjs2.min.js", From 9cd134052c52269ae4d4cd01e0543ec2ac07b40b Mon Sep 17 00:00:00 2001 From: Sebastian Gerske Date: Wed, 28 Nov 2018 13:54:37 +0100 Subject: [PATCH 29/53] example for adding hdwallet --- src/examples/GetHDWalletAccounts.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/examples/GetHDWalletAccounts.ts diff --git a/src/examples/GetHDWalletAccounts.ts b/src/examples/GetHDWalletAccounts.ts new file mode 100644 index 0000000..ebb7b63 --- /dev/null +++ b/src/examples/GetHDWalletAccounts.ts @@ -0,0 +1,19 @@ +import * as HDWalletProvider from "truffle-hdwallet-provider" +import {Logger, Ocean} from "../squid" +import * as config from "./config.json" + +(async () => { + const seedphrase = "genuine oyster tonight funny fat chimney initial answer potato myself doll enable" + + // @ts-ignore + config.web3Provider = new HDWalletProvider( + seedphrase, + config.nodeUri, + 0, 100, + ) + const ocean: Ocean = await Ocean.getInstance(config) + + const accounts = await ocean.getAccounts() + + Logger.log(JSON.stringify(accounts, null, 2)) +})() From f65bb4e0503ec24e18d759b92a8bacebeb9cba02 Mon Sep 17 00:00:00 2001 From: Sebastian Gerske Date: Thu, 29 Nov 2018 08:44:58 +0100 Subject: [PATCH 30/53] added support for poa mainnet (core) and testnet (sokol) --- src/keeper/Keeper.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/keeper/Keeper.ts b/src/keeper/Keeper.ts index 621041a..7f62454 100644 --- a/src/keeper/Keeper.ts +++ b/src/keeper/Keeper.ts @@ -1,3 +1,4 @@ +// import Logger from "../utils/Logger" import OceanAuth from "./contracts/Auth" import AccessConditions from "./contracts/conditions/AccessConditions" import PaymentConditions from "./contracts/conditions/PaymentConditions" @@ -53,6 +54,12 @@ export default class Keeper { case 4: network = "Rinkeby" break + case 77: + network = "POA_Sokol" + break + case 99: + network = "POA_Core" + break case 42: network = "Kovan" break @@ -63,6 +70,7 @@ export default class Keeper { network = "Ocean_POA_AWS" break default: + // Logger.log(`NetworkId ${networkId} not found defaulting`) network = "Development" } return network From 9ebe43510f429c8342fac07e2f65df81621a4660 Mon Sep 17 00:00:00 2001 From: Sebastian Gerske Date: Thu, 29 Nov 2018 08:45:10 +0100 Subject: [PATCH 31/53] added logging of brizo args --- src/brizo/Brizo.ts | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/brizo/Brizo.ts b/src/brizo/Brizo.ts index f28d969..974e258 100644 --- a/src/brizo/Brizo.ts +++ b/src/brizo/Brizo.ts @@ -1,4 +1,5 @@ import Config from "../models/Config" +import Logger from "../utils/Logger" import WebServiceConnectorProvider from "../utils/WebServiceConnectorProvider" const apiPath = "/api/v1/brizo/services" @@ -31,17 +32,21 @@ export default class Brizo { signature: string, consumerAddress: string): Promise { + const args = { + did, + serviceAgreementId, + serviceDefinitionId, + signature, + consumerAddress, + } + + Logger.log(args) + return WebServiceConnectorProvider .getConnector() .post( `${this.url}${apiPath}/access/initialize`, - JSON.stringify({ - did, - serviceAgreementId, - serviceDefinitionId, - signature, - consumerAddress, - }), + decodeURI(JSON.stringify(args)), ) } From b82bfd47e4bab6aa181271872dc5f832a472710b Mon Sep 17 00:00:00 2001 From: Sebastian Gerske Date: Thu, 29 Nov 2018 09:16:01 +0100 Subject: [PATCH 32/53] add hdwallet package --- package-lock.json | 6 ++++++ package.json | 1 + 2 files changed, 7 insertions(+) diff --git a/package-lock.json b/package-lock.json index b4fc634..5a263b6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7222,6 +7222,12 @@ "integrity": "sha1-yy4SAwZ+DI3h9hQJS5/kVwTqYAM=", "dev": true }, + "truffle-hdwallet-provider": { + "version": "1.0.0-web3one.2", + "resolved": "https://registry.npmjs.org/truffle-hdwallet-provider/-/truffle-hdwallet-provider-1.0.0-web3one.2.tgz", + "integrity": "sha512-rFrGIsbTyeieSsYG/mxmQN+xH6eD/45H2q3bY7jnlex1ICWReh+gXSeIXl1MH9glFt2ESZ0gFJPZDzjfGpxUdg==", + "dev": true + }, "tryer": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/tryer/-/tryer-1.0.1.tgz", diff --git a/package.json b/package.json index 9d8fda1..55f8230 100644 --- a/package.json +++ b/package.json @@ -74,6 +74,7 @@ "nyc": "^13.1.0", "rollup": "^0.67.3", "source-map-support": "^0.5.9", + "truffle-hdwallet-provider": "^1.0.0-web3one.2", "ts-node": "^7.0.1", "tslint": "^5.11.0", "typedoc": "^0.13.0", From e433437926d7d3a7e78ef0d10a7c3aa7f8111cf7 Mon Sep 17 00:00:00 2001 From: Sebastian Gerske Date: Thu, 29 Nov 2018 16:39:48 +0100 Subject: [PATCH 33/53] keeper-contracts 0.5.0 --- package-lock.json | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index 5a263b6..e487977 100644 --- a/package-lock.json +++ b/package-lock.json @@ -136,9 +136,9 @@ "dev": true }, "@oceanprotocol/keeper-contracts": { - "version": "0.4.0", - "resolved": "https://registry.npmjs.org/@oceanprotocol/keeper-contracts/-/keeper-contracts-0.4.0.tgz", - "integrity": "sha512-fDu8uuMBf0jf2GVAxJ814avE/2+KoMbvC9i/zZ3GN0whkt50/H1wyhDzgKw3ZpviWq3ZT9UvhNgI9s8ZgejaYQ==" + "version": "0.5.0", + "resolved": "https://registry.npmjs.org/@oceanprotocol/keeper-contracts/-/keeper-contracts-0.5.0.tgz", + "integrity": "sha512-lQDFUhFgQkAnbKtH5nuYXr+IyUy4HC6Z90Ipc0T8OTS4VcvLqbt7F+24scb8W8K9p3suh+eTuEnfPIbcKJqE7A==" }, "@oceanprotocol/secret-store-client": { "version": "0.0.12", diff --git a/package.json b/package.json index 55f8230..501acf6 100644 --- a/package.json +++ b/package.json @@ -51,7 +51,7 @@ }, "homepage": "https://github.com/oceanprotocol/squid-js#readme", "dependencies": { - "@oceanprotocol/keeper-contracts": "0.4.0", + "@oceanprotocol/keeper-contracts": "0.5.0", "@oceanprotocol/secret-store-client": "0.0.12", "bignumber.js": "^8.0.1", "eth-crypto": "^1.2.7", From 6d1d14dfc432d8f99f51852664397f36073a66cd Mon Sep 17 00:00:00 2001 From: Sebastian Gerske Date: Thu, 29 Nov 2018 16:45:41 +0100 Subject: [PATCH 34/53] v0.2.0 --- .bumpversion.cfg | 2 +- package-lock.json | 2 +- package.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.bumpversion.cfg b/.bumpversion.cfg index 19b1e23..2e29434 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 0.1.28 +current_version = 0.2.0 [bumpversion:file:package.json] diff --git a/package-lock.json b/package-lock.json index e487977..062f909 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@oceanprotocol/squid", - "version": "0.1.28", + "version": "0.2.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 501acf6..4ccd40e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@oceanprotocol/squid", - "version": "0.1.28", + "version": "0.2.0", "description": "JavaScript client library for Ocean Protocol", "main": "./dist/node/squid.js", "browser": "./dist/browser/squid.cjs2.min.js", From 04c8a7fedace273e4217583a595290422a1c2f32 Mon Sep 17 00:00:00 2001 From: ssallam Date: Tue, 4 Dec 2018 21:21:13 +0100 Subject: [PATCH 35/53] Fix aquarius url and the keeper registered url type. --- src/aquarius/Aquarius.ts | 2 +- src/ocean/Ocean.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/aquarius/Aquarius.ts b/src/aquarius/Aquarius.ts index 2e6a14c..c6c24c0 100644 --- a/src/aquarius/Aquarius.ts +++ b/src/aquarius/Aquarius.ts @@ -137,6 +137,6 @@ export default class Aquarius { } public getServiceEndpoint(did) { - return `${this.url}/api/v1/provider/assets/metadata/${did}` + return `${this.url}/api/v1/aquarius/assets/metadata/${did}` } } diff --git a/src/ocean/Ocean.ts b/src/ocean/Ocean.ts index b577503..fcd2ce4 100644 --- a/src/ocean/Ocean.ts +++ b/src/ocean/Ocean.ts @@ -149,7 +149,7 @@ export default class Ocean { await didRegistry.registerAttribute( assetId, - ValueType.DID, + ValueType.URL, "Metadata", serviceEndpoint, publisher.getId()) From d4b6366a4a5626b16da8cdb39e0276782b1f7c86 Mon Sep 17 00:00:00 2001 From: Sebastian Gerske Date: Wed, 5 Dec 2018 12:40:38 +0100 Subject: [PATCH 36/53] latest adoption --- src/ddo/DDO.ts | 2 +- src/ddo/PublicKey.ts | 2 +- src/ocean/Ocean.ts | 9 ++------- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/ddo/DDO.ts b/src/ddo/DDO.ts index 2158d37..49b447f 100644 --- a/src/ddo/DDO.ts +++ b/src/ddo/DDO.ts @@ -22,7 +22,7 @@ export default class DDO { public constructor(ddo?: { id?: string, - publicKey?: any[], + publicKey?: PublicKey[], authentication?: Authentication[], service?: Service[], }) { diff --git a/src/ddo/PublicKey.ts b/src/ddo/PublicKey.ts index 4de771c..81bf2f6 100644 --- a/src/ddo/PublicKey.ts +++ b/src/ddo/PublicKey.ts @@ -1,6 +1,6 @@ export default class PublicKey { public id: string = "did:op:123456789abcdefghi#keys-1" - public type: string = "RsaVerificationKey2018" + public type: string = "Ed25519VerificationKey2018" public owner: string = "did:op:123456789abcdefghi" public publicKeyPem?: string = "-----BEGIN PUBLIC KEY...END PUBLIC KEY-----\r\n" public publicKeyBase58?: string = "H3C2AVvLMv6gmMNam3uVAjZpfkcJCwDwnZn6z3wXmqPV" diff --git a/src/ocean/Ocean.ts b/src/ocean/Ocean.ts index fcd2ce4..80d1b26 100644 --- a/src/ocean/Ocean.ts +++ b/src/ocean/Ocean.ts @@ -9,6 +9,7 @@ import DDO from "../ddo/DDO" import Event from "../ddo/Event" import EventHandlers from "../ddo/EventHandlers" import MetaData from "../ddo/MetaData" +import PublicKey from "../ddo/PublicKey" import Service from "../ddo/Service" import ContractEvent from "../keeper/Event" import Keeper from "../keeper/Keeper" @@ -90,16 +91,10 @@ export default class Ocean { publicKey: [ { id: did + "#keys-1", - }, - { type: "Ed25519VerificationKey2018", - }, - { owner: did, - }, - { publicKeyBase58: await publisher.getPublicKey(), - }, + } as PublicKey, ], service: [ { From ce7027590e9843dd84b4aace417d848e346c4bc8 Mon Sep 17 00:00:00 2001 From: Sebastian Gerske Date: Fri, 7 Dec 2018 15:19:16 +0100 Subject: [PATCH 37/53] new access template --- src/ddo/Event.ts | 6 +- src/ddo/{EventHandlers.ts => EventHandler.ts} | 2 +- src/keeper/Keeper.ts | 5 +- src/keeper/contracts/ServiceAgreement.ts | 2 + .../contracts/conditions/AccessConditions.ts | 2 + src/ocean/Ocean.ts | 8 +-- .../ServiceAgreements/Templates/Access.ts | 57 ++++++++++--------- 7 files changed, 45 insertions(+), 37 deletions(-) rename src/ddo/{EventHandlers.ts => EventHandler.ts} (79%) diff --git a/src/ddo/Event.ts b/src/ddo/Event.ts index 2ca59ba..2195acf 100644 --- a/src/ddo/Event.ts +++ b/src/ddo/Event.ts @@ -1,7 +1,7 @@ -import EventHandlers from "./EventHandlers" +import EventHandler from "./EventHandler" export default class Event { public name: string - public actorType: string[] - public handlers: EventHandlers + public actorType: string + public handler: EventHandler } diff --git a/src/ddo/EventHandlers.ts b/src/ddo/EventHandler.ts similarity index 79% rename from src/ddo/EventHandlers.ts rename to src/ddo/EventHandler.ts index 9f7e4b0..5819cda 100644 --- a/src/ddo/EventHandlers.ts +++ b/src/ddo/EventHandler.ts @@ -1,4 +1,4 @@ -export default class EventHandlers { +export default class EventHandler { public moduleName: string = "serviceAgreement" public functionName: string = "fulfillAgreement" public version: string = "0.1" diff --git a/src/keeper/Keeper.ts b/src/keeper/Keeper.ts index 7f62454..e96c08f 100644 --- a/src/keeper/Keeper.ts +++ b/src/keeper/Keeper.ts @@ -64,10 +64,11 @@ export default class Keeper { network = "Kovan" break case 8996: - network = "Ocean_POA_net_local" + network = "Spree" + // network = "ocean_poa_net_local" break case 8995: - network = "Ocean_POA_AWS" + network = "Nile" break default: // Logger.log(`NetworkId ${networkId} not found defaulting`) diff --git a/src/keeper/contracts/ServiceAgreement.ts b/src/keeper/contracts/ServiceAgreement.ts index ca2d4c7..c2637b4 100644 --- a/src/keeper/contracts/ServiceAgreement.ts +++ b/src/keeper/contracts/ServiceAgreement.ts @@ -25,6 +25,8 @@ export default class ServiceAgreement extends ContractBase { ]) } + // todo get service agreement consumer + public async getTemplateStatus(templateId: string) { return this.call("getTemplateStatus", [templateId]) diff --git a/src/keeper/contracts/conditions/AccessConditions.ts b/src/keeper/contracts/conditions/AccessConditions.ts index 6bd5e65..9eacfea 100644 --- a/src/keeper/contracts/conditions/AccessConditions.ts +++ b/src/keeper/contracts/conditions/AccessConditions.ts @@ -9,6 +9,8 @@ export default class AccessConditions extends ContractBase { return accessConditions } + // todo add check permissions proxy + public async grantAccess(serviceAgreementId: any, assetId: any, documentKeyId: any, publisherAddress: string) : Promise { return this.send("grantAccess", publisherAddress, [ diff --git a/src/ocean/Ocean.ts b/src/ocean/Ocean.ts index 80d1b26..0e2b1c3 100644 --- a/src/ocean/Ocean.ts +++ b/src/ocean/Ocean.ts @@ -7,7 +7,7 @@ import Condition from "../ddo/Condition" import Contract from "../ddo/Contract" import DDO from "../ddo/DDO" import Event from "../ddo/Event" -import EventHandlers from "../ddo/EventHandlers" +import EventHandler from "../ddo/EventHandler" import MetaData from "../ddo/MetaData" import PublicKey from "../ddo/PublicKey" import Service from "../ddo/Service" @@ -112,12 +112,12 @@ export default class Ocean { events: [ { name: "ExecuteAgreement", - actorType: ["consumer"], - handlers: { + actorType: "consumer", + handler: { moduleName: "payment", functionName: "lockPayment", version: "0.1", - } as EventHandlers, + } as EventHandler, } as Event, ], } as Contract, diff --git a/src/ocean/ServiceAgreements/Templates/Access.ts b/src/ocean/ServiceAgreements/Templates/Access.ts index 0f92da5..dabd675 100644 --- a/src/ocean/ServiceAgreements/Templates/Access.ts +++ b/src/ocean/ServiceAgreements/Templates/Access.ts @@ -18,8 +18,7 @@ export default class Access extends TemplateBase { { name: "assetId", type: "bytes32", - } as Parameter, - { + } as Parameter, { name: "price", type: "uint256", } as Parameter, @@ -38,12 +37,11 @@ export default class Access extends TemplateBase { dependencies: [], dependencyTimeoutFlags: [], isTerminalCondition: false, - } as Method, - { + } as Method, { name: "grantAccess", contractName: "AccessConditions", methodName: "grantAccess", - timeout: 10, + timeout: 0, parameters: [ { name: "assetId", @@ -55,15 +53,6 @@ export default class Access extends TemplateBase { } as Parameter, ], events: [ - { - name: "AccessGranted", - actorType: "consumer", - handler: { - moduleName: "asset", - functionName: "consumeService", - version: "0.1", - } as EventHandler, - } as Event, { name: "AccessGranted", actorType: "publisher", @@ -73,22 +62,38 @@ export default class Access extends TemplateBase { version: "0.1", } as EventHandler, } as Event, + { + name: "AccessGranted", + actorType: "consumer", + handler: { + moduleName: "accessControl", + functionName: "consumeAsset", + version: "0.1", + } as EventHandler, + } as Event, + { + name: "AccessTimeout", + actorType: "consumer", + handler: { + moduleName: "payment", + functionName: "refundPayment", + version: "0.1", + } as EventHandler, + } as Event, ], dependencies: ["lockPayment"], dependencyTimeoutFlags: [0], isTerminalCondition: false, - } as Method, - { + } as Method, { name: "releasePayment", contractName: "PaymentConditions", methodName: "releasePayment", - timeout: 10, + timeout: 0, parameters: [ { name: "assetId", type: "bytes32", - } as Parameter, - { + } as Parameter, { name: "price", type: "uint256", } as Parameter, @@ -96,7 +101,7 @@ export default class Access extends TemplateBase { events: [ { name: "PaymentReleased", - actorType: "publisher", + actorType: "consumer", handler: { moduleName: "serviceAgreement", functionName: "fulfillAgreement", @@ -107,18 +112,16 @@ export default class Access extends TemplateBase { dependencies: ["grantAccess"], dependencyTimeoutFlags: [0], isTerminalCondition: true, - } as Method, - { + } as Method, { name: "refundPayment", contractName: "PaymentConditions", methodName: "refundPayment", - timeout: 10, + timeout: 1, parameters: [ { name: "assetId", type: "bytes32", - } as Parameter, - { + } as Parameter, { name: "price", type: "uint256", } as Parameter, @@ -126,10 +129,10 @@ export default class Access extends TemplateBase { events: [ { name: "PaymentRefund", - actorType: "consumer", + actorType: "publisher", handler: { moduleName: "serviceAgreement", - functionName: "fulfillAgreement", + functionName: "terminateAgreement", version: "0.1", } as EventHandler, } as Event, From 382207b904a55fa2875591353486f79643bcb508 Mon Sep 17 00:00:00 2001 From: Sebastian Gerske Date: Fri, 7 Dec 2018 15:23:17 +0100 Subject: [PATCH 38/53] fix registering --- .../ServiceAgreements/ServiceAgreementTemplate.ts | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/ocean/ServiceAgreements/ServiceAgreementTemplate.ts b/src/ocean/ServiceAgreements/ServiceAgreementTemplate.ts index 6c8130b..e5ea68f 100644 --- a/src/ocean/ServiceAgreements/ServiceAgreementTemplate.ts +++ b/src/ocean/ServiceAgreements/ServiceAgreementTemplate.ts @@ -1,7 +1,7 @@ import DDOCondition from "../../ddo/Condition" import Dependency from "../../ddo/Dependency" import Event from "../../ddo/Event" -import EventHandlers from "../../ddo/EventHandlers" +import EventHandler from "../../ddo/EventHandler" import MetaData from "../../ddo/MetaData" import Parameter from "../../ddo/Parameter" import ContractReflector from "../../keeper/ContractReflector" @@ -108,14 +108,12 @@ export default class ServiceAgreementTemplate extends OceanBase { const events: Event[] = [ { name: "PaymentReleased", - actorType: [ - "consumer", - ], - handlers: { + actorType: "consumer", + handler: { moduleName: "serviceAgreement", functionName: "fulfillAgreement", version: "0.1", - } as EventHandlers, + } as EventHandler, } as Event, ] From 2c8546028564f81cc6ccc09cd29b99e188723e8f Mon Sep 17 00:00:00 2001 From: Sebastian Gerske Date: Fri, 7 Dec 2018 15:30:54 +0100 Subject: [PATCH 39/53] fix timeout --- src/ocean/ServiceAgreements/Templates/Access.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ocean/ServiceAgreements/Templates/Access.ts b/src/ocean/ServiceAgreements/Templates/Access.ts index dabd675..0abc776 100644 --- a/src/ocean/ServiceAgreements/Templates/Access.ts +++ b/src/ocean/ServiceAgreements/Templates/Access.ts @@ -116,7 +116,7 @@ export default class Access extends TemplateBase { name: "refundPayment", contractName: "PaymentConditions", methodName: "refundPayment", - timeout: 1, + timeout: 3, parameters: [ { name: "assetId", From 0f262f5f03e25a600ef3776c8365a35c2fa2fed5 Mon Sep 17 00:00:00 2001 From: Sebastian Gerske Date: Fri, 7 Dec 2018 16:00:33 +0100 Subject: [PATCH 40/53] map events properly --- src/ocean/ServiceAgreements/Condition.ts | 2 ++ .../ServiceAgreementTemplate.ts | 16 ++-------------- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/src/ocean/ServiceAgreements/Condition.ts b/src/ocean/ServiceAgreements/Condition.ts index b8db3d6..4af0c4e 100644 --- a/src/ocean/ServiceAgreements/Condition.ts +++ b/src/ocean/ServiceAgreements/Condition.ts @@ -1,3 +1,4 @@ +import Event from "../../ddo/Event" import MethodReflection from "../../models/MethodReflection" import Parameter from "./Parameter" @@ -8,5 +9,6 @@ export default class Condition { public dependencyTimeoutFlags: number[] public isTerminalCondition: boolean public timeout: number + public events: Event[] public parameters: Parameter[] } diff --git a/src/ocean/ServiceAgreements/ServiceAgreementTemplate.ts b/src/ocean/ServiceAgreements/ServiceAgreementTemplate.ts index e5ea68f..657aca8 100644 --- a/src/ocean/ServiceAgreements/ServiceAgreementTemplate.ts +++ b/src/ocean/ServiceAgreements/ServiceAgreementTemplate.ts @@ -1,7 +1,5 @@ import DDOCondition from "../../ddo/Condition" import Dependency from "../../ddo/Dependency" -import Event from "../../ddo/Event" -import EventHandler from "../../ddo/EventHandler" import MetaData from "../../ddo/MetaData" import Parameter from "../../ddo/Parameter" import ContractReflector from "../../keeper/ContractReflector" @@ -105,17 +103,6 @@ export default class ServiceAgreementTemplate extends OceanBase { public async getConditions(metadata: MetaData, assetId: string): Promise { const conditions = await this.blendConditions() return conditions.map((condition: Condition, index: number): DDOCondition => { - const events: Event[] = [ - { - name: "PaymentReleased", - actorType: "consumer", - handler: { - moduleName: "serviceAgreement", - functionName: "fulfillAgreement", - version: "0.1", - } as EventHandler, - } as Event, - ] const mapParameterValueToName = (name) => { @@ -159,7 +146,7 @@ export default class ServiceAgreementTemplate extends OceanBase { functionName: condition.methodReflection.methodName, index, parameters, - events, + events: condition.events, } as DDOCondition }) } @@ -172,6 +159,7 @@ export default class ServiceAgreementTemplate extends OceanBase { return { methodReflection, timeout: method.timeout, + events: method.events, parameters: method.parameters, dependencies: method.dependencies, dependencyTimeoutFlags: method.dependencyTimeoutFlags, From 2310c7103e8a5d3a4559cec51f5d472c8ada24e7 Mon Sep 17 00:00:00 2001 From: Sebastian Gerske Date: Fri, 7 Dec 2018 16:55:32 +0100 Subject: [PATCH 41/53] increase timeout --- src/ocean/ServiceAgreements/Templates/Access.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ocean/ServiceAgreements/Templates/Access.ts b/src/ocean/ServiceAgreements/Templates/Access.ts index 0abc776..b96b9bb 100644 --- a/src/ocean/ServiceAgreements/Templates/Access.ts +++ b/src/ocean/ServiceAgreements/Templates/Access.ts @@ -116,7 +116,7 @@ export default class Access extends TemplateBase { name: "refundPayment", contractName: "PaymentConditions", methodName: "refundPayment", - timeout: 3, + timeout: 10 * 60, parameters: [ { name: "assetId", From 8ab5f7408b5adaea006e1ce2b7208343aefb59f8 Mon Sep 17 00:00:00 2001 From: Sebastian Gerske Date: Fri, 7 Dec 2018 17:19:16 +0100 Subject: [PATCH 42/53] remove logging --- src/brizo/Brizo.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/brizo/Brizo.ts b/src/brizo/Brizo.ts index 974e258..2e455f8 100644 --- a/src/brizo/Brizo.ts +++ b/src/brizo/Brizo.ts @@ -1,5 +1,4 @@ import Config from "../models/Config" -import Logger from "../utils/Logger" import WebServiceConnectorProvider from "../utils/WebServiceConnectorProvider" const apiPath = "/api/v1/brizo/services" @@ -40,8 +39,6 @@ export default class Brizo { consumerAddress, } - Logger.log(args) - return WebServiceConnectorProvider .getConnector() .post( From 7b0d34a42046a7182a1c00920cd2f5819cc388d7 Mon Sep 17 00:00:00 2001 From: Sebastian Gerske Date: Fri, 7 Dec 2018 17:19:53 +0100 Subject: [PATCH 43/53] hardened event listening --- src/keeper/Event.ts | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/keeper/Event.ts b/src/keeper/Event.ts index 39d9401..6dc4207 100644 --- a/src/keeper/Event.ts +++ b/src/keeper/Event.ts @@ -1,6 +1,7 @@ import GenericContract from "./contracts/GenericContract" import EventListener from "./EventListener" import Web3Provider from "./Web3Provider" +// import Logger from "../utils/Logger" export default class Event { @@ -39,15 +40,19 @@ export default class Event { private async handler(callback: any) { const contract = await GenericContract.getInstance(this.contractName) - const events = await contract.getEventData(this.eventName, { - filter: this.filter, - fromBlock: this.lastBlock, - toBlock: "latest", - }) + try { + const events = await contract.getEventData(this.eventName, { + filter: this.filter, + fromBlock: this.lastBlock, + toBlock: "latest", + }) - if (events.length > 0) { - this.lastBlock = events[events.length - 1].blockNumber + 1 - callback(events) + if (events.length > 0) { + this.lastBlock = events[events.length - 1].blockNumber + 1 + callback(events) + } + } catch (err) { + // Logger.log("err") } } } From d221b14931c48a040842539e0ecfb746e81826a1 Mon Sep 17 00:00:00 2001 From: Sebastian Gerske Date: Fri, 7 Dec 2018 17:20:20 +0100 Subject: [PATCH 44/53] fix pay asset --- src/ocean/Ocean.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/ocean/Ocean.ts b/src/ocean/Ocean.ts index 0e2b1c3..7ef242e 100644 --- a/src/ocean/Ocean.ts +++ b/src/ocean/Ocean.ts @@ -179,14 +179,14 @@ export default class Ocean { serviceAgreementId, }) - event.listenOnce((data) => { + event.listenOnce(async (data) => { - Logger.log("Paying asset") - new ServiceAgreement(data.returnValues.serviceAgreementId) - .payAsset(id, - metadataService.metadata.base.price, - consumer, - ) + const sa: ServiceAgreement = new ServiceAgreement(data.returnValues.serviceAgreementId) + await sa.payAsset(id, + metadataService.metadata.base.price, + consumer, + ) + Logger.log("Paid asset") }) return { @@ -213,7 +213,7 @@ export default class Ocean { serviceAgreementSignature, consumer.getId()) - Logger.log(result) + Logger.log(result.status) } public async executeServiceAgreement(did: string, From 30fa16d1d5229e48fd8757d9c1819c5f8f9eb439 Mon Sep 17 00:00:00 2001 From: Sebastian Gerske Date: Fri, 7 Dec 2018 18:11:23 +0100 Subject: [PATCH 45/53] update packages --- package-lock.json | 36 +++++++++++++++++++++--------------- package.json | 10 +++++----- 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/package-lock.json b/package-lock.json index 062f909..84dd27a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -231,9 +231,9 @@ "dev": true }, "@types/node": { - "version": "10.12.10", - "resolved": "https://registry.npmjs.org/@types/node/-/node-10.12.10.tgz", - "integrity": "sha512-8xZEYckCbUVgK8Eg7lf5Iy4COKJ5uXlnIOnePN0WUwSQggy9tolM+tDJf7wMOnT/JT/W9xDYIaYggt3mRV2O5w==" + "version": "10.12.12", + "resolved": "https://registry.npmjs.org/@types/node/-/node-10.12.12.tgz", + "integrity": "sha512-Pr+6JRiKkfsFvmU/LK68oBRCQeEg36TyAbPhc2xpez24OOZZCuoIhWGTd39VZy6nGafSbxzGouFPTFD/rR1A0A==" }, "@types/shelljs": { "version": "0.8.0", @@ -6325,9 +6325,9 @@ } }, "rollup": { - "version": "0.67.3", - "resolved": "https://registry.npmjs.org/rollup/-/rollup-0.67.3.tgz", - "integrity": "sha512-TyNQCz97rKuVVbsKUTXfwIjV7UljWyTVd7cTMuE+aqlQ7WJslkYF5QaYGjMLR2BlQtUOO5CAxSVnpQ55iYp5jg==", + "version": "0.67.4", + "resolved": "https://registry.npmjs.org/rollup/-/rollup-0.67.4.tgz", + "integrity": "sha512-AVuP73mkb4BBMUmksQ3Jw0jTrBTU1i7rLiUYjFxLZGb3xiFmtVEg40oByphkZAsiL0bJC3hRAJUQos/e5EBd+w==", "dev": true, "requires": { "@types/estree": "0.0.39", @@ -7031,9 +7031,9 @@ } }, "terser": { - "version": "3.10.12", - "resolved": "https://registry.npmjs.org/terser/-/terser-3.10.12.tgz", - "integrity": "sha512-3ODPC1eVt25EVNb04s/PkHxOmzKBQUF6bwwuR6h2DbEF8/j265Y1UkwNtOk9am/pRxfJ5HPapOlUlO6c16mKQQ==", + "version": "3.11.0", + "resolved": "https://registry.npmjs.org/terser/-/terser-3.11.0.tgz", + "integrity": "sha512-5iLMdhEPIq3zFWskpmbzmKwMQixKmTYwY3Ox9pjtSklBLnHiuQ0GKJLhL1HSYtyffHM3/lDIFBnb82m9D7ewwQ==", "dev": true, "requires": { "commander": "~2.17.1", @@ -7382,6 +7382,12 @@ "requires": { "graceful-fs": "^4.1.6" } + }, + "typescript": { + "version": "3.1.6", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.1.6.tgz", + "integrity": "sha512-tDMYfVtvpb96msS1lDX9MEdHrW4yOuZ4Kdc4Him9oU796XldPYF/t2+uKoX0BBa0hXXwDlqYQbXY5Rzjzc5hBA==", + "dev": true } } }, @@ -7392,9 +7398,9 @@ "dev": true }, "typescript": { - "version": "3.1.6", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.1.6.tgz", - "integrity": "sha512-tDMYfVtvpb96msS1lDX9MEdHrW4yOuZ4Kdc4Him9oU796XldPYF/t2+uKoX0BBa0hXXwDlqYQbXY5Rzjzc5hBA==", + "version": "3.2.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.2.2.tgz", + "integrity": "sha512-VCj5UiSyHBjwfYacmDuc/NOk4QQixbE+Wn7MFJuS0nRuPQbof132Pw4u53dm264O8LPc2MVsc7RJNml5szurkg==", "dev": true }, "uglify-es": { @@ -8185,9 +8191,9 @@ "integrity": "sha512-YQ+BmxuTgd6UXZW3+ICGfyqRyHXVlD5GtQr5+qjiNW7bF0cqrzX500HVXPBOvgXb5YnzDd+h0zqyv61KUD7+Sg==" }, "webpack": { - "version": "4.26.1", - "resolved": "https://registry.npmjs.org/webpack/-/webpack-4.26.1.tgz", - "integrity": "sha512-i2oOvEvuvLLSuSCkdVrknaxAhtUZ9g+nLSoHCWV0gDzqGX2DXaCrMmMUpbRsTSSLrUqAI56PoEiyMUZIZ1msug==", + "version": "4.27.1", + "resolved": "https://registry.npmjs.org/webpack/-/webpack-4.27.1.tgz", + "integrity": "sha512-WArHiLvHrlfyRM8i7f+2SFbr/XbQ0bXqTkPF8JpHOzub5482Y3wx7rEO8stuLGOKOgZJcqcisLhD7LrM/+fVMw==", "dev": true, "requires": { "@webassemblyjs/ast": "1.7.11", diff --git a/package.json b/package.json index 4ccd40e..3674063 100644 --- a/package.json +++ b/package.json @@ -51,7 +51,7 @@ }, "homepage": "https://github.com/oceanprotocol/squid-js#readme", "dependencies": { - "@oceanprotocol/keeper-contracts": "0.5.0", + "@oceanprotocol/keeper-contracts": "^0.5.0", "@oceanprotocol/secret-store-client": "0.0.12", "bignumber.js": "^8.0.1", "eth-crypto": "^1.2.7", @@ -67,20 +67,20 @@ "devDependencies": { "@types/chai": "^4.1.7", "@types/mocha": "^5.2.5", - "@types/node": "^10.12.10", + "@types/node": "^10.12.12", "chai": "^4.2.0", "cross-env": "^5.2.0", "mocha": "^5.2.0", "nyc": "^13.1.0", - "rollup": "^0.67.3", + "rollup": "^0.67.4", "source-map-support": "^0.5.9", "truffle-hdwallet-provider": "^1.0.0-web3one.2", "ts-node": "^7.0.1", "tslint": "^5.11.0", "typedoc": "^0.13.0", - "typescript": "^3.1.6", + "typescript": "^3.2.2", "uglify-js": "^3.4.9", - "webpack": "^4.26.1", + "webpack": "^4.27.1", "webpack-cli": "^3.1.2", "webpack-concat-plugin": "^3.0.0", "webpack-merge": "^4.1.4" From 17569030054b487f1d0d87f86f924ef4116cd559 Mon Sep 17 00:00:00 2001 From: ssallam Date: Sat, 8 Dec 2018 00:46:18 +0100 Subject: [PATCH 46/53] Handle the access granted event. Invoke the consume endpoint. Fix issue in the generated serviceEndpoint. --- package-lock.json | 5 +++++ package.json | 1 + src/brizo/Brizo.ts | 4 ++-- src/examples/InitializeAgreement.ts | 7 +++--- src/ocean/Ocean.ts | 35 ++++++++++++++++++++++++++--- 5 files changed, 43 insertions(+), 9 deletions(-) diff --git a/package-lock.json b/package-lock.json index 84dd27a..9c2fa3e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2350,6 +2350,11 @@ "integrity": "sha512-vNKxJHTEKNThjfrdJwHc7brvM6eVevuO5nTj6ez8ZQ1qbXTvGthucRF7S4vf2cr71QVnT70V34v0S1DyQsti0w==", "dev": true }, + "file-saver": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/file-saver/-/file-saver-2.0.0.tgz", + "integrity": "sha512-cYM1ic5DAkg25pHKgi5f10ziAM7RJU37gaH1XQlyNDrtUnzhC/dfoV9zf2OmF0RMKi42jG5B0JWBnPQqyj/G6g==" + }, "file-type": { "version": "5.2.0", "resolved": "https://registry.npmjs.org/file-type/-/file-type-5.2.0.tgz", diff --git a/package.json b/package.json index 3674063..d518620 100644 --- a/package.json +++ b/package.json @@ -57,6 +57,7 @@ "eth-crypto": "^1.2.7", "eth-ecies": "^1.0.3", "ethereumjs-util": "^6.0.0", + "file-saver": "^2.0.0", "jsonwebtoken": "^8.4.0", "node-fetch": "^2.3.0", "uuid": "^3.3.2", diff --git a/src/brizo/Brizo.ts b/src/brizo/Brizo.ts index 2e455f8..fe7a465 100644 --- a/src/brizo/Brizo.ts +++ b/src/brizo/Brizo.ts @@ -15,8 +15,8 @@ export default class Brizo { return `${this.url}${apiPath}/access/purchase?` } - public getConsumeEndpoint(pubKey: string, serviceId: string, url: string) { - return `${this.url}${apiPath}/consume?pubKey=${pubKey}&serviceId=${serviceId}&url=${url}` + public getConsumeEndpoint() { + return `${this.url}${apiPath}/consume` } public getComputeEndpoint(pubKey: string, serviceId: string, algo: string, container: string) { diff --git a/src/examples/InitializeAgreement.ts b/src/examples/InitializeAgreement.ts index c7207a4..775bdb6 100644 --- a/src/examples/InitializeAgreement.ts +++ b/src/examples/InitializeAgreement.ts @@ -23,12 +23,11 @@ import * as config from "./config.json" copyrightHolder: "Met Office", encoding: "UTF-8", compression: "zip", - contentType: "text/csv", + contentType: "Application/pdf", // tslint:disable-next-line workExample: "stationId,latitude,longitude,datetime,temperature,humidity423432fsd,51.509865,-0.118092,2011-01-01T10:55:11+00:00,7.2,68", contentUrls: [ - "https://testocnfiles.blob.core.windows.net/testfiles/testzkp.zip", - "https://testocnfiles.blob.core.windows.net/testfiles/testzkp.zip", + "https://testocnfiles.blob.core.windows.net/testfiles/testzkp.pdf" ], links: [ {sample1: "http://data.ceda.ac.uk/badc/ukcp09/data/gridded-land-obs/gridded-land-obs-daily/"}, @@ -42,7 +41,7 @@ import * as config from "./config.json" } as MetaData) const ddo: DDO = await ocean.registerAsset(metaData, publisher) - Logger.log("did", ddo.id) + Logger.log("Registered asset with did:", ddo.id) const accessService = ddo.findServiceByType("Access") diff --git a/src/ocean/Ocean.ts b/src/ocean/Ocean.ts index 7ef242e..5f2fdae 100644 --- a/src/ocean/Ocean.ts +++ b/src/ocean/Ocean.ts @@ -24,7 +24,10 @@ import ServiceAgreement from "./ServiceAgreements/ServiceAgreement" import ServiceAgreementTemplate from "./ServiceAgreements/ServiceAgreementTemplate" import Access from "./ServiceAgreements/Templates/Access" +import { saveAs } from "file-saver" + import EventListener from "../keeper/EventListener" +import WebServiceConnectorProvider from "../utils/WebServiceConnectorProvider" export default class Ocean { @@ -100,8 +103,7 @@ export default class Ocean { { type: template.templateName, purchaseEndpoint: brizo.getPurchaseEndpoint(), - serviceEndpoint: brizo.getConsumeEndpoint(publisher.getId(), - accessServiceDefinitionId, metadata.base.contentUrls[0]), + serviceEndpoint: brizo.getConsumeEndpoint(), // the id of the service agreement? serviceDefinitionId: accessServiceDefinitionId, // the id of the service agreement template @@ -186,7 +188,34 @@ export default class Ocean { metadataService.metadata.base.price, consumer, ) - Logger.log("Paid asset") + Logger.log("Completed asset payment, now access should be granted.") + }) + const accessEvent: ContractEvent = EventListener.subscribe( + accessService.conditions[1].contractName, + accessService.conditions[1].events[1].name, {}) + accessEvent.listenOnce(async (data) => { + Logger.log("Awesome; got a AccessGranted Event. Let's download the asset files.") + const webConnector = WebServiceConnectorProvider.getConnector() + const contentUrls = await SecretStoreProvider.getSecretStore() + .decryptDocument(id, metadataService.metadata.base.contentUrls[0]) + const serviceUrl: string = accessService.serviceEndpoint + Logger.log("Consuming asset files using service url: ", serviceUrl) + for (const cUrl of contentUrls) { + let url: string = serviceUrl + `?url=${cUrl}` + url = url + `&serviceAgreementId=${serviceAgreementId}` + url = url + `&consumerAddress=${consumer.getId()}` + Logger.log("Fetching asset from: ", url) + const response: any = await webConnector.get(url) + const blob: object = await response.blob() + // Logger.log("response: ", response.headers, response) + const parts: string[] = cUrl.split("/") + const filename: string = parts[parts.length - 1] + Logger.log("got blob: ", filename, blob) + // :FIXME: this does not save the file, debug and fix + saveAs(blob, "./downloads/" + filename) + Logger.log("saved file to:", "./downloads/" + filename) + } + Logger.log("Done downloading asset files.") }) return { From 5a1016d1fbde7160176367e9709780f925d4df76 Mon Sep 17 00:00:00 2001 From: Sebastian Gerske Date: Sat, 8 Dec 2018 21:51:37 +0100 Subject: [PATCH 47/53] fixed codacy --- src/examples/InitializeAgreement.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/examples/InitializeAgreement.ts b/src/examples/InitializeAgreement.ts index 775bdb6..3c77705 100644 --- a/src/examples/InitializeAgreement.ts +++ b/src/examples/InitializeAgreement.ts @@ -27,7 +27,7 @@ import * as config from "./config.json" // tslint:disable-next-line workExample: "stationId,latitude,longitude,datetime,temperature,humidity423432fsd,51.509865,-0.118092,2011-01-01T10:55:11+00:00,7.2,68", contentUrls: [ - "https://testocnfiles.blob.core.windows.net/testfiles/testzkp.pdf" + "https://testocnfiles.blob.core.windows.net/testfiles/testzkp.pdf", ], links: [ {sample1: "http://data.ceda.ac.uk/badc/ukcp09/data/gridded-land-obs/gridded-land-obs-daily/"}, From 4f05e3f4557bcc7cb70eb75290fa6f002b95904e Mon Sep 17 00:00:00 2001 From: ssallam Date: Mon, 10 Dec 2018 00:15:40 +0100 Subject: [PATCH 48/53] fix saving downloaded file. --- package.json | 1 - src/examples/InitializeAgreement.ts | 2 +- src/examples/config.json | 8 ++++---- src/ocean/Ocean.ts | 22 ++++++++++++++++------ 4 files changed, 21 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index d518620..3674063 100644 --- a/package.json +++ b/package.json @@ -57,7 +57,6 @@ "eth-crypto": "^1.2.7", "eth-ecies": "^1.0.3", "ethereumjs-util": "^6.0.0", - "file-saver": "^2.0.0", "jsonwebtoken": "^8.4.0", "node-fetch": "^2.3.0", "uuid": "^3.3.2", diff --git a/src/examples/InitializeAgreement.ts b/src/examples/InitializeAgreement.ts index 3c77705..ef541e8 100644 --- a/src/examples/InitializeAgreement.ts +++ b/src/examples/InitializeAgreement.ts @@ -8,7 +8,7 @@ import * as config from "./config.json" (async () => { const ocean: Ocean = await Ocean.getInstance(config) - const publisher: Account = (await ocean.getAccounts())[0] + const publisher: Account = (await ocean.getAccounts())[1] const consumer: Account = (await ocean.getAccounts())[1] const metaData = new MetaData({ diff --git a/src/examples/config.json b/src/examples/config.json index f6efecd..54d38c4 100644 --- a/src/examples/config.json +++ b/src/examples/config.json @@ -1,10 +1,10 @@ { "nodeUri": "http://localhost:8545", - "aquariusUri": "http://localhost:5000", - "brizoUri": "http://localhost:8030", + "aquariusUri": "http://172.15.0.15:5000", + "brizoUri": "http://172.15.0.17:8030", "parityUri": "http://localhost:8545", "secretStoreUri": "http://localhost:12001", "threshold": 0, - "password": "secret", - "address": "0xa99d43d86a0758d5632313b8fa3972b6088a21bb" + "password": "node0", + "address": "0x00bd138abd70e2f00903268f3db08f2d25677c9e" } diff --git a/src/ocean/Ocean.ts b/src/ocean/Ocean.ts index 5f2fdae..7d7600c 100644 --- a/src/ocean/Ocean.ts +++ b/src/ocean/Ocean.ts @@ -24,7 +24,7 @@ import ServiceAgreement from "./ServiceAgreements/ServiceAgreement" import ServiceAgreementTemplate from "./ServiceAgreements/ServiceAgreementTemplate" import Access from "./ServiceAgreements/Templates/Access" -import { saveAs } from "file-saver" +import * as fs from "fs" import EventListener from "../keeper/EventListener" import WebServiceConnectorProvider from "../utils/WebServiceConnectorProvider" @@ -206,13 +206,23 @@ export default class Ocean { url = url + `&consumerAddress=${consumer.getId()}` Logger.log("Fetching asset from: ", url) const response: any = await webConnector.get(url) - const blob: object = await response.blob() - // Logger.log("response: ", response.headers, response) + const buffer: Buffer = await response.buffer() const parts: string[] = cUrl.split("/") const filename: string = parts[parts.length - 1] - Logger.log("got blob: ", filename, blob) - // :FIXME: this does not save the file, debug and fix - saveAs(blob, "./downloads/" + filename) + Logger.debug(`Got response: filename is ${filename}, url is ${response.url}`) + fs.open("./downloads/" + filename, "w", (err, fd) => { + if (err) { + throw Error("error opening file for writing." + err) + } + fs.write(fd, buffer, 0, buffer.length, null, (writeErr) => { + if (err) { + throw Error("error writing file: " + writeErr) + } + fs.close(fd, () => { + Logger.debug("file written.") + }) + }) + }) Logger.log("saved file to:", "./downloads/" + filename) } Logger.log("Done downloading asset files.") From 8c4813b9089acfc6c3bd8c2a2968458e9513be06 Mon Sep 17 00:00:00 2001 From: Sebastian Gerske Date: Mon, 10 Dec 2018 10:11:36 +0100 Subject: [PATCH 49/53] added hdwallet support to examples --- src/examples/BuyAsset.ts | 2 +- src/examples/ExecuteAgreement.ts | 3 ++- src/examples/GetAccounts.ts | 3 ++- src/examples/GetBalance.ts | 2 +- src/examples/GetHDWalletAccounts.ts | 11 +---------- src/examples/GrantAccess.ts | 2 +- src/examples/InitializeAgreement.ts | 4 +++- src/examples/Listener.ts | 2 +- src/examples/RegisterAsset.ts | 3 ++- .../RegisterServiceAgreementTemplates.ts | 7 ++++--- src/examples/Search.ts | 2 +- src/examples/SignAgreement.ts | 2 +- src/examples/config.json | 10 ---------- src/examples/config.ts | 16 ++++++++++++++++ src/examples/config/config.json | 10 ++++++++++ 15 files changed, 46 insertions(+), 33 deletions(-) delete mode 100644 src/examples/config.json create mode 100644 src/examples/config.ts create mode 100644 src/examples/config/config.json diff --git a/src/examples/BuyAsset.ts b/src/examples/BuyAsset.ts index 3c591d9..53b1376 100644 --- a/src/examples/BuyAsset.ts +++ b/src/examples/BuyAsset.ts @@ -3,7 +3,7 @@ import MetaData from "../ddo/MetaData" import MetaDataBase from "../ddo/MetaDataBase" import Service from "../ddo/Service" import {Account, Logger, Ocean, ServiceAgreement} from "../squid" -import * as config from "./config.json" +import config from "./config" (async () => { const ocean: Ocean = await Ocean.getInstance(config) diff --git a/src/examples/ExecuteAgreement.ts b/src/examples/ExecuteAgreement.ts index 84e928f..c48e783 100644 --- a/src/examples/ExecuteAgreement.ts +++ b/src/examples/ExecuteAgreement.ts @@ -3,9 +3,10 @@ import MetaData from "../ddo/MetaData" import MetaDataBase from "../ddo/MetaDataBase" import Service from "../ddo/Service" import {Account, Logger, Ocean, ServiceAgreement} from "../squid" -import * as config from "./config.json" +import config from "./config" (async () => { + const ocean: Ocean = await Ocean.getInstance(config) const publisher: Account = (await ocean.getAccounts())[0] diff --git a/src/examples/GetAccounts.ts b/src/examples/GetAccounts.ts index 8497c91..d895761 100644 --- a/src/examples/GetAccounts.ts +++ b/src/examples/GetAccounts.ts @@ -1,7 +1,8 @@ import {Logger, Ocean} from "../squid" -import * as config from "./config.json" +import config from "./config" (async () => { + const ocean: Ocean = await Ocean.getInstance(config) const accounts = await ocean.getAccounts() diff --git a/src/examples/GetBalance.ts b/src/examples/GetBalance.ts index 85f7811..1961943 100644 --- a/src/examples/GetBalance.ts +++ b/src/examples/GetBalance.ts @@ -1,5 +1,5 @@ import {Logger, Ocean} from "../squid" -import * as config from "./config.json" +import config from "./config" (async () => { const ocean: Ocean = await Ocean.getInstance(config) diff --git a/src/examples/GetHDWalletAccounts.ts b/src/examples/GetHDWalletAccounts.ts index ebb7b63..e285e2e 100644 --- a/src/examples/GetHDWalletAccounts.ts +++ b/src/examples/GetHDWalletAccounts.ts @@ -1,16 +1,7 @@ -import * as HDWalletProvider from "truffle-hdwallet-provider" import {Logger, Ocean} from "../squid" -import * as config from "./config.json" +import config from "./config" (async () => { - const seedphrase = "genuine oyster tonight funny fat chimney initial answer potato myself doll enable" - - // @ts-ignore - config.web3Provider = new HDWalletProvider( - seedphrase, - config.nodeUri, - 0, 100, - ) const ocean: Ocean = await Ocean.getInstance(config) const accounts = await ocean.getAccounts() diff --git a/src/examples/GrantAccess.ts b/src/examples/GrantAccess.ts index 57ece2b..5da474a 100644 --- a/src/examples/GrantAccess.ts +++ b/src/examples/GrantAccess.ts @@ -3,7 +3,7 @@ import MetaData from "../ddo/MetaData" import MetaDataBase from "../ddo/MetaDataBase" import Service from "../ddo/Service" import {Account, Logger, Ocean, ServiceAgreement} from "../squid" -import * as config from "./config.json" +import config from "./config" (async () => { const ocean: Ocean = await Ocean.getInstance(config) diff --git a/src/examples/InitializeAgreement.ts b/src/examples/InitializeAgreement.ts index ef541e8..8fde379 100644 --- a/src/examples/InitializeAgreement.ts +++ b/src/examples/InitializeAgreement.ts @@ -3,7 +3,7 @@ import MetaData from "../ddo/MetaData" import MetaDataBase from "../ddo/MetaDataBase" import Service from "../ddo/Service" import {Account, Logger, Ocean} from "../squid" -import * as config from "./config.json" +import config from "./config" (async () => { const ocean: Ocean = await Ocean.getInstance(config) @@ -45,6 +45,8 @@ import * as config from "./config.json" const accessService = ddo.findServiceByType("Access") + await consumer.requestTokens(100) + const serviceAgreementSignatureResult: any = await ocean .signServiceAgreement( ddo.id, diff --git a/src/examples/Listener.ts b/src/examples/Listener.ts index b23cbd3..fb460a4 100644 --- a/src/examples/Listener.ts +++ b/src/examples/Listener.ts @@ -1,7 +1,7 @@ import {Logger, Ocean} from "../squid" // tslint:disable-next-line import EventListener from "../keeper/EventListener" -import * as config from "./config.json" +import config from "./config" (async () => { Ocean.getInstance(config) diff --git a/src/examples/RegisterAsset.ts b/src/examples/RegisterAsset.ts index cdb6b1f..e13a821 100644 --- a/src/examples/RegisterAsset.ts +++ b/src/examples/RegisterAsset.ts @@ -2,9 +2,10 @@ import DDO from "../ddo/DDO" import MetaData from "../ddo/MetaData" import MetaDataBase from "../ddo/MetaDataBase" import {Account, Logger, Ocean} from "../squid" -import * as config from "./config.json" +import config from "./config" (async () => { + const ocean: Ocean = await Ocean.getInstance(config) const publisher: Account = (await ocean.getAccounts())[0] diff --git a/src/examples/RegisterServiceAgreementTemplates.ts b/src/examples/RegisterServiceAgreementTemplates.ts index 497c828..e0d23af 100644 --- a/src/examples/RegisterServiceAgreementTemplates.ts +++ b/src/examples/RegisterServiceAgreementTemplates.ts @@ -1,14 +1,15 @@ import {Account, Logger, Ocean, ServiceAgreementTemplate, Templates} from "../squid" -import * as config from "./config.json" +import config from "./config" (async () => { + const ocean: Ocean = await Ocean.getInstance(config) - const templateOwner: Account = (await ocean.getAccounts())[5] + const templateOwner: Account = (await ocean.getAccounts())[0] const serviceAgreementTemplate: ServiceAgreementTemplate = new ServiceAgreementTemplate(new Templates.Access()) const serviceAgreementRegistered: boolean = await serviceAgreementTemplate.register(templateOwner.getId()) - Logger.log("ServiceAgreement registered:", serviceAgreementRegistered, + Logger.log("ServiceAgreementTemplate registered:", serviceAgreementRegistered, "templateId:", serviceAgreementTemplate.getId()) })() diff --git a/src/examples/Search.ts b/src/examples/Search.ts index 8b24ad1..c056291 100644 --- a/src/examples/Search.ts +++ b/src/examples/Search.ts @@ -1,6 +1,6 @@ import DDO from "../ddo/DDO" import {Logger, Ocean} from "../squid" -import * as config from "./config.json" +import config from "./config" (async () => { const ocean: Ocean = await Ocean.getInstance(config) diff --git a/src/examples/SignAgreement.ts b/src/examples/SignAgreement.ts index 9536f43..80668bc 100644 --- a/src/examples/SignAgreement.ts +++ b/src/examples/SignAgreement.ts @@ -5,7 +5,7 @@ import MetaData from "../ddo/MetaData" import MetaDataBase from "../ddo/MetaDataBase" import Service from "../ddo/Service" import {Account, Logger, Ocean} from "../squid" -import * as config from "./config.json" +import config from "./config" (async () => { const ocean: Ocean = await Ocean.getInstance(config) diff --git a/src/examples/config.json b/src/examples/config.json deleted file mode 100644 index 54d38c4..0000000 --- a/src/examples/config.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "nodeUri": "http://localhost:8545", - "aquariusUri": "http://172.15.0.15:5000", - "brizoUri": "http://172.15.0.17:8030", - "parityUri": "http://localhost:8545", - "secretStoreUri": "http://localhost:12001", - "threshold": 0, - "password": "node0", - "address": "0x00bd138abd70e2f00903268f3db08f2d25677c9e" -} diff --git a/src/examples/config.ts b/src/examples/config.ts new file mode 100644 index 0000000..bddea88 --- /dev/null +++ b/src/examples/config.ts @@ -0,0 +1,16 @@ +import * as HDWalletProvider from "truffle-hdwallet-provider" +import Config from "../models/Config" +import * as config from "./config/config.json" + +if (false) { + const seedphrase = "xxx" + + // @ts-ignore + config.web3Provider = new HDWalletProvider( + seedphrase, + config.nodeUri, + 0, 10, + ) +} + +export default config as Config diff --git a/src/examples/config/config.json b/src/examples/config/config.json new file mode 100644 index 0000000..f760ba1 --- /dev/null +++ b/src/examples/config/config.json @@ -0,0 +1,10 @@ +{ + "nodeUri": "http://localhost:8545", + "aquariusUri": "http://aquarius.dev-ocean.com:5000", + "brizoUri": "http://localhost:8030", + "parityUri": "http://localhost:9545", + "secretStoreUri": "http://localhost:12001", + "threshold": 0, + "password": "secret", + "address": "0xa99d43d86a0758d5632313b8fa3972b6088a21bb" +} From 8e779a171ee2513eb0d8e38a0d9e1d0f5f382e4c Mon Sep 17 00:00:00 2001 From: Sebastian Gerske Date: Mon, 10 Dec 2018 10:28:31 +0100 Subject: [PATCH 50/53] v0.2.1 --- .bumpversion.cfg | 2 +- package-lock.json | 7 +------ package.json | 2 +- 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/.bumpversion.cfg b/.bumpversion.cfg index 2e29434..d505cfc 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 0.2.0 +current_version = 0.2.1 [bumpversion:file:package.json] diff --git a/package-lock.json b/package-lock.json index 9c2fa3e..0b84c4d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@oceanprotocol/squid", - "version": "0.2.0", + "version": "0.2.1", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -2350,11 +2350,6 @@ "integrity": "sha512-vNKxJHTEKNThjfrdJwHc7brvM6eVevuO5nTj6ez8ZQ1qbXTvGthucRF7S4vf2cr71QVnT70V34v0S1DyQsti0w==", "dev": true }, - "file-saver": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/file-saver/-/file-saver-2.0.0.tgz", - "integrity": "sha512-cYM1ic5DAkg25pHKgi5f10ziAM7RJU37gaH1XQlyNDrtUnzhC/dfoV9zf2OmF0RMKi42jG5B0JWBnPQqyj/G6g==" - }, "file-type": { "version": "5.2.0", "resolved": "https://registry.npmjs.org/file-type/-/file-type-5.2.0.tgz", diff --git a/package.json b/package.json index 3674063..acfbb67 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@oceanprotocol/squid", - "version": "0.2.0", + "version": "0.2.1", "description": "JavaScript client library for Ocean Protocol", "main": "./dist/node/squid.js", "browser": "./dist/browser/squid.cjs2.min.js", From 83ce3755885698cee52f47376f62825bc91e37b6 Mon Sep 17 00:00:00 2001 From: Sebastian Gerske Date: Mon, 10 Dec 2018 13:26:07 +0100 Subject: [PATCH 51/53] remove dead code --- src/keeper/contracts/ContractBase.ts | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/src/keeper/contracts/ContractBase.ts b/src/keeper/contracts/ContractBase.ts index a916d2a..1b23262 100644 --- a/src/keeper/contracts/ContractBase.ts +++ b/src/keeper/contracts/ContractBase.ts @@ -15,22 +15,6 @@ export default abstract class ContractBase { this.contractName = contractName } - /* - public async listenToEventOnce(eventName: string, options: any): Promise { - return new Promise((resolve, reject) => { - if (!this.contract.events[eventName]) { - throw new Error(`Event ${eventName} not found on contract ${this.contractName}`) - } - this.contract.events[eventName](options, (err) => { - reject(err) - }) - .on("data", (eventData: any) => { - resolve(eventData) - }) - }) - } - */ - public async getEventData(eventName: any, options: any): Promise { if (!this.contract.events[eventName]) { throw new Error(`Event "${eventName}" not found on contract "${this.contractName}"`) From ce009dcd94ac4523bb2d3aba3fbbd2dd555d8553 Mon Sep 17 00:00:00 2001 From: Sebastian Gerske Date: Mon, 10 Dec 2018 13:26:33 +0100 Subject: [PATCH 52/53] remove fs because it does not work in the browser --- src/ocean/Ocean.ts | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/src/ocean/Ocean.ts b/src/ocean/Ocean.ts index 7d7600c..23ee5be 100644 --- a/src/ocean/Ocean.ts +++ b/src/ocean/Ocean.ts @@ -1,3 +1,4 @@ +import {saveAs} from "file-saver" import AquariusProvider from "../aquarius/AquariusProvider" import SearchQuery from "../aquarius/query/SearchQuery" import BrizoProvider from "../brizo/BrizoProvider" @@ -24,8 +25,6 @@ import ServiceAgreement from "./ServiceAgreements/ServiceAgreement" import ServiceAgreementTemplate from "./ServiceAgreements/ServiceAgreementTemplate" import Access from "./ServiceAgreements/Templates/Access" -import * as fs from "fs" - import EventListener from "../keeper/EventListener" import WebServiceConnectorProvider from "../utils/WebServiceConnectorProvider" @@ -210,20 +209,9 @@ export default class Ocean { const parts: string[] = cUrl.split("/") const filename: string = parts[parts.length - 1] Logger.debug(`Got response: filename is ${filename}, url is ${response.url}`) - fs.open("./downloads/" + filename, "w", (err, fd) => { - if (err) { - throw Error("error opening file for writing." + err) - } - fs.write(fd, buffer, 0, buffer.length, null, (writeErr) => { - if (err) { - throw Error("error writing file: " + writeErr) - } - fs.close(fd, () => { - Logger.debug("file written.") - }) - }) - }) - Logger.log("saved file to:", "./downloads/" + filename) + const target = `${__dirname}/downloads/${filename}` + await saveAs([buffer.toString("utf8")], filename) + Logger.log("saved file to:", target) } Logger.log("Done downloading asset files.") }) From 213261bcbbb3fd416ed1d7f873c5511652d90ee3 Mon Sep 17 00:00:00 2001 From: Sebastian Gerske Date: Mon, 10 Dec 2018 13:27:41 +0100 Subject: [PATCH 53/53] added file-saver again --- package-lock.json | 5 +++++ package.json | 1 + 2 files changed, 6 insertions(+) diff --git a/package-lock.json b/package-lock.json index 0b84c4d..fdd54f5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2350,6 +2350,11 @@ "integrity": "sha512-vNKxJHTEKNThjfrdJwHc7brvM6eVevuO5nTj6ez8ZQ1qbXTvGthucRF7S4vf2cr71QVnT70V34v0S1DyQsti0w==", "dev": true }, + "file-saver": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/file-saver/-/file-saver-2.0.0.tgz", + "integrity": "sha512-cYM1ic5DAkg25pHKgi5f10ziAM7RJU37gaH1XQlyNDrtUnzhC/dfoV9zf2OmF0RMKi42jG5B0JWBnPQqyj/G6g==" + }, "file-type": { "version": "5.2.0", "resolved": "https://registry.npmjs.org/file-type/-/file-type-5.2.0.tgz", diff --git a/package.json b/package.json index acfbb67..73035b1 100644 --- a/package.json +++ b/package.json @@ -57,6 +57,7 @@ "eth-crypto": "^1.2.7", "eth-ecies": "^1.0.3", "ethereumjs-util": "^6.0.0", + "file-saver": "^2.0.0", "jsonwebtoken": "^8.4.0", "node-fetch": "^2.3.0", "uuid": "^3.3.2",