Remove outdated examples.

This commit is contained in:
Pedro Gutiérrez 2019-05-15 12:57:52 +02:00 committed by Pedro Gutiérrez
parent 4d6622e3f3
commit 5910552f20
18 changed files with 5 additions and 609 deletions

View File

@ -68,7 +68,9 @@ const ocean: Ocean = await Ocean.getInstance({
### Examples
* [Examples](/src/examples/)
You can see how `squid-js` is used on:
* [Integration test](/src/integration/ocean/)
* [Tuna](https://github.com/oceanprotocol/tuna/tree/develop/node)
## Documentation
@ -149,4 +151,4 @@ Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
limitations under the License.

View File

@ -13,7 +13,6 @@
"integration:nile": "export NETWORK_NAME=nile; mocha --opts integration/mocha.opts",
"integration:watch": "mocha -w --watch-extensions js,ts,json --opts integration/mocha.opts",
"integration:cover": "nyc --report-dir coverage/integration mocha --opts integration/mocha.opts",
"examples": "./src/examples/fire_lazers.sh",
"clean": "rm -rf ./dist/ ./doc/ ./.nyc_output",
"lint": "tslint -c tslint.json 'src/**/*.ts' 'test/**/*.ts' 'integration/**/*.ts'",
"start": "npm link @oceanprotocol/keeper-contracts @oceanprotocol/secret-store-client && npm run build:watch",
@ -21,7 +20,7 @@
"build:tsc": "tsc --sourceMap",
"build:dist": "cross-env NODE_ENV=production webpack",
"build:watch": "tsc -w",
"doc": "typedoc --mode modules --exclude \"**/examples/**\" --out ./doc/ ./src/",
"doc": "typedoc --mode modules --out ./doc/ ./src/",
"merge-coverages": "npx lcov-result-merger \"coverage/*/lcov.info\" coverage/lcov.info",
"report-coverage": "npm run report-coverage:unit && npm run report-coverage:integration",
"report-coverage:unit": "cat coverage/unit/lcov.info | codacy-coverage --token 71ef0d15f6f04ac29b31d704b28f866a",

View File

@ -1,79 +0,0 @@
import { DDO } from "../ddo/DDO"
import { MetaData } from "../ddo/MetaData"
import DID from "../ocean/DID"
import {Account, Logger, Ocean, ServiceAgreement} from "../squid"
import config from "./config"
import {runner} from "./runner"
async function exec() {
const ocean: Ocean = await Ocean.getInstance(config)
const publisher: Account = (await ocean.getAccounts())[0]
publisher.setPassword(process.env.ACCOUNT_PASSWORD)
const consumer: Account = (await ocean.getAccounts())[1]
const metaData: Partial<MetaData> = {
base: {
name: "Office Humidity",
type: "dataset",
description: "Weather information of UK including temperature and humidity",
size: "3.1gb",
dateCreated: "2012-02-01T10:55:11+00:00",
author: "Met Office",
license: "CC-BY",
copyrightHolder: "Met Office",
encoding: "UTF-8",
compression: "zip",
contentType: "text/csv",
// tslint:disable-next-line
workExample: "stationId,latitude,longitude,datetime,temperature,humidity423432fsd,51.509865,-0.118092,2011-01-01T10:55:11+00:00,7.2,68",
files: [
{
url: "https://testocnfiles.blob.core.windows.net/testfiles/testzkp.zip",
checksum: "085340abffh21495345af97c6b0e761",
contentLength: "12324",
},
{
url: "https://testocnfiles.blob.core.windows.net/testfiles/testzkp2.zip",
},
],
links: [
{sample1: "http://data.ceda.ac.uk/badc/ukcp09/data/gridded-land-obs/gridded-land-obs-daily/"},
{sample2: "http://data.ceda.ac.uk/badc/ukcp09/data/gridded-land-obs/gridded-land-obs-averages-25km/"},
{fieldsDescription: "http://data.ceda.ac.uk/badc/ukcp09/"},
],
inLanguage: "en",
tags: "weather, uk, 2011, temperature, humidity",
price: 10,
},
}
const ddo: DDO = await ocean.registerAsset(metaData as any, publisher)
Logger.log("did", ddo.id)
const did: DID = DID.parse(ddo.id)
const accessService = ddo.findServiceByType("Access")
await consumer.requestTokens(metaData.base.price)
const serviceAgreementSignatureResult: any = await ocean.signServiceAgreement(ddo.id,
accessService.serviceDefinitionId, consumer)
Logger.log("ServiceAgreement Id:", serviceAgreementSignatureResult.serviceAgreementId)
Logger.log("ServiceAgreement Signature:", serviceAgreementSignatureResult.serviceAgreementSignature)
const service = ddo.findServiceByType("Access")
const serviceAgreement: ServiceAgreement = await ocean.executeServiceAgreement(
ddo.id,
service.serviceDefinitionId,
serviceAgreementSignatureResult.serviceAgreementId,
serviceAgreementSignatureResult.serviceAgreementSignature,
consumer,
publisher)
Logger.log("ServiceAgreement Id:", serviceAgreement.getId())
const paid = await serviceAgreement.payAsset(did.getId(), metaData.base.price, consumer)
Logger.log(`Asset paid: ${paid}`)
}
runner(exec)

View File

@ -1,74 +0,0 @@
import { DDO } from "../ddo/DDO"
import { MetaData } from "../ddo/MetaData"
import {Account, Logger, Ocean, ServiceAgreement} from "../squid"
import config from "./config"
import {runner} from "./runner"
async function exec() {
const ocean: Ocean = await Ocean.getInstance(config)
const publisher: Account = (await ocean.getAccounts())[0]
publisher.setPassword(process.env.ACCOUNT_PASSWORD)
const consumer: Account = (await ocean.getAccounts())[1]
const metaData: Partial<MetaData> = {
base: {
name: "Office Humidity",
type: "dataset",
description: "Weather information of UK including temperature and humidity",
size: "3.1gb",
dateCreated: "2012-02-01T10:55:11+00:00",
author: "Met Office",
license: "CC-BY",
copyrightHolder: "Met Office",
encoding: "UTF-8",
compression: "zip",
contentType: "text/csv",
// tslint:disable-next-line
workExample: "stationId,latitude,longitude,datetime,temperature,humidity423432fsd,51.509865,-0.118092,2011-01-01T10:55:11+00:00,7.2,68",
files: [
{
url: "https://testocnfiles.blob.core.windows.net/testfiles/testzkp.zip",
checksum: "085340abffh21495345af97c6b0e761",
contentLength: "12324",
},
{
url: "https://testocnfiles.blob.core.windows.net/testfiles/testzkp2.zip",
},
],
links: [
{sample1: "http://data.ceda.ac.uk/badc/ukcp09/data/gridded-land-obs/gridded-land-obs-daily/"},
{sample2: "http://data.ceda.ac.uk/badc/ukcp09/data/gridded-land-obs/gridded-land-obs-averages-25km/"},
{fieldsDescription: "http://data.ceda.ac.uk/badc/ukcp09/"},
],
inLanguage: "en",
tags: "weather, uk, 2011, temperature, humidity",
price: 10,
},
}
const ddo: DDO = await ocean.registerAsset(metaData as any, publisher)
Logger.log("did", ddo.id)
const accessService = ddo.findServiceByType("Access")
await consumer.requestTokens(metaData.base.price)
const serviceAgreementSignatureResult: any = await ocean.signServiceAgreement(ddo.id,
accessService.serviceDefinitionId, consumer)
Logger.log("ServiceAgreement Id:", serviceAgreementSignatureResult.serviceAgreementId)
Logger.log("ServiceAgreement Signature:", serviceAgreementSignatureResult.serviceAgreementSignature)
const service = ddo.findServiceByType("Access")
const serviceAgreement: ServiceAgreement = await ocean.executeServiceAgreement(
ddo.id,
service.serviceDefinitionId,
serviceAgreementSignatureResult.serviceAgreementId,
serviceAgreementSignatureResult.serviceAgreementSignature,
consumer,
publisher)
Logger.log("ServiceAgreement Id:", serviceAgreement.getId())
}
runner(exec)

View File

@ -1,13 +0,0 @@
import {Logger, Ocean} from "../squid"
import config from "./config"
import {runner} from "./runner"
async function exec() {
const ocean: Ocean = await Ocean.getInstance(config)
const accounts = await ocean.getAccounts()
Logger.log(JSON.stringify(accounts, null, 2))
}
runner(exec)

View File

@ -1,13 +0,0 @@
import {Logger, Ocean} from "../squid"
import config from "./config"
import {runner} from "./runner"
async function exec() {
const ocean: Ocean = await Ocean.getInstance(config)
const accounts = await ocean.getAccounts()
Logger.log(await accounts[0].getBalance())
}
runner(exec)

View File

@ -1,13 +0,0 @@
import {Logger, Ocean} from "../squid"
import config from "./config"
import {runner} from "./runner"
async function exec() {
const ocean: Ocean = await Ocean.getInstance(config)
const accounts = await ocean.getAccounts()
Logger.log(JSON.stringify(accounts, null, 2))
}
runner(exec)

View File

@ -1,82 +0,0 @@
import { DDO } from "../ddo/DDO"
import { MetaData } from "../ddo/MetaData"
import DID from "../ocean/DID"
import {Account, Logger, Ocean, ServiceAgreement} from "../squid"
import config from "./config"
import {runner} from "./runner"
async function exec() {
const ocean: Ocean = await Ocean.getInstance(config)
const publisher: Account = (await ocean.getAccounts())[0]
publisher.setPassword(process.env.ACCOUNT_PASSWORD)
const consumer: Account = (await ocean.getAccounts())[1]
const metaData: Partial<MetaData> = {
base: {
name: "Office Humidity",
type: "dataset",
description: "Weather information of UK including temperature and humidity",
size: "3.1gb",
dateCreated: "2012-02-01T10:55:11+00:00",
author: "Met Office",
license: "CC-BY",
copyrightHolder: "Met Office",
encoding: "UTF-8",
compression: "zip",
contentType: "text/csv",
// tslint:disable-next-line
workExample: "stationId,latitude,longitude,datetime,temperature,humidity423432fsd,51.509865,-0.118092,2011-01-01T10:55:11+00:00,7.2,68",
files: [
{
url: "https://testocnfiles.blob.core.windows.net/testfiles/testzkp.zip",
checksum: "085340abffh21495345af97c6b0e761",
contentLength: "12324",
},
{
url: "https://testocnfiles.blob.core.windows.net/testfiles/testzkp2.zip",
},
],
links: [
{sample1: "http://data.ceda.ac.uk/badc/ukcp09/data/gridded-land-obs/gridded-land-obs-daily/"},
{sample2: "http://data.ceda.ac.uk/badc/ukcp09/data/gridded-land-obs/gridded-land-obs-averages-25km/"},
{fieldsDescription: "http://data.ceda.ac.uk/badc/ukcp09/"},
],
inLanguage: "en",
tags: "weather, uk, 2011, temperature, humidity",
price: 10,
},
}
const ddo: DDO = await ocean.registerAsset(metaData as any, publisher)
Logger.log("did", ddo.id)
const did: DID = DID.parse(ddo.id)
const accessService = ddo.findServiceByType("Access")
const serviceAgreementSignatureResult: any = await ocean.signServiceAgreement(ddo.id,
accessService.serviceDefinitionId, consumer)
Logger.log("ServiceAgreement Id:", serviceAgreementSignatureResult.serviceAgreementId)
Logger.log("ServiceAgreement Signature:", serviceAgreementSignatureResult.serviceAgreementSignature)
const service = ddo.findServiceByType("Access")
const serviceAgreement: ServiceAgreement = await ocean.executeServiceAgreement(
ddo.id,
service.serviceDefinitionId,
serviceAgreementSignatureResult.serviceAgreementId,
serviceAgreementSignatureResult.serviceAgreementSignature,
consumer,
publisher)
Logger.log("ServiceAgreement Id:", serviceAgreement.getId())
await consumer.requestTokens(metaData.base.price)
const paid = await serviceAgreement.payAsset(did.getId(), metaData.base.price, consumer)
Logger.log(`Asset paid: ${paid}`)
const accessGranted = await serviceAgreement.grantAccess(did.getId(), publisher)
Logger.log(`Asset access granted: ${accessGranted}`)
}
runner(exec)

View File

@ -1,81 +0,0 @@
import { DDO } from "../ddo/DDO"
import { MetaData } from "../ddo/MetaData"
import {Account, Logger, Ocean} from "../squid"
import config from "./config"
import {runner} from "./runner"
async function exec() {
const ocean: Ocean = await Ocean.getInstance(config)
const publisher: Account = (await ocean.getAccounts())[1]
const consumer: Account = (await ocean.getAccounts())[1]
const metaData: Partial<MetaData> = {
base: {
name: "Office Humidity",
type: "dataset",
description: "Weather information of UK including temperature and humidity",
size: "3.1gb",
dateCreated: "2012-02-01T10:55:11+00:00",
author: "Met Office",
license: "CC-BY",
copyrightHolder: "Met Office",
encoding: "UTF-8",
compression: "zip",
contentType: "Application/pdf",
// tslint:disable-next-line
workExample: "stationId,latitude,longitude,datetime,temperature,humidity423432fsd,51.509865,-0.118092,2011-01-01T10:55:11+00:00,7.2,68",
files: [
{
url: "https://testocnfiles.blob.core.windows.net/testfiles/testzkp.zip",
checksum: "085340abffh21495345af97c6b0e761",
contentLength: "12324",
},
{
url: "https://testocnfiles.blob.core.windows.net/testfiles/testzkp2.zip",
},
],
links: [
{sample1: "http://data.ceda.ac.uk/badc/ukcp09/data/gridded-land-obs/gridded-land-obs-daily/"},
{sample2: "http://data.ceda.ac.uk/badc/ukcp09/data/gridded-land-obs/gridded-land-obs-averages-25km/"},
{fieldsDescription: "http://data.ceda.ac.uk/badc/ukcp09/"},
],
inLanguage: "en",
tags: "weather, uk, 2011, temperature, humidity",
price: 10,
},
}
const ddo: DDO = await ocean.registerAsset(metaData as any, publisher)
Logger.log("Registered asset with did:", ddo.id)
const accessService = ddo.findServiceByType("Access")
await consumer.requestTokens(100)
const serviceAgreementSignatureResult = await ocean
.signServiceAgreement(
ddo.id,
accessService.serviceDefinitionId,
consumer)
Logger.log("ServiceAgreement Id:", serviceAgreementSignatureResult.agreementId)
Logger.log("ServiceAgreement Signature:", serviceAgreementSignatureResult.signature)
const service = ddo.findServiceByType("Access")
try {
await ocean
.initializeServiceAgreement(
ddo.id,
service.serviceDefinitionId,
serviceAgreementSignatureResult.agreementId,
serviceAgreementSignatureResult.signature,
(files) => Logger.log(`Got files, first files length in bytes: ${files[0].length}`),
consumer,
)
} catch (e) {
throw new Error(`"Error on initializeServiceAgreement: ${e}`)
}
}
runner(exec)

View File

@ -1,20 +0,0 @@
import {Logger, Ocean} from "../squid"
// tslint:disable-next-line
import EventListener from "../keeper/EventListener"
import config from "./config"
(async () => {
Ocean.getInstance(config)
})()
const event = EventListener.subscribe("OceanToken", "Transfer", {})
Logger.log(`Listening to Transfer event of OceanToken`)
event.listen((data: any[]) => {
Logger.log(Date.now())
Logger.log("From", data[0].returnValues.from)
Logger.log("To", data[0].returnValues.to)
Logger.log("Value", data[0].returnValues.value)
})

View File

@ -1,53 +0,0 @@
import { DDO } from "../ddo/DDO"
import { MetaData } from "../ddo/MetaData"
import { Account, Logger, Ocean } from "../squid"
import config from "./config"
import {runner} from "./runner"
async function exec() {
const ocean: Ocean = await Ocean.getInstance(config)
const publisher: Account = (await ocean.getAccounts())[0]
publisher.setPassword(process.env.ACCOUNT_PASSWORD)
const metaData: Partial<MetaData> = {
base: {
name: "Office Humidity",
type: "dataset",
description: "Weather information of UK including temperature and humidity",
size: "3.1gb",
dateCreated: "2012-02-01T10:55:11+00:00",
author: "Met Office",
license: "CC-BY",
copyrightHolder: "Met Office",
encoding: "UTF-8",
compression: "zip",
contentType: "text/csv",
// tslint:disable-next-line
workExample: "stationId,latitude,longitude,datetime,temperature,humidity423432fsd,51.509865,-0.118092,2011-01-01T10:55:11+00:00,7.2,68",
files: [
{
url: "https://testocnfiles.blob.core.windows.net/testfiles/testzkp.zip",
checksum: "085340abffh21495345af97c6b0e761",
contentLength: "12324",
},
{
url: "https://testocnfiles.blob.core.windows.net/testfiles/testzkp2.zip",
},
],
links: [
{sample1: "http://data.ceda.ac.uk/badc/ukcp09/data/gridded-land-obs/gridded-land-obs-daily/"},
{sample2: "http://data.ceda.ac.uk/badc/ukcp09/data/gridded-land-obs/gridded-land-obs-averages-25km/"},
{fieldsDescription: "http://data.ceda.ac.uk/badc/ukcp09/"},
],
inLanguage: "en",
tags: "weather, uk, 2011, temperature, humidity",
price: 10,
},
}
const ddo: DDO = await ocean.registerAsset(metaData as any, publisher)
Logger.log(ddo.id)
}
runner(exec)

View File

@ -1,17 +0,0 @@
import {Account, Logger, Ocean, ServiceAgreementTemplate, Templates} from "../squid"
import config from "./config"
import {runner} from "./runner"
async function exec() {
const ocean: Ocean = await Ocean.getInstance(config)
const templateOwner: Account = (await ocean.getAccounts())[0]
const serviceAgreementTemplate: ServiceAgreementTemplate = new ServiceAgreementTemplate(new Templates.Access())
const serviceAgreementRegistered: boolean = await serviceAgreementTemplate.register(templateOwner.getId())
Logger.log("ServiceAgreementTemplate registered:", serviceAgreementRegistered,
"templateId:", serviceAgreementTemplate.getId())
}
runner(exec)

View File

@ -1,20 +0,0 @@
import { DDO } from "../ddo/DDO"
import {Logger, Ocean} from "../squid"
import config from "./config"
import {runner} from "./runner"
async function exec() {
const ocean: Ocean = await Ocean.getInstance(config)
const result: DDO[] = await ocean.searchAssetsByText("Office Humidity")
const names: string[] = result.map((ddo: DDO): string => {
const service = ddo.findServiceByType("Metadata")
if (service && service.metadata) {
return service.metadata.base.name
}
})
Logger.log(names.length, names)
}
runner(exec)

View File

@ -1,85 +0,0 @@
import { DDO } from "../ddo/DDO"
import { MetaData } from "../ddo/MetaData"
import {Account, Logger, Ocean} from "../squid"
import config from "./config"
import {runner} from "./runner"
async function exec() {
const ocean: Ocean = await Ocean.getInstance(config)
const publisher: Account = (await ocean.getAccounts())[0]
const consumer: Account = (await ocean.getAccounts())[1]
const metaData: MetaData = {
additionalInformation: {
structuredMarkup: [
{
mediaType: "application/ld+json",
uri: "http://skos.um.es/unescothes/C01194/jsonld",
},
{
mediaType: "text/turtle",
uri: "http://skos.um.es/unescothes/C01194/turtle",
},
],
updateFrecuency: "yearly",
checksum: "efdd14d39feb726e321931f408b3454d26f1a4899bcc608a68b5397f23203174",
},
base: {
name: "Office Humidity",
type: "dataset",
description: "Weather information of UK including temperature and humidity",
size: "3.1gb",
dateCreated: "2012-02-01T10:55:11+00:00",
author: "Met Office",
license: "CC-BY",
copyrightHolder: "Met Office",
encoding: "UTF-8",
compression: "zip",
contentType: "text/csv",
// tslint:disable-next-line
workExample: "stationId,latitude,longitude,datetime,temperature,humidity423432fsd,51.509865,-0.118092,2011-01-01T10:55:11+00:00,7.2,68",
files: [
{
url: "https://testocnfiles.blob.core.windows.net/testfiles/testzkp.zip",
checksum: "085340abffh21495345af97c6b0e761",
contentLength: "12324",
},
{
url: "https://testocnfiles.blob.core.windows.net/testfiles/testzkp2.zip",
},
],
links: [
{sample1: "http://data.ceda.ac.uk/badc/ukcp09/data/gridded-land-obs/gridded-land-obs-daily/"},
{sample2: "http://data.ceda.ac.uk/badc/ukcp09/data/gridded-land-obs/gridded-land-obs-averages-25km/"},
{fieldsDescription: "http://data.ceda.ac.uk/badc/ukcp09/"},
],
inLanguage: "en",
tags: "weather, uk, 2011, temperature, humidity",
price: 10,
},
curation: {
rating: 0.94,
numVotes: 124,
schema: "Binary Votting",
},
}
const ddo: DDO = await ocean.registerAsset(metaData, publisher)
Logger.log("did", ddo.id)
const accessService = ddo.findServiceByType("Access")
await consumer.requestTokens(metaData.base.price)
const serviceAgreementResult: any = await ocean
.signServiceAgreement(
ddo.id,
accessService.serviceDefinitionId,
consumer)
Logger.log("ServiceAgreement Id:", serviceAgreementResult.serviceAgreementId)
Logger.log("ServiceAgreement Signature:", serviceAgreementResult.serviceAgreementSignature)
}
runner(exec)

View File

@ -1,17 +0,0 @@
import * as HDWalletProvider from "truffle-hdwallet-provider"
import Config from "../models/Config"
import * as config from "./config/config.json"
if (process.env.SEED_WORDS) {
const seedphrase = process.env.SEED_WORDS
// @ts-ignore
config.web3Provider = new HDWalletProvider(
seedphrase,
config.nodeUri,
0,
2,
)
}
export default config as Config

View File

@ -1,11 +0,0 @@
{
"nodeUri": "http://localhost:8545",
"aquariusUri": "https://nginx-aquarius.dev-ocean.com",
"brizoUri": "http://localhost:8030",
"parityUri": "http://localhost:9545",
"secretStoreUri": "http://localhost:12001",
"threshold": 0,
"password": "secret",
"address": "0xa99d43d86a0758d5632313b8fa3972b6088a21bb",
"verbose": false
}

View File

@ -1,17 +0,0 @@
#!/bin/bash
set -e
# First of all to log the accounts
npm run run src/examples/GetAccounts.ts
# Before rest of examples
npm run run src/examples/RegisterServiceAgreementTemplates.ts
# Examples
npm run run src/examples/BuyAsset.ts
npm run run src/examples/ExecuteAgreement.ts
npm run run src/examples/GetBalance.ts
# npm run run src/examples/GrantAccess.ts
npm run run src/examples/RegisterAsset.ts
npm run run src/examples/Search.ts

View File

@ -1,10 +0,0 @@
import {Logger} from "../squid"
export function runner(fn: () => Promise<any>) {
fn()
.then(() => process.exit(0))
.catch((e) => {
Logger.error(e)
process.exit(1)
})
}