1
0
mirror of https://github.com/oceanprotocol-archive/squid-js.git synced 2024-02-02 15:31:51 +01:00

fixed error related to asset consuming #114

This commit is contained in:
Pedro Gutiérrez 2019-01-23 12:29:56 +01:00
parent 1ecbb69937
commit 83cf56b57e

View File

@ -245,7 +245,7 @@ export default class Ocean {
const event: ContractEvent = EventListener.subscribe( const event: ContractEvent = EventListener.subscribe(
accessService.serviceAgreementContract.contractName, accessService.serviceAgreementContract.contractName,
accessService.serviceAgreementContract.events[0].name, { accessService.serviceAgreementContract.events[0].name, {
serviceAgreementId, serviceAgreementId: `0x${serviceAgreementId}`,
}) })
event.listenOnce(async (data) => { event.listenOnce(async (data) => {
@ -296,24 +296,26 @@ export default class Ocean {
const accessEvent: ContractEvent = EventListener.subscribe( const accessEvent: ContractEvent = EventListener.subscribe(
accessService.conditions[1].contractName, accessService.conditions[1].contractName,
accessService.conditions[1].events[1].name, {}) accessService.conditions[1].events[1].name, {})
const files = new Promise(resolve => {
accessEvent.listenOnce(async () => {
Logger.log("Awesome; got a AccessGranted Event. Let's download the asset files.")
const contentUrls = await SecretStoreProvider
.getSecretStore()
.decryptDocument(d.getId(), metadataService.metadata.base.contentUrls[0])
const serviceUrl: string = accessService.serviceEndpoint
Logger.log("Consuming asset files using service url: ", serviceUrl)
const files = []
accessEvent.listenOnce(async () => { for (const cUrl of contentUrls) {
Logger.log("Awesome; got a AccessGranted Event. Let's download the asset files.") let url: string = serviceUrl + `?url=${cUrl}`
const contentUrls = await SecretStoreProvider url = url + `&serviceAgreementId=${serviceAgreementId}`
.getSecretStore() url = url + `&consumerAddress=${consumer.getId()}`
.decryptDocument(d.getId(), metadataService.metadata.base.contentUrls[0]) files.push(url)
const serviceUrl: string = accessService.serviceEndpoint }
Logger.log("Consuming asset files using service url: ", serviceUrl)
const files = []
for (const cUrl of contentUrls) { cb(files)
let url: string = serviceUrl + `?url=${cUrl}` resolve(files)
url = url + `&serviceAgreementId=${serviceAgreementId}` })
url = url + `&consumerAddress=${consumer.getId()}`
files.push(url)
}
cb(files)
}) })
await BrizoProvider await BrizoProvider
@ -324,6 +326,8 @@ export default class Ocean {
serviceDefinitionId, serviceDefinitionId,
serviceAgreementSignature, serviceAgreementSignature,
consumer.getId()) consumer.getId())
await files
} }
/** /**