From bbc4620cd4dcfcc20535db299da88f1ce27c39be Mon Sep 17 00:00:00 2001 From: yann300 Date: Wed, 23 Nov 2016 15:25:11 +0100 Subject: [PATCH 1/4] fix send tx through web3 --- src/universal-dapp.js | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/universal-dapp.js b/src/universal-dapp.js index b7720c543b..352ffaf7db 100644 --- a/src/universal-dapp.js +++ b/src/universal-dapp.js @@ -35,7 +35,7 @@ function UniversalDApp (executionContext, options, txdebugger) { }) self.txRunner = new TxRunner(executionContext, { queueTxs: true, - personalMode: true + personalMode: this.personalMode }) } @@ -43,7 +43,7 @@ UniversalDApp.prototype.reset = function (contracts, getAddress, getValue, getGa this.$el.empty() this.txRunner = new TxRunner(this.executionContext, { queueTxs: true, - personalMode: true + personalMode: this.personalMode }) this.contracts = contracts this.getAddress = getAddress @@ -57,6 +57,17 @@ UniversalDApp.prototype.reset = function (contracts, getAddress, getValue, getGa this._addAccount('dae9801649ba2d95a21e688b56f77905e5667c44ce868ec83f82e838712a2c7a') this._addAccount('d74aa6d18aa79a05f3473dd030a97d3305737cbc8337d940344345c1f6b72eea') this._addAccount('71975fbf7fe448e004ac7ae54cad0a383c3906055a65468714156a07385e96ce') + } else { + var self = this + this.getAccounts(function (error, accounts) { + if (error) { + console.log('cannot retrieve accounts from web3') + } else { + accounts.map(function (item, index) { + self.accounts[item] = item + }) + } + }) } } @@ -549,11 +560,14 @@ UniversalDApp.prototype.getCallButton = function (args) { var decoded self.runTx({ to: args.address, data: data, useCall: args.abi.constant && !isConstructor }, function (err, txResult) { - var result = txResult.result + var result if (err) { replaceOutput($result, $('').text(err).addClass('error')) // VM only - } else if (self.executionContext.isVM() && result.vm.exception === 0 && result.vm.exceptionError) { + } else { + result = txResult.result + } + if (self.executionContext.isVM() && result.vm.exception === 0 && result.vm.exceptionError) { replaceOutput($result, $('').text('VM Exception: ' + result.vm.exceptionError).addClass('error')) $result.append(getDebugTransaction(txResult)) // VM only From bca94adda85f589ab45b0a3357e53bb20d92ddcf Mon Sep 17 00:00:00 2001 From: yann300 Date: Mon, 28 Nov 2016 19:04:38 +0100 Subject: [PATCH 2/4] fix use of accounts in web3 mode --- src/universal-dapp.js | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/src/universal-dapp.js b/src/universal-dapp.js index 352ffaf7db..299f832a94 100644 --- a/src/universal-dapp.js +++ b/src/universal-dapp.js @@ -57,17 +57,6 @@ UniversalDApp.prototype.reset = function (contracts, getAddress, getValue, getGa this._addAccount('dae9801649ba2d95a21e688b56f77905e5667c44ce868ec83f82e838712a2c7a') this._addAccount('d74aa6d18aa79a05f3473dd030a97d3305737cbc8337d940344345c1f6b72eea') this._addAccount('71975fbf7fe448e004ac7ae54cad0a383c3906055a65468714156a07385e96ce') - } else { - var self = this - this.getAccounts(function (error, accounts) { - if (error) { - console.log('cannot retrieve accounts from web3') - } else { - accounts.map(function (item, index) { - self.accounts[item] = item - }) - } - }) } } @@ -695,7 +684,6 @@ UniversalDApp.prototype.runTx = function (args, cb) { data: args.data, useCall: args.useCall } - var accounts = this.accounts async.waterfall([ // query gas limit function (callback) { @@ -739,7 +727,8 @@ UniversalDApp.prototype.runTx = function (args, cb) { return callback(err) } - tx.from = accounts[ret] + tx.from = self.executionContext.isVM() ? self.accounts[ret] : ret + callback() }) } else { @@ -752,10 +741,12 @@ UniversalDApp.prototype.runTx = function (args, cb) { return callback('No accounts available') } - tx.from = accounts[ret[0]] - if (self.executionContext.isVM() && !self.accounts[tx.from]) { + if (self.executionContext.isVM() && !self.accounts[ret[0]]) { return callback('Invalid account selected') } + + tx.from = self.executionContext.isVM() ? self.accounts[ret[0]] : ret[0] + callback() }) } From e6239d1a087b70647c6c2489622aa58a704cdabc Mon Sep 17 00:00:00 2001 From: yann300 Date: Tue, 29 Nov 2016 16:52:47 +0100 Subject: [PATCH 3/4] fix txResult --- src/universal-dapp.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/universal-dapp.js b/src/universal-dapp.js index 299f832a94..0c95698aab 100644 --- a/src/universal-dapp.js +++ b/src/universal-dapp.js @@ -549,14 +549,15 @@ UniversalDApp.prototype.getCallButton = function (args) { var decoded self.runTx({ to: args.address, data: data, useCall: args.abi.constant && !isConstructor }, function (err, txResult) { - var result + if (!txResult) { + replaceOutput($result, $('').text('callback contain no result ' + err).addClass('error')) + return + } + var result = txResult.result if (err) { replaceOutput($result, $('').text(err).addClass('error')) // VM only - } else { - result = txResult.result - } - if (self.executionContext.isVM() && result.vm.exception === 0 && result.vm.exceptionError) { + } else if (self.executionContext.isVM() && result.vm.exception === 0 && result.vm.exceptionError) { replaceOutput($result, $('').text('VM Exception: ' + result.vm.exceptionError).addClass('error')) $result.append(getDebugTransaction(txResult)) // VM only From 821489c2fd41754dbd14ef3fb300eb4a4a4c2352 Mon Sep 17 00:00:00 2001 From: yann300 Date: Wed, 30 Nov 2016 16:04:12 +0100 Subject: [PATCH 4/4] fix vmaccounts --- src/app/txRunner.js | 11 ++++++++--- src/universal-dapp.js | 14 +++++++------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/app/txRunner.js b/src/app/txRunner.js index 7905ac8eb2..7b2aedeab3 100644 --- a/src/app/txRunner.js +++ b/src/app/txRunner.js @@ -4,7 +4,7 @@ var EthJSBlock = require('ethereumjs-block') var ethJSUtil = require('ethereumjs-util') var BN = ethJSUtil.BN -function TxRunner (executionContext, opts) { +function TxRunner (executionContext, vmaccounts, opts) { this.executionContext = executionContext this.web3 = executionContext.web3() this.vm = executionContext.vm() @@ -16,6 +16,7 @@ function TxRunner (executionContext, opts) { } this.running = false this.pendingTxs = [] + this.vmaccounts = vmaccounts } TxRunner.prototype.rawRun = function (args, cb) { @@ -83,15 +84,19 @@ TxRunner.prototype.execute = function () { } } else { try { + var account = self.vmaccounts[from] + if (!account) { + return cb('Invalid account selected') + } tx = new EthJSTX({ - nonce: new BN(from.nonce++), + nonce: new BN(account.nonce++), gasPrice: new BN(1), gasLimit: new BN(gasLimit, 10), to: to, value: new BN(value, 10), data: new Buffer(data.slice(2), 'hex') }) - tx.sign(from.privateKey) + tx.sign(account.privateKey) var block = new EthJSBlock({ header: { // FIXME: support coinbase, difficulty and gasLimit diff --git a/src/universal-dapp.js b/src/universal-dapp.js index 0c95698aab..bb9362745c 100644 --- a/src/universal-dapp.js +++ b/src/universal-dapp.js @@ -33,7 +33,7 @@ function UniversalDApp (executionContext, options, txdebugger) { self.executionContext.event.register('contextChanged', this, function (context) { self.reset(self.contracts) }) - self.txRunner = new TxRunner(executionContext, { + self.txRunner = new TxRunner(executionContext, {}, { queueTxs: true, personalMode: this.personalMode }) @@ -41,10 +41,6 @@ function UniversalDApp (executionContext, options, txdebugger) { UniversalDApp.prototype.reset = function (contracts, getAddress, getValue, getGasLimit, renderer) { this.$el.empty() - this.txRunner = new TxRunner(this.executionContext, { - queueTxs: true, - personalMode: this.personalMode - }) this.contracts = contracts this.getAddress = getAddress this.getValue = getValue @@ -58,6 +54,10 @@ UniversalDApp.prototype.reset = function (contracts, getAddress, getValue, getGa this._addAccount('d74aa6d18aa79a05f3473dd030a97d3305737cbc8337d940344345c1f6b72eea') this._addAccount('71975fbf7fe448e004ac7ae54cad0a383c3906055a65468714156a07385e96ce') } + this.txRunner = new TxRunner(this.executionContext, this.accounts, { + queueTxs: true, + personalMode: this.personalMode + }) } UniversalDApp.prototype.newAccount = function (password) { @@ -728,7 +728,7 @@ UniversalDApp.prototype.runTx = function (args, cb) { return callback(err) } - tx.from = self.executionContext.isVM() ? self.accounts[ret] : ret + tx.from = ret callback() }) @@ -746,7 +746,7 @@ UniversalDApp.prototype.runTx = function (args, cb) { return callback('Invalid account selected') } - tx.from = self.executionContext.isVM() ? self.accounts[ret[0]] : ret[0] + tx.from = ret[0] callback() })