1
0
mirror of https://github.com/oceanprotocol-archive/squid-js.git synced 2024-02-02 15:31:51 +01:00
squid-js/src/examples/SignAgreement.ts

84 lines
3.2 KiB
TypeScript
Raw Normal View History

2018-11-16 14:26:06 +01:00
import AdditionalInformation from "../ddo/AdditionalInformation"
import Curation from "../ddo/Curation"
2018-11-12 08:33:19 +01:00
import DDO from "../ddo/DDO"
2018-11-12 12:36:31 +01:00
import MetaData from "../ddo/MetaData"
2018-11-16 14:26:06 +01:00
import MetaDataBase from "../ddo/MetaDataBase"
import Service from "../ddo/Service"
2018-11-12 08:33:19 +01:00
import {Account, Logger, Ocean} from "../squid"
2018-12-10 10:11:36 +01:00
import config from "./config"
import {runner} from "./runner"
2018-11-12 08:33:19 +01:00
async function exec() {
2018-11-27 13:38:18 +01:00
const ocean: Ocean = await Ocean.getInstance(config)
2018-11-12 08:33:19 +01:00
const publisher: Account = (await ocean.getAccounts())[0]
const consumer: Account = (await ocean.getAccounts())[1]
2018-11-12 12:36:31 +01:00
const metaData = {
2018-11-16 14:26:06 +01:00
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",
} as AdditionalInformation,
2018-11-12 12:36:31 +01:00
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",
contentUrls: [
"https://testocnfiles.blob.core.windows.net/testfiles/testzkp.zip",
"https://testocnfiles.blob.core.windows.net/testfiles/testzkp.zip",
],
links: [
2018-11-16 14:26:06 +01:00
{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/"},
2018-11-12 12:36:31 +01:00
],
inLanguage: "en",
tags: "weather, uk, 2011, temperature, humidity",
price: 10,
2018-11-16 14:26:06 +01:00
} as MetaDataBase,
curation: {
rating: 0.94,
numVotes: 124,
schema: "Binary Votting",
} as Curation,
2018-11-12 12:36:31 +01:00
}
const ddo: DDO = await ocean.registerAsset(metaData as MetaData, publisher)
Logger.log("did", ddo.id)
2018-11-12 08:33:19 +01:00
2018-11-16 14:26:06 +01:00
const accessService: Service = ddo.findServiceByType("Access")
2018-11-26 15:24:59 +01:00
await consumer.requestTokens(metaData.base.price)
2018-11-21 14:59:22 +01:00
const serviceAgreementResult: any = await ocean
.signServiceAgreement(
ddo.id,
accessService.serviceDefinitionId,
consumer)
2018-11-16 14:26:06 +01:00
Logger.log("ServiceAgreement Id:", serviceAgreementResult.serviceAgreementId)
Logger.log("ServiceAgreement Signature:", serviceAgreementResult.serviceAgreementSignature)
}
2019-01-11 11:17:42 +01:00
runner(exec)