1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-12-02 05:57:29 +01:00

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,24 +32,10 @@ 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 service: Service = { const metadata: Metadata = {
type: access,
files: filesEncrypted,
datatokenAddress: '', // how to get before publish?
serviceEndpoint: providerUrl,
timeout
}
const newDdo: DDO = {
'@context': ['https://w3id.org/did/v1'],
id: '', // how to get before publish? sha256(address of ERC721 contract + data.chainId)
version: '4.0.0',
created: currentTime, created: currentTime,
updated: currentTime, updated: currentTime,
chainId: data.chainId,
metadata: {
type, type,
name, name,
description, description,
@ -62,14 +47,47 @@ export function transformPublishFormToDdo(data: Partial<FormPublishData>): DDO {
termsAndConditions termsAndConditions
}, },
...(type === 'algorithm' && { ...(type === 'algorithm' && {
...getAlgorithmComponent( algorithm: {
image, language: getUrlFileExtension(fileUrl),
containerTag, version: '0.1',
entrypoint, container: {
getAlgorithmFileExtension(fileUrl) entrypoint: entrypoint,
) image: image,
tag: containerTag,
checksum: ''
}
}
}) })
}, }
const service: Service = {
type: access,
files: encryptMe(files),
datatokenAddress: '', // how to get before publish?
serviceEndpoint: providerUrl,
timeout,
...(access === 'compute' && {
compute: {
namespace: '',
cpu: 1,
gpu: 1,
gpuType: '',
memory: '',
volumeSize: '',
allowRawAlgorithm: false,
allowNetworkAccess: false,
publisherTrustedAlgorithmPublishers: null,
publisherTrustedAlgorithms: null
}
})
}
const newDdo: DDO = {
'@context': ['https://w3id.org/did/v1'],
id: '', // how to get before publish? sha256(address of ERC721 contract + data.chainId)
version: '4.0.0',
chainId: data.chainId,
metadata,
services: [service] services: [service]
} }

View File

@ -93,8 +93,7 @@ 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 />
@ -103,8 +102,7 @@ export default function PublishPage({
</Form> </Form>
<Debug values={values} /> <Debug values={values} />
</> </>
) )}
}}
</Formik> </Formik>
)} )}
</> </>