Commit 93d240df authored by chriseth's avatar chriseth

Merge pull request #151 from axic/patch/account-cleanup

Cosmetic cleanup of the account code
parents 2875a5bb f48306ca
...@@ -890,11 +890,7 @@ $(document).ready(function() { ...@@ -890,11 +890,7 @@ $(document).ready(function() {
} else $txOrigin.val('unknown'); } else $txOrigin.val('unknown');
} }
if (executionContext === 'vm') { dapp.getAccounts(renderAccounts);
dapp.getAccounts(renderAccounts);
} else {
web3.eth.getAccounts(renderAccounts);
}
$contractOutput.find('.title').click(function(ev){ $(this).closest('.contract').toggleClass('hide'); }); $contractOutput.find('.title').click(function(ev){ $(this).closest('.contract').toggleClass('hide'); });
$('#output').append( $contractOutput ); $('#output').append( $contractOutput );
...@@ -994,4 +990,4 @@ $(document).ready(function() { ...@@ -994,4 +990,4 @@ $(document).ready(function() {
syncStorage() syncStorage()
}); });
\ No newline at end of file
...@@ -25,22 +25,26 @@ function UniversalDApp (contracts, options) { ...@@ -25,22 +25,26 @@ function UniversalDApp (contracts, options) {
} }
UniversalDApp.prototype.addAccount = function (privateKey, balance) { UniversalDApp.prototype.addAccount = function (privateKey, balance) {
if (this.accounts) { if (this.accounts) {
privateKey = new Buffer(privateKey, 'hex') privateKey = new Buffer(privateKey, 'hex')
var address = EthJS.Util.privateToAddress(privateKey); var address = EthJS.Util.privateToAddress(privateKey);
var account = new EthJS.Account(); var account = new EthJS.Account();
account.balance = balance || 'f00000000000000001'; account.balance = balance || 'f00000000000000001';
this.vm.stateManager.trie.put(address, account.serialize()); this.vm.stateManager.trie.put(address, account.serialize());
this.accounts['0x' + address.toString('hex')] = { privateKey: privateKey, nonce: 0 }; this.accounts['0x' + address.toString('hex')] = { privateKey: privateKey, nonce: 0 };
} }
}; };
UniversalDApp.prototype.getAccounts = function (cb) { UniversalDApp.prototype.getAccounts = function (cb) {
if (!this.accounts) return cb("No accounts?"); if (!this.vm) {
web3.eth.getAccounts(cb);
} else {
if (!this.accounts) return cb("No accounts?");
cb(null, Object.keys(this.accounts)); cb(null, Object.keys(this.accounts));
}
}; };
UniversalDApp.prototype.render = function () { UniversalDApp.prototype.render = function () {
......
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