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
|
||||
```
|
||||
|
||||
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
|
||||
// ES6
|
||||
import { OceanAgent, Ocean } from '@oceanprotocol/squid'
|
||||
import { Ocean, Logger } from '@oceanprotocol/squid'
|
||||
|
||||
// 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.:
|
||||
|
||||
```js
|
||||
const ocean = await new Ocean({uri: 'http://localhost:8545', network: 'development'})
|
||||
const oceanAgent = new OceanAgent('http://localhost:5000/api/v1/provider')
|
||||
const ocean = await new Ocean({nodeUri: 'http://localhost:8545', network: 'development', providerUri: 'http://localhost:5000'})
|
||||
```
|
||||
|
||||
## Development
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
/* global fetch */
|
||||
import Logger from './utils/logger'
|
||||
import Logger from '../utils/logger'
|
||||
|
||||
export default class OceanAgent {
|
||||
constructor(connectionUrl) {
|
||||
this.assetsUrl = connectionUrl + '/assets'
|
||||
|
||||
Logger.warn('OceanAgent is deprecated use the Ocean object from squid instead')
|
||||
}
|
||||
|
||||
getAssetsMetadata() {
|
|
@ -1,6 +1,6 @@
|
|||
import Web3 from 'web3'
|
||||
import ContractLoader from './keeper/contractLoader'
|
||||
import Logger from './utils/logger'
|
||||
import ContractLoader from '../keeper/contractLoader'
|
||||
import Logger from '../utils/logger'
|
||||
|
||||
const DEFAULT_GAS = 300000
|
||||
|
|
@ -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 Logger from './utils/logger'
|
||||
import Web3Helper from './utils/Web3Helper'
|
||||
import MetaData from './metadata'
|
||||
|
||||
const DEFAULT_GAS = 300000
|
||||
|
||||
export default class Ocean {
|
||||
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._defaultGas = config.gas || DEFAULT_GAS
|
||||
this._network = config.network || 'development'
|
||||
this._providerUri = config.providerUri || null
|
||||
|
||||
this.helper = new Web3Helper(this._web3)
|
||||
this.metadata = new MetaData(this._providerUri)
|
||||
|
||||
return (async () => {
|
||||
this.market = await new OceanMarket(this._web3, this._network)
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
import OceanAgent from './ocean-agent'
|
||||
import OceanKeeper from './ocean-keeper'
|
||||
import OceanAgent from './deprecated/ocean-agent'
|
||||
import OceanKeeper from './deprecated/ocean-keeper'
|
||||
import Ocean from './ocean'
|
||||
import Logger from './utils/logger'
|
||||
|
||||
export {
|
||||
Ocean,
|
||||
OceanAgent,
|
||||
OceanKeeper,
|
||||
OceanAgent, // deprecated
|
||||
OceanKeeper, // deprecated
|
||||
Logger
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue