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

View File

@ -9,7 +9,7 @@ describe('AssetDetails', () => {
it('renders loading without crashing', () => {
const { container } = render(
<AssetDetails
metadata={({ base: { name: '' } } as any) as MetaData}
metadata={({ main: { name: '' } } as any) as MetaData}
ddo={({} as any) as DDO}
/>
)
@ -22,11 +22,13 @@ describe('AssetDetails', () => {
<AssetDetails
metadata={
({
base: {
main: {
name: 'Hello',
description: 'Description',
categories: ['Category'],
files: [{ index: 0 }]
},
additionalInformation: {
description: 'Description',
categories: ['Category']
}
} 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) {
const { base } = metadata
const price = base.price && Web3.utils.fromWei(base.price.toString())
const { main, additionalInformation } = metadata
const price = main.price && Web3.utils.fromWei(main.price.toString())
const metaFixed = [
{
name: 'Author',
value: base.author,
value: main.author,
show: true
},
{
name: 'License',
value: base.license,
value: main.license,
show: true
},
{
@ -60,36 +60,45 @@ export default function AssetDetails({ metadata, ddo }: AssetDetailsProps) {
return (
<>
<aside className={styles.metaPrimary}>
<h2 className={styles.copyrightHolder} title="Copyright Holder">
{base.copyrightHolder}
</h2>
{additionalInformation &&
additionalInformation.copyrightHolder && (
<h2
className={styles.copyrightHolder}
title="Copyright Holder"
>
{additionalInformation.copyrightHolder}
</h2>
)}
<div className={styles.metaPrimaryData}>
<span
title={`Date created, published on ${base.datePublished}`}
title={`Date created, published on ${main.datePublished}`}
>
<Moment
date={base.dateCreated}
date={main.dateCreated}
format="L"
interval={0}
/>
</span>
{base.categories && (
<CategoryLink category={base.categories[0]} />
)}
{additionalInformation &&
additionalInformation.categories && (
<CategoryLink
category={additionalInformation.categories[0]}
/>
)}
{base.files && datafilesLine(base.files)}
{main.files && datafilesLine(main.files)}
</div>
</aside>
{base.description && (
{additionalInformation && additionalInformation.description && (
<Markdown
text={base.description}
text={additionalInformation.description}
className={styles.description}
/>
)}
<Report did={ddo.id} title={metadata.base.name} />
<Report did={ddo.id} title={main.name} />
<div className={styles.metaFixed}>
<h2
@ -111,7 +120,7 @@ export default function AssetDetails({ metadata, ddo }: AssetDetailsProps) {
</ul>
</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 = ({
id: 'xxx',
findServiceByType: () => {
return { serviceDefinitionId: 'xxx' }
return { index: 'xxx' }
}
} as any) as DDO

View File

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

View File

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

View File

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

View File

@ -280,23 +280,28 @@ class Publish extends Component<{}, PublishState> {
const newAsset = {
// OEP-08 Attributes
// 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,
description: this.state.description,
dateCreated:
new Date(this.state.dateCreated)
.toISOString()
.split('.')[0] + 'Z', // remove milliseconds
author: this.state.author,
license: this.state.license,
copyrightHolder: this.state.copyrightHolder,
files,
price: allowPricing
? Web3.utils.toWei(this.state.price, 'ether')
: this.state.price,
type: this.state.type,
categories: [this.state.categories]
})
files
}),
additionalInformation: Object.assign(
AssetModel.additionalInformation,
{
description: this.state.description,
copyrightHolder: this.state.copyrightHolder,
categories: [this.state.categories]
}
)
}
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"
}
}