Commit 255849e5 authored by Alex Beregszaszi's avatar Alex Beregszaszi

Introduce personalMode switch to control eth vs. personal accounts from outside

parent e6cee02e
...@@ -18,6 +18,7 @@ function UniversalDApp (executionContext, options, txdebugger) { ...@@ -18,6 +18,7 @@ function UniversalDApp (executionContext, options, txdebugger) {
self.options = options || {}; self.options = options || {};
self.$el = $('<div class="udapp" />'); self.$el = $('<div class="udapp" />');
self.personalMode = self.options.personalMode || false;
self.contracts; self.contracts;
self.getAddress; self.getAddress;
self.getValue; self.getValue;
...@@ -52,6 +53,9 @@ UniversalDApp.prototype.reset = function (contracts, getAddress, getValue, getGa ...@@ -52,6 +53,9 @@ UniversalDApp.prototype.reset = function (contracts, getAddress, getValue, getGa
UniversalDApp.prototype.newAccount = function (password) { UniversalDApp.prototype.newAccount = function (password) {
if (!this.executionContext.isVM()) { if (!this.executionContext.isVM()) {
if (!this.personalMode) {
throw new Error('Not running in personal mode');
}
this.web3.personal.newAccount(password); this.web3.personal.newAccount(password);
} else { } else {
var privateKey; var privateKey;
...@@ -86,13 +90,11 @@ UniversalDApp.prototype.getAccounts = function (cb) { ...@@ -86,13 +90,11 @@ UniversalDApp.prototype.getAccounts = function (cb) {
if (!self.executionContext.isVM()) { if (!self.executionContext.isVM()) {
// Weirdness of web3: listAccounts() is sync, `getListAccounts()` is async // Weirdness of web3: listAccounts() is sync, `getListAccounts()` is async
// See: https://github.com/ethereum/web3.js/issues/442 // See: https://github.com/ethereum/web3.js/issues/442
self.web3.personal.getListAccounts(function (err, res) { if (self.personalMode) {
if (err) { self.web3.personal.getListAccounts(cb);
self.web3.eth.getAccounts(cb);
} else { } else {
cb(err, res); self.web3.eth.getAccounts(cb);
} }
});
} else { } else {
if (!self.accounts) { if (!self.accounts) {
return cb('No accounts?'); return cb('No accounts?');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment