Commit 39c5e31e authored by Iuri Matias's avatar Iuri Matias

cleanup

parent 85c0c518
...@@ -118,8 +118,6 @@ function ExecutionContext () { ...@@ -118,8 +118,6 @@ function ExecutionContext () {
} }
this.web3 = function () { this.web3 = function () {
console.dir("isVM")
console.dir(this.isVM())
return this.isVM() ? vms.constantinople.web3vm : web3 return this.isVM() ? vms.constantinople.web3vm : web3
} }
...@@ -188,9 +186,6 @@ function ExecutionContext () { ...@@ -188,9 +186,6 @@ function ExecutionContext () {
if (context === 'vm') { if (context === 'vm') {
executionContext = context executionContext = context
// vms.constantinople.stateManager.revert(() => {
// vms.constantinople.stateManager.checkpoint(() => {})
// })
self.event.trigger('contextChanged', ['vm']) self.event.trigger('contextChanged', ['vm'])
return cb() return cb()
} }
......
...@@ -94,7 +94,7 @@ class TxRunner { ...@@ -94,7 +94,7 @@ class TxRunner {
} }
} }
runInVm (from, to, data, value, gasLimit, useCall, timestamp, callback) { runInVm(from, to, data, value, gasLimit, useCall, timestamp, callback) {
const self = this const self = this
var account = self.vmaccounts[from] var account = self.vmaccounts[from]
if (!account) { if (!account) {
...@@ -111,106 +111,50 @@ class TxRunner { ...@@ -111,106 +111,50 @@ class TxRunner {
}) })
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: timestamp || (new Date().getTime() / 1000 | 0), timestamp: 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],
// coinbase: coinbases[0],
//difficulty: difficulties[0],
coinbase: coinbases[0], coinbase: coinbases[0],
// gasLimit: new BN(gasLimit, 10).imuln(200),
gasLimit: new BN("5000000").imuln(1) gasLimit: new BN("5000000").imuln(1)
}, },
transactions: [tx], transactions: [tx],
//transactions: [],
uncleHeaders: [] uncleHeaders: []
}) })
if (!useCall) { if (!useCall) {
++self.blockNumber ++self.blockNumber
} else { } else {
executionContext.vm().stateManager.checkpoint(() => {}) executionContext.vm().stateManager.checkpoint(() => { })
} }
//block.transactions.push(tx);
this.checkpointAndCommit(() => { this.checkpointAndCommit(() => {
executionContext.vm().runBlock({ block: block, generate: true, skipBlockValidation: true, skipBalance: false }, function (err, results) {
let result = results.results[0]
console.dir(result)
if (useCall) {
executionContext.vm().stateManager.revert(function () { })
}
err = err ? err.message : err
if (result) {
result.status = '0x' + result.vm.exception.toString(16)
}
//executionContext.vm().blockchain.getLatestBlock((a, b) => { executionContext.addBlock(block)
executionContext.trackTx("0x" + tx.hash().toString('hex'), block)
// console.dir("b.hash()")
// console.dir(b.hash())
// console.dir(b.hash().length)
// console.dir(b.hash().toString('hex'))
// console.dir(b.hash().toString('hex').length)
// block.header.parentHash = b.hash()
// block.header.parentHash = b.hash().toString('hex')
//block.header.parentHash = Buffer.from(b.hash(), 'hex')
//block.header.parentHash = "4599f6765f1d5a50Bf1E3DBFa14A72dF"
// block.header.parentHash = b.hash()
// block.header.difficulty = block.header.canonicalDifficulty(b)
//executionContext.vm().runTx({block: block, tx: tx, skipBalance: true, skipNonce: true}, function (err, result) {
executionContext.vm().runBlock({block: block, generate: true, skipBlockValidation: true, skipBalance: false}, function (err, results) {
console.dir("-- runBlock result")
console.dir(err)
//console.dir(results)
let result = results.results[0]
console.dir(result)
if (useCall) {
executionContext.vm().stateManager.revert(function () {})
}
err = err ? err.message : err
if (result) {
result.status = '0x' + result.vm.exception.toString(16)
}
//executionContext.vm().blockchain.putBlock(block, (err, savedBlock) => {
executionContext.addBlock(block)
executionContext.trackTx("0x" + tx.hash().toString('hex'), block)
// result.blockHash = "0x" + block.hash().toString('hex')
// result.blockNumber = "0x" + block.header.number.toString('hex')
callback(err, {
result: result,
transactionHash: ethJSUtil.bufferToHex(Buffer.from(tx.hash()))
})
//})
callback(err, {
result: result,
transactionHash: ethJSUtil.bufferToHex(Buffer.from(tx.hash()))
}) })
})
//})
}) })
//})
} }
checkpointAndCommit (cb) { checkpointAndCommit (cb) {
console.dir("------------------------")
console.dir("------------------------")
console.dir("------------------------")
console.dir("------------------------")
console.dir("------------------------")
console.dir("------------------------")
console.dir(executionContext.vm().stateManager._checkpointCount)
console.dir("------------------------")
console.dir("------------------------")
console.dir("------------------------")
console.dir("------------------------")
console.dir("------------------------")
console.dir("------------------------")
if (executionContext.vm().stateManager._checkpointCount > 0) { if (executionContext.vm().stateManager._checkpointCount > 0) {
return executionContext.vm().stateManager.commit(() => { return executionContext.vm().stateManager.commit(() => {
cb() cb()
......
...@@ -194,8 +194,6 @@ web3VmProvider.prototype.pushTrace = function (self, data) { ...@@ -194,8 +194,6 @@ web3VmProvider.prototype.pushTrace = function (self, data) {
} }
web3VmProvider.prototype.getCode = function (address, cb) { web3VmProvider.prototype.getCode = function (address, cb) {
console.dir("===> web3VmProvider: ")
const account = ethutil.toBuffer(address) const account = ethutil.toBuffer(address)
this.vm.stateManager.getContractCode(account, function (error, result) { this.vm.stateManager.getContractCode(account, function (error, result) {
cb(error, util.hexConvert(result)) cb(error, util.hexConvert(result))
......
...@@ -56,12 +56,6 @@ function toHex(value) { ...@@ -56,12 +56,6 @@ function toHex(value) {
} }
Blocks.prototype.eth_getBlockByHash = function (payload, cb) { Blocks.prototype.eth_getBlockByHash = function (payload, cb) {
console.dir("eth_getBlockByHash")
console.dir(payload)
console.dir(Object.keys(executionContext.blocks))
console.dir("== toJSON")
console.dir(executionContext.blocks[payload.params[0]].toJSON())
var block = executionContext.blocks[payload.params[0]] var block = executionContext.blocks[payload.params[0]]
let b = { let b = {
......
...@@ -40,8 +40,6 @@ Transactions.prototype.eth_sendTransaction = function (payload, cb) { ...@@ -40,8 +40,6 @@ Transactions.prototype.eth_sendTransaction = function (payload, cb) {
} }
Transactions.prototype.eth_getTransactionReceipt = function (payload, cb) { Transactions.prototype.eth_getTransactionReceipt = function (payload, cb) {
console.dir("== eth_getTransactionReceipt")
console.dir(payload.params)
executionContext.web3().eth.getTransactionReceipt(payload.params[0], (error, receipt) => { executionContext.web3().eth.getTransactionReceipt(payload.params[0], (error, receipt) => {
if (error) { if (error) {
return cb(error) return cb(error)
...@@ -70,22 +68,13 @@ Transactions.prototype.eth_estimateGas = function (payload, cb) { ...@@ -70,22 +68,13 @@ Transactions.prototype.eth_estimateGas = function (payload, cb) {
} }
Transactions.prototype.eth_getCode = function (payload, cb) { Transactions.prototype.eth_getCode = function (payload, cb) {
console.dir("== eth_getCode")
console.dir(payload.params)
let address = payload.params[0] let address = payload.params[0]
console.dir(address);
// const account = ethJSUtil.toBuffer(address)
// console.dir(account)
//executionContext.vm().stateManager.getContractCode(account, (error, result) => {
//executionContext.web3().eth.getContractCode(address, (error, result) => {
executionContext.web3().eth.getCode(address, (error, result) => { executionContext.web3().eth.getCode(address, (error, result) => {
if (error) { if (error) {
console.dir("error getting code"); console.dir("error getting code");
console.dir(error); console.dir(error);
} }
//cb(error, hexConvert(result))
cb(error, result) cb(error, result)
}) })
} }
...@@ -107,8 +96,6 @@ Transactions.prototype.eth_getTransactionCount = function (payload, cb) { ...@@ -107,8 +96,6 @@ Transactions.prototype.eth_getTransactionCount = function (payload, cb) {
} }
Transactions.prototype.eth_getTransactionByHash = function (payload, cb) { Transactions.prototype.eth_getTransactionByHash = function (payload, cb) {
console.dir("== eth_getTransactionByHash")
console.dir(payload.params)
const address = payload.params[0] const address = payload.params[0]
executionContext.web3().eth.getTransactionReceipt(address, (error, receipt) => { executionContext.web3().eth.getTransactionReceipt(address, (error, receipt) => {
...@@ -116,14 +103,11 @@ Transactions.prototype.eth_getTransactionByHash = function (payload, cb) { ...@@ -116,14 +103,11 @@ Transactions.prototype.eth_getTransactionByHash = function (payload, cb) {
return cb(error) return cb(error)
} }
console.dir("== receipt")
console.dir(receipt)
var test = executionContext.web3(); var test = executionContext.web3();
var txBlock = executionContext.txs[receipt.transactionHash]; var txBlock = executionContext.txs[receipt.transactionHash];
// executionContext.web3().eth.getBlock(receipt.hash).then((block) => { // TODO: params to add later
let r = { let r = {
'blockHash': "0x" + txBlock.hash().toString('hex'), 'blockHash': "0x" + txBlock.hash().toString('hex'),
'blockNumber': "0x" + txBlock.header.number.toString('hex'), 'blockNumber': "0x" + txBlock.header.number.toString('hex'),
...@@ -151,14 +135,10 @@ Transactions.prototype.eth_getTransactionByHash = function (payload, cb) { ...@@ -151,14 +135,10 @@ Transactions.prototype.eth_getTransactionByHash = function (payload, cb) {
} }
cb(null, r) cb(null, r)
// })
}) })
} }
Transactions.prototype.eth_getTransactionByBlockHashAndIndex = function (payload, cb) { Transactions.prototype.eth_getTransactionByBlockHashAndIndex = function (payload, cb) {
console.dir("== eth_getTransactionByHash")
console.dir(payload.params)
// const address = payload.params[0]
const txIndex = payload.params[1] const txIndex = payload.params[1]
var txBlock = executionContext.blocks[payload.params[0]] var txBlock = executionContext.blocks[payload.params[0]]
...@@ -169,7 +149,7 @@ Transactions.prototype.eth_getTransactionByBlockHashAndIndex = function (payload ...@@ -169,7 +149,7 @@ Transactions.prototype.eth_getTransactionByBlockHashAndIndex = function (payload
return cb(error) return cb(error)
} }
// executionContext.web3().eth.getBlock(receipt.hash).then((block) => { // TODO: params to add later
let r = { let r = {
'blockHash': "0x" + txBlock.hash().toString('hex'), 'blockHash': "0x" + txBlock.hash().toString('hex'),
'blockNumber': "0x" + txBlock.header.number.toString('hex'), 'blockNumber': "0x" + txBlock.header.number.toString('hex'),
...@@ -197,14 +177,10 @@ Transactions.prototype.eth_getTransactionByBlockHashAndIndex = function (payload ...@@ -197,14 +177,10 @@ Transactions.prototype.eth_getTransactionByBlockHashAndIndex = function (payload
} }
cb(null, r) cb(null, r)
// })
}) })
} }
Transactions.prototype.eth_getTransactionByBlockNumberAndIndex = function (payload, cb) { Transactions.prototype.eth_getTransactionByBlockNumberAndIndex = function (payload, cb) {
console.dir("== eth_getTransactionByHash")
console.dir(payload.params)
// const address = payload.params[0]
const txIndex = payload.params[1] const txIndex = payload.params[1]
var txBlock = executionContext.blocks[payload.params[0]] var txBlock = executionContext.blocks[payload.params[0]]
...@@ -215,7 +191,7 @@ Transactions.prototype.eth_getTransactionByBlockNumberAndIndex = function (paylo ...@@ -215,7 +191,7 @@ Transactions.prototype.eth_getTransactionByBlockNumberAndIndex = function (paylo
return cb(error) return cb(error)
} }
// executionContext.web3().eth.getBlock(receipt.hash).then((block) => { // TODO: params to add later
let r = { let r = {
'blockHash': "0x" + txBlock.hash().toString('hex'), 'blockHash': "0x" + txBlock.hash().toString('hex'),
'blockNumber': "0x" + txBlock.header.number.toString('hex'), 'blockNumber': "0x" + txBlock.header.number.toString('hex'),
...@@ -243,7 +219,6 @@ Transactions.prototype.eth_getTransactionByBlockNumberAndIndex = function (paylo ...@@ -243,7 +219,6 @@ Transactions.prototype.eth_getTransactionByBlockNumberAndIndex = function (paylo
} }
cb(null, r) cb(null, r)
// })
}) })
} }
......
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