|
|
|
@ -7,6 +7,7 @@ var ethJSABI = require('ethereumjs-abi'); |
|
|
|
|
var EthJSBlock = require('ethereumjs-block'); |
|
|
|
|
var BN = ethJSUtil.BN; |
|
|
|
|
var EventManager = require('./lib/eventManager'); |
|
|
|
|
var crypto = require('crypto'); |
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
trigger debugRequested |
|
|
|
@ -17,6 +18,7 @@ function UniversalDApp (executionContext, options, txdebugger) { |
|
|
|
|
|
|
|
|
|
self.options = options || {}; |
|
|
|
|
self.$el = $('<div class="udapp" />'); |
|
|
|
|
self.personalMode = self.options.personalMode || false; |
|
|
|
|
self.contracts; |
|
|
|
|
self.getAddress; |
|
|
|
|
self.getValue; |
|
|
|
@ -41,17 +43,36 @@ UniversalDApp.prototype.reset = function (contracts, getAddress, getValue, getGa |
|
|
|
|
this.renderOutputModifier = renderer; |
|
|
|
|
this.accounts = {}; |
|
|
|
|
if (this.executionContext.isVM()) { |
|
|
|
|
this.addAccount('3cd7232cd6f3fc66a57a6bedc1a8ed6c228fff0a327e169c2bcc5e869ed49511'); |
|
|
|
|
this.addAccount('2ac6c190b09897cd8987869cc7b918cfea07ee82038d492abce033c75c1b1d0c'); |
|
|
|
|
this.addAccount('dae9801649ba2d95a21e688b56f77905e5667c44ce868ec83f82e838712a2c7a'); |
|
|
|
|
this.addAccount('d74aa6d18aa79a05f3473dd030a97d3305737cbc8337d940344345c1f6b72eea'); |
|
|
|
|
this.addAccount('71975fbf7fe448e004ac7ae54cad0a383c3906055a65468714156a07385e96ce'); |
|
|
|
|
this._addAccount('3cd7232cd6f3fc66a57a6bedc1a8ed6c228fff0a327e169c2bcc5e869ed49511'); |
|
|
|
|
this._addAccount('2ac6c190b09897cd8987869cc7b918cfea07ee82038d492abce033c75c1b1d0c'); |
|
|
|
|
this._addAccount('dae9801649ba2d95a21e688b56f77905e5667c44ce868ec83f82e838712a2c7a'); |
|
|
|
|
this._addAccount('d74aa6d18aa79a05f3473dd030a97d3305737cbc8337d940344345c1f6b72eea'); |
|
|
|
|
this._addAccount('71975fbf7fe448e004ac7ae54cad0a383c3906055a65468714156a07385e96ce'); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
UniversalDApp.prototype.addAccount = function (privateKey, balance) { |
|
|
|
|
UniversalDApp.prototype.newAccount = function (password) { |
|
|
|
|
if (!this.executionContext.isVM()) { |
|
|
|
|
if (!this.personalMode) { |
|
|
|
|
throw new Error('Not running in personal mode'); |
|
|
|
|
} |
|
|
|
|
this.web3.personal.newAccount(password); |
|
|
|
|
} else { |
|
|
|
|
var privateKey; |
|
|
|
|
do { |
|
|
|
|
privateKey = crypto.randomBytes(32); |
|
|
|
|
} while (!ethJSUtil.isValidPrivate(privateKey)); |
|
|
|
|
this._addAccount(privateKey); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
UniversalDApp.prototype._addAccount = function (privateKey, balance) { |
|
|
|
|
var self = this; |
|
|
|
|
|
|
|
|
|
if (!self.executionContext.isVM()) { |
|
|
|
|
throw new Error('_addAccount() cannot be called in non-VM mode'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (self.accounts) { |
|
|
|
|
privateKey = new Buffer(privateKey, 'hex'); |
|
|
|
|
var address = ethJSUtil.privateToAddress(privateKey); |
|
|
|
@ -67,7 +88,13 @@ UniversalDApp.prototype.getAccounts = function (cb) { |
|
|
|
|
var self = this; |
|
|
|
|
|
|
|
|
|
if (!self.executionContext.isVM()) { |
|
|
|
|
self.web3.eth.getAccounts(cb); |
|
|
|
|
// Weirdness of web3: listAccounts() is sync, `getListAccounts()` is async
|
|
|
|
|
// See: https://github.com/ethereum/web3.js/issues/442
|
|
|
|
|
if (self.personalMode) { |
|
|
|
|
self.web3.personal.getListAccounts(cb); |
|
|
|
|
} else { |
|
|
|
|
self.web3.eth.getAccounts(cb); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
if (!self.accounts) { |
|
|
|
|
return cb('No accounts?'); |
|
|
|
@ -703,7 +730,9 @@ UniversalDApp.prototype.runTx = function (data, args, cb) { |
|
|
|
|
|
|
|
|
|
tx.gas = resp; |
|
|
|
|
|
|
|
|
|
self.web3.eth.sendTransaction(tx, function (err, resp) { |
|
|
|
|
var sendTransaction = self.personalMode ? self.web3.personal.unlockAccountAndSendTransaction : self.web3.eth.sendTransaction; |
|
|
|
|
|
|
|
|
|
sendTransaction(tx, function (err, resp) { |
|
|
|
|
if (err) { |
|
|
|
|
return cb(err, resp); |
|
|
|
|
} |
|
|
|
|