aboutsummaryrefslogtreecommitdiffstats
path: root/packages/web3-wrapper/src/web3_wrapper.ts
diff options
context:
space:
mode:
authorAlex Browne <stephenalexbrowne@gmail.com>2018-07-03 09:44:37 +0800
committerAlex Browne <stephenalexbrowne@gmail.com>2018-07-03 09:57:33 +0800
commit5b64b3ea937326978b5742ec1b3692ebe5c41991 (patch)
tree34f4029b1985295490479d3da93cae62de5396d1 /packages/web3-wrapper/src/web3_wrapper.ts
parentb1dc20bbb35e8fb6370820a94d6f56306453fc4d (diff)
downloaddexon-0x-contracts-5b64b3ea937326978b5742ec1b3692ebe5c41991.tar
dexon-0x-contracts-5b64b3ea937326978b5742ec1b3692ebe5c41991.tar.gz
dexon-0x-contracts-5b64b3ea937326978b5742ec1b3692ebe5c41991.tar.bz2
dexon-0x-contracts-5b64b3ea937326978b5742ec1b3692ebe5c41991.tar.lz
dexon-0x-contracts-5b64b3ea937326978b5742ec1b3692ebe5c41991.tar.xz
dexon-0x-contracts-5b64b3ea937326978b5742ec1b3692ebe5c41991.tar.zst
dexon-0x-contracts-5b64b3ea937326978b5742ec1b3692ebe5c41991.zip
Improve robustness of revert reason assertions
Diffstat (limited to 'packages/web3-wrapper/src/web3_wrapper.ts')
-rw-r--r--packages/web3-wrapper/src/web3_wrapper.ts21
1 files changed, 21 insertions, 0 deletions
diff --git a/packages/web3-wrapper/src/web3_wrapper.ts b/packages/web3-wrapper/src/web3_wrapper.ts
index 6ea69883c..e4df31def 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,21 @@ 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. This
+ * function caches the result and so subsequent calls are fast.
+ */
+ 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 = {