From 21c8879efed420d4aa2c2fae2ab3c139bbc893bc Mon Sep 17 00:00:00 2001 From: alexcos20 Date: Thu, 28 May 2020 06:41:49 -0700 Subject: [PATCH] add configHelper --- src/lib.ts | 3 ++- src/utils/ConfigHelper.ts | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 src/utils/ConfigHelper.ts diff --git a/src/lib.ts b/src/lib.ts index 392654af..ceebb68f 100644 --- a/src/lib.ts +++ b/src/lib.ts @@ -5,6 +5,7 @@ import { Ocean } from './ocean/Ocean' import { LoggerInstance as Logger } from './utils/Logger' import { Aquarius } from './aquarius/Aquarius' import { DataTokens } from './datatokens/Datatokens' +import { ConfigHelper} from './utils/ConfigHelper' import * as utils from './utils' @@ -20,4 +21,4 @@ export { OceanPlatformVersions } from './ocean/Versions' -export { Ocean, Account, Config, DID, Logger, Aquarius, DataTokens, utils } +export { Ocean, Account, Config, DID, Logger, Aquarius, DataTokens, utils , ConfigHelper} diff --git a/src/utils/ConfigHelper.ts b/src/utils/ConfigHelper.ts new file mode 100644 index 00000000..5200ae56 --- /dev/null +++ b/src/utils/ConfigHelper.ts @@ -0,0 +1,33 @@ +export interface ConfigHelper { + network: string, + url: string, + factoryAddress: string +} + + +const configs = [ + { network: 'development', url: 'http://localhost:8545', factoryAddress: null }, + { network: 'pacific', url: 'https://pacific.oceanprotocol.com', factoryAddress: '0x1234' }, + { network: 'mainnet', url: 'https://mainnet.infura.io/v3/YOUR-PROJECT-ID', factoryAddress: '0x1234' } + +] + + + +export class ConfigHelper { + public getConfig(network: string): ConfigHelper { + const confighelp = new ConfigHelper + //fill unknown values + confighelp.factoryAddress = null + confighelp.url = null + confighelp.network = network + const knownconfig = configs.find(c => c.network === network) + if (knownconfig) { + confighelp.factoryAddress = knownconfig.factoryAddress + confighelp.url = knownconfig.url + confighelp.network = knownconfig.network + } + return (confighelp) + + } +} \ No newline at end of file