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() {
} else $txOrigin.val('unknown');
}
if (executionContext === 'vm') {
dapp.getAccounts(renderAccounts);
} else {
web3.eth.getAccounts(renderAccounts);
}
dapp.getAccounts(renderAccounts);
$contractOutput.find('.title').click(function(ev){ $(this).closest('.contract').toggleClass('hide'); });
$('#output').append( $contractOutput );
......@@ -994,4 +990,4 @@ $(document).ready(function() {
syncStorage()
});
\ No newline at end of file
});
......@@ -25,22 +25,26 @@ function UniversalDApp (contracts, options) {
}
UniversalDApp.prototype.addAccount = function (privateKey, balance) {
if (this.accounts) {
privateKey = new Buffer(privateKey, 'hex')
var address = EthJS.Util.privateToAddress(privateKey);
if (this.accounts) {
privateKey = new Buffer(privateKey, 'hex')
var address = EthJS.Util.privateToAddress(privateKey);
var account = new EthJS.Account();
account.balance = balance || 'f00000000000000001';
this.vm.stateManager.trie.put(address, account.serialize());
var account = new EthJS.Account();
account.balance = balance || 'f00000000000000001';
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) {
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 () {
......
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