fix use of accounts in web3 mode

pull/1/head
yann300 8 years ago committed by Alex Beregszaszi
parent bbc4620cd4
commit bca94adda8
  1. 21
      src/universal-dapp.js

@ -57,17 +57,6 @@ UniversalDApp.prototype.reset = function (contracts, getAddress, getValue, getGa
this._addAccount('dae9801649ba2d95a21e688b56f77905e5667c44ce868ec83f82e838712a2c7a') this._addAccount('dae9801649ba2d95a21e688b56f77905e5667c44ce868ec83f82e838712a2c7a')
this._addAccount('d74aa6d18aa79a05f3473dd030a97d3305737cbc8337d940344345c1f6b72eea') this._addAccount('d74aa6d18aa79a05f3473dd030a97d3305737cbc8337d940344345c1f6b72eea')
this._addAccount('71975fbf7fe448e004ac7ae54cad0a383c3906055a65468714156a07385e96ce') 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, data: args.data,
useCall: args.useCall useCall: args.useCall
} }
var accounts = this.accounts
async.waterfall([ async.waterfall([
// query gas limit // query gas limit
function (callback) { function (callback) {
@ -739,7 +727,8 @@ UniversalDApp.prototype.runTx = function (args, cb) {
return callback(err) return callback(err)
} }
tx.from = accounts[ret] tx.from = self.executionContext.isVM() ? self.accounts[ret] : ret
callback() callback()
}) })
} else { } else {
@ -752,10 +741,12 @@ UniversalDApp.prototype.runTx = function (args, cb) {
return callback('No accounts available') return callback('No accounts available')
} }
tx.from = accounts[ret[0]] if (self.executionContext.isVM() && !self.accounts[ret[0]]) {
if (self.executionContext.isVM() && !self.accounts[tx.from]) {
return callback('Invalid account selected') return callback('Invalid account selected')
} }
tx.from = self.executionContext.isVM() ? self.accounts[ret[0]] : ret[0]
callback() callback()
}) })
} }

Loading…
Cancel
Save