mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
Merge branch 'feature/cleaning' into dependabot/npm_and_yarn/release-it/bumper-1.4.0
This commit is contained in:
commit
a65e940a59
8
.github/dependabot.yml
vendored
Normal file
8
.github/dependabot.yml
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: npm
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: daily
|
||||
time: '03:00'
|
||||
timezone: Europe/Berlin
|
27
.travis.yml
Normal file
27
.travis.yml
Normal file
@ -0,0 +1,27 @@
|
||||
dist: xenial
|
||||
sudo: required
|
||||
language: node_js
|
||||
node_js:
|
||||
- '12'
|
||||
|
||||
services:
|
||||
- docker
|
||||
|
||||
cache: npm
|
||||
|
||||
matrix:
|
||||
fast_finish: true
|
||||
|
||||
before_install:
|
||||
- npm install -g npm
|
||||
- npm install -g ganache-cli@~6.5.1
|
||||
|
||||
before_script:
|
||||
- ganache-cli --port 18545 > ganache-cli.log &
|
||||
|
||||
script:
|
||||
- npm run lint
|
||||
- npm run build
|
||||
|
||||
notifications:
|
||||
email: false
|
@ -1,5 +1,6 @@
|
||||
[](https://oceanprotocol.com)
|
||||
|
||||
|[](https://travis-ci.com/oceanprotocol/lib-js)
|
||||
|
||||
<h1 align="center">Ocean-js</h1>
|
||||
|
||||
|
154
README_marketplace_flow.md
Normal file
154
README_marketplace_flow.md
Normal file
@ -0,0 +1,154 @@
|
||||
# ocean-lib
|
||||
|
||||
|
||||
`ocean-lib-js` is a Javascript/Typescript library to privately & securely publish, exchange, and consume data. With it, you can:
|
||||
* **Publish** data services: static data, streaming data, or compute-to-data. Every data service gets its own [ERC20](https://github.com/ethereum/EIPs/blob/7f4f0377730f5fc266824084188cc17cf246932e/EIPS/eip-20.md) token.
|
||||
* **Mint** data tokens for a given data service
|
||||
* **Transfer** data tokens to another owner
|
||||
* **Consume** data tokens, to access the service
|
||||
|
||||
`ocean-lib-js` is part of the [Ocean Protocol](www.oceanprotocol.com) toolset.
|
||||
|
||||
# Installation
|
||||
```
|
||||
// ES6
|
||||
import { Ocean, Logger } from '@oceanprotocol/lib'
|
||||
|
||||
// ES2015
|
||||
const { Ocean, Logger } = require('@oceanprotocol/lib')
|
||||
|
||||
```
|
||||
|
||||
# Quickstart
|
||||
|
||||
This section describes a marketplace flow with multiple services
|
||||
|
||||
Here's the steps.
|
||||
1. Alice publishes a dataset (= publishes a datatoken contract)
|
||||
1. Alice mints 100 tokens
|
||||
1. Alice transfers 1 token to Bob
|
||||
1. Bob consumes dataset
|
||||
|
||||
Let's go through each of these in detail.
|
||||
|
||||
|
||||
## 1. Alice hosts the dataset
|
||||
|
||||
A locally providerService ,metadatastore and marketplace are required:
|
||||
|
||||
Run the providerService and metadatastore:
|
||||
```
|
||||
docker run @oceanprotocol/provider-py:latest
|
||||
docker run @oceanprotocol/aquarius:latest
|
||||
docker run @oceanprotocol/marketplace:latest
|
||||
```
|
||||
|
||||
|
||||
## 2. Alice publishes a dataset (= publishes a datatoken contract)
|
||||
|
||||
For now, you're Alice:) Let's proceed.
|
||||
|
||||
|
||||
```javascript
|
||||
const { Ocean, Logger } = require('@oceanprotocol/lib')
|
||||
|
||||
const marketPlaceAddress='0x9876'
|
||||
//Alice's config
|
||||
const config={
|
||||
network: 'rinkeby',
|
||||
privateKey:'8da4ef21b864d2cc526dbdb2a120bd2874c36c9d0a1fb7f8c63d7f7a8b41de8f',
|
||||
metadataStoreURI: 'localhost:5000',
|
||||
providerUri: 'localhost:8030'
|
||||
}
|
||||
const ocean = Ocean(alice_config)
|
||||
const account = await ocean.accounts.list()[0]
|
||||
|
||||
|
||||
const myToken = ocean.datatoken.create(config.metadataStoreURI,account)
|
||||
//Alice allows MarketPlace to transfer 20 DT
|
||||
myToken.approve(marketPlaceAddress,20)
|
||||
|
||||
const dt_address=myToken.getAddress()
|
||||
|
||||
//create asset 1
|
||||
const metaData={
|
||||
"did":"did:op:1234",
|
||||
"owner":"0xaaaaa",
|
||||
"dtAddress":dt_address,
|
||||
"name":"Asset1",
|
||||
"services="[
|
||||
{ "id":0, "serviceEndpoint":"providerUri", "type":"download", "dtCost":10, "timeout":0,
|
||||
"files":[{"url":"http://example.net"},{"url":"http://example.com" }]
|
||||
},
|
||||
{ "id":1, "type":"compute", "serviceEndpoint":"providerUri", "dtCost":1,"timeout":3600},
|
||||
{ "id":2, "type":"compute", "serviceEndpoint":"providerUri", "dtCost":2, "timeout":7200 },
|
||||
]
|
||||
}
|
||||
//create will encrypt the URLs using publisher and update the ddo before pushing to aquarius
|
||||
//create will require that metaData.dtAddress is a valid DT Contract address
|
||||
const asset = ocean.assets.create(metaData,account)
|
||||
const did = asset.did
|
||||
```
|
||||
|
||||
|
||||
|
||||
## 3. Alice mints 100 tokens
|
||||
|
||||
```javascript
|
||||
myToken.mint(100)
|
||||
```
|
||||
|
||||
## 4. Exchange of value : How Bob gets DT
|
||||
```javascript
|
||||
const bob_config={
|
||||
network: 'rinkeby',
|
||||
privateKey:'1234ef21b864d2cc526dbdb2a120bd2874c36c9d0a1fb7f8c63d7f7a8b41de8f'
|
||||
marketPlaceUri: 'localhost:3000'
|
||||
}
|
||||
const bob_ocean = Ocean(bob_config)
|
||||
const bob_account = await bob_ocean.accounts.list()[0]
|
||||
|
||||
const asset = ocean.assets.resolve(did)
|
||||
const serviceIndex = assets.findServiceByType('compute')
|
||||
const num_dt_needed = assets.getDtCost(serviceIndex)
|
||||
//Bob need to buy num_dt_needed . DTAddress = asset.dtAddress
|
||||
|
||||
const {price, currency } = ocean.marketplace.getPrice(num_dt_needed,asset.dtAddress)
|
||||
bob_account.approve(price, currency, marketPlaceAddress)
|
||||
ocean.marketplace.buy(num_dt_needed,asset.dtAddress)
|
||||
```
|
||||
|
||||
## 5. Bob consumes dataset
|
||||
|
||||
Now, you are Bob :)
|
||||
|
||||
|
||||
```javascript
|
||||
|
||||
const bob_config={
|
||||
network: 'rinkeby',
|
||||
privateKey:'1234ef21b864d2cc526dbdb2a120bd2874c36c9d0a1fb7f8c63d7f7a8b41de8f'
|
||||
}
|
||||
const bob_ocean = Ocean(bob_config)
|
||||
|
||||
|
||||
const account = await bob_ocean.accounts.list()[0]
|
||||
const asset = ocean.assets.getFromDID(did)
|
||||
const serviceIndex = assets.findServiceByType('compute')
|
||||
|
||||
export const rawAlgoMeta = {
|
||||
rawcode: `console.log('Hello world'!)`,
|
||||
format: 'docker-image',
|
||||
version: '0.1',
|
||||
container: {
|
||||
entrypoint: 'node $ALGO',
|
||||
image: 'node',
|
||||
tag: '10'
|
||||
}
|
||||
}
|
||||
|
||||
const computeJob=asset.StartCompute(serviceIndex, rawAlgoMeta, account)
|
||||
|
||||
```
|
||||
|
||||
|
102
README_simpleflow.md
Normal file
102
README_simpleflow.md
Normal file
@ -0,0 +1,102 @@
|
||||
|
||||
# ocean-lib
|
||||
|
||||
`ocean-lib-js` is a Javascript/Typescript library to privately & securely publish, exchange, and consume data. With it, you can:
|
||||
* **Publish** data services: static data, streaming data, or compute-to-data. Every data service gets its own [ERC20](https://github.com/ethereum/EIPs/blob/7f4f0377730f5fc266824084188cc17cf246932e/EIPS/eip-20.md) token.
|
||||
* **Mint** data tokens for a given data service
|
||||
* **Transfer** data tokens to another owner
|
||||
* **Consume** data tokens, to access the service
|
||||
|
||||
`ocean-lib-js` is part of the [Ocean Protocol](www.oceanprotocol.com) toolset.
|
||||
|
||||
# Installation
|
||||
```
|
||||
// ES6
|
||||
import { Ocean, Logger } from '@oceanprotocol/lib'
|
||||
|
||||
// ES2015
|
||||
const { Ocean, Logger } = require('@oceanprotocol/lib')
|
||||
|
||||
```
|
||||
|
||||
# Quickstart
|
||||
|
||||
This section describes a flow with the simplest transfer of value, for static data.
|
||||
|
||||
Here's the steps.
|
||||
1. Alice publishes a dataset (= publishes a datatoken contract)
|
||||
1. Alice mints 100 tokens
|
||||
1. Alice transfers 1 token to Bob
|
||||
1. Bob consumes dataset
|
||||
|
||||
Let's go through each of these in detail.
|
||||
|
||||
|
||||
## 1. Alice publishes a dataset (= publishes a datatoken contract)
|
||||
|
||||
For now, you're Alice:) Let's proceed.
|
||||
|
||||
|
||||
```javascript
|
||||
const { Ocean, Logger } = require('@oceanprotocol/lib')
|
||||
const config={
|
||||
network: 'rinkeby',
|
||||
privateKey:'8da4ef21b864d2cc526dbdb2a120bd2874c36c9d0a1fb7f8c63d7f7a8b41de8f',
|
||||
}
|
||||
const ocean = Ocean(alice_config)
|
||||
const account = await ocean.accounts.list()[0]
|
||||
const myToken = ocean.datatoken.create('localhost:8030',account)
|
||||
const dt_address=myToken.getAddress()
|
||||
console.log(dt_address)
|
||||
```
|
||||
|
||||
## 2. Alice hosts the dataset
|
||||
|
||||
A locally providerService is required, which will serve just one file for this demo.
|
||||
Let's create the file to be shared:
|
||||
```
|
||||
touch /var/mydata/myFolder1/file
|
||||
````
|
||||
|
||||
Run the providerService:
|
||||
(given that ERC20 contract address from the above is 0x1234)
|
||||
|
||||
```
|
||||
ENV DT="{'0x1234':'/var/mydata/myFolder1'}"
|
||||
docker run @oceanprotocol/provider-py -e CONFIG=DT
|
||||
```
|
||||
|
||||
|
||||
## 3. Alice mints 100 tokens
|
||||
|
||||
```javascript
|
||||
myToken.mint(100)
|
||||
```
|
||||
|
||||
## 4. Alice transfers 1 token to Bob
|
||||
|
||||
```javascript
|
||||
myToken.transfer(1,BobAddress)
|
||||
```
|
||||
|
||||
## 5. Bob consumes dataset
|
||||
|
||||
Now, you are Bob :)
|
||||
|
||||
|
||||
```javascript
|
||||
|
||||
const bob_config={
|
||||
network: 'rinkeby',
|
||||
privateKey:'1234ef21b864d2cc526dbdb2a120bd2874c36c9d0a1fb7f8c63d7f7a8b41de8f'
|
||||
}
|
||||
const bob_ocean = Ocean(bob_config)
|
||||
|
||||
|
||||
const account = await bob_ocean.accounts.list()[0]
|
||||
const asset=bob_ocean.assets.getFromDTAddress(dt_address)[0]
|
||||
const file=asset.download(account)
|
||||
|
||||
```
|
||||
|
||||
|
1072
package-lock.json
generated
1072
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
20
package.json
20
package.json
@ -6,10 +6,9 @@
|
||||
"typings": "./dist/node/lib.d.ts",
|
||||
"unpkg": "./dist/browser/lib.cjs2.min.js",
|
||||
"scripts": {
|
||||
"build": "npm run clean && npm run build:tsc && npm run build:dist",
|
||||
"build": "npm run clean && npm run build:metadata && npm run build:tsc",
|
||||
"build:tsc": "tsc --sourceMap",
|
||||
"build:metadata": "./scripts/get-metadata.js > src/metadata.json",
|
||||
"build:dist": "cross-env NODE_ENV=production webpack",
|
||||
"clean": "rm -rf ./dist/ ./doc/ ./.nyc_output",
|
||||
"lint": "eslint --ignore-path .gitignore --ext .ts,.tsx .",
|
||||
"format": "prettier --parser typescript --ignore-path .gitignore --write '**/*.{js,jsx,ts,tsx}'",
|
||||
@ -41,40 +40,41 @@
|
||||
"node-fetch": "^2.6.0",
|
||||
"save-file": "^2.3.1",
|
||||
"uuid": "^8.0.0",
|
||||
"web3": "^1.2.6",
|
||||
"web3": "^1.2.9",
|
||||
"web3-eth-contract": "^1.2.9",
|
||||
"whatwg-url": "^8.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@release-it/bumper": "^1.4.0",
|
||||
"@oceanprotocol/contracts": "^0.2.0",
|
||||
"@truffle/hdwallet-provider": "^1.0.33",
|
||||
"@types/chai": "^4.2.11",
|
||||
"@types/chai-spies": "^1.0.1",
|
||||
"@types/mocha": "^7.0.2",
|
||||
"@types/node": "^14.0.0",
|
||||
"@types/node": "^14.0.13",
|
||||
"@types/node-fetch": "^2.5.5",
|
||||
"@types/sinon": "^9.0.0",
|
||||
"@typescript-eslint/eslint-plugin": "^2.23.0",
|
||||
"@typescript-eslint/parser": "^2.23.0",
|
||||
"auto-changelog": "^2.0.0",
|
||||
"auto-changelog": "^2.1.0",
|
||||
"chai": "^4.2.0",
|
||||
"chai-spies": "^1.0.0",
|
||||
"cross-env": "^7.0.2",
|
||||
"eslint": "^6.8.0",
|
||||
"eslint-config-oceanprotocol": "^1.5.0",
|
||||
"eslint-config-prettier": "^6.10.0",
|
||||
"eslint-plugin-prettier": "^3.1.2",
|
||||
"eslint-plugin-prettier": "^3.1.4",
|
||||
"lcov-result-merger": "^3.1.0",
|
||||
"mocha": "^7.1.0",
|
||||
"mocha": "^8.0.1",
|
||||
"mock-local-storage": "^1.1.11",
|
||||
"nyc": "^15.0.0",
|
||||
"nyc": "^15.1.0",
|
||||
"ora": "^4.0.2",
|
||||
"prettier": "^1.19.1",
|
||||
"sinon": "^9.0.1",
|
||||
"source-map-support": "^0.5.16",
|
||||
"ts-node": "^8.6.2",
|
||||
"ts-node": "^8.10.2",
|
||||
"typedoc": "^0.17.1",
|
||||
"typescript": "^3.8.3",
|
||||
"typescript": "^3.9.5",
|
||||
"uglifyjs-webpack-plugin": "^2.2.0",
|
||||
"webpack": "^4.42.0",
|
||||
"webpack-cli": "^3.3.11",
|
||||
|
@ -2,7 +2,6 @@
|
||||
'use strict'
|
||||
|
||||
const packageInfo = require('../package.json')
|
||||
|
||||
const execSync = require('child_process').execSync
|
||||
|
||||
process.stdout.write(
|
||||
|
@ -1,11 +1,9 @@
|
||||
import Account from '../ocean/Account'
|
||||
|
||||
const defaultFactoryABI = require('../datatokens/FactoryABI.json')
|
||||
const defaultDatatokensABI = require('../datatokens/DatatokensABI.json')
|
||||
const defaultFactoryABI = require('@oceanprotocol/artifacts/development/Factory.json')
|
||||
const defaultDatatokensABI = require('@oceanprotocol/artifacts/development/DatatokenTemplate.json')
|
||||
|
||||
/**
|
||||
* Provides a interface to DataTokens
|
||||
|
||||
*/
|
||||
export class DataTokens {
|
||||
public factoryAddress: string
|
||||
@ -40,34 +38,13 @@ export class DataTokens {
|
||||
* @param {Account} account
|
||||
* @return {Promise<string>} datatoken address
|
||||
*/
|
||||
public async create(
|
||||
metaDataStoreURI: string,
|
||||
account: Account
|
||||
): Promise<string> {
|
||||
public async create(metaDataStoreURI: string, account: Account): Promise<string> {
|
||||
// Create factory contract object
|
||||
const tokenAddress = null
|
||||
const factory = new this.web3.eth.Contract(this.factoryABI, this.factoryAddress, {
|
||||
from: account
|
||||
})
|
||||
const estGas = await factory.methods
|
||||
.createToken(metaDataStoreURI)
|
||||
.estimateGas(function(err, estGas){
|
||||
return estGas
|
||||
})
|
||||
// Invoke createToken function of the contract
|
||||
const trxReceipt = await factory.methods
|
||||
.createToken(metaDataStoreURI)
|
||||
.send({
|
||||
from: account,
|
||||
gas: estGas+1,
|
||||
gasPrice: '3000000000'
|
||||
})
|
||||
|
||||
let tokenAddress = null
|
||||
try {
|
||||
tokenAddress = trxReceipt.events.TokenCreated.returnValues[0]
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
// TODO:
|
||||
return tokenAddress
|
||||
}
|
||||
|
||||
@ -114,19 +91,8 @@ export class DataTokens {
|
||||
dataTokenAddress,
|
||||
{ from: account }
|
||||
)
|
||||
|
||||
const estGas = await datatoken.methods.mint(address, amount)
|
||||
.estimateGas(function(err, estGas){
|
||||
return estGas
|
||||
})
|
||||
|
||||
const trxReceipt = await datatoken.methods.mint(address, amount)
|
||||
.send({
|
||||
from:account,
|
||||
gas: estGas*2,
|
||||
gasPrice: '3000000000'
|
||||
})
|
||||
|
||||
const trxReceipt = null
|
||||
// TODO:
|
||||
return trxReceipt
|
||||
}
|
||||
|
||||
@ -253,4 +219,4 @@ export class DataTokens {
|
||||
const trxReceipt = await datatoken.methods.cap().call()
|
||||
return trxReceipt
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,450 +0,0 @@
|
||||
[
|
||||
{
|
||||
"constant": false,
|
||||
"inputs": [
|
||||
{
|
||||
"name": "spender",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"name": "value",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "approve",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "",
|
||||
"type": "bool"
|
||||
}
|
||||
],
|
||||
"payable": false,
|
||||
"stateMutability": "nonpayable",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [],
|
||||
"name": "totalSupply",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"payable": false,
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": false,
|
||||
"inputs": [
|
||||
{
|
||||
"name": "from",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"name": "to",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"name": "value",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "transferFrom",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "",
|
||||
"type": "bool"
|
||||
}
|
||||
],
|
||||
"payable": false,
|
||||
"stateMutability": "nonpayable",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": false,
|
||||
"inputs": [
|
||||
{
|
||||
"name": "spender",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"name": "addedValue",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "increaseAllowance",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "",
|
||||
"type": "bool"
|
||||
}
|
||||
],
|
||||
"payable": false,
|
||||
"stateMutability": "nonpayable",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [
|
||||
{
|
||||
"name": "account",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"name": "balanceOf",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"payable": false,
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": false,
|
||||
"inputs": [
|
||||
{
|
||||
"name": "spender",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"name": "subtractedValue",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "decreaseAllowance",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "",
|
||||
"type": "bool"
|
||||
}
|
||||
],
|
||||
"payable": false,
|
||||
"stateMutability": "nonpayable",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": false,
|
||||
"inputs": [
|
||||
{
|
||||
"name": "to",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"name": "value",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "transfer",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "",
|
||||
"type": "bool"
|
||||
}
|
||||
],
|
||||
"payable": false,
|
||||
"stateMutability": "nonpayable",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [
|
||||
{
|
||||
"name": "owner",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"name": "spender",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"name": "allowance",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"payable": false,
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"name": "name",
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"name": "symbol",
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"name": "minter",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"name": "cap",
|
||||
"type": "uint256"
|
||||
},
|
||||
{
|
||||
"name": "blob",
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"payable": false,
|
||||
"stateMutability": "nonpayable",
|
||||
"type": "constructor"
|
||||
},
|
||||
{
|
||||
"anonymous": false,
|
||||
"inputs": [
|
||||
{
|
||||
"indexed": true,
|
||||
"name": "from",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"indexed": true,
|
||||
"name": "to",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"indexed": false,
|
||||
"name": "value",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "Transfer",
|
||||
"type": "event"
|
||||
},
|
||||
{
|
||||
"anonymous": false,
|
||||
"inputs": [
|
||||
{
|
||||
"indexed": true,
|
||||
"name": "owner",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"indexed": true,
|
||||
"name": "spender",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"indexed": false,
|
||||
"name": "value",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "Approval",
|
||||
"type": "event"
|
||||
},
|
||||
{
|
||||
"constant": false,
|
||||
"inputs": [
|
||||
{
|
||||
"name": "name",
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"name": "symbol",
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"name": "minter",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"name": "cap",
|
||||
"type": "uint256"
|
||||
},
|
||||
{
|
||||
"name": "blob",
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"name": "initialize",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "",
|
||||
"type": "bool"
|
||||
}
|
||||
],
|
||||
"payable": false,
|
||||
"stateMutability": "nonpayable",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": false,
|
||||
"inputs": [
|
||||
{
|
||||
"name": "account",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"name": "value",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "mint",
|
||||
"outputs": [],
|
||||
"payable": true,
|
||||
"stateMutability": "payable",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": false,
|
||||
"inputs": [],
|
||||
"name": "pause",
|
||||
"outputs": [],
|
||||
"payable": false,
|
||||
"stateMutability": "nonpayable",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": false,
|
||||
"inputs": [],
|
||||
"name": "unpause",
|
||||
"outputs": [],
|
||||
"payable": false,
|
||||
"stateMutability": "nonpayable",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": false,
|
||||
"inputs": [
|
||||
{
|
||||
"name": "minter",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"name": "setMinter",
|
||||
"outputs": [],
|
||||
"payable": false,
|
||||
"stateMutability": "nonpayable",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [],
|
||||
"name": "name",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "",
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"payable": false,
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [],
|
||||
"name": "symbol",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "",
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"payable": false,
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [],
|
||||
"name": "blob",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "",
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"payable": false,
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [],
|
||||
"name": "decimals",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"payable": false,
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [],
|
||||
"name": "cap",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"payable": false,
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [
|
||||
{
|
||||
"name": "account",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"name": "isMinter",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "",
|
||||
"type": "bool"
|
||||
}
|
||||
],
|
||||
"payable": false,
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [],
|
||||
"name": "isInitialized",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "",
|
||||
"type": "bool"
|
||||
}
|
||||
],
|
||||
"payable": false,
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [],
|
||||
"name": "isPaused",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "",
|
||||
"type": "bool"
|
||||
}
|
||||
],
|
||||
"payable": false,
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
}
|
||||
]
|
@ -1,150 +0,0 @@
|
||||
[
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [
|
||||
{
|
||||
"name": "str1",
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"name": "str2",
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"name": "concatenateStrings",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "",
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"payable": false,
|
||||
"stateMutability": "pure",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [
|
||||
{
|
||||
"name": "value",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "uintToString",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "",
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"payable": false,
|
||||
"stateMutability": "pure",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"name": "_template",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"payable": false,
|
||||
"stateMutability": "nonpayable",
|
||||
"type": "constructor"
|
||||
},
|
||||
{
|
||||
"anonymous": false,
|
||||
"inputs": [
|
||||
{
|
||||
"indexed": false,
|
||||
"name": "newTokenAddress",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"indexed": false,
|
||||
"name": "templateAddress",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"indexed": false,
|
||||
"name": "tokenName",
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"name": "TokenCreated",
|
||||
"type": "event"
|
||||
},
|
||||
{
|
||||
"anonymous": false,
|
||||
"inputs": [
|
||||
{
|
||||
"indexed": true,
|
||||
"name": "tokenAddress",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"indexed": true,
|
||||
"name": "tokenName",
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"indexed": true,
|
||||
"name": "tokenSymbol",
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"indexed": false,
|
||||
"name": "tokenCap",
|
||||
"type": "uint256"
|
||||
},
|
||||
{
|
||||
"indexed": false,
|
||||
"name": "RegisteredBy",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"indexed": false,
|
||||
"name": "RegisteredAt",
|
||||
"type": "uint256"
|
||||
},
|
||||
{
|
||||
"indexed": false,
|
||||
"name": "blob",
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"name": "TokenRegistered",
|
||||
"type": "event"
|
||||
},
|
||||
{
|
||||
"anonymous": false,
|
||||
"inputs": [
|
||||
{
|
||||
"indexed": false,
|
||||
"name": "instance",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"name": "InstanceDeployed",
|
||||
"type": "event"
|
||||
},
|
||||
{
|
||||
"constant": false,
|
||||
"inputs": [
|
||||
{
|
||||
"name": "blob",
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"name": "createToken",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "token",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"payable": false,
|
||||
"stateMutability": "nonpayable",
|
||||
"type": "function"
|
||||
}
|
||||
]
|
@ -52,8 +52,7 @@ export class Assets extends Instantiable {
|
||||
const publisherURI = this.ocean.brizo.getURI()
|
||||
const jsonBlob = { t: 0, url: publisherURI }
|
||||
const { datatokens } = this.ocean
|
||||
return datatokens.create( JSON.stringify(jsonBlob), publisher)
|
||||
|
||||
return datatokens.create(JSON.stringify(jsonBlob), publisher)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -80,7 +79,7 @@ export class Assets extends Instantiable {
|
||||
const metadataStoreURI = this.ocean.aquarius.getURI()
|
||||
const jsonBlob = { t: 1, url: metadataStoreURI }
|
||||
const { datatokens } = this.ocean
|
||||
dtAddress = await datatokens.create(JSON.stringify(jsonBlob), publisher )
|
||||
dtAddress = await datatokens.create(JSON.stringify(jsonBlob), publisher)
|
||||
this.logger.log('DataToken creted')
|
||||
observer.next(CreateProgressStep.DataTokenCreated)
|
||||
}
|
||||
|
9
test/integration/tsconfig.json
Normal file
9
test/integration/tsconfig.json
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"resolveJsonModule": true,
|
||||
"lib": ["es6", "es7", "dom"],
|
||||
"noUnusedLocals": true,
|
||||
"esModuleInterop": true,
|
||||
"allowSyntheticDefaultImports": true
|
||||
}
|
||||
}
|
@ -1,66 +0,0 @@
|
||||
import { assert } from 'chai'
|
||||
import { TestContractHandler } from './TestContractHandler'
|
||||
import { DataTokens } from '../../src/datatokens/Datatokens'
|
||||
|
||||
const Web3 = require('web3')
|
||||
const web3 = new Web3("http://127.0.0.1:8545")
|
||||
|
||||
const factoryABI = require('../../src/datatokens/FactoryABI.json')
|
||||
const datatokensABI = require('../../src/datatokens/DatatokensABI.json')
|
||||
|
||||
describe('DataTokens', () => {
|
||||
|
||||
let minter
|
||||
let spender
|
||||
let balance
|
||||
let contracts
|
||||
let datatoken
|
||||
let tokenAddress
|
||||
|
||||
let tokenAmount = 100
|
||||
let blob = 'https://example.com/dataset-1'
|
||||
|
||||
describe('#test', () => {
|
||||
it('should deploy contracts', async () => {
|
||||
contracts = new TestContractHandler(factoryABI,datatokensABI)
|
||||
await contracts.getAccounts()
|
||||
minter = contracts.accounts[0]
|
||||
spender = contracts.accounts[1]
|
||||
await contracts.deployContracts(minter)
|
||||
})
|
||||
|
||||
it('should create Datatoken object', async () => {
|
||||
datatoken = new DataTokens(contracts.factoryAddress, factoryABI, datatokensABI, web3)
|
||||
assert(datatoken !== null)
|
||||
})
|
||||
|
||||
it('should create Datatoken contract', async () => {
|
||||
tokenAddress = await datatoken.create(blob, minter)
|
||||
assert(tokenAddress !== null)
|
||||
})
|
||||
|
||||
it('should mint Datatokens', async () => {
|
||||
await datatoken.mint(tokenAddress, minter, tokenAmount)
|
||||
balance = await datatoken.balance(tokenAddress, minter)
|
||||
assert(balance.toString() === tokenAmount.toString())
|
||||
})
|
||||
|
||||
it('should transfer Datatokens to spender', async () => {
|
||||
await datatoken.transfer(tokenAddress, spender, tokenAmount, minter)
|
||||
balance = await datatoken.balance(tokenAddress, spender)
|
||||
assert(balance.toString() === tokenAmount.toString())
|
||||
|
||||
})
|
||||
|
||||
it('should approve Datatokens to spend', async () => {
|
||||
await datatoken.approve(tokenAddress, minter, tokenAmount, spender)
|
||||
})
|
||||
|
||||
it('should transferFrom Datatokens back to the minter', async () => {
|
||||
await datatoken.transferFrom(tokenAddress, spender, tokenAmount, minter)
|
||||
minter = await datatoken.balance(tokenAddress, spender)
|
||||
assert(balance.toString() === tokenAmount.toString())
|
||||
})
|
||||
|
||||
})
|
||||
})
|
File diff suppressed because one or more lines are too long
@ -1,8 +0,0 @@
|
||||
--require ts-node/register
|
||||
--require source-map-support/register
|
||||
--require mock-local-storage
|
||||
--full-trace
|
||||
--bail
|
||||
--exit
|
||||
--timeout 20000
|
||||
test/unit/config.ts test/unit/**/*.test.ts
|
9
test/unit/tsconfig.json
Normal file
9
test/unit/tsconfig.json
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"resolveJsonModule": true,
|
||||
"lib": ["es6", "es7"],
|
||||
"noUnusedLocals": true,
|
||||
"esModuleInterop": true,
|
||||
"allowSyntheticDefaultImports": true
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user