WIP(utils)move defaultConfig from messenger to utils/chain

dev
neeboo 5 years ago
parent 8a654d7944
commit eb3858a3e6
  1. 12
      packages/harmony-core/src/harmony.ts
  2. 35
      packages/harmony-network/src/messenger/messenger.ts
  3. 20
      packages/harmony-utils/src/chain.ts

@ -8,8 +8,6 @@ import { Wallet, Account } from '@harmony-js/account';
import { Blockchain } from './blockchain';
import { HarmonyConfig } from './util';
const defaultUrl = 'http://localhost:9500';
export class Harmony extends utils.HarmonyCore {
Modules = {
HttpProvider,
@ -31,11 +29,11 @@ export class Harmony extends utils.HarmonyCore {
utils: any;
private provider: HttpProvider | WSProvider;
constructor(
url: string = defaultUrl,
url: string = utils.defaultConfig.Default.Chain_URL,
config: HarmonyConfig = {
chainUrl: defaultUrl,
chainId: utils.ChainID.Default,
chainType: utils.ChainType.Harmony,
chainUrl: utils.defaultConfig.Default.Chain_URL,
chainId: utils.defaultConfig.Default.Chain_ID,
chainType: utils.defaultConfig.Default.Chain_Type,
},
) {
super(config.chainType, config.chainId);
@ -71,6 +69,6 @@ export class Harmony extends utils.HarmonyCore {
? new HttpProvider(providerUrl)
: utils.isWs(providerUrl)
? new WSProvider(providerUrl)
: new HttpProvider(defaultUrl);
: new HttpProvider(utils.defaultConfig.Default.Chain_URL);
}
}

@ -1,4 +1,10 @@
import { HarmonyCore, ChainType, isString, ChainID } from '@harmony-js/utils';
import {
HarmonyCore,
ChainType,
isString,
ChainID,
defaultConfig,
} from '@harmony-js/utils';
import { JsonRpc } from '../rpcMethod/rpcbuilder';
import { ResponseMiddleware } from './responseMiddleware';
import { HttpProvider } from '../providers/http';
@ -7,29 +13,6 @@ import { WSProvider } from '../providers/ws';
import { RPCMethod } from '../rpcMethod/rpc';
import { SubscribeReturns } from '../types';
const defaultConfig = {
Default: {
CHAIN_ID: 0,
Network_ID: 'Default',
nodeProviderUrl: 'http://localhost:9128',
},
DevNet: {
CHAIN_ID: 333,
Network_ID: 'DevNet',
nodeProviderUrl: 'https://devnet.harmony.one',
},
TestNet: {
CHAIN_ID: 2,
Network_ID: 'TestNet',
nodeProviderUrl: 'https://devnet.harmony.one',
},
MainNet: {
CHAIN_ID: 1,
Network_ID: 'MainNet',
nodeProviderUrl: 'https://mainnet.harmony.one',
},
};
/**
* @class Messenger
* @description Messenger instance
@ -46,8 +29,8 @@ class Messenger extends HarmonyCore {
constructor(
provider: HttpProvider | WSProvider,
chainType: ChainType = ChainType.Harmony,
chainId: ChainID = ChainID.Default,
chainType: ChainType = defaultConfig.Default.Chain_Type,
chainId: ChainID = defaultConfig.Default.Chain_ID,
config?: object,
) {
super(chainType, chainId);

@ -18,10 +18,28 @@ export const enum ChainID {
Ganache = 0,
}
export const defaultConfig = {
Default: {
Chain_ID: ChainID.Default,
Chain_Type: ChainType.Harmony,
Chain_URL: 'http://localhost:9500',
Network_ID: 'Local',
},
DefaultWS: {
Chain_ID: ChainID.Default,
Chain_Type: ChainType.Harmony,
Chain_URL: 'ws://localhost:9800',
Network_ID: 'LocalWS',
},
};
export abstract class HarmonyCore {
chainType: ChainType;
chainId: ChainID;
constructor(chainType: ChainType, chainId: ChainID = ChainID.Default) {
constructor(
chainType: ChainType,
chainId: ChainID = defaultConfig.Default.Chain_ID,
) {
this.chainType = chainType;
this.chainId = chainId;
}

Loading…
Cancel
Save