mirror of
https://github.com/oceanprotocol-archive/squid-js.git
synced 2024-02-02 15:31:51 +01:00
Merge branch 'develop' into feature/export-eventlistener
This commit is contained in:
commit
62c3e77b44
@ -1,5 +1,5 @@
|
||||
[bumpversion]
|
||||
current_version = 0.2.3
|
||||
current_version = 0.2.4
|
||||
|
||||
[bumpversion:file:package.json]
|
||||
|
||||
|
13
package-lock.json
generated
13
package-lock.json
generated
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@oceanprotocol/squid",
|
||||
"version": "0.2.3",
|
||||
"version": "0.2.4",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
@ -141,9 +141,9 @@
|
||||
"integrity": "sha512-lQDFUhFgQkAnbKtH5nuYXr+IyUy4HC6Z90Ipc0T8OTS4VcvLqbt7F+24scb8W8K9p3suh+eTuEnfPIbcKJqE7A=="
|
||||
},
|
||||
"@oceanprotocol/secret-store-client": {
|
||||
"version": "0.0.13",
|
||||
"resolved": "https://registry.npmjs.org/@oceanprotocol/secret-store-client/-/secret-store-client-0.0.13.tgz",
|
||||
"integrity": "sha512-uEofITszJh72IAHcjXBzPx1I2xAxNUJ5kEDFako9jhQqz0seR1xGP40gj/fp+cmGU8lIq30dKWeGcYZisf735Q==",
|
||||
"version": "0.0.14",
|
||||
"resolved": "https://registry.npmjs.org/@oceanprotocol/secret-store-client/-/secret-store-client-0.0.14.tgz",
|
||||
"integrity": "sha512-Yo2/9MJC1vlWXGIaU+35naYHWWYGbtzTu2t5dW4Ro1JuIRkzxfM3TSNzPUAgsCrUBUxsCsu9pd/RjvPuE45SGw==",
|
||||
"requires": {
|
||||
"node-fetch": "^2.3.0"
|
||||
}
|
||||
@ -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",
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@oceanprotocol/squid",
|
||||
"version": "0.2.3",
|
||||
"version": "0.2.4",
|
||||
"description": "JavaScript client library for Ocean Protocol",
|
||||
"main": "./dist/node/squid.js",
|
||||
"browser": "./dist/browser/squid.cjs2.min.js",
|
||||
@ -52,12 +52,11 @@
|
||||
"homepage": "https://github.com/oceanprotocol/squid-js#readme",
|
||||
"dependencies": {
|
||||
"@oceanprotocol/keeper-contracts": "~0.5.0",
|
||||
"@oceanprotocol/secret-store-client": "~0.0.13",
|
||||
"@oceanprotocol/secret-store-client": "~0.0.14",
|
||||
"bignumber.js": "^8.0.1",
|
||||
"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",
|
||||
|
@ -63,6 +63,8 @@ import config from "./config"
|
||||
service.serviceDefinitionId,
|
||||
serviceAgreementSignatureResult.serviceAgreementId,
|
||||
serviceAgreementSignatureResult.serviceAgreementSignature,
|
||||
consumer)
|
||||
(files) => Logger.log(`Got files, first files length in bytes: ${files[0].length}`),
|
||||
consumer,
|
||||
)
|
||||
|
||||
})()
|
||||
|
@ -1,4 +1,3 @@
|
||||
import {saveAs} from "file-saver"
|
||||
import AquariusProvider from "../aquarius/AquariusProvider"
|
||||
import SearchQuery from "../aquarius/query/SearchQuery"
|
||||
import BrizoProvider from "../brizo/BrizoProvider"
|
||||
@ -190,39 +189,13 @@ export default class Ocean {
|
||||
)
|
||||
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 buffer: Buffer = await response.buffer()
|
||||
const parts: string[] = cUrl.split("/")
|
||||
const filename: string = parts[parts.length - 1]
|
||||
Logger.debug(`Got response: filename is ${filename}, url is ${response.url}`)
|
||||
const target = `${__dirname}/downloads/${filename}`
|
||||
await saveAs([buffer.toString("utf8")], filename)
|
||||
Logger.log("saved file to:", target)
|
||||
}
|
||||
Logger.log("Done downloading asset files.")
|
||||
})
|
||||
|
||||
return {
|
||||
serviceAgreementId,
|
||||
serviceAgreementSignature,
|
||||
}
|
||||
} catch (err) {
|
||||
|
||||
} catch (err) {
|
||||
Logger.error("Signing ServiceAgreement failed!", err)
|
||||
}
|
||||
}
|
||||
@ -231,8 +204,47 @@ export default class Ocean {
|
||||
serviceDefinitionId: string,
|
||||
serviceAgreementId: string,
|
||||
serviceAgreementSignature: string,
|
||||
cb,
|
||||
consumer: Account) {
|
||||
const result = await BrizoProvider
|
||||
|
||||
const ddo = await AquariusProvider.getAquarius().retrieveDDO(did)
|
||||
const id = did.replace("did:op:", "")
|
||||
|
||||
const accessService: Service = ddo.findServiceByType("Access")
|
||||
const metadataService: Service = ddo.findServiceByType("Metadata")
|
||||
|
||||
const accessEvent: ContractEvent = EventListener.subscribe(
|
||||
accessService.conditions[1].contractName,
|
||||
accessService.conditions[1].events[1].name, {})
|
||||
|
||||
accessEvent.listenOnce(async () => {
|
||||
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)
|
||||
const files = []
|
||||
|
||||
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 responseBuffer: Buffer = await response.buffer()
|
||||
const urlParts: string[] = cUrl.split("/")
|
||||
const filename: string = urlParts[urlParts.length - 1]
|
||||
Logger.debug(`Got response: filename is ${filename}, url is ${response.url}`)
|
||||
files.push(responseBuffer.toString("utf8"))
|
||||
}
|
||||
Logger.log("Done downloading asset files.")
|
||||
|
||||
cb(files)
|
||||
})
|
||||
|
||||
await BrizoProvider
|
||||
.getBrizo()
|
||||
.initializeServiceAgreement(
|
||||
did,
|
||||
@ -240,8 +252,6 @@ export default class Ocean {
|
||||
serviceDefinitionId,
|
||||
serviceAgreementSignature,
|
||||
consumer.getId())
|
||||
|
||||
Logger.log(result.status)
|
||||
}
|
||||
|
||||
public async executeServiceAgreement(did: string,
|
||||
|
@ -109,6 +109,12 @@ export default class ServiceAgreement extends OceanBase {
|
||||
throw new Error(`TemplateId not found in service "${service.type}" ddo.`)
|
||||
}
|
||||
|
||||
const templateActive = await serviceAgreement.getTemplateStatus(service.templateId)
|
||||
|
||||
if (!templateActive) {
|
||||
throw new Error(`Template with id ${service.templateId} is not active.`)
|
||||
}
|
||||
|
||||
const executeAgreementReceipt = await serviceAgreement
|
||||
.executeAgreement(
|
||||
service.templateId,
|
||||
|
Loading…
Reference in New Issue
Block a user