1
0
mirror of https://github.com/oceanprotocol/ocean.js.git synced 2024-11-26 20:39:05 +01:00

fix readme

This commit is contained in:
Ahmed Ali 2020-06-25 16:03:42 +02:00
commit ae39f7df28
5 changed files with 80 additions and 89 deletions

101
README.md
View File

@ -1,100 +1,47 @@
[![banner](https://raw.githubusercontent.com/oceanprotocol/art/master/github/repo-banner%402x.png)](https://oceanprotocol.com)
|[![Build Status](https://travis-ci.com/oceanprotocol/lib-js.svg?token=soMi2nNfCZq19zS1Rx4i&branch=develop)](https://travis-ci.com/oceanprotocol/lib-js)
[![Build Status](https://travis-ci.com/oceanprotocol/ocean-lib-js.svg?token=soMi2nNfCZq19zS1Rx4i&branch=develop)](https://travis-ci.com/oceanprotocol/lib-js)
<h1 align="center">Lib-js</h1>
<h1 align="center">Ocean-lib</h1>
> JavaScript client library for Ocean Protocol
> [oceanprotocol.com](https://oceanprotocol.com)
`ocean-lib` is a Javascript library to privately & securely publish, exchange,
and consume data. With it, you can:
* **Publish** data services: downloadable files, streaming data, or compute-to-data.
Ocean creates a new [ERC20](https://github.com/ethereum/EIPs/blob/7f4f0377730f5fc266824084188cc17cf246932e/EIPS/eip-20.md)
data token for each data service or set of services.
* **Mint** data tokens for the service
* **Consume** data tokens, to access the service
* **Transfer** data tokens to another owner, and **all other ERC20 actions**
using [web3.js](https://web3js.readthedocs.io/en/v1.2.9/web3-eth-contract.html) etc.
`ocean-lib` is part of the [Ocean Protocol](https://oceanprotocol.com) toolset.
This is in alpha state and you can expect running into problems. If you run into them, please open up a [new issue](/issues).
## Table of Contents
## Quick Install
- [Get Started](#get-started)
- [Local development](#local-development)
- [Testing](#testing)
- [Code Linting](#code-linting)
- [Packages](#packages)
- [Documentation](#documentation)
- [Contributing](#contributing)
- [Prior Art](#prior-art)
- [License](#license)
```npm i @oceanprotocol/lib```
# Get Started
## Quickstart: Simple Flow
TBD
This stripped-down flow shows the essence of Ocean. Just downloading, no metadata.
### Local development
[Go to simple flow](README_simple_flow.md)
As a pre-requisite, you need:
## Quickstart: Marketplace Flow
- Node.js
- npm
This batteries-included flow includes metadata, multiple services for one datatoken, and compute-to-data.
Note: For MacOS, make sure to have `node@10` installed.
[Go to marketplace flow](README_marketplace_flow.md)
Clone the project and install all dependencies:
## For ocean-lib Developers
```bash
git clone git@github.com:oceanprotocol/ocean-js.git
cd ocean-js/
# install packages
npm i
```
Generate metadata:
```bash
./scripts/get-metadata.js > src/metadata.json
```
# Testing
Run tests with
```bash
# for unit tests
TBD
# for test coverage
TBD
```
### Code Linting
Linting is setup for `JavaScript` with [ESLint](https://eslint.org)
```bash
# to check lint issues
npm run lint
```
Code style is enforced through the CI test process, builds will fail if there're any linting errors.
## Documentation
* [Release process](doc/RELEASE_PROCESS.md)
* [Core Documentation](doc/contracts/README.md)
* [Packaging of libraries](doc/PACKAGING.md)
## Contributing
See the page titled "[Ways to Contribute](https://docs.oceanprotocol.com/concepts/contributing/)" in the Ocean Protocol documentation.
## Prior Art
This project builds on top of the work done in open source projects:
- [OpenZeppelin/openzeppelin-contracts](https://github.com/OpenZeppelin/openzeppelin-contracts)
[Go to ocean-lib-developers flow](README_ocean-lib-developers.md)
## License
```
Copyright 2018 Ocean Protocol Foundation
Copyright ((C)) 2020 Ocean Protocol Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.

6
package-lock.json generated
View File

@ -1548,9 +1548,9 @@
"dev": true
},
"@types/node": {
"version": "14.0.13",
"resolved": "https://registry.npmjs.org/@types/node/-/node-14.0.13.tgz",
"integrity": "sha512-rouEWBImiRaSJsVA+ITTFM6ZxibuAlTuNOCyxVbwreu6k6+ujs7DfnU9o+PShFhET78pMBl3eH+AGSI5eOTkPA=="
"version": "14.0.14",
"resolved": "https://registry.npmjs.org/@types/node/-/node-14.0.14.tgz",
"integrity": "sha512-syUgf67ZQpaJj01/tRTknkMNoBBLWJOBODF0Zm4NrXmiSuxjymFrxnTu1QVYRubhVkRcZLYZG8STTwJRdVm/WQ=="
},
"@types/node-fetch": {
"version": "2.5.7",

View File

@ -54,7 +54,7 @@
"@types/chai": "^4.2.11",
"@types/chai-spies": "^1.0.1",
"@types/mocha": "^7.0.2",
"@types/node": "^14.0.13",
"@types/node": "^14.0.14",
"@types/node-fetch": "^2.5.5",
"@types/sinon": "^9.0.0",
"@typescript-eslint/eslint-plugin": "^2.23.0",

View File

@ -1,7 +1,7 @@
import Account from '../ocean/Account'
import { noZeroX } from '../utils'
import { Instantiable, InstantiableConfig } from '../Instantiable.abstract'
import { DDO } from '../ddo/DDO'
import { File } from '../ddo/interfaces/File'
const apiPath = '/api/v1/provider/services'
@ -74,14 +74,21 @@ export class Provider extends Instantiable {
serviceType: string,
consumerAddress: string
): Promise<any> {
const DDO = await this.ocean.assets.resolve(did)
let DDO
try {
DDO = await this.ocean.assets.resolve(did)
} catch (e) {
this.logger.error(e)
throw new Error('Failed to resolve DID')
}
const { dtAddress } = DDO
const args = {
did,
dtAddress,
serviceIndex,
serviceType,
consumerAddress
documentId: did,
serviceId: serviceIndex,
serviceType: serviceType,
tokenAddress: dtAddress,
consumerAddress: consumerAddress
}
try {
@ -95,6 +102,43 @@ export class Provider extends Instantiable {
}
}
public async download(
did: string,
txId: string,
tokenAddress: string,
serviceType: string,
serviceIndex: string,
destination: string,
account: Account,
files: File[],
index: number = -1
): Promise<any> {
const signature = await this.createSignature(account, did)
const filesPromises = files
.filter((_, i) => index === -1 || i === index)
.map(async ({ index: i }) => {
let consumeUrl = this.getDownloadEndpoint()
consumeUrl += `?index=${i}`
consumeUrl += `&documentId=${did}`
consumeUrl += `&serviceId=${serviceIndex}`
consumeUrl += `&serviceType=${serviceType}`
consumeUrl += `tokenAddress=${tokenAddress}`
consumeUrl += `&transferTxId=${txId}`
consumeUrl += `&consumerAddress=${account.getId()}`
consumeUrl += `&signature=${signature}`
try {
await this.ocean.utils.fetch.downloadFile(consumeUrl, destination, i)
} catch (e) {
this.logger.error('Error consuming assets')
this.logger.error(e)
throw e
}
})
await Promise.all(filesPromises)
return destination
}
public async getVersionInfo() {
return (await this.ocean.utils.fetch.get(this.url)).json()
}