ddo updates

This commit is contained in:
Matthias Kretschmann 2021-11-11 09:22:22 +00:00
parent a865556394
commit 4e985ba633
Signed by: m
GPG Key ID: 606EEEF3C479A91F
11 changed files with 78 additions and 75 deletions

View File

@ -81,7 +81,7 @@ function usePublish(): UsePublish {
new Date(Date.now()).toISOString().split('.')[0] + 'Z' new Date(Date.now()).toISOString().split('.')[0] + 'Z'
const services: Service[] = [] const services: Service[] = []
const price = '1' const price = '1'
asset.created = publishedDate asset.metadata.created = publishedDate
switch (serviceType) { switch (serviceType) {
case 'access': { case 'access': {

View File

@ -10,6 +10,8 @@ interface MetadataAlgorithm {
} }
interface Metadata { interface Metadata {
created: string
updated: string
name: string name: string
description: string description: string
type: 'dataset' | 'algorithm' type: 'dataset' | 'algorithm'

View File

@ -4,7 +4,13 @@ interface PublisherTrustedAlgorithm {
containerSectionChecksum: string containerSectionChecksum: string
} }
interface ServiceComputePrivacy { interface ServiceComputeOptions {
namespace: string
cpu?: number
gpu?: number
gpuType?: string
memory?: string
volumeSize?: string
allowRawAlgorithm: boolean allowRawAlgorithm: boolean
allowNetworkAccess: boolean allowNetworkAccess: boolean
publisherTrustedAlgorithmPublishers: string[] publisherTrustedAlgorithmPublishers: string[]
@ -19,5 +25,5 @@ interface Service {
timeout: string timeout: string
name?: string name?: string
description?: string description?: string
privacy?: ServiceComputePrivacy compute?: ServiceComputeOptions
} }

View File

@ -4,8 +4,6 @@ interface DDO {
id: string id: string
version: string version: string
chainId: number chainId: number
created: string
updated?: string
metadata: Metadata metadata: Metadata
services: Service[] services: Service[]
credentials?: Credentials credentials?: Credentials

View File

@ -1,5 +1,4 @@
import slugify from 'slugify' import slugify from 'slugify'
import { MetadataAlgorithm } from '@oceanprotocol/lib'
export function getServiceByName( export function getServiceByName(
ddo: Asset | DDO, ddo: Asset | DDO,
@ -80,25 +79,7 @@ export function checkIfTimeoutInPredefinedValues(
return false return false
} }
export function getAlgorithmComponent( export function getUrlFileExtension(fileUrl: string): string {
image: string,
containerTag: string,
entrypoint: string,
algorithmLanguage: string
): MetadataAlgorithm {
return {
language: algorithmLanguage,
format: 'docker-image',
version: '0.1',
container: {
entrypoint: entrypoint,
image: image,
tag: containerTag
}
}
}
export function getAlgorithmFileExtension(fileUrl: string): string {
const splitedFileUrl = fileUrl.split('.') const splitedFileUrl = fileUrl.split('.')
return splitedFileUrl[splitedFileUrl.length - 1] return splitedFileUrl[splitedFileUrl.length - 1]
} }

View File

@ -139,15 +139,15 @@ export default function Compute({
const computeService = ddo.services[0] const computeService = ddo.services[0]
let algorithmSelectionList: AssetSelectionAsset[] let algorithmSelectionList: AssetSelectionAsset[]
if ( if (
!computeService.privacy || !computeService.compute ||
!computeService.privacy.publisherTrustedAlgorithms || !computeService.compute.publisherTrustedAlgorithms ||
computeService.privacy.publisherTrustedAlgorithms.length === 0 computeService.compute.publisherTrustedAlgorithms.length === 0
) { ) {
algorithmSelectionList = [] algorithmSelectionList = []
} else { } else {
const gueryResults = await queryMetadata( const gueryResults = await queryMetadata(
getQuerryString( getQuerryString(
computeService.privacy.publisherTrustedAlgorithms, computeService.compute.publisherTrustedAlgorithms,
ddo.chainId ddo.chainId
), ),
source.token source.token

View File

@ -35,7 +35,7 @@ export default function FormEditComputeDataset({
const { publisherTrustedAlgorithms } = getServiceByName( const { publisherTrustedAlgorithms } = getServiceByName(
ddo, ddo,
'compute' 'compute'
).privacy ).compute
async function getAlgorithmList( async function getAlgorithmList(
publisherTrustedAlgorithms: PublisherTrustedAlgorithm[] publisherTrustedAlgorithms: PublisherTrustedAlgorithm[]

View File

@ -75,7 +75,7 @@ export default function EditHistory(): ReactElement {
))} ))}
<li className={styles.item}> <li className={styles.item}>
<ExplorerLink networkId={ddo.chainId} path={`/tx/${creationTx}`}> <ExplorerLink networkId={ddo.chainId} path={`/tx/${creationTx}`}>
published <Time date={ddo.created} relative /> published <Time date={ddo.metadata.created} relative />
</ExplorerLink> </ExplorerLink>
</li> </li>
</ul> </ul>

View File

@ -55,12 +55,12 @@ export default function MetaMain(): ReactElement {
<div className={styles.byline}> <div className={styles.byline}>
Published By <Publisher account={owner} /> Published By <Publisher account={owner} />
<p> <p>
<Time date={ddo?.created} relative /> <Time date={ddo?.metadata.created} relative />
{ddo?.created !== ddo?.updated && ( {ddo?.metadata.created !== ddo?.metadata.updated && (
<> <>
{' — '} {' — '}
<span className={styles.updated}> <span className={styles.updated}>
updated <Time date={ddo?.updated} relative /> updated <Time date={ddo?.metadata.updated} relative />
</span> </span>
</> </>
)} )}

View File

@ -1,8 +1,7 @@
import { import {
dateToStringNoMS, dateToStringNoMS,
transformTags, transformTags,
getAlgorithmComponent, getUrlFileExtension
getAlgorithmFileExtension
} from '@utils/ddo' } from '@utils/ddo'
import { FormPublishData } from './_types' import { FormPublishData } from './_types'
@ -19,8 +18,8 @@ export function getFieldContent(
export function transformPublishFormToDdo(data: Partial<FormPublishData>): DDO { export function transformPublishFormToDdo(data: Partial<FormPublishData>): DDO {
const currentTime = dateToStringNoMS(new Date()) const currentTime = dateToStringNoMS(new Date())
const { type } = data.metadata const { type, name, description, tags, author, termsAndConditions } =
const { name, description, tags, author, termsAndConditions } = data.metadata data.metadata
const { const {
access, access,
files, files,
@ -33,43 +32,62 @@ export function transformPublishFormToDdo(data: Partial<FormPublishData>): DDO {
} = data.services[0] } = data.services[0]
const fileUrl = typeof files !== 'string' && files[0].url const fileUrl = typeof files !== 'string' && files[0].url
const filesEncrypted = encryptMe(files)
const metadata: Metadata = {
created: currentTime,
updated: currentTime,
type,
name,
description,
tags: transformTags(tags),
author,
license: 'https://market.oceanprotocol.com/terms',
links,
additionalInformation: {
termsAndConditions
},
...(type === 'algorithm' && {
algorithm: {
language: getUrlFileExtension(fileUrl),
version: '0.1',
container: {
entrypoint: entrypoint,
image: image,
tag: containerTag,
checksum: ''
}
}
})
}
const service: Service = { const service: Service = {
type: access, type: access,
files: filesEncrypted, files: encryptMe(files),
datatokenAddress: '', // how to get before publish? datatokenAddress: '', // how to get before publish?
serviceEndpoint: providerUrl, serviceEndpoint: providerUrl,
timeout timeout,
...(access === 'compute' && {
compute: {
namespace: '',
cpu: 1,
gpu: 1,
gpuType: '',
memory: '',
volumeSize: '',
allowRawAlgorithm: false,
allowNetworkAccess: false,
publisherTrustedAlgorithmPublishers: null,
publisherTrustedAlgorithms: null
}
})
} }
const newDdo: DDO = { const newDdo: DDO = {
'@context': ['https://w3id.org/did/v1'], '@context': ['https://w3id.org/did/v1'],
id: '', // how to get before publish? sha256(address of ERC721 contract + data.chainId) id: '', // how to get before publish? sha256(address of ERC721 contract + data.chainId)
version: '4.0.0', version: '4.0.0',
created: currentTime,
updated: currentTime,
chainId: data.chainId, chainId: data.chainId,
metadata: { metadata,
type,
name,
description,
tags: transformTags(tags),
author,
license: 'https://market.oceanprotocol.com/terms',
links,
additionalInformation: {
termsAndConditions
},
...(type === 'algorithm' && {
...getAlgorithmComponent(
image,
containerTag,
entrypoint,
getAlgorithmFileExtension(fileUrl)
)
})
},
services: [service] services: [service]
} }

View File

@ -93,18 +93,16 @@ export default function PublishPage({
// await handleSubmit(values, resetForm) // await handleSubmit(values, resetForm)
}} }}
> >
{({ values }) => { {({ values }) => (
return ( <>
<> <Form className={styles.form} ref={scrollToRef}>
<Form className={styles.form} ref={scrollToRef}> <Navigation />
<Navigation /> <Steps step={values.step} />
<Steps step={values.step} /> <Actions scrollToRef={scrollToRef} />
<Actions scrollToRef={scrollToRef} /> </Form>
</Form> <Debug values={values} />
<Debug values={values} /> </>
</> )}
)
}}
</Formik> </Formik>
)} )}
</> </>