diff --git a/src/blockchain/blockchain.js b/src/blockchain/blockchain.js index 7b0616e9f6..58a788b6bf 100644 --- a/src/blockchain/blockchain.js +++ b/src/blockchain/blockchain.js @@ -34,7 +34,7 @@ class Blockchain { this.executionContext.detectNetwork(cb) }, personalMode: () => { - return this.executionContext.getProvider() === 'web3' ? this.config.get('settings/personal-mode') : false + return this.getProvider() === 'web3' ? this.config.get('settings/personal-mode') : false } }, this.executionContext) this.executionContext.event.register('contextChanged', this.resetEnvironment.bind(this)) @@ -66,7 +66,7 @@ class Blockchain { } getCurrentProvider () { - const provider = this.executionContext.getProvider() + const provider = this.getProvider() return this.providers[provider] } @@ -199,10 +199,6 @@ class Blockchain { return this.executionContext.setProviderFromEndpoint(target, context, cb) } - getProvider () { - return this.executionContext.getProvider() - } - updateNetwork (cb) { this.networkcallid++ ((callid) => { @@ -221,14 +217,18 @@ class Blockchain { return this.executionContext.detectNetwork(cb) } + getProvider () { + return this.executionContext.getProvider() + } + isWeb3Provider () { - const isVM = this.executionContext.isVM() - const isInjected = this.executionContext.getProvider() === 'injected' + const isVM = this.getProvider === 'vm' + const isInjected = this.getProvider() === 'injected' return (!isVM && !isInjected) } isInjectedWeb3 () { - return this.executionContext.getProvider() === 'injected' + return this.getProvider() === 'injected' } signMessage (message, account, passphrase, cb) { @@ -263,13 +263,6 @@ class Blockchain { if (error) { return logCallback(`${logMsg} errored: ${error} `) } - const isVM = this.executionContext.isVM() - if (isVM) { - const vmError = txExecution.checkVMError(txResult) - if (vmError.error) { - return logCallback(`${logMsg} errored: ${vmError.message} `) - } - } if (lookupOnly) { const returnValue = (this.executionContext.isVM() ? txResult.result.execResult.returnValue : ethJSUtil.toBuffer(txResult.result)) outputCb(returnValue) @@ -322,7 +315,7 @@ class Blockchain { this.executionContext.detectNetwork(cb) }, personalMode: () => { - return this.executionContext.getProvider() === 'web3' ? this.config.get('settings/personal-mode') : false + return this.getProvider() === 'web3' ? this.config.get('settings/personal-mode') : false } }, this.executionContext) this.txRunner.event.register('transactionBroadcasted', (txhash) => { @@ -338,7 +331,7 @@ class Blockchain { * @param {{privateKey: string, balance: string}} newAccount The new account to create */ createVMAccount (newAccount) { - if (this.executionContext.getProvider() !== 'vm') { + if (this.getProvider() !== 'vm') { throw new Error('plugin API does not allow creating a new account through web3 connection. Only vm mode is allowed') } return this.providers.vm.createVMAccount(newAccount) @@ -368,6 +361,14 @@ class Blockchain { callFunction (to, data, funAbi, confirmationCb, continueCb, promptCb, callback) { const useCall = funAbi.stateMutability === 'view' || funAbi.stateMutability === 'pure' this.runTx({to, data, useCall}, confirmationCb, continueCb, promptCb, (error, txResult) => { + const isVM = this.executionContext.isVM() + if (isVM) { + const vmError = txExecution.checkVMError(txResult) + if (vmError.error) { + return callback(vmError.message) + } + } + // see universaldapp.js line 660 => 700 to check possible values of txResult (error case) callback(error, txResult) }) diff --git a/src/blockchain/providers/injected.js b/src/blockchain/providers/injected.js index b9484533d4..b62daea306 100644 --- a/src/blockchain/providers/injected.js +++ b/src/blockchain/providers/injected.js @@ -40,6 +40,10 @@ class InjectedProvider { cb(e.message) } } + + getProvider () { + return 'injected' + } } module.exports = InjectedProvider diff --git a/src/blockchain/providers/node.js b/src/blockchain/providers/node.js index 5f013a3ef4..98a4ea1cf6 100644 --- a/src/blockchain/providers/node.js +++ b/src/blockchain/providers/node.js @@ -49,6 +49,10 @@ class NodeProvider { cb(e.message) } } + + getProvider () { + return this.executionContext.getProvider() + } } module.exports = NodeProvider diff --git a/src/blockchain/providers/vm.js b/src/blockchain/providers/vm.js index 6e8dd6a870..99eb6b0dbc 100644 --- a/src/blockchain/providers/vm.js +++ b/src/blockchain/providers/vm.js @@ -83,6 +83,10 @@ class VMProvider { cb(e.message) } } + + getProvider () { + return 'vm' + } } module.exports = VMProvider