mirror of
https://github.com/oceanprotocol-archive/squid-js.git
synced 2024-02-02 15:31:51 +01:00
Merge pull request #381 from oceanprotocol/feature/compute_service
Feature/compute service
This commit is contained in:
commit
6a67b08314
@ -2,7 +2,7 @@ import { TransactionReceipt } from 'web3-core'
|
|||||||
import { SearchQuery } from '../aquarius/Aquarius'
|
import { SearchQuery } from '../aquarius/Aquarius'
|
||||||
import { DDO } from '../ddo/DDO'
|
import { DDO } from '../ddo/DDO'
|
||||||
import { MetaData } from '../ddo/MetaData'
|
import { MetaData } from '../ddo/MetaData'
|
||||||
import { Service } from '../ddo/Service'
|
import { Service, ServiceAccess } from '../ddo/Service'
|
||||||
import Account from './Account'
|
import Account from './Account'
|
||||||
import DID from './DID'
|
import DID from './DID'
|
||||||
import { fillConditionsWithDDO, SubscribablePromise } from '../utils'
|
import { fillConditionsWithDDO, SubscribablePromise } from '../utils'
|
||||||
@ -76,6 +76,16 @@ export class OceanAssets extends Instantiable {
|
|||||||
this.logger.log('Files encrypted')
|
this.logger.log('Files encrypted')
|
||||||
observer.next(CreateProgressStep.FilesEncrypted)
|
observer.next(CreateProgressStep.FilesEncrypted)
|
||||||
|
|
||||||
|
// make sure that access service is defined if services is empty
|
||||||
|
if (services.length === 0) {
|
||||||
|
const accessService = await this.createAccessServiceAttributes(
|
||||||
|
publisher,
|
||||||
|
metadata.main.price,
|
||||||
|
metadata.main.datePublished
|
||||||
|
)
|
||||||
|
services.push(accessService)
|
||||||
|
}
|
||||||
|
|
||||||
const serviceAgreementTemplate = await templates.escrowAccessSecretStoreTemplate.getServiceAgreementTemplate()
|
const serviceAgreementTemplate = await templates.escrowAccessSecretStoreTemplate.getServiceAgreementTemplate()
|
||||||
|
|
||||||
const serviceEndpoint = this.ocean.aquarius.getServiceEndpoint(did)
|
const serviceEndpoint = this.ocean.aquarius.getServiceEndpoint(did)
|
||||||
@ -98,21 +108,6 @@ export class OceanAssets extends Instantiable {
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
service: [
|
service: [
|
||||||
{
|
|
||||||
type: 'access',
|
|
||||||
serviceEndpoint: this.ocean.brizo.getConsumeEndpoint(),
|
|
||||||
templateId: templates.escrowAccessSecretStoreTemplate.getId(),
|
|
||||||
attributes: {
|
|
||||||
main: {
|
|
||||||
creator: publisher.getId(),
|
|
||||||
datePublished: metadata.main.datePublished,
|
|
||||||
name: 'dataAssetAccessServiceAgreement',
|
|
||||||
price: metadata.main.price,
|
|
||||||
timeout: 3600
|
|
||||||
},
|
|
||||||
serviceAgreementTemplate
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
type: 'authorization',
|
type: 'authorization',
|
||||||
service: 'SecretStore',
|
service: 'SecretStore',
|
||||||
@ -396,4 +391,29 @@ export class OceanAssets extends Instantiable {
|
|||||||
}
|
}
|
||||||
} as SearchQuery)
|
} as SearchQuery)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async createAccessServiceAttributes(
|
||||||
|
consumerAccount: Account,
|
||||||
|
price: string,
|
||||||
|
datePublished: string
|
||||||
|
): Promise<ServiceAccess> {
|
||||||
|
const { templates } = this.ocean.keeper
|
||||||
|
const serviceAgreementTemplate = await templates.escrowAccessSecretStoreTemplate.getServiceAgreementTemplate()
|
||||||
|
return {
|
||||||
|
type: 'access',
|
||||||
|
index: 2,
|
||||||
|
serviceEndpoint: this.ocean.brizo.getConsumeEndpoint(),
|
||||||
|
templateId: templates.escrowAccessSecretStoreTemplate.getId(),
|
||||||
|
attributes: {
|
||||||
|
main: {
|
||||||
|
creator: consumerAccount.getId(),
|
||||||
|
datePublished,
|
||||||
|
price,
|
||||||
|
timeout: 3600,
|
||||||
|
name: 'dataAssetAccessServiceAgreement'
|
||||||
|
},
|
||||||
|
serviceAgreementTemplate
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import { DDO } from '../ddo/DDO'
|
|||||||
import { SubscribablePromise } from '../utils'
|
import { SubscribablePromise } from '../utils'
|
||||||
import { OrderProgressStep } from './utils/ServiceUtils'
|
import { OrderProgressStep } from './utils/ServiceUtils'
|
||||||
import { DID } from '../squid'
|
import { DID } from '../squid'
|
||||||
|
import { ServiceCompute } from '../ddo/Service'
|
||||||
|
|
||||||
export const ComputeJobStatus = Object.freeze({
|
export const ComputeJobStatus = Object.freeze({
|
||||||
Started: 10,
|
Started: 10,
|
||||||
@ -261,4 +262,30 @@ export class OceanCompute extends Instantiable {
|
|||||||
|
|
||||||
return computeJobsList[0] as ComputeJob
|
return computeJobsList[0] as ComputeJob
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async createComputeServiceAttributes(
|
||||||
|
consumerAccount: Account,
|
||||||
|
price: string,
|
||||||
|
datePublished: string
|
||||||
|
): Promise<ServiceCompute> {
|
||||||
|
const { templates } = this.ocean.keeper
|
||||||
|
const serviceAgreementTemplate = await templates.escrowComputeExecutionTemplate.getServiceAgreementTemplate()
|
||||||
|
const name = 'dataAssetComputingServiceAgreement'
|
||||||
|
return {
|
||||||
|
type: 'compute',
|
||||||
|
index: 3,
|
||||||
|
serviceEndpoint: this.ocean.brizo.getComputeEndpoint(),
|
||||||
|
templateId: templates.escrowComputeExecutionTemplate.getId(),
|
||||||
|
attributes: {
|
||||||
|
main: {
|
||||||
|
creator: consumerAccount.getId(),
|
||||||
|
datePublished,
|
||||||
|
price,
|
||||||
|
timeout: 3600,
|
||||||
|
name
|
||||||
|
},
|
||||||
|
serviceAgreementTemplate
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ import {
|
|||||||
Config,
|
Config,
|
||||||
MetaDataAlgorithm
|
MetaDataAlgorithm
|
||||||
} from '../../../src'
|
} from '../../../src'
|
||||||
import { getMetadata, createComputeService } from '../utils'
|
import { getMetadata } from '../utils'
|
||||||
import { ServiceCompute } from '../../../src/ddo/Service'
|
import { ServiceCompute } from '../../../src/ddo/Service'
|
||||||
|
|
||||||
const metadataAsset = getMetadata()
|
const metadataAsset = getMetadata()
|
||||||
@ -37,12 +37,6 @@ describe('Compute', () => {
|
|||||||
before(async () => {
|
before(async () => {
|
||||||
ocean = await Ocean.getInstance(customConfig)
|
ocean = await Ocean.getInstance(customConfig)
|
||||||
;[account] = await ocean.accounts.list()
|
;[account] = await ocean.accounts.list()
|
||||||
computeService = await createComputeService(
|
|
||||||
ocean,
|
|
||||||
account,
|
|
||||||
'1000',
|
|
||||||
metadataAsset.main.datePublished
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should authenticate the consumer account', async () => {
|
it('should authenticate the consumer account', async () => {
|
||||||
@ -51,7 +45,11 @@ describe('Compute', () => {
|
|||||||
|
|
||||||
it('should publish a dataset with a compute service object', async () => {
|
it('should publish a dataset with a compute service object', async () => {
|
||||||
const stepsAsset = []
|
const stepsAsset = []
|
||||||
|
computeService = await ocean.compute.createComputeServiceAttributes(
|
||||||
|
account,
|
||||||
|
'1000',
|
||||||
|
metadataAsset.main.datePublished
|
||||||
|
)
|
||||||
dataset = await ocean.assets
|
dataset = await ocean.assets
|
||||||
.create(metadataAsset as MetaData, account, [computeService])
|
.create(metadataAsset as MetaData, account, [computeService])
|
||||||
.next(step => stepsAsset.push(step))
|
.next(step => stepsAsset.push(step))
|
||||||
|
@ -77,31 +77,3 @@ export const generateMetadata = (
|
|||||||
|
|
||||||
export const getMetadata = (price?: number, type?: 'dataset' | 'algorithm') =>
|
export const getMetadata = (price?: number, type?: 'dataset' | 'algorithm') =>
|
||||||
generateMetadata('TestAsset', type, price)
|
generateMetadata('TestAsset', type, price)
|
||||||
|
|
||||||
export const createComputeService = async (
|
|
||||||
ocean: Ocean,
|
|
||||||
publisher: Account,
|
|
||||||
price: string,
|
|
||||||
datePublished: string
|
|
||||||
): Promise<ServiceCompute> => {
|
|
||||||
const { templates } = ocean.keeper
|
|
||||||
const serviceAgreementTemplate = await templates.escrowComputeExecutionTemplate.getServiceAgreementTemplate()
|
|
||||||
|
|
||||||
const name = 'dataAssetComputingServiceAgreement'
|
|
||||||
return {
|
|
||||||
type: 'compute',
|
|
||||||
index: 3,
|
|
||||||
serviceEndpoint: ocean.brizo.getComputeEndpoint(),
|
|
||||||
templateId: templates.escrowComputeExecutionTemplate.getId(),
|
|
||||||
attributes: {
|
|
||||||
main: {
|
|
||||||
creator: publisher.getId(),
|
|
||||||
datePublished,
|
|
||||||
price,
|
|
||||||
timeout: 3600,
|
|
||||||
name
|
|
||||||
},
|
|
||||||
serviceAgreementTemplate
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user