mirror of
https://github.com/oceanprotocol-archive/squid-js.git
synced 2024-02-02 15:31:51 +01:00
made OceanAgent deprecated, moved code to MetaData
This commit is contained in:
parent
71ec45d42b
commit
3d65274d9b
@ -36,21 +36,20 @@ Start by adding the package to your dependencies:
|
|||||||
npm i @oceanprotocol/squid
|
npm i @oceanprotocol/squid
|
||||||
```
|
```
|
||||||
|
|
||||||
The package exposes `OceanAgent` and `Ocean` which you can import in your code like so:
|
The package exposes `Ocean` and `Logger` which you can import in your code like this:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
// ES6
|
// ES6
|
||||||
import { OceanAgent, Ocean } from '@oceanprotocol/squid'
|
import { Ocean, Logger } from '@oceanprotocol/squid'
|
||||||
|
|
||||||
// ES2015
|
// ES2015
|
||||||
const { OceanAgent, Ocean } = require('@oceanprotocol/squid')
|
const { Ocean, Logger } = require('@oceanprotocol/squid')
|
||||||
```
|
```
|
||||||
|
|
||||||
You can then connect to a running [Keeper](https://github.com/oceanprotocol/keeper-contracts) & [Provider](https://github.com/oceanprotocol/provider) instance, e.g.:
|
You can then connect to a running [Keeper](https://github.com/oceanprotocol/keeper-contracts) & [Provider](https://github.com/oceanprotocol/provider) instance, e.g.:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const ocean = await new Ocean({uri: 'http://localhost:8545', network: 'development'})
|
const ocean = await new Ocean({nodeUri: 'http://localhost:8545', network: 'development', providerUri: 'http://localhost:5000'})
|
||||||
const oceanAgent = new OceanAgent('http://localhost:5000/api/v1/provider')
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Development
|
## Development
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
/* global fetch */
|
/* global fetch */
|
||||||
import Logger from './utils/logger'
|
import Logger from '../utils/logger'
|
||||||
|
|
||||||
export default class OceanAgent {
|
export default class OceanAgent {
|
||||||
constructor(connectionUrl) {
|
constructor(connectionUrl) {
|
||||||
this.assetsUrl = connectionUrl + '/assets'
|
this.assetsUrl = connectionUrl + '/assets'
|
||||||
|
|
||||||
|
Logger.warn('OceanAgent is deprecated use the Ocean object from squid instead')
|
||||||
}
|
}
|
||||||
|
|
||||||
getAssetsMetadata() {
|
getAssetsMetadata() {
|
@ -1,6 +1,6 @@
|
|||||||
import Web3 from 'web3'
|
import Web3 from 'web3'
|
||||||
import ContractLoader from './keeper/contractLoader'
|
import ContractLoader from '../keeper/contractLoader'
|
||||||
import Logger from './utils/logger'
|
import Logger from '../utils/logger'
|
||||||
|
|
||||||
const DEFAULT_GAS = 300000
|
const DEFAULT_GAS = 300000
|
||||||
|
|
37
src/metadata.js
Normal file
37
src/metadata.js
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
/* global fetch */
|
||||||
|
import Logger from './utils/logger'
|
||||||
|
|
||||||
|
export default class MetaData {
|
||||||
|
constructor(providerUri) {
|
||||||
|
this.assetsUrl = providerUri + '/assets'
|
||||||
|
}
|
||||||
|
|
||||||
|
getAssetsMetadata() {
|
||||||
|
return fetch(this.assetsUrl + '/metadata', { method: 'GET' })
|
||||||
|
.then(res => res.json())
|
||||||
|
.then(data => JSON.parse(data))
|
||||||
|
}
|
||||||
|
|
||||||
|
publishDataAsset(asset) {
|
||||||
|
return fetch(this.assetsUrl + '/metadata',
|
||||||
|
{
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify(asset),
|
||||||
|
headers: { 'Content-type': 'application/json' }
|
||||||
|
})
|
||||||
|
.then(response => {
|
||||||
|
Logger.log('Success:', response)
|
||||||
|
if (response.ok) {
|
||||||
|
Logger.log('Success:', response)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
Logger.log('Failed: ', response.status, response.statusText)
|
||||||
|
return false
|
||||||
|
// throw new Error(response.statusText ? response.statusText : `publish asset failed with status ${response.status}`)
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
Logger.log(`Publish asset to ocean database could not be completed: ${error.message()}`)
|
||||||
|
return false
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
@ -4,17 +4,20 @@ import OceanAuth from './keeper/auth'
|
|||||||
import OceanToken from './keeper/token'
|
import OceanToken from './keeper/token'
|
||||||
import Logger from './utils/logger'
|
import Logger from './utils/logger'
|
||||||
import Web3Helper from './utils/Web3Helper'
|
import Web3Helper from './utils/Web3Helper'
|
||||||
|
import MetaData from './metadata'
|
||||||
|
|
||||||
const DEFAULT_GAS = 300000
|
const DEFAULT_GAS = 300000
|
||||||
|
|
||||||
export default class Ocean {
|
export default class Ocean {
|
||||||
constructor(config) {
|
constructor(config) {
|
||||||
const web3Provider = config.web3Provider || new Web3.providers.HttpProvider(config.uri)
|
const web3Provider = config.web3Provider || new Web3.providers.HttpProvider(config.nodeUri)
|
||||||
this._web3 = new Web3(web3Provider)
|
this._web3 = new Web3(web3Provider)
|
||||||
this._defaultGas = config.gas || DEFAULT_GAS
|
this._defaultGas = config.gas || DEFAULT_GAS
|
||||||
this._network = config.network || 'development'
|
this._network = config.network || 'development'
|
||||||
|
this._providerUri = config.providerUri || null
|
||||||
|
|
||||||
this.helper = new Web3Helper(this._web3)
|
this.helper = new Web3Helper(this._web3)
|
||||||
|
this.metadata = new MetaData(this._providerUri)
|
||||||
|
|
||||||
return (async () => {
|
return (async () => {
|
||||||
this.market = await new OceanMarket(this._web3, this._network)
|
this.market = await new OceanMarket(this._web3, this._network)
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
import OceanAgent from './ocean-agent'
|
import OceanAgent from './deprecated/ocean-agent'
|
||||||
import OceanKeeper from './ocean-keeper'
|
import OceanKeeper from './deprecated/ocean-keeper'
|
||||||
import Ocean from './ocean'
|
import Ocean from './ocean'
|
||||||
import Logger from './utils/logger'
|
import Logger from './utils/logger'
|
||||||
|
|
||||||
export {
|
export {
|
||||||
Ocean,
|
Ocean,
|
||||||
OceanAgent,
|
OceanAgent, // deprecated
|
||||||
OceanKeeper,
|
OceanKeeper, // deprecated
|
||||||
Logger
|
Logger
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user