mirror of
https://github.com/oceanprotocol/react-tutorial
synced 2024-11-22 09:47:01 +01:00
cleanup and style fixes
This commit is contained in:
parent
5ca05440e4
commit
3fecbc4cbf
@ -3,7 +3,7 @@
|
|||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "React + squid.js interacting in the most minimal way with Ocean Protocol.",
|
"description": "React + squid.js interacting in the most minimal way with Ocean Protocol.",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@oceanprotocol/squid": "^2.0.0-beta.2",
|
"@oceanprotocol/squid": "^2.0.0-beta.4",
|
||||||
"react": "^16.12.0",
|
"react": "^16.12.0",
|
||||||
"react-dom": "^16.12.0",
|
"react-dom": "^16.12.0",
|
||||||
"react-scripts": "^3.3.0",
|
"react-scripts": "^3.3.0",
|
||||||
|
@ -2,48 +2,54 @@ import React, { useState } from 'react'
|
|||||||
import * as Assets from './asset'
|
import * as Assets from './asset'
|
||||||
|
|
||||||
export default function Compute({ ocean, web3 }) {
|
export default function Compute({ ocean, web3 }) {
|
||||||
const [ddoAsset, setDdoAsset] = useState('')
|
const [ddoAsset, setDdoAsset] = useState({ id: '' })
|
||||||
const [jobStatus, setJobStatus] = useState('')
|
const [jobStatus, setJobStatus] = useState('')
|
||||||
const [jobId, setJobId] = useState('')
|
const [jobId, setJobId] = useState('')
|
||||||
const [agreementId, setAgreementId] = useState('')
|
const [agreementId, setAgreementId] = useState('')
|
||||||
const [ddoAlgorithm, setDdoAlgorithm] = useState('')
|
const [ddoAlgorithm, setDdoAlgorithm] = useState({ id: '' })
|
||||||
const computestate = {
|
|
||||||
inputdid: '',
|
|
||||||
algodid: '',
|
|
||||||
algooutput:''
|
|
||||||
}
|
|
||||||
// publish a dataset and an algorithm
|
// publish a dataset and an algorithm
|
||||||
async function publish() {
|
async function publish() {
|
||||||
try {
|
try {
|
||||||
const accounts = await ocean.accounts.list()
|
const accounts = await ocean.accounts.list()
|
||||||
console.log('Publishing asset.')
|
console.log('Publishing asset.')
|
||||||
|
|
||||||
|
const service = await Assets.createComputeService(
|
||||||
const service=await Assets.createComputeService(ocean,accounts[0],"0","2020-03-10T10:00:00Z")
|
ocean,
|
||||||
|
accounts[0],
|
||||||
|
'0',
|
||||||
|
'2020-03-10T10:00:00Z'
|
||||||
|
)
|
||||||
console.log(service)
|
console.log(service)
|
||||||
const ddoAssetNew = await ocean.assets.create(Assets.getAsset(), accounts[0],[service])
|
const ddoAssetNew = await ocean.assets.create(
|
||||||
|
Assets.getAsset(),
|
||||||
|
accounts[0],
|
||||||
|
[service]
|
||||||
|
)
|
||||||
console.log('Asset successfully submitted.')
|
console.log('Asset successfully submitted.')
|
||||||
console.log(ddoAssetNew)
|
console.log(ddoAssetNew)
|
||||||
// keep track of this registered asset for consumption later on
|
// keep track of this registered asset for consumption later on
|
||||||
setDdoAsset(ddoAssetNew)
|
setDdoAsset(ddoAssetNew)
|
||||||
alert( 'Asset successfully submitted.' )
|
alert('Asset successfully submitted.')
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error.message)
|
console.error(error.message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async function publishalgo() {
|
async function publishalgo() {
|
||||||
try {
|
try {
|
||||||
const accounts = await ocean.accounts.list()
|
const accounts = await ocean.accounts.list()
|
||||||
console.log('Publishing algo.')
|
console.log('Publishing algo.')
|
||||||
|
|
||||||
const ddoAlgorithmNew = await ocean.assets.create(Assets.getAlgoAsset(), accounts[0])
|
const ddoAlgorithmNew = await ocean.assets.create(
|
||||||
|
Assets.getAlgoAsset(),
|
||||||
|
accounts[0]
|
||||||
|
)
|
||||||
console.log(ddoAlgorithmNew)
|
console.log(ddoAlgorithmNew)
|
||||||
console.log('Algo asset successfully submitted.')
|
console.log('Algo asset successfully submitted.')
|
||||||
// keep track of this registered asset for consumption later on
|
// keep track of this registered asset for consumption later on
|
||||||
setDdoAlgorithm(ddoAlgorithmNew)
|
setDdoAlgorithm(ddoAlgorithmNew)
|
||||||
alert( 'Algorithm successfully submitted.' )
|
alert('Algorithm successfully submitted.')
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error.message)
|
console.error(error.message)
|
||||||
}
|
}
|
||||||
@ -65,7 +71,7 @@ export default function Compute({ ocean, web3 }) {
|
|||||||
)
|
)
|
||||||
setJobId(status.jobId)
|
setJobId(status.jobId)
|
||||||
console.log(status)
|
console.log(status)
|
||||||
alert( 'Job created. You can query for status now' )
|
alert('Job created. You can query for status now')
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error.message)
|
console.error(error.message)
|
||||||
}
|
}
|
||||||
@ -76,11 +82,7 @@ export default function Compute({ ocean, web3 }) {
|
|||||||
const accounts = await ocean.accounts.list()
|
const accounts = await ocean.accounts.list()
|
||||||
// start a compute job
|
// start a compute job
|
||||||
|
|
||||||
const status = await ocean.compute.status(
|
const status = await ocean.compute.status(accounts[0], agreementId, jobId)
|
||||||
accounts[0],
|
|
||||||
agreementId,
|
|
||||||
jobId
|
|
||||||
)
|
|
||||||
setJobStatus(JSON.stringify(status, null, '\t'))
|
setJobStatus(JSON.stringify(status, null, '\t'))
|
||||||
console.log(status)
|
console.log(status)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -99,7 +101,6 @@ export default function Compute({ ocean, web3 }) {
|
|||||||
<button onClick={() => publishalgo()} disabled={!web3}>
|
<button onClick={() => publishalgo()} disabled={!web3}>
|
||||||
2) Publish algorithm
|
2) Publish algorithm
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<button onClick={() => start()} disabled={!web3}>
|
<button onClick={() => start()} disabled={!web3}>
|
||||||
3)Order and start compute service
|
3)Order and start compute service
|
||||||
</button>
|
</button>
|
||||||
@ -107,14 +108,17 @@ export default function Compute({ ocean, web3 }) {
|
|||||||
4)Get Job Status
|
4)Get Job Status
|
||||||
</button>
|
</button>
|
||||||
<hr />
|
<hr />
|
||||||
Asset DID:<input type="text" value={ddoAsset.id}></input>
|
Asset DID:
|
||||||
|
<input type="text" value={ddoAsset.id} readOnly />
|
||||||
<hr />
|
<hr />
|
||||||
Algo DID:<input type="text" value={ddoAlgorithm.id}></input>
|
Algo DID:
|
||||||
|
<input type="text" value={ddoAlgorithm.id} readOnly />
|
||||||
<hr />
|
<hr />
|
||||||
Job ID:<input type="text" value={jobId}></input>
|
Job ID:
|
||||||
|
<input type="text" value={jobId} readOnly />
|
||||||
<hr />
|
<hr />
|
||||||
Compute status:<textarea rows="10" cols="180" value={jobStatus}></textarea>
|
Compute status:
|
||||||
|
<textarea rows="10" cols="180" value={jobStatus} readOnly />
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
233
src/asset.js
233
src/asset.js
@ -1,121 +1,120 @@
|
|||||||
|
export function getAsset() {
|
||||||
|
const asset = {
|
||||||
export function getAsset(){
|
main: {
|
||||||
const asset = {
|
name: '10 Monkey Species Small',
|
||||||
main: {
|
dateCreated: '2012-02-01T10:55:11Z',
|
||||||
name: '10 Monkey Species Small',
|
author: 'Mario',
|
||||||
dateCreated: '2012-02-01T10:55:11Z',
|
type: 'dataset',
|
||||||
author: 'Mario',
|
license: 'CC0: Public Domain',
|
||||||
type: 'dataset',
|
price: '0',
|
||||||
license: 'CC0: Public Domain',
|
files: [
|
||||||
price: '0',
|
{
|
||||||
files: [
|
index: 0,
|
||||||
{
|
contentType: 'application/zip',
|
||||||
index: 0,
|
checksum: '2bf9d229d110d1976cdf85e9f3256c7f',
|
||||||
contentType: 'application/zip',
|
checksumType: 'MD5',
|
||||||
checksum: '2bf9d229d110d1976cdf85e9f3256c7f',
|
contentLength: '12057507',
|
||||||
checksumType: 'MD5',
|
compression: 'zip',
|
||||||
contentLength: '12057507',
|
encoding: 'UTF-8',
|
||||||
compression: 'zip',
|
url:
|
||||||
encoding: 'UTF-8',
|
'https://s3.amazonaws.com/datacommons-seeding-us-east/10_Monkey_Species_Small/assets/training.zip'
|
||||||
url:
|
},
|
||||||
'https://s3.amazonaws.com/datacommons-seeding-us-east/10_Monkey_Species_Small/assets/training.zip'
|
{
|
||||||
},
|
index: 1,
|
||||||
{
|
contentType: 'text/txt',
|
||||||
index: 1,
|
checksum: '354d19c0733c47ef3a6cce5b633116b0',
|
||||||
contentType: 'text/txt',
|
checksumType: 'MD5',
|
||||||
checksum: '354d19c0733c47ef3a6cce5b633116b0',
|
contentLength: '928',
|
||||||
checksumType: 'MD5',
|
url:
|
||||||
contentLength: '928',
|
'https://s3.amazonaws.com/datacommons-seeding-us-east/10_Monkey_Species_Small/assets/monkey_labels.txt'
|
||||||
url:
|
}
|
||||||
'https://s3.amazonaws.com/datacommons-seeding-us-east/10_Monkey_Species_Small/assets/monkey_labels.txt'
|
]
|
||||||
}
|
},
|
||||||
]
|
additionalInformation: {
|
||||||
},
|
categories: ['Biology'],
|
||||||
additionalInformation: {
|
tags: ['image data', 'classification', 'animals'],
|
||||||
categories: ['Biology'],
|
description: 'EXAMPLE ONLY ',
|
||||||
tags: ['image data', 'classification', 'animals'],
|
copyrightHolder: 'Unknown',
|
||||||
description: 'EXAMPLE ONLY ',
|
workExample: 'image path, id, label',
|
||||||
copyrightHolder: 'Unknown',
|
links: [
|
||||||
workExample: 'image path, id, label',
|
{
|
||||||
links: [
|
name: 'example model',
|
||||||
{
|
url:
|
||||||
name: 'example model',
|
'https://drive.google.com/open?id=1uuz50RGiAW8YxRcWeQVgQglZpyAebgSM'
|
||||||
url:
|
},
|
||||||
'https://drive.google.com/open?id=1uuz50RGiAW8YxRcWeQVgQglZpyAebgSM'
|
{
|
||||||
},
|
name: 'example code',
|
||||||
{
|
type: 'example code',
|
||||||
name: 'example code',
|
url:
|
||||||
type: 'example code',
|
'https://github.com/slothkong/CNN_classification_10_monkey_species'
|
||||||
url: 'https://github.com/slothkong/CNN_classification_10_monkey_species'
|
}
|
||||||
}
|
],
|
||||||
],
|
inLanguage: 'en'
|
||||||
inLanguage: 'en'
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
return(asset)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
export function getAlgoAsset(){
|
|
||||||
const algoasset = {
|
|
||||||
main: {
|
|
||||||
name: 'My great algo',
|
|
||||||
dateCreated: '2012-02-01T10:55:11Z',
|
|
||||||
author: 'Alex',
|
|
||||||
type: "algorithm",
|
|
||||||
algorithm: {
|
|
||||||
format: "docker-image",
|
|
||||||
version: "0.1",
|
|
||||||
container: {
|
|
||||||
entrypoint: "node $ALGO",
|
|
||||||
image: "node",
|
|
||||||
tag: "10"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
license: 'CC0: Public Domain',
|
|
||||||
price: '0',
|
|
||||||
files: [
|
|
||||||
{
|
|
||||||
index: 0,
|
|
||||||
contentType: 'application/text',
|
|
||||||
contentLength: '12057507',
|
|
||||||
compression: 'zip',
|
|
||||||
encoding: 'UTF-8',
|
|
||||||
url: 'https://raw.githubusercontent.com/oceanprotocol/test-algorithm/master/javascript/algo.js'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
additionalInformation: {
|
|
||||||
description: 'My super algo '
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return(algoasset)
|
|
||||||
}
|
}
|
||||||
|
return asset
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getAlgoAsset() {
|
||||||
export async function createComputeService(ocean: Ocean,publisher: Account,price: string,datePublished: string){
|
const algoasset = {
|
||||||
const { templates } = ocean.keeper
|
main: {
|
||||||
const serviceAgreementTemplate = await templates.escrowComputeExecutionTemplate.getServiceAgreementTemplate()
|
name: 'My great algo',
|
||||||
const name = 'dataAssetComputingServiceAgreement'
|
dateCreated: '2012-02-01T10:55:11Z',
|
||||||
const service = {
|
author: 'Alex',
|
||||||
type: 'compute',
|
type: 'algorithm',
|
||||||
serviceEndpoint: ocean.brizo.getComputeEndpoint(),
|
algorithm: {
|
||||||
templateId: templates.escrowComputeExecutionTemplate.getId(),
|
format: 'docker-image',
|
||||||
attributes: {
|
version: '0.1',
|
||||||
main: {
|
container: {
|
||||||
creator: publisher.getId(),
|
entrypoint: 'node $ALGO',
|
||||||
datePublished,
|
image: 'node',
|
||||||
price,
|
tag: '10'
|
||||||
timeout: 3600,
|
}
|
||||||
name
|
},
|
||||||
},
|
license: 'CC0: Public Domain',
|
||||||
serviceAgreementTemplate
|
price: '0',
|
||||||
}
|
files: [
|
||||||
}
|
{
|
||||||
return(service)
|
index: 0,
|
||||||
|
contentType: 'application/text',
|
||||||
|
contentLength: '12057507',
|
||||||
|
compression: 'zip',
|
||||||
|
encoding: 'UTF-8',
|
||||||
|
url:
|
||||||
|
'https://raw.githubusercontent.com/oceanprotocol/test-algorithm/master/javascript/algo.js'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
additionalInformation: {
|
||||||
|
description: 'My super algo '
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return algoasset
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function createComputeService(
|
||||||
|
ocean,
|
||||||
//export default Assets
|
publisher,
|
||||||
|
price,
|
||||||
|
datePublished
|
||||||
|
) {
|
||||||
|
const { templates } = ocean.keeper
|
||||||
|
const serviceAgreementTemplate = await templates.escrowComputeExecutionTemplate.getServiceAgreementTemplate()
|
||||||
|
const name = 'dataAssetComputingServiceAgreement'
|
||||||
|
const service = {
|
||||||
|
type: 'compute',
|
||||||
|
serviceEndpoint: ocean.brizo.getComputeEndpoint(),
|
||||||
|
templateId: templates.escrowComputeExecutionTemplate.getId(),
|
||||||
|
attributes: {
|
||||||
|
main: {
|
||||||
|
creator: publisher.getId(),
|
||||||
|
datePublished,
|
||||||
|
price,
|
||||||
|
timeout: 3600,
|
||||||
|
name
|
||||||
|
},
|
||||||
|
serviceAgreementTemplate
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return service
|
||||||
|
}
|
||||||
|
@ -42,7 +42,10 @@ class App extends Component {
|
|||||||
async registerAsset() {
|
async registerAsset() {
|
||||||
try {
|
try {
|
||||||
const accounts = await this.state.ocean.accounts.list()
|
const accounts = await this.state.ocean.accounts.list()
|
||||||
const ddo = await this.state.ocean.assets.create(Assets.getAsset(), accounts[0])
|
const ddo = await this.state.ocean.assets.create(
|
||||||
|
Assets.getAsset(),
|
||||||
|
accounts[0]
|
||||||
|
)
|
||||||
console.log('Asset successfully submitted.')
|
console.log('Asset successfully submitted.')
|
||||||
console.log(ddo)
|
console.log(ddo)
|
||||||
// keep track of this registered asset for consumption later on
|
// keep track of this registered asset for consumption later on
|
||||||
|
Loading…
Reference in New Issue
Block a user