Skip to content

Commit

Permalink
Merge branch 'main' into fix/logger
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahmed Ali authored Oct 21, 2020
2 parents b9f0384 + 5577e1d commit 57b5f83
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 30 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@ All notable changes to this project will be documented in this file. Dates are d

Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

#### [v0.7.1](https://github.com/oceanprotocol/ocean.js/compare/v0.7.0...v0.7.1)

- BestPrice type tweak [`47d3282`](https://github.com/oceanprotocol/ocean.js/commit/47d328219746dd4fb05e364e24492eef0a0c5907)

#### [v0.7.0](https://github.com/oceanprotocol/ocean.js/compare/v0.6.7...v0.7.0)

> 21 October 2020
- make create methods subscribable [`#389`](https://github.com/oceanprotocol/ocean.js/pull/389)
- Bump @types/node from 14.11.10 to 14.14.0 [`#383`](https://github.com/oceanprotocol/ocean.js/pull/383)
- make pool.create subscribable [`dec9c57`](https://github.com/oceanprotocol/ocean.js/commit/dec9c57c94f777201355c1356c881989002931c1)
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@oceanprotocol/lib",
"version": "0.7.0",
"version": "0.7.1",
"description": "JavaScript client library for Ocean Protocol",
"main": "./dist/node/lib.js",
"typings": "./dist/node/lib.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion src/ddo/interfaces/BestPrice.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export interface BestPrice {
type: 'pool' | 'exchange'
type: 'pool' | 'exchange' | ''
address: string
value: number
ocean?: number
Expand Down
75 changes: 48 additions & 27 deletions src/utils/ConfigHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Config from '../models/Config'
import { Logger } from '../lib'
import fs from 'fs'
import { homedir } from 'os'

import * as DefaultContractsAddresses from '@oceanprotocol/contracts/artifacts/address.json'
export declare type ConfigHelperNetworkName =
| 'mainnet'
| 'rinkeby'
Expand All @@ -21,9 +21,10 @@ const configs: ConfigHelperConfig[] = [
networkId: null,
network: 'unknown',
nodeUri: 'http://localhost:8545',
factoryAddress: null,
metadataCacheUri: 'http://127.0.0.1:5000',
providerUri: 'http://127.0.0.1:8030',
oceanTokenAddress: null,
factoryAddress: '0x1234',
poolFactoryAddress: null,
fixedRateExchangeAddress: null,
metadataContractAddress: null
Expand All @@ -33,9 +34,10 @@ const configs: ConfigHelperConfig[] = [
networkId: 8996,
network: 'development',
nodeUri: 'http://localhost:8545',
factoryAddress: null,
metadataCacheUri: 'http://127.0.0.1:5000',
providerUri: 'http://127.0.0.1:8030',
oceanTokenAddress: null,
factoryAddress: null,
poolFactoryAddress: null,
fixedRateExchangeAddress: null,
metadataContractAddress: null
Expand All @@ -44,22 +46,22 @@ const configs: ConfigHelperConfig[] = [
networkId: 4,
network: 'rinkeby',
nodeUri: 'https://rinkeby.infura.io/v3',
factoryAddress: '0x3fd7A00106038Fb5c802c6d63fa7147Fe429E83a',
oceanTokenAddress: '0x8967BCF84170c91B0d24D4302C2376283b0B3a07',
metadataCacheUri: 'https://aquarius.rinkeby.v3.dev-ocean.com',
providerUri: 'https://provider.rinkeby.v3.dev-ocean.com',
poolFactoryAddress: '0x53eDF9289B0898e1652Ce009AACf8D25fA9A42F8',
fixedRateExchangeAddress: '0xeD1DfC5F3a589CfC4E8B91C1fbfC18FC6699Fbde',
metadataContractAddress: '0xFD8a7b6297153397B7eb4356C47dbd381d58bFF4'
oceanTokenAddress: null,
factoryAddress: null,
poolFactoryAddress: null,
fixedRateExchangeAddress: null,
metadataContractAddress: null
},
{
networkId: 1,
network: 'mainnet',
nodeUri: 'https://mainnet.infura.io/v3',
factoryAddress: '0x1234',
oceanTokenAddress: '0x7AFeBBB46fDb47ed17b22ed075Cde2447694fB9e',
metadataCacheUri: null,
providerUri: null,
oceanTokenAddress: null,
factoryAddress: null,
poolFactoryAddress: null,
fixedRateExchangeAddress: null,
metadataContractAddress: null
Expand All @@ -69,31 +71,50 @@ const configs: ConfigHelperConfig[] = [
export class ConfigHelper {
/* Load contract addresses from env ADDRESS_FILE (generated by ocean-contracts) */
public getAddressesFromEnv(network: string): Partial<ConfigHelperConfig> {
try {
const data = JSON.parse(
fs.readFileSync(
process.env.ADDRESS_FILE ||
`${homedir}/.ocean/ocean-contracts/artifacts/address.json`,
'utf8'
)
)

const { DTFactory, BFactory, FixedRateExchange, Metadata, Ocean } = data[network]

const configAddresses: Partial<ConfigHelperConfig> = {
// use the defaults first
let configAddresses: Partial<ConfigHelperConfig>
if (DefaultContractsAddresses[network]) {
const {
DTFactory,
BFactory,
FixedRateExchange,
Metadata,
Ocean
} = DefaultContractsAddresses[network]
configAddresses = {
factoryAddress: DTFactory,
poolFactoryAddress: BFactory,
fixedRateExchangeAddress: FixedRateExchange,
metadataContractAddress: Metadata,
oceanTokenAddress: Ocean,
...(process.env.AQUARIUS_URI && { metadataCacheUri: process.env.AQUARIUS_URI })
}

return configAddresses
} catch (e) {
Logger.error(`ERROR: Could not load local contract address file: ${e.message}`)
return null
}
// try ADDRESS_FILE env
if (fs && process.env.ADDRESS_FILE) {
try {
const data = JSON.parse(
fs.readFileSync(
process.env.ADDRESS_FILE ||
`${homedir}/.ocean/ocean-contracts/artifacts/address.json`,
'utf8'
)
)
const { DTFactory, BFactory, FixedRateExchange, Metadata, Ocean } = data[network]
configAddresses = {
factoryAddress: DTFactory,
poolFactoryAddress: BFactory,
fixedRateExchangeAddress: FixedRateExchange,
metadataContractAddress: Metadata,
oceanTokenAddress: Ocean,
...(process.env.AQUARIUS_URI && { metadataCacheUri: process.env.AQUARIUS_URI })
}
} catch (e) {
// console.error(`ERROR: Could not load local contract address file: ${e.message}`)
// return null
}
}
return configAddresses
}

public getConfig(
Expand Down
8 changes: 8 additions & 0 deletions test/unit/utils/ConfigHelper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,32 @@ describe('ConfigHelper', () => {
const network = 'rinkeby'
const config = new ConfigHelper().getConfig(network)
assert(config.nodeUri.includes(network))
assert(config.factoryAddress != null)
})

it('should get config based on network name, and add passed Infura ID', () => {
const network = 'rinkeby'
const infuraId = 'helloInfura'
const config = new ConfigHelper().getConfig(network, infuraId)
assert(config.nodeUri.includes(infuraId))
assert(config.factoryAddress != null)
})

it('should get config based on chain ID', () => {
const network = 4
const config = new ConfigHelper().getConfig(network)
assert(config.nodeUri.includes('rinkeby'))
assert(config.factoryAddress != null)
})

it('should return nothing with unknown network', () => {
const network = 'blabla'
const config = new ConfigHelper().getConfig(network)
assert(config === null)
})
it('should get a custom config', () => {
const network = 'unknown'
const config = new ConfigHelper().getConfig(network)
assert(config.factoryAddress === '0x1234')
})
})

0 comments on commit 57b5f83

Please sign in to comment.