1
0
mirror of https://github.com/oceanprotocol/ocean.js.git synced 2024-11-26 20:39:05 +01:00
This commit is contained in:
mihaisc 2021-12-08 06:35:48 -08:00 committed by GitHub
parent 061c4c76aa
commit b81eb8fd8c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 56 additions and 30 deletions

View File

@ -132,10 +132,43 @@ export class Config {
*/ */
public authTokenExpiration?: number public authTokenExpiration?: number
// Parity config /**
* Parity config
* @type {string}
*/
public parityUri?: string public parityUri?: string
public threshold?: number public threshold?: number
/**
* Chain ID
* @type {number}
*/
chainId: number
/**
* Network name ex: mainnet, rinkeby, polygon
* @type {string}
*/
network: string
/**
* Url of the relevant subgraph instance ex: https://subgraph.mainnet.oceanprotocol.com
* @type {string}
*/
subgraphUri: string
/**
* Url of the blockchain exporer ex: https://etherscan.io
* @type {string}
*/
explorerUri: string
/**
* Ocean toke symbol on the chain, it's used just for convenience to reduce number of calls
* @type {string}
*/
oceanTokenSymbol: string
} }
export default Config export default Config

View File

@ -5,16 +5,8 @@ import { homedir } from 'os'
import { default as DefaultContractsAddresses } from '@oceanprotocol/contracts/addresses/address.json' import { default as DefaultContractsAddresses } from '@oceanprotocol/contracts/addresses/address.json'
import LoggerInstance from './Logger' import LoggerInstance from './Logger'
export interface ConfigHelperConfig extends Config { const configHelperNetworksBase: Config = {
networkId: number chainId: null,
network: string
subgraphUri: string
explorerUri: string
oceanTokenSymbol: string
}
const configHelperNetworksBase: ConfigHelperConfig = {
networkId: null,
network: 'unknown', network: 'unknown',
metadataCacheUri: 'https://aquarius.oceanprotocol.com', metadataCacheUri: 'https://aquarius.oceanprotocol.com',
nodeUri: 'http://localhost:8545', nodeUri: 'http://localhost:8545',
@ -31,20 +23,20 @@ const configHelperNetworksBase: ConfigHelperConfig = {
startBlock: 0 startBlock: 0
} }
export const configHelperNetworks: ConfigHelperConfig[] = [ export const configHelperNetworks: Config[] = [
{ {
...configHelperNetworksBase ...configHelperNetworksBase
}, },
{ {
// barge // barge
...configHelperNetworksBase, ...configHelperNetworksBase,
networkId: 8996, chainId: 8996,
network: 'development', network: 'development',
metadataCacheUri: 'http://127.0.0.1:5000' metadataCacheUri: 'http://127.0.0.1:5000'
}, },
{ {
...configHelperNetworksBase, ...configHelperNetworksBase,
networkId: 3, chainId: 3,
network: 'ropsten', network: 'ropsten',
nodeUri: 'https://ropsten.infura.io/v3', nodeUri: 'https://ropsten.infura.io/v3',
providerUri: 'https://provider.ropsten.oceanprotocol.com', providerUri: 'https://provider.ropsten.oceanprotocol.com',
@ -54,7 +46,7 @@ export const configHelperNetworks: ConfigHelperConfig[] = [
}, },
{ {
...configHelperNetworksBase, ...configHelperNetworksBase,
networkId: 4, chainId: 4,
network: 'rinkeby', network: 'rinkeby',
nodeUri: 'https://rinkeby.infura.io/v3', nodeUri: 'https://rinkeby.infura.io/v3',
providerUri: 'https://provider.rinkeby.oceanprotocol.com', providerUri: 'https://provider.rinkeby.oceanprotocol.com',
@ -64,7 +56,7 @@ export const configHelperNetworks: ConfigHelperConfig[] = [
}, },
{ {
...configHelperNetworksBase, ...configHelperNetworksBase,
networkId: 1, chainId: 1,
network: 'mainnet', network: 'mainnet',
nodeUri: 'https://mainnet.infura.io/v3', nodeUri: 'https://mainnet.infura.io/v3',
providerUri: 'https://provider.mainnet.oceanprotocol.com', providerUri: 'https://provider.mainnet.oceanprotocol.com',
@ -74,7 +66,7 @@ export const configHelperNetworks: ConfigHelperConfig[] = [
}, },
{ {
...configHelperNetworksBase, ...configHelperNetworksBase,
networkId: 137, chainId: 137,
network: 'polygon', network: 'polygon',
nodeUri: 'https://polygon-mainnet.infura.io/v3', nodeUri: 'https://polygon-mainnet.infura.io/v3',
providerUri: 'https://provider.polygon.oceanprotocol.com', providerUri: 'https://provider.polygon.oceanprotocol.com',
@ -85,7 +77,7 @@ export const configHelperNetworks: ConfigHelperConfig[] = [
}, },
{ {
...configHelperNetworksBase, ...configHelperNetworksBase,
networkId: 1287, chainId: 1287,
network: 'moonbeamalpha', network: 'moonbeamalpha',
nodeUri: 'https://rpc.testnet.moonbeam.network', nodeUri: 'https://rpc.testnet.moonbeam.network',
providerUri: 'https://provider.moonbeamalpha.oceanprotocol.com', providerUri: 'https://provider.moonbeamalpha.oceanprotocol.com',
@ -95,7 +87,7 @@ export const configHelperNetworks: ConfigHelperConfig[] = [
}, },
{ {
...configHelperNetworksBase, ...configHelperNetworksBase,
networkId: 2021000, chainId: 2021000,
network: 'gaiaxtestnet', network: 'gaiaxtestnet',
nodeUri: 'https://rpc.gaiaxtestnet.oceanprotocol.com', nodeUri: 'https://rpc.gaiaxtestnet.oceanprotocol.com',
providerUri: 'https://provider.gaiaxtestnet.oceanprotocol.com', providerUri: 'https://provider.gaiaxtestnet.oceanprotocol.com',
@ -104,7 +96,7 @@ export const configHelperNetworks: ConfigHelperConfig[] = [
}, },
{ {
...configHelperNetworksBase, ...configHelperNetworksBase,
networkId: 2021001, chainId: 2021001,
network: 'catenaxtestnet', network: 'catenaxtestnet',
nodeUri: 'https://rpc.catenaxtestnet.oceanprotocol.com', nodeUri: 'https://rpc.catenaxtestnet.oceanprotocol.com',
providerUri: 'https://provider.catenaxtestnet.oceanprotocol.com', providerUri: 'https://provider.catenaxtestnet.oceanprotocol.com',
@ -114,7 +106,7 @@ export const configHelperNetworks: ConfigHelperConfig[] = [
}, },
{ {
...configHelperNetworksBase, ...configHelperNetworksBase,
networkId: 80001, chainId: 80001,
network: 'mumbai', network: 'mumbai',
nodeUri: 'https://polygon-mumbai.infura.io/v3', nodeUri: 'https://polygon-mumbai.infura.io/v3',
providerUri: 'https://provider.mumbai.oceanprotocol.com', providerUri: 'https://provider.mumbai.oceanprotocol.com',
@ -123,7 +115,7 @@ export const configHelperNetworks: ConfigHelperConfig[] = [
}, },
{ {
...configHelperNetworksBase, ...configHelperNetworksBase,
networkId: 56, chainId: 56,
network: 'bsc', network: 'bsc',
nodeUri: 'https://bsc-dataseed.binance.org', nodeUri: 'https://bsc-dataseed.binance.org',
providerUri: 'https://provider.bsc.oceanprotocol.com', providerUri: 'https://provider.bsc.oceanprotocol.com',
@ -132,7 +124,7 @@ export const configHelperNetworks: ConfigHelperConfig[] = [
}, },
{ {
...configHelperNetworksBase, ...configHelperNetworksBase,
networkId: 44787, chainId: 44787,
network: 'celoalfajores', network: 'celoalfajores',
nodeUri: 'https://alfajores-forno.celo-testnet.org', nodeUri: 'https://alfajores-forno.celo-testnet.org',
providerUri: 'https://provider.celoalfajores.oceanprotocol.com', providerUri: 'https://provider.celoalfajores.oceanprotocol.com',
@ -141,7 +133,7 @@ export const configHelperNetworks: ConfigHelperConfig[] = [
}, },
{ {
...configHelperNetworksBase, ...configHelperNetworksBase,
networkId: 246, chainId: 246,
network: 'energyweb', network: 'energyweb',
nodeUri: 'https://rpc.energyweb.org', nodeUri: 'https://rpc.energyweb.org',
providerUri: 'https://provider.energyweb.oceanprotocol.com', providerUri: 'https://provider.energyweb.oceanprotocol.com',
@ -150,7 +142,7 @@ export const configHelperNetworks: ConfigHelperConfig[] = [
}, },
{ {
...configHelperNetworksBase, ...configHelperNetworksBase,
networkId: 1285, chainId: 1285,
network: 'moonriver', network: 'moonriver',
nodeUri: 'https://moonriver.api.onfinality.io/public', nodeUri: 'https://moonriver.api.onfinality.io/public',
providerUri: 'https://provider.moonriver.oceanprotocol.com', providerUri: 'https://provider.moonriver.oceanprotocol.com',
@ -161,9 +153,9 @@ export const configHelperNetworks: ConfigHelperConfig[] = [
export class ConfigHelper { export class ConfigHelper {
/* Load contract addresses from env ADDRESS_FILE (generated by ocean-contracts) */ /* Load contract addresses from env ADDRESS_FILE (generated by ocean-contracts) */
public getAddressesFromEnv(network: string): Partial<ConfigHelperConfig> { public getAddressesFromEnv(network: string): Partial<Config> {
// use the defaults first // use the defaults first
let configAddresses: Partial<ConfigHelperConfig> let configAddresses: Partial<Config>
if (DefaultContractsAddresses[network]) { if (DefaultContractsAddresses[network]) {
const { const {
DTFactory, DTFactory,
@ -182,7 +174,7 @@ export class ConfigHelper {
dispenserAddress: Dispenser, dispenserAddress: Dispenser,
metadataContractAddress: Metadata, metadataContractAddress: Metadata,
oceanTokenAddress: Ocean, oceanTokenAddress: Ocean,
networkId: chainId, chainId: chainId,
startBlock: startBlock, startBlock: startBlock,
...(process.env.AQUARIUS_URI && { metadataCacheUri: process.env.AQUARIUS_URI }) ...(process.env.AQUARIUS_URI && { metadataCacheUri: process.env.AQUARIUS_URI })
} }
@ -214,7 +206,7 @@ export class ConfigHelper {
dispenserAddress: Dispenser, dispenserAddress: Dispenser,
metadataContractAddress: Metadata, metadataContractAddress: Metadata,
oceanTokenAddress: Ocean, oceanTokenAddress: Ocean,
networkId: chainId, chainId: chainId,
startBlock: startBlock, startBlock: startBlock,
...(process.env.AQUARIUS_URI && { metadataCacheUri: process.env.AQUARIUS_URI }) ...(process.env.AQUARIUS_URI && { metadataCacheUri: process.env.AQUARIUS_URI })
} }
@ -227,7 +219,7 @@ export class ConfigHelper {
} }
public getConfig(network: string | number, infuraProjectId?: string): Config { public getConfig(network: string | number, infuraProjectId?: string): Config {
const filterBy = typeof network === 'string' ? 'network' : 'networkId' const filterBy = typeof network === 'string' ? 'network' : 'chainId'
let config = configHelperNetworks.find((c) => c[filterBy] === network) let config = configHelperNetworks.find((c) => c[filterBy] === network)
if (!config) { if (!config) {

View File

@ -4,3 +4,4 @@ export * from './Logger'
export * from './DatatokenName' export * from './DatatokenName'
export * from './ContractParams' export * from './ContractParams'
export * from './FetchHelper' export * from './FetchHelper'
export * from './ConfigHelper'