Commit 62ed083f authored by Iuri Matias's avatar Iuri Matias

refactor: remove unnecessary level of depth from runInVm

parent adfdea8b
...@@ -68,60 +68,60 @@ TxRunner.prototype.execute = function (args, callback) { ...@@ -68,60 +68,60 @@ TxRunner.prototype.execute = function (args, callback) {
if (!executionContext.isVM()) { if (!executionContext.isVM()) {
self.runInNode(args.from, args.to, data, args.value, args.gasLimit, args.useCall, callback) self.runInNode(args.from, args.to, data, args.value, args.gasLimit, args.useCall, callback)
} else { } else {
self.runInVm(args.from, args.to, data, args.value, args.gasLimit, args.useCall, callback) try {
self.runInVm(args.from, args.to, data, args.value, args.gasLimit, args.useCall, callback)
} catch (e) {
callback(e, null)
}
} }
} }
TxRunner.prototype.runInVm = function (from, to, data, value, gasLimit, useCall, callback) { TxRunner.prototype.runInVm = function (from, to, data, value, gasLimit, useCall, callback) {
const self = this const self = this
try { var account = self.vmaccounts[from]
var account = self.vmaccounts[from] if (!account) {
if (!account) { return callback('Invalid account selected')
return callback('Invalid account selected') }
} var tx = new EthJSTX({
var tx = new EthJSTX({ nonce: new BN(account.nonce++),
nonce: new BN(account.nonce++), gasPrice: new BN(1),
gasPrice: new BN(1), gasLimit: new BN(gasLimit, 10),
gasLimit: new BN(gasLimit, 10), to: to,
to: to, value: new BN(value, 10),
value: new BN(value, 10), data: new Buffer(data.slice(2), 'hex')
data: new Buffer(data.slice(2), 'hex') })
}) tx.sign(account.privateKey)
tx.sign(account.privateKey)
const coinbases = [ '0x0e9281e9c6a0808672eaba6bd1220e144c9bb07a', '0x8945a1288dc78a6d8952a92c77aee6730b414778', '0x94d76e24f818426ae84aa404140e8d5f60e10e7e' ] const coinbases = [ '0x0e9281e9c6a0808672eaba6bd1220e144c9bb07a', '0x8945a1288dc78a6d8952a92c77aee6730b414778', '0x94d76e24f818426ae84aa404140e8d5f60e10e7e' ]
const difficulties = [ new BN('69762765929000', 10), new BN('70762765929000', 10), new BN('71762765929000', 10) ] const difficulties = [ new BN('69762765929000', 10), new BN('70762765929000', 10), new BN('71762765929000', 10) ]
var block = new EthJSBlock({ var block = new EthJSBlock({
header: { header: {
timestamp: new Date().getTime() / 1000 | 0, timestamp: new Date().getTime() / 1000 | 0,
number: self.blockNumber, number: self.blockNumber,
coinbase: coinbases[self.blockNumber % coinbases.length], coinbase: coinbases[self.blockNumber % coinbases.length],
difficulty: difficulties[self.blockNumber % difficulties.length], difficulty: difficulties[self.blockNumber % difficulties.length],
gasLimit: new BN(gasLimit, 10).imuln(2) gasLimit: new BN(gasLimit, 10).imuln(2)
}, },
transactions: [], transactions: [],
uncleHeaders: [] uncleHeaders: []
}) })
if (!useCall) { if (!useCall) {
++self.blockNumber ++self.blockNumber
} else { } else {
executionContext.vm().stateManager.checkpoint() executionContext.vm().stateManager.checkpoint()
} }
executionContext.vm().runTx({block: block, tx: tx, skipBalance: true, skipNonce: true}, function (err, result) { executionContext.vm().runTx({block: block, tx: tx, skipBalance: true, skipNonce: true}, function (err, result) {
if (useCall) { if (useCall) {
executionContext.vm().stateManager.revert(function () {}) executionContext.vm().stateManager.revert(function () {})
} }
err = err ? err.message : err err = err ? err.message : err
result.status = '0x' + result.vm.exception.toString(16) result.status = '0x' + result.vm.exception.toString(16)
callback(err, { callback(err, {
result: result, result: result,
transactionHash: ethJSUtil.bufferToHex(new Buffer(tx.hash())) transactionHash: ethJSUtil.bufferToHex(new Buffer(tx.hash()))
})
}) })
} catch (e) { })
callback(e, null)
}
} }
TxRunner.prototype.runInNode = function (from, to, data, value, gasLimit, useCall, callback) { TxRunner.prototype.runInNode = function (from, to, data, value, gasLimit, useCall, callback) {
......
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