aboutsummaryrefslogtreecommitdiffstats
path: root/packages/web3-wrapper
diff options
context:
space:
mode:
Diffstat (limited to 'packages/web3-wrapper')
-rw-r--r--packages/web3-wrapper/CHANGELOG.json10
-rw-r--r--packages/web3-wrapper/package.json2
-rw-r--r--packages/web3-wrapper/src/index.ts2
-rw-r--r--packages/web3-wrapper/src/web3_wrapper.ts20
4 files changed, 32 insertions, 2 deletions
diff --git a/packages/web3-wrapper/CHANGELOG.json b/packages/web3-wrapper/CHANGELOG.json
index 624ad7151..f8b1dab85 100644
--- a/packages/web3-wrapper/CHANGELOG.json
+++ b/packages/web3-wrapper/CHANGELOG.json
@@ -1,6 +1,16 @@
[
{
"timestamp": 1529397769,
+ "version": "0.7.2",
+ "changes": [
+ {
+ "note": "Add `getNodeTypeAsync` method",
+ "pr": 812
+ }
+ ]
+ },
+ {
+ "timestamp": 1529397769,
"version": "0.7.1",
"changes": [
{
diff --git a/packages/web3-wrapper/package.json b/packages/web3-wrapper/package.json
index f12142d3c..2084cce73 100644
--- a/packages/web3-wrapper/package.json
+++ b/packages/web3-wrapper/package.json
@@ -68,7 +68,7 @@
"@0xproject/typescript-typings": "^0.4.1",
"@0xproject/utils": "^0.7.1",
"bn.js": "^4.11.8",
- "ethereum-types": "^0.0.1",
+ "ethereum-types": "^0.0.2",
"ethereumjs-util": "^5.1.1",
"ethers": "3.0.22",
"lodash": "^4.17.4",
diff --git a/packages/web3-wrapper/src/index.ts b/packages/web3-wrapper/src/index.ts
index b14fa7406..66ef0a784 100644
--- a/packages/web3-wrapper/src/index.ts
+++ b/packages/web3-wrapper/src/index.ts
@@ -1,2 +1,2 @@
-export { Web3Wrapper, uniqueVersionIds } from './web3_wrapper';
+export { Web3Wrapper, uniqueVersionIds, NodeType } from './web3_wrapper';
export { Web3WrapperErrors } from './types';
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 = {