|
|
@ -3,7 +3,6 @@ var EthJSVM = require('ethereumjs-vm'); |
|
|
|
var Trie = require('merkle-patricia-tree'); |
|
|
|
var Trie = require('merkle-patricia-tree'); |
|
|
|
var ethJSUtil = require('ethereumjs-util'); |
|
|
|
var ethJSUtil = require('ethereumjs-util'); |
|
|
|
var EthJSTX = require('ethereumjs-tx'); |
|
|
|
var EthJSTX = require('ethereumjs-tx'); |
|
|
|
var EthJSAccount = require('ethereumjs-account'); |
|
|
|
|
|
|
|
var ethJSABI = require('ethereumjs-abi'); |
|
|
|
var ethJSABI = require('ethereumjs-abi'); |
|
|
|
var EthJSBlock = require('ethereumjs-block'); |
|
|
|
var EthJSBlock = require('ethereumjs-block'); |
|
|
|
var web3 = require('./web3-adapter.js'); |
|
|
|
var web3 = require('./web3-adapter.js'); |
|
|
@ -39,9 +38,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 }; |
|
|
|
} |
|
|
|
} |
|
|
@ -57,6 +55,30 @@ UniversalDApp.prototype.getAccounts = function (cb) { |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UniversalDApp.prototype.getBalance = function (address, cb) { |
|
|
|
|
|
|
|
address = ethJSUtil.stripHexPrefix(address); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!this.vm) { |
|
|
|
|
|
|
|
web3.eth.getBalance(address, function (err, res) { |
|
|
|
|
|
|
|
if (err) { |
|
|
|
|
|
|
|
cb(err); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
cb(null, res.toString(10)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
if (!this.accounts) return cb("No accounts?"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.vm.stateManager.getAccountBalance(new Buffer(address, 'hex'), function (err, res) { |
|
|
|
|
|
|
|
if (err) { |
|
|
|
|
|
|
|
cb("Account not found"); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
cb(null, new ethJSUtil.BN(res).toString(10)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
UniversalDApp.prototype.render = function () { |
|
|
|
UniversalDApp.prototype.render = function () { |
|
|
|
if (this.contracts.length == 0) { |
|
|
|
if (this.contracts.length == 0) { |
|
|
|
this.$el.append( this.getABIInputForm() ); |
|
|
|
this.$el.append( this.getABIInputForm() ); |
|
|
|