1
0
mirror of https://github.com/oceanprotocol/commons.git synced 2023-03-15 18:03:00 +01:00

update to new DDO structure

This commit is contained in:
Matthias Kretschmann 2019-11-07 17:38:17 +01:00
parent c3c8ca5368
commit 985803d43e
Signed by: m
GPG Key ID: 606EEEF3C479A91F
9 changed files with 98 additions and 260 deletions

View File

@ -17,18 +17,18 @@ const AssetTeaser = ({
list?: boolean list?: boolean
minimal?: boolean minimal?: boolean
}) => { }) => {
const { metadata } = asset.findServiceByType('Metadata') const { attributes } = asset.findServiceByType('metadata')
const { base } = metadata const { main, additionalInformation } = attributes
return list ? ( return list ? (
<article className={styles.assetList}> <article className={styles.assetList}>
<Link to={`/asset/${asset.id}`}> <Link to={`/asset/${asset.id}`}>
<h1>{base.name}</h1> <h1>{main.name}</h1>
<div <div
className={styles.date} className={styles.date}
title={`Published on ${base.datePublished}`} title={`Published on ${main.datePublished}`}
> >
{moment(base.datePublished, 'YYYYMMDD').fromNow()} {moment(main.datePublished, 'YYYYMMDD').fromNow()}
</div> </div>
</Link> </Link>
</article> </article>
@ -39,22 +39,29 @@ const AssetTeaser = ({
} }
> >
<Link to={`/asset/${asset.id}`}> <Link to={`/asset/${asset.id}`}>
{base.categories && !minimal && ( {additionalInformation.categories && !minimal && (
<CategoryImage dimmed category={base.categories[0]} /> <CategoryImage
dimmed
category={additionalInformation.categories[0]}
/>
)} )}
<h1>{base.name}</h1> <h1>{main.name}</h1>
{!minimal && ( {!minimal && (
<div className={styles.description}> <div className={styles.description}>
<Dotdotdot clamp={3}>{base.description}</Dotdotdot> <Dotdotdot clamp={3}>
{additionalInformation.description}
</Dotdotdot>
</div> </div>
)} )}
<footer className={styles.assetFooter}> <footer className={styles.assetFooter}>
{base.categories && <div>{base.categories[0]}</div>} {additionalInformation.categories && (
<div>{additionalInformation.categories[0]}</div>
)}
{allowPricing && ( {allowPricing && (
<div className={styles.price}> <div className={styles.price}>
<span> <span>
{Web3.utils.fromWei(base.price.toString())} {Web3.utils.fromWei(main.price.toString())}
</span>{' '} </span>{' '}
OCEAN OCEAN
</div> </div>

View File

@ -9,7 +9,7 @@ describe('AssetDetails', () => {
it('renders loading without crashing', () => { it('renders loading without crashing', () => {
const { container } = render( const { container } = render(
<AssetDetails <AssetDetails
metadata={({ base: { name: '' } } as any) as MetaData} metadata={({ main: { name: '' } } as any) as MetaData}
ddo={({} as any) as DDO} ddo={({} as any) as DDO}
/> />
) )
@ -22,11 +22,13 @@ describe('AssetDetails', () => {
<AssetDetails <AssetDetails
metadata={ metadata={
({ ({
base: { main: {
name: 'Hello', name: 'Hello',
description: 'Description',
categories: ['Category'],
files: [{ index: 0 }] files: [{ index: 0 }]
},
additionalInformation: {
description: 'Description',
categories: ['Category']
} }
} as any) as MetaData } as any) as MetaData
} }

View File

@ -31,18 +31,18 @@ const MetaFixedItem = ({ name, value }: { name: string; value: string }) => (
) )
export default function AssetDetails({ metadata, ddo }: AssetDetailsProps) { export default function AssetDetails({ metadata, ddo }: AssetDetailsProps) {
const { base } = metadata const { main, additionalInformation } = metadata
const price = base.price && Web3.utils.fromWei(base.price.toString()) const price = main.price && Web3.utils.fromWei(main.price.toString())
const metaFixed = [ const metaFixed = [
{ {
name: 'Author', name: 'Author',
value: base.author, value: main.author,
show: true show: true
}, },
{ {
name: 'License', name: 'License',
value: base.license, value: main.license,
show: true show: true
}, },
{ {
@ -60,36 +60,45 @@ export default function AssetDetails({ metadata, ddo }: AssetDetailsProps) {
return ( return (
<> <>
<aside className={styles.metaPrimary}> <aside className={styles.metaPrimary}>
<h2 className={styles.copyrightHolder} title="Copyright Holder"> {additionalInformation &&
{base.copyrightHolder} additionalInformation.copyrightHolder && (
</h2> <h2
className={styles.copyrightHolder}
title="Copyright Holder"
>
{additionalInformation.copyrightHolder}
</h2>
)}
<div className={styles.metaPrimaryData}> <div className={styles.metaPrimaryData}>
<span <span
title={`Date created, published on ${base.datePublished}`} title={`Date created, published on ${main.datePublished}`}
> >
<Moment <Moment
date={base.dateCreated} date={main.dateCreated}
format="L" format="L"
interval={0} interval={0}
/> />
</span> </span>
{base.categories && ( {additionalInformation &&
<CategoryLink category={base.categories[0]} /> additionalInformation.categories && (
)} <CategoryLink
category={additionalInformation.categories[0]}
/>
)}
{base.files && datafilesLine(base.files)} {main.files && datafilesLine(main.files)}
</div> </div>
</aside> </aside>
{base.description && ( {additionalInformation && additionalInformation.description && (
<Markdown <Markdown
text={base.description} text={additionalInformation.description}
className={styles.description} className={styles.description}
/> />
)} )}
<Report did={ddo.id} title={metadata.base.name} /> <Report did={ddo.id} title={main.name} />
<div className={styles.metaFixed}> <div className={styles.metaFixed}>
<h2 <h2
@ -111,7 +120,7 @@ export default function AssetDetails({ metadata, ddo }: AssetDetailsProps) {
</ul> </ul>
</div> </div>
<AssetFilesDetails files={base.files ? base.files : []} ddo={ddo} /> <AssetFilesDetails files={main.files ? main.files : []} ddo={ddo} />
</> </>
) )
} }

View File

@ -20,7 +20,7 @@ const file = {
const ddo = ({ const ddo = ({
id: 'xxx', id: 'xxx',
findServiceByType: () => { findServiceByType: () => {
return { serviceDefinitionId: 'xxx' } return { index: 'xxx' }
} }
} as any) as DDO } as any) as DDO

View File

@ -59,7 +59,7 @@ export default class AssetFile extends PureComponent<
try { try {
const accounts = await ocean.accounts.list() const accounts = await ocean.accounts.list()
const service = ddo.findServiceByType('Access') const service = ddo.findServiceByType('access')
const agreements = await ocean.keeper.conditions.accessSecretStoreCondition.getGrantedDidByConsumer( const agreements = await ocean.keeper.conditions.accessSecretStoreCondition.getGrantedDidByConsumer(
accounts[0].id accounts[0].id
@ -74,7 +74,7 @@ export default class AssetFile extends PureComponent<
;({ agreementId } = agreement) ;({ agreementId } = agreement)
} else { } else {
agreementId = await ocean.assets agreementId = await ocean.assets
.order(ddo.id, service.serviceDefinitionId, accounts[0]) .order(ddo.id, service.index, accounts[0])
.next((step: number) => this.setState({ step })) .next((step: number) => this.setState({ step }))
} }
@ -84,7 +84,7 @@ export default class AssetFile extends PureComponent<
const path = await ocean.assets.consume( const path = await ocean.assets.consume(
agreementId, agreementId,
ddo.id, ddo.id,
service.serviceDefinitionId, service.index,
accounts[0], accounts[0],
'', '',
index index

View File

@ -23,6 +23,7 @@ interface AssetState {
ddo: DDO ddo: DDO
metadata: MetaData metadata: MetaData
error: string error: string
isLoading: boolean
} }
class Asset extends Component<AssetProps, AssetState> { class Asset extends Component<AssetProps, AssetState> {
@ -30,8 +31,9 @@ class Asset extends Component<AssetProps, AssetState> {
public state = { public state = {
ddo: ({} as any) as DDO, ddo: ({} as any) as DDO,
metadata: ({ base: { name: '' } } as any) as MetaData, metadata: ({ main: { name: '' } } as any) as MetaData,
error: '' error: '',
isLoading: true
} }
public async componentDidMount() { public async componentDidMount() {
@ -42,8 +44,12 @@ class Asset extends Component<AssetProps, AssetState> {
try { try {
const { ocean } = this.context const { ocean } = this.context
const ddo = await ocean.assets.resolve(this.props.match.params.did) const ddo = await ocean.assets.resolve(this.props.match.params.did)
const { metadata } = ddo.findServiceByType('Metadata') const { attributes } = ddo.findServiceByType('metadata')
this.setState({ ddo, metadata }) this.setState({
ddo,
metadata: attributes,
isLoading: false
})
} catch (error) { } catch (error) {
Logger.error(error.message) Logger.error(error.message)
this.setState({ this.setState({
@ -53,8 +59,9 @@ class Asset extends Component<AssetProps, AssetState> {
} }
public render() { public render() {
const { metadata, ddo, error } = this.state const { metadata, ddo, error, isLoading } = this.state
const isLoading = metadata.base.name === '' const { main, additionalInformation } = metadata
const hasError = error !== '' const hasError = error !== ''
return isLoading && !hasError ? ( return isLoading && !hasError ? (
@ -68,13 +75,14 @@ class Asset extends Component<AssetProps, AssetState> {
</Content> </Content>
) : ( ) : (
<Route <Route
title={metadata.base.name} title={main.name}
image={ image={
metadata.base.categories && ( additionalInformation &&
additionalInformation.categories && (
<CategoryImage <CategoryImage
header header
dimmed dimmed
category={metadata.base.categories[0]} category={additionalInformation.categories[0]}
/> />
) )
} }

View File

@ -1,24 +1,21 @@
const AssetModel = { import { MetaData } from '@oceanprotocol/squid'
assetId: null,
publisherId: null,
const AssetModel: MetaData = {
// OEP-08 Attributes // OEP-08 Attributes
// https://github.com/oceanprotocol/OEPs/tree/master/8 // https://github.com/oceanprotocol/OEPs/tree/master/8
base: { main: {
name: null, type: 'dataset',
description: null, name: '',
dateCreated: null, dateCreated: '',
author: null, author: '',
type: '', license: '',
license: null, price: '',
copyrightHolder: null, files: []
workExample: '', },
files: [], additionalInformation: {
categories: [], description: '',
links: [], copyrightHolder: '',
inLanguage: '', categories: []
tags: [],
price: ''
} }
} }

View File

@ -280,23 +280,28 @@ class Publish extends Component<{}, PublishState> {
const newAsset = { const newAsset = {
// OEP-08 Attributes // OEP-08 Attributes
// https://github.com/oceanprotocol/OEPs/tree/master/8 // https://github.com/oceanprotocol/OEPs/tree/master/8
base: Object.assign(AssetModel.base, { main: Object.assign(AssetModel.main, {
type: this.state.type,
name: this.state.name, name: this.state.name,
description: this.state.description,
dateCreated: dateCreated:
new Date(this.state.dateCreated) new Date(this.state.dateCreated)
.toISOString() .toISOString()
.split('.')[0] + 'Z', // remove milliseconds .split('.')[0] + 'Z', // remove milliseconds
author: this.state.author, author: this.state.author,
license: this.state.license, license: this.state.license,
copyrightHolder: this.state.copyrightHolder,
files,
price: allowPricing price: allowPricing
? Web3.utils.toWei(this.state.price, 'ether') ? Web3.utils.toWei(this.state.price, 'ether')
: this.state.price, : this.state.price,
type: this.state.type, files
categories: [this.state.categories] }),
}) additionalInformation: Object.assign(
AssetModel.additionalInformation,
{
description: this.state.description,
copyrightHolder: this.state.copyrightHolder,
categories: [this.state.categories]
}
)
} }
try { try {

View File

@ -1,190 +0,0 @@
{
"@context": "https://w3id.org/did/v1",
"id": "did:op:52f2ed716f97463e97beeb414195a075b606675874204e3da39b0c237377dbd3",
"publicKey": [
{
"id": "did:op:52f2ed716f97463e97beeb414195a075b606675874204e3da39b0c237377dbd3",
"type": "EthereumECDSAKey",
"owner": "0x5e3264A651303b93A3a3BC5eaB5c8676f5C3D7b1"
}
],
"authentication": [
{
"type": "RsaSignatureAuthentication2018",
"publicKey": "did:op:52f2ed716f97463e97beeb414195a075b606675874204e3da39b0c237377dbd3"
}
],
"service": [
{
"type": "Access",
"creator": "",
"purchaseEndpoint": "https://brizo.duero.dev-ocean.com:443/api/v1/brizo/services/access/initialize",
"serviceEndpoint": "https://brizo.duero.dev-ocean.com:443/api/v1/brizo/services/consume",
"name": "dataAssetAccessServiceAgreement",
"templateId": "0xfA16d26e9F4fffC6e40963B281a0bB08C31ed40C",
"serviceAgreementTemplate": {
"contractName": "EscrowAccessSecretStoreTemplate",
"events": [
{
"name": "AgreementCreated",
"actorType": "consumer",
"handler": {
"moduleName": "escrowAccessSecretStoreTemplate",
"functionName": "fulfillLockRewardCondition",
"version": "0.1"
}
}
],
"fulfillmentOrder": [
"lockReward.fulfill",
"accessSecretStore.fulfill",
"escrowReward.fulfill"
],
"conditionDependency": {
"lockReward": [],
"accessSecretStore": [],
"escrowReward": ["lockReward", "accessSecretStore"]
},
"conditions": [
{
"name": "lockReward",
"timelock": 0,
"timeout": 0,
"contractName": "LockRewardCondition",
"functionName": "fulfill",
"parameters": [
{
"name": "_rewardAddress",
"type": "address",
"value": "0x5e3264A651303b93A3a3BC5eaB5c8676f5C3D7b1"
},
{ "name": "_amount", "type": "uint256", "value": 0 }
],
"events": [
{
"name": "Fulfilled",
"actorType": "publisher",
"handler": {
"moduleName": "lockRewardCondition",
"functionName": "fulfillAccessSecretStoreCondition",
"version": "0.1"
}
}
]
},
{
"name": "accessSecretStore",
"timelock": 0,
"timeout": 0,
"contractName": "AccessSecretStoreCondition",
"functionName": "fulfill",
"parameters": [
{
"name": "_documentId",
"type": "bytes32",
"value": "52f2ed716f97463e97beeb414195a075b606675874204e3da39b0c237377dbd3"
},
{ "name": "_grantee", "type": "address", "value": "" }
],
"events": [
{
"name": "Fulfilled",
"actorType": "publisher",
"handler": {
"moduleName": "accessSecretStore",
"functionName": "fulfillEscrowRewardCondition",
"version": "0.1"
}
},
{
"name": "TimedOut",
"actorType": "consumer",
"handler": {
"moduleName": "accessSecretStore",
"functionName": "fulfillEscrowRewardCondition",
"version": "0.1"
}
}
]
},
{
"name": "escrowReward",
"timelock": 0,
"timeout": 0,
"contractName": "EscrowReward",
"functionName": "fulfill",
"parameters": [
{ "name": "_amount", "type": "uint256", "value": 0 },
{ "name": "_receiver", "type": "address", "value": "" },
{ "name": "_sender", "type": "address", "value": "" },
{ "name": "_lockCondition", "type": "bytes32", "value": "" },
{ "name": "_releaseCondition", "type": "bytes32", "value": "" }
],
"events": [
{
"name": "Fulfilled",
"actorType": "publisher",
"handler": {
"moduleName": "escrowRewardCondition",
"functionName": "verifyRewardTokens",
"version": "0.1"
}
}
]
}
]
},
"serviceDefinitionId": "0"
},
{
"type": "Authorization",
"service": "SecretStore",
"serviceEndpoint": "https://secret-store.duero.dev-ocean.com:443",
"serviceDefinitionId": "1"
},
{
"type": "Metadata",
"serviceEndpoint": "https://aquarius.duero.dev-ocean.com:443/api/v1/aquarius/assets/ddo/did:op:52f2ed716f97463e97beeb414195a075b606675874204e3da39b0c237377dbd3",
"metadata": {
"curation": { "rating": 0.0, "numVotes": 0, "isListed": true },
"base": {
"name": "Technical Whitepaper",
"description": "This paper presents Ocean Protocol. Ocean is a decentralized protocol and network of artificial intelligence (AI) data/services. \n\nOcean does decentralized orchestration: at its core are decentralized service agreements and decentralized access control, which execute on decentralized virtual machines. This allows connection to, monetization of, and curation of arbitrary data services. On that, Ocean adds network rewards to incentivize data sharing, including privacy-preserving data commons.",
"dateCreated": "2019-05-10T11:55:58.492Z",
"author": "Ocean Protocol",
"type": "dataset",
"license": "Public Domain",
"copyrightHolder": "Ocean Protocol Foundation Ltd.",
"files": [
{
"found": true,
"contentLength": "2989228",
"contentType": "application/pdf",
"compression": "none",
"index": 0
}
],
"categories": ["Engineering"],
"links": [],
"tags": "",
"price": 0,
"encryptedFiles": "0x95116a697eadb4b5058682749f587321cb918ec6239a193a7e1e3587d7de28e761e8819e2241e9375b035eacc3dcec4799e0da4cd52552ab583082366ff4e0fb1f72a63ae071206859cfc53abdea2135c660cfba1e81361efce10bfcec323d63b0dcf009dd2c48dfcde09c95dcf69d6c6a318e869ac26b7dc0fcb085e1421b394aaf4d4fac05e992c13a225c5c1e138a7fb27185ba5e1709760ecd43e89eafef435ad97ffb",
"checksum": "9b624a8f9cd7f9d1127c818f32453f43dc6c633472a682bb880d69093b4b9615",
"datePublished": "2019-05-10T14:40:01Z"
},
"additionalInformation": {
"updateFrequency": null,
"structuredMarkup": []
}
},
"serviceDefinitionId": "2"
}
],
"created": "2019-05-10T14:39:53Z",
"proof": {
"created": "2019-05-10T14:39:55Z",
"creator": "0x5e3264A651303b93A3a3BC5eaB5c8676f5C3D7b1",
"type": "DDOIntegritySignature",
"signatureValue": "0x94c3042facdb0601cb5c90264b1e8d1ae6902043af4303c57869d2881748621b03d943f4bb2ccd5d18429964f4ebc425d77baffc576884cfd78ae0987082c5931b"
}
}