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 { DDO } from '../ddo/DDO'
|
||||
import { MetaData } from '../ddo/MetaData'
|
||||
import { Service } from '../ddo/Service'
|
||||
import { Service, ServiceAccess } from '../ddo/Service'
|
||||
import Account from './Account'
|
||||
import DID from './DID'
|
||||
import { fillConditionsWithDDO, SubscribablePromise } from '../utils'
|
||||
@ -76,6 +76,16 @@ export class OceanAssets extends Instantiable {
|
||||
this.logger.log('Files encrypted')
|
||||
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 serviceEndpoint = this.ocean.aquarius.getServiceEndpoint(did)
|
||||
@ -98,21 +108,6 @@ export class OceanAssets extends Instantiable {
|
||||
}
|
||||
],
|
||||
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',
|
||||
service: 'SecretStore',
|
||||
@ -396,4 +391,29 @@ export class OceanAssets extends Instantiable {
|
||||
}
|
||||
} 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 { OrderProgressStep } from './utils/ServiceUtils'
|
||||
import { DID } from '../squid'
|
||||
import { ServiceCompute } from '../ddo/Service'
|
||||
|
||||
export const ComputeJobStatus = Object.freeze({
|
||||
Started: 10,
|
||||
@ -261,4 +262,30 @@ export class OceanCompute extends Instantiable {
|
||||
|
||||
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,
|
||||
MetaDataAlgorithm
|
||||
} from '../../../src'
|
||||
import { getMetadata, createComputeService } from '../utils'
|
||||
import { getMetadata } from '../utils'
|
||||
import { ServiceCompute } from '../../../src/ddo/Service'
|
||||
|
||||
const metadataAsset = getMetadata()
|
||||
@ -37,12 +37,6 @@ describe('Compute', () => {
|
||||
before(async () => {
|
||||
ocean = await Ocean.getInstance(customConfig)
|
||||
;[account] = await ocean.accounts.list()
|
||||
computeService = await createComputeService(
|
||||
ocean,
|
||||
account,
|
||||
'1000',
|
||||
metadataAsset.main.datePublished
|
||||
)
|
||||
})
|
||||
|
||||
it('should authenticate the consumer account', async () => {
|
||||
@ -51,7 +45,11 @@ describe('Compute', () => {
|
||||
|
||||
it('should publish a dataset with a compute service object', async () => {
|
||||
const stepsAsset = []
|
||||
|
||||
computeService = await ocean.compute.createComputeServiceAttributes(
|
||||
account,
|
||||
'1000',
|
||||
metadataAsset.main.datePublished
|
||||
)
|
||||
dataset = await ocean.assets
|
||||
.create(metadataAsset as MetaData, account, [computeService])
|
||||
.next(step => stepsAsset.push(step))
|
||||
|
@ -77,31 +77,3 @@ export const generateMetadata = (
|
||||
|
||||
export const getMetadata = (price?: number, type?: 'dataset' | 'algorithm') =>
|
||||
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