aboutsummaryrefslogtreecommitdiffstats
path: root/packages/web3-wrapper
diff options
context:
space:
mode:
authorJacob Evans <dekz@dekz.net>2018-07-04 18:07:05 +0800
committerJacob Evans <jacob@dekz.net>2018-07-04 18:29:54 +0800
commit5915f8430c252a341cac9c5ef645836efd4d7e92 (patch)
tree2d973f3b39d19247855a6320cc48858f0011df40 /packages/web3-wrapper
parent9e0f06d06055022fff80bbf7a8b6444f72f898ec (diff)
parentaeea3817a48473aec0eb378b0ad6cbe7e7877044 (diff)
downloaddexon-sol-tools-5915f8430c252a341cac9c5ef645836efd4d7e92.tar
dexon-sol-tools-5915f8430c252a341cac9c5ef645836efd4d7e92.tar.gz
dexon-sol-tools-5915f8430c252a341cac9c5ef645836efd4d7e92.tar.bz2
dexon-sol-tools-5915f8430c252a341cac9c5ef645836efd4d7e92.tar.lz
dexon-sol-tools-5915f8430c252a341cac9c5ef645836efd4d7e92.tar.xz
dexon-sol-tools-5915f8430c252a341cac9c5ef645836efd4d7e92.tar.zst
dexon-sol-tools-5915f8430c252a341cac9c5ef645836efd4d7e92.zip
Merge branch 'v2-prototype' into eth-lightwallet-subprovider-final
Diffstat (limited to 'packages/web3-wrapper')
-rw-r--r--packages/web3-wrapper/CHANGELOG.json10
-rw-r--r--packages/web3-wrapper/src/index.ts2
-rw-r--r--packages/web3-wrapper/src/web3_wrapper.ts20
3 files changed, 31 insertions, 1 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/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 6ea69883c..b79ade278 100644
--- a/packages/web3-wrapper/src/web3_wrapper.ts
+++ b/packages/web3-wrapper/src/web3_wrapper.ts
@@ -31,6 +31,12 @@ export const uniqueVersionIds = {
ganache: 'EthereumJS TestRPC',
};
+// NodeType represents the type of the backing Ethereum node.
+export enum NodeType {
+ Geth = 'GETH',
+ Ganache = 'GANACHE',
+}
+
/**
* A wrapper around the Web3.js 0.x library that provides a consistent, clean promise-based interface.
*/
@@ -489,6 +495,20 @@ export class Web3Wrapper {
public async setHeadAsync(blockNumber: number): Promise<void> {
await this._sendRawPayloadAsync<void>({ method: 'debug_setHead', params: [this._web3.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._web3.currentProvider.sendAsync.bind(this._web3.currentProvider);
const payloadWithDefaults = {