diff options
author | Fabio Berger <me@fabioberger.com> | 2018-07-05 06:38:15 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2018-07-05 06:38:15 +0800 |
commit | a0b9c7777b2171456a19aa6ddcf2a023b663a816 (patch) | |
tree | b9cf9fe6d0030bf0e2591d3facccf38ff2d622c6 /packages/web3-wrapper/src/web3_wrapper.ts | |
parent | 5204e4c08da7d32012047ee6ca4d898b0c45a47d (diff) | |
parent | 5176d929fa6d3c6ce414448ea2441bd450f04e3c (diff) | |
download | dexon-0x-contracts-a0b9c7777b2171456a19aa6ddcf2a023b663a816.tar dexon-0x-contracts-a0b9c7777b2171456a19aa6ddcf2a023b663a816.tar.gz dexon-0x-contracts-a0b9c7777b2171456a19aa6ddcf2a023b663a816.tar.bz2 dexon-0x-contracts-a0b9c7777b2171456a19aa6ddcf2a023b663a816.tar.lz dexon-0x-contracts-a0b9c7777b2171456a19aa6ddcf2a023b663a816.tar.xz dexon-0x-contracts-a0b9c7777b2171456a19aa6ddcf2a023b663a816.tar.zst dexon-0x-contracts-a0b9c7777b2171456a19aa6ddcf2a023b663a816.zip |
merge v2-prototype
Diffstat (limited to 'packages/web3-wrapper/src/web3_wrapper.ts')
-rw-r--r-- | packages/web3-wrapper/src/web3_wrapper.ts | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/packages/web3-wrapper/src/web3_wrapper.ts b/packages/web3-wrapper/src/web3_wrapper.ts index 29adb18ff..e56b99366 100644 --- a/packages/web3-wrapper/src/web3_wrapper.ts +++ b/packages/web3-wrapper/src/web3_wrapper.ts @@ -39,6 +39,12 @@ export const uniqueVersionIds = { ganache: 'EthereumJS TestRPC', }; +// NodeType represents the type of the backing Ethereum node. +export enum NodeType { + Geth = 'GETH', + Ganache = 'GANACHE', +} + /** * An alternative to the Web3.js library that provides a consistent, clean, promise-based interface. */ @@ -595,6 +601,20 @@ export class Web3Wrapper { assert.isNumber('blockNumber', blockNumber); await this._sendRawPayloadAsync<void>({ method: 'debug_setHead', params: [web3Utils.toHex(blockNumber)] }); } + /** + * Returns either NodeType.Geth or NodeType.Ganache depending on the type of + * the backing Ethereum node. Throws for any other type of node. + */ + public async getNodeTypeAsync(): Promise<NodeType> { + const version = await this.getNodeVersionAsync(); + if (_.includes(version, uniqueVersionIds.geth)) { + return NodeType.Geth; + } else if (_.includes(version, uniqueVersionIds.ganache)) { + return NodeType.Ganache; + } else { + throw new Error(`Unknown client version: ${version}`); + } + } private async _sendRawPayloadAsync<A>(payload: Partial<JSONRPCRequestPayload>): Promise<A> { const sendAsync = this._provider.sendAsync.bind(this._provider); const payloadWithDefaults = { |