Skip to content

Commit

Permalink
allow compute status without signature
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcos20 committed Oct 22, 2020
1 parent 5577e1d commit 2371124
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 13 deletions.
14 changes: 12 additions & 2 deletions src/ocean/Compute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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[]
Expand Down
25 changes: 14 additions & 11 deletions src/provider/Provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,20 +171,24 @@ 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)}`
if (sign) {
let signatureMessage = address
signatureMessage += jobId || ''
signatureMessage += (did && `${noZeroX(did)}`) || ''
signatureMessage += this.nonce
const signature = await this.createHashSignature(consumerAccount, signatureMessage)
url += `?signature=${signature}`
url += `&documentId=${noZeroX(did)}`
} else {
url += `?documentId=${noZeroX(did)}`
}
// consitnue to construct Provider URL
url += (output && `&output=${JSON.stringify(output)}`) || ''
url += (algorithmDid && `&algorithmDid=${algorithmDid}`) || ''
url +=
Expand Down Expand Up @@ -215,7 +219,6 @@ export class Provider extends Instantiable {

// switch fetch method
let fetch

switch (method) {
case 'post':
fetch = this.ocean.utils.fetch.post(url, '')
Expand Down
9 changes: 9 additions & 0 deletions test/integration/ComputeFlow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,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)
Expand Down

0 comments on commit 2371124

Please sign in to comment.