From 31d3125bafbb402933de123d0f9ed4194e51b46d Mon Sep 17 00:00:00 2001 From: emizzle Date: Mon, 17 Sep 2018 13:03:55 +1000 Subject: [PATCH] Fix for embark run crashing after console connects to it The providerUrl being provided to the console VM was looking for a WebsocketProvider-specific property which did not exist on the HttpProvider. Type checking was added to provide the necessary type-dependent property. --- lib/core/modules/coderunner/runCode.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/core/modules/coderunner/runCode.js b/lib/core/modules/coderunner/runCode.js index 746dd0d5..236bc00b 100644 --- a/lib/core/modules/coderunner/runCode.js +++ b/lib/core/modules/coderunner/runCode.js @@ -29,7 +29,16 @@ class RunCode { } getWeb3Config() { - return {defaultAccount: this.context.web3.eth.defaultAccount, providerUrl: this.context.web3.currentProvider.connection._url}; + const Web3 = require('web3'); + const provider = this.context.web3.currentProvider; + let providerUrl; + if(provider instanceof Web3.providers.HttpProvider){ + providerUrl = provider.host; + } + else if(provider instanceof Web3.provider.WebsocketProvider){ + providerUrl = provider.connection._url; + } + return {defaultAccount: this.context.web3.eth.defaultAccount, providerUrl: providerUrl}; } }