1
0
mirror of https://github.com/oceanprotocol/ocean.js.git synced 2024-11-26 20:39:05 +01:00

Merge pull request #396 from oceanprotocol/feature/compute_job_status

allow compute status without signature
This commit is contained in:
Alex Coseru 2020-10-22 12:02:30 +03:00 committed by GitHub
commit b9ec4b4660
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 13 deletions

View File

@ -176,12 +176,14 @@ export class Compute extends Instantiable {
* @param {Account} consumerAccount The account of the consumer ordering the service.
* @param {string} did Decentralized identifier.
* @param {string} jobId The ID of the compute job to be stopped
* @param {boolean} sign If the provider request is going to be signed(default) (full status) or not (short status)
* @return {Promise<ComputeJob[]>} Returns the status
*/
public async status(
consumerAccount: Account,
did?: string,
jobId?: string
jobId?: string,
sign = true
): Promise<ComputeJob[]> {
let provider: Provider
@ -200,7 +202,15 @@ export class Compute extends Instantiable {
consumerAccount,
undefined,
undefined,
jobId
jobId,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
sign
)
return computeJobsList as ComputeJob[]

View File

@ -171,20 +171,22 @@ export class Provider extends Instantiable {
serviceType?: string,
tokenAddress?: string,
algorithmTransferTxId?: string,
algorithmDataToken?: string
algorithmDataToken?: string,
sign = true
): Promise<ComputeJob | ComputeJob[]> {
const address = consumerAccount.getId()
await this.getNonce(consumerAccount.getId())
let signatureMessage = address
signatureMessage += jobId || ''
signatureMessage += (did && `${noZeroX(did)}`) || ''
signatureMessage += this.nonce
const signature = await this.createHashSignature(consumerAccount, signatureMessage)
// construct Brizo URL
let url = this.getComputeEndpoint()
url += `?signature=${signature}`
url += `&documentId=${noZeroX(did)}`
url += `?documentId=${noZeroX(did)}`
if (sign) {
let signatureMessage = address
signatureMessage += jobId || ''
signatureMessage += (did && `${noZeroX(did)}`) || ''
signatureMessage += this.nonce
const signature = await this.createHashSignature(consumerAccount, signatureMessage)
url += `&signature=${signature}`
}
// continue to construct Provider URL
url += (output && `&output=${JSON.stringify(output)}`) || ''
url += (algorithmDid && `&algorithmDid=${algorithmDid}`) || ''
url +=
@ -215,7 +217,6 @@ export class Provider extends Instantiable {
// switch fetch method
let fetch
switch (method) {
case 'post':
fetch = this.ocean.utils.fetch.post(url, '')

View File

@ -352,7 +352,16 @@ describe('Compute flow', () => {
jobId = response.jobId
assert(response.status >= 10)
})
it('Bob should get status of a compute job without signing', async () => {
assert(jobId != null)
const response = await ocean.compute.status(bob, ddo.id, jobId, false)
assert(response[0].jobId === jobId)
})
it('should get status of all compute jobs for an address without signing', async () => {
const response = await ocean.compute.status(bob, undefined, undefined, false)
assert(response.length > 0)
})
it('Bob should get status of a compute job', async () => {
assert(jobId != null)
const response = await ocean.compute.status(bob, ddo.id, jobId)