aboutsummaryrefslogtreecommitdiffstats
path: root/packages/dev-utils/src/web3_factory.ts
diff options
context:
space:
mode:
authorHsuan Lee <hsuan@cobinhood.com>2019-01-19 18:42:04 +0800
committerHsuan Lee <hsuan@cobinhood.com>2019-01-19 18:42:04 +0800
commit7ae38906926dc09bc10670c361af0d2bf0050426 (patch)
tree5fb10ae366b987db09e4ddb4bc3ba0f75404ad08 /packages/dev-utils/src/web3_factory.ts
parentb5fd3c72a08aaa6957917d74c333387a16edf66b (diff)
downloaddexon-sol-tools-7ae38906926dc09bc10670c361af0d2bf0050426.tar.gz
dexon-sol-tools-7ae38906926dc09bc10670c361af0d2bf0050426.tar.zst
dexon-sol-tools-7ae38906926dc09bc10670c361af0d2bf0050426.zip
Update dependency packages
Diffstat (limited to 'packages/dev-utils/src/web3_factory.ts')
-rw-r--r--packages/dev-utils/src/web3_factory.ts71
1 files changed, 0 insertions, 71 deletions
diff --git a/packages/dev-utils/src/web3_factory.ts b/packages/dev-utils/src/web3_factory.ts
deleted file mode 100644
index 5f8981a46..000000000
--- a/packages/dev-utils/src/web3_factory.ts
+++ /dev/null
@@ -1,71 +0,0 @@
-import {
- EmptyWalletSubprovider,
- FakeGasEstimateSubprovider,
- GanacheSubprovider,
- RPCSubprovider,
- Web3ProviderEngine,
-} from '@0x/subproviders';
-import * as fs from 'fs';
-import * as _ from 'lodash';
-
-import { constants } from './constants';
-import { env, EnvVars } from './env';
-
-export interface Web3Config {
- hasAddresses?: boolean; // default: true
- shouldUseInProcessGanache?: boolean; // default: false
- shouldThrowErrorsOnGanacheRPCResponse?: boolean; // default: true
- rpcUrl?: string; // default: localhost:8545
- shouldUseFakeGasEstimate?: boolean; // default: true
- ganacheDatabasePath?: string; // default: undefined, creates a tmp dir
-}
-
-export const web3Factory = {
- getRpcProvider(config: Web3Config = {}): Web3ProviderEngine {
- const provider = new Web3ProviderEngine();
- const hasAddresses = _.isUndefined(config.hasAddresses) || config.hasAddresses;
- config.shouldUseFakeGasEstimate =
- _.isUndefined(config.shouldUseFakeGasEstimate) || config.shouldUseFakeGasEstimate;
- if (!hasAddresses) {
- provider.addProvider(new EmptyWalletSubprovider());
- }
-
- if (config.shouldUseFakeGasEstimate) {
- provider.addProvider(new FakeGasEstimateSubprovider(constants.GAS_LIMIT));
- }
- const logger = {
- log: (arg: any) => {
- fs.appendFileSync('ganache.log', `${arg}\n`);
- },
- };
- const shouldUseInProcessGanache = !!config.shouldUseInProcessGanache;
- if (shouldUseInProcessGanache) {
- if (!_.isUndefined(config.rpcUrl)) {
- throw new Error('Cannot use both GanacheSubrovider and RPCSubprovider');
- }
- const shouldThrowErrorsOnGanacheRPCResponse =
- _.isUndefined(config.shouldThrowErrorsOnGanacheRPCResponse) ||
- config.shouldThrowErrorsOnGanacheRPCResponse;
- if (!_.isUndefined(config.ganacheDatabasePath)) {
- // Saving the snapshot to a local db. Ganache requires this directory to exist
- fs.mkdirSync(config.ganacheDatabasePath);
- }
- provider.addProvider(
- new GanacheSubprovider({
- vmErrorsOnRPCResponse: shouldThrowErrorsOnGanacheRPCResponse,
- db_path: config.ganacheDatabasePath,
- gasLimit: constants.GAS_LIMIT,
- logger,
- verbose: env.parseBoolean(EnvVars.VerboseGanache),
- port: 8545,
- network_id: 50,
- mnemonic: 'concert load couple harbor equip island argue ramp clarify fence smart topic',
- } as any), // TODO remove any once types are merged in DefinitelyTyped
- );
- } else {
- provider.addProvider(new RPCSubprovider(config.rpcUrl || constants.RPC_URL));
- }
- provider.start();
- return provider;
- },
-};