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:
commit
b9ec4b4660
@ -176,12 +176,14 @@ export class Compute extends Instantiable {
|
|||||||
* @param {Account} consumerAccount The account of the consumer ordering the service.
|
* @param {Account} consumerAccount The account of the consumer ordering the service.
|
||||||
* @param {string} did Decentralized identifier.
|
* @param {string} did Decentralized identifier.
|
||||||
* @param {string} jobId The ID of the compute job to be stopped
|
* @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
|
* @return {Promise<ComputeJob[]>} Returns the status
|
||||||
*/
|
*/
|
||||||
public async status(
|
public async status(
|
||||||
consumerAccount: Account,
|
consumerAccount: Account,
|
||||||
did?: string,
|
did?: string,
|
||||||
jobId?: string
|
jobId?: string,
|
||||||
|
sign = true
|
||||||
): Promise<ComputeJob[]> {
|
): Promise<ComputeJob[]> {
|
||||||
let provider: Provider
|
let provider: Provider
|
||||||
|
|
||||||
@ -200,7 +202,15 @@ export class Compute extends Instantiable {
|
|||||||
consumerAccount,
|
consumerAccount,
|
||||||
undefined,
|
undefined,
|
||||||
undefined,
|
undefined,
|
||||||
jobId
|
jobId,
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
sign
|
||||||
)
|
)
|
||||||
|
|
||||||
return computeJobsList as ComputeJob[]
|
return computeJobsList as ComputeJob[]
|
||||||
|
@ -171,20 +171,22 @@ export class Provider extends Instantiable {
|
|||||||
serviceType?: string,
|
serviceType?: string,
|
||||||
tokenAddress?: string,
|
tokenAddress?: string,
|
||||||
algorithmTransferTxId?: string,
|
algorithmTransferTxId?: string,
|
||||||
algorithmDataToken?: string
|
algorithmDataToken?: string,
|
||||||
|
sign = true
|
||||||
): Promise<ComputeJob | ComputeJob[]> {
|
): Promise<ComputeJob | ComputeJob[]> {
|
||||||
const address = consumerAccount.getId()
|
const address = consumerAccount.getId()
|
||||||
await this.getNonce(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()
|
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 += (output && `&output=${JSON.stringify(output)}`) || ''
|
||||||
url += (algorithmDid && `&algorithmDid=${algorithmDid}`) || ''
|
url += (algorithmDid && `&algorithmDid=${algorithmDid}`) || ''
|
||||||
url +=
|
url +=
|
||||||
@ -215,7 +217,6 @@ export class Provider extends Instantiable {
|
|||||||
|
|
||||||
// switch fetch method
|
// switch fetch method
|
||||||
let fetch
|
let fetch
|
||||||
|
|
||||||
switch (method) {
|
switch (method) {
|
||||||
case 'post':
|
case 'post':
|
||||||
fetch = this.ocean.utils.fetch.post(url, '')
|
fetch = this.ocean.utils.fetch.post(url, '')
|
||||||
|
@ -352,7 +352,16 @@ describe('Compute flow', () => {
|
|||||||
jobId = response.jobId
|
jobId = response.jobId
|
||||||
assert(response.status >= 10)
|
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 () => {
|
it('Bob should get status of a compute job', async () => {
|
||||||
assert(jobId != null)
|
assert(jobId != null)
|
||||||
const response = await ocean.compute.status(bob, ddo.id, jobId)
|
const response = await ocean.compute.status(bob, ddo.id, jobId)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user