Commit def263f6 authored by Alex Beregszaszi's avatar Alex Beregszaszi

Use VM.stateManager.get/putAccountBalance

parent 6731cb5f
...@@ -39,10 +39,8 @@ UniversalDApp.prototype.addAccount = function (privateKey, balance) { ...@@ -39,10 +39,8 @@ UniversalDApp.prototype.addAccount = function (privateKey, balance) {
privateKey = new Buffer(privateKey, 'hex') privateKey = new Buffer(privateKey, 'hex')
var address = ethJSUtil.privateToAddress(privateKey); var address = ethJSUtil.privateToAddress(privateKey);
var account = new EthJSAccount(); // FIXME: we don't care about the callback, but we should still make this proper
account.balance = balance || 'f00000000000000001'; this.vm.stateManager.putAccountBalance(address, balance || 'f00000000000000001', function cb() {} );
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 };
} }
...@@ -72,11 +70,11 @@ UniversalDApp.prototype.getBalance = function (address, cb) { ...@@ -72,11 +70,11 @@ UniversalDApp.prototype.getBalance = function (address, cb) {
} else { } else {
if (!this.accounts) return cb("No accounts?"); if (!this.accounts) return cb("No accounts?");
this.vm.stateManager.trie.get(new Buffer(address, 'hex'), function (err, res) { this.vm.stateManager.getAccountBalance(new Buffer(address, 'hex'), function (err, res) {
if (err) { if (err) {
cb("Account not found"); cb("Account not found");
} else { } else {
cb(null, new ethJSUtil.BN(new EthJSAccount(res).toString(), 16).toString(10)); cb(null, new ethJSUtil.BN(res).toString(10));
} }
}); });
} }
......
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