From c5fcea1dbd5e64e72eb5cf360558de9f9b886a16 Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Tue, 3 Jul 2018 10:40:54 -0700 Subject: Actually cache node type in web3-wrapper --- packages/web3-wrapper/src/web3_wrapper.ts | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'packages/web3-wrapper') diff --git a/packages/web3-wrapper/src/web3_wrapper.ts b/packages/web3-wrapper/src/web3_wrapper.ts index e4df31def..c2754a13e 100644 --- a/packages/web3-wrapper/src/web3_wrapper.ts +++ b/packages/web3-wrapper/src/web3_wrapper.ts @@ -49,6 +49,7 @@ export class Web3Wrapper { private _web3: Web3; private _txDefaults: Partial; private _jsonRpcRequestId: number; + private _nodeType: NodeType | undefined; /** * Check if an address is a valid Ethereum address * @param address Address to check @@ -501,10 +502,15 @@ export class Web3Wrapper { * function caches the result and so subsequent calls are fast. */ public async getNodeTypeAsync(): Promise { + if (!_.isUndefined(this._nodeType)) { + return this._nodeType; + } const version = await this.getNodeVersionAsync(); if (_.includes(version, uniqueVersionIds.geth)) { + this._nodeType = NodeType.Geth; return NodeType.Geth; } else if (_.includes(version, uniqueVersionIds.ganache)) { + this._nodeType = NodeType.Ganache; return NodeType.Ganache; } else { throw new Error(`Unknown client version: ${version}`); -- cgit