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

add Output interface

This commit is contained in:
alexcos20 2020-02-01 16:11:06 +02:00
parent 6e2289b27d
commit 9cf716ebe4
2 changed files with 25 additions and 17 deletions

View File

@ -4,7 +4,7 @@ import { noZeroX } from '../utils'
import { Instantiable, InstantiableConfig } from '../Instantiable.abstract'
import { DDO } from '../ddo/DDO'
import { ServiceType } from '../ddo/Service'
import { ComputeJob } from '../ocean/OceanCompute'
import { ComputeJob, Output } from '../ocean/OceanCompute'
const apiPath = '/api/v1/brizo/services'
@ -117,7 +117,7 @@ export class Brizo extends Instantiable {
algorithmDid?: string,
algorithmMeta?: MetaData,
jobId?: string,
output?: Record<string, any>
output?: Output
): Promise<ComputeJob | ComputeJob[]> {
const signature = await this.createSignature(consumerAccount, serviceAgreementId)
const address = consumerAccount.getId()

View File

@ -17,6 +17,19 @@ export enum ComputeJobStatus {
Deleted
}
export interface Output {
publishAlgorithmLog?: boolean
publishOutput?: boolean
brizoAddress?: string
brizoUrl?: string
metadata?: Record<string, any>
metadataUrl?: string
nodeUri?: string
owner?: string
secretStoreUrl?: string
whitelist?: Array<string>
}
export interface ComputeJob {
owner: string
agreementId: string
@ -78,31 +91,26 @@ export class OceanCompute extends Instantiable {
* return minimal output object
* @return {Promise<Object>} Returns output object
*/
public async getminimaloutput(): Promise<Record<string, any>> {
const minimaloutput = Object()
minimaloutput.publishAlgorithmLog = false
minimaloutput.publishOutput = false
return minimaloutput
public async getminimaloutput(): Promise<Output> {
const minimaloutput: Output = {
publishAlgorithmLog: false,
publishOutput: false
}
return minimaloutput as Output
}
/**
* Check the output object and add default properties if needed
* @param {Account} consumerAccount The account of the consumer ordering the service.
* @param {Object} output Output section used for publishing the result.
* @return {Promise<Object>} Returns output object
* @return {Promise<Output>} Returns output object
*/
public async checkoutput(
consumerAccount: Account,
output?: Record<string, any>
): Promise<Record<string, any>> {
public async checkoutput(consumerAccount: Account, output?: Output): Promise<Output> {
if (!output) {
// build a minimal object and return it
return this.getminimaloutput()
}
if (
(!output.publishAlgorithmLog || output.publishAlgorithmLog === false) &&
(!output.publishOutput || output.publishOutput === false)
) {
if (!output.publishAlgorithmLog && !output.publishOutput) {
return this.getminimaloutput()
}
if (!output.brizoAddress) output.brizoAddress = this.config.brizoAddress
@ -128,7 +136,7 @@ export class OceanCompute extends Instantiable {
agreementId: string,
algorithmDid?: string,
algorithmMeta?: MetaData,
output?: Record<string, any>
output?: Output
): Promise<ComputeJob> {
output = await this.checkoutput(consumerAccount, output)
const status = await this.ocean.brizo.compute(