From 1774bfbc22725139b4922305b46c4a9ddfeb072f Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Sat, 4 Jun 2016 21:40:23 +0100 Subject: [PATCH] Pass web3 instance in every case and have a mode selector between vm and web3 --- src/app/renderer.js | 4 ++-- src/universal-dapp.js | 14 ++++++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/app/renderer.js b/src/app/renderer.js index 130a5db5b2..985a8a0046 100644 --- a/src/app/renderer.js +++ b/src/app/renderer.js @@ -101,8 +101,8 @@ function Renderer(editor, compiler, updateFiles) { } var dapp = new UniversalDApp(udappContracts, { - vm: executionContext === 'vm', - web3: executionContext !== 'vm' ? web3 : null, + mode: executionContext === 'vm' ? 'vm' : 'web3', + web3: web3, removable: false, getAddress: function(){ return $('#txorigin').val(); }, getValue: function(){ diff --git a/src/universal-dapp.js b/src/universal-dapp.js index a6a369415f..c4ca3d0ea4 100644 --- a/src/universal-dapp.js +++ b/src/universal-dapp.js @@ -12,7 +12,15 @@ function UniversalDApp (contracts, options) { this.contracts = contracts; this.renderOutputModifier = options.renderOutputModifier || function(name, content) { return content; }; - if (options.vm) { + this.web3 = options.web3; + if (!this.web3) { + throw new Error('Web3 is required for ABI encoding'); + } + + if (options.mode === 'vm') { + // FIXME: use `options.vm` or `this.vm` consistently + options.vm = true; + this.accounts = {}; this.BN = ethJSUtil.BN; @@ -21,9 +29,7 @@ function UniversalDApp (contracts, options) { this.addAccount('3cd7232cd6f3fc66a57a6bedc1a8ed6c228fff0a327e169c2bcc5e869ed49511'); this.addAccount('2ac6c190b09897cd8987869cc7b918cfea07ee82038d492abce033c75c1b1d0c'); - } else if (options.web3) { - this.web3 = options.web3; - } else { + } else if (options.mode !== 'web3') { throw new Error("Either VM or Web3 mode must be selected"); } }