From 7882c2340f6a70e168b4d5aa5993eb64877a85cf Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Tue, 4 Jun 2019 12:48:08 -0400 Subject: [PATCH] cleanup --- remix-lib/src/execution/execution-context.js | 5 - remix-lib/src/execution/txRunner.js | 100 ++++--------------- remix-lib/src/web3Provider/web3VmProvider.js | 2 - remix-simulator/src/methods/blocks.js | 6 -- remix-simulator/src/methods/transactions.js | 31 +----- 5 files changed, 25 insertions(+), 119 deletions(-) diff --git a/remix-lib/src/execution/execution-context.js b/remix-lib/src/execution/execution-context.js index 4fcbb77af9..b9a317e74a 100644 --- a/remix-lib/src/execution/execution-context.js +++ b/remix-lib/src/execution/execution-context.js @@ -118,8 +118,6 @@ function ExecutionContext () { } this.web3 = function () { - console.dir("isVM") - console.dir(this.isVM()) return this.isVM() ? vms.constantinople.web3vm : web3 } @@ -188,9 +186,6 @@ function ExecutionContext () { if (context === 'vm') { executionContext = context - // vms.constantinople.stateManager.revert(() => { - // vms.constantinople.stateManager.checkpoint(() => {}) - // }) self.event.trigger('contextChanged', ['vm']) return cb() } diff --git a/remix-lib/src/execution/txRunner.js b/remix-lib/src/execution/txRunner.js index cb77229f6d..dc2a9e584b 100644 --- a/remix-lib/src/execution/txRunner.js +++ b/remix-lib/src/execution/txRunner.js @@ -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 var account = self.vmaccounts[from] if (!account) { @@ -111,106 +111,50 @@ class TxRunner { }) tx.sign(account.privateKey) - const coinbases = [ '0x0e9281e9c6a0808672eaba6bd1220e144c9bb07a', '0x8945a1288dc78a6d8952a92c77aee6730b414778', '0x94d76e24f818426ae84aa404140e8d5f60e10e7e' ] - const difficulties = [ new BN('69762765929000', 10), new BN('70762765929000', 10), new BN('71762765929000', 10) ] + const coinbases = ['0x0e9281e9c6a0808672eaba6bd1220e144c9bb07a', '0x8945a1288dc78a6d8952a92c77aee6730b414778', '0x94d76e24f818426ae84aa404140e8d5f60e10e7e'] + const difficulties = [new BN('69762765929000', 10), new BN('70762765929000', 10), new BN('71762765929000', 10)] var block = new EthJSBlock({ header: { timestamp: timestamp || (new Date().getTime() / 1000 | 0), number: self.blockNumber, - // coinbase: coinbases[self.blockNumber % coinbases.length], - // difficulty: difficulties[self.blockNumber % difficulties.length], - // coinbase: coinbases[0], - //difficulty: difficulties[0], + coinbase: coinbases[self.blockNumber % coinbases.length], + difficulty: difficulties[self.blockNumber % difficulties.length], coinbase: coinbases[0], - // gasLimit: new BN(gasLimit, 10).imuln(200), gasLimit: new BN("5000000").imuln(1) }, transactions: [tx], - //transactions: [], uncleHeaders: [] }) if (!useCall) { ++self.blockNumber } else { - executionContext.vm().stateManager.checkpoint(() => {}) + executionContext.vm().stateManager.checkpoint(() => { }) } - //block.transactions.push(tx); - 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) => { - - // 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())) - }) - //}) + executionContext.addBlock(block) + executionContext.trackTx("0x" + tx.hash().toString('hex'), block) + callback(err, { + result: result, + transactionHash: ethJSUtil.bufferToHex(Buffer.from(tx.hash())) }) - - - //}) - - + }) }) - //}) } 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) { return executionContext.vm().stateManager.commit(() => { cb() diff --git a/remix-lib/src/web3Provider/web3VmProvider.js b/remix-lib/src/web3Provider/web3VmProvider.js index 250c6ab20d..8cc8d344ad 100644 --- a/remix-lib/src/web3Provider/web3VmProvider.js +++ b/remix-lib/src/web3Provider/web3VmProvider.js @@ -194,8 +194,6 @@ web3VmProvider.prototype.pushTrace = function (self, data) { } web3VmProvider.prototype.getCode = function (address, cb) { - console.dir("===> web3VmProvider: ") - const account = ethutil.toBuffer(address) this.vm.stateManager.getContractCode(account, function (error, result) { cb(error, util.hexConvert(result)) diff --git a/remix-simulator/src/methods/blocks.js b/remix-simulator/src/methods/blocks.js index c9705cb3d5..d8486fb179 100644 --- a/remix-simulator/src/methods/blocks.js +++ b/remix-simulator/src/methods/blocks.js @@ -56,12 +56,6 @@ function toHex(value) { } 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]] let b = { diff --git a/remix-simulator/src/methods/transactions.js b/remix-simulator/src/methods/transactions.js index 23faa32bfa..f51df66d7f 100644 --- a/remix-simulator/src/methods/transactions.js +++ b/remix-simulator/src/methods/transactions.js @@ -40,8 +40,6 @@ Transactions.prototype.eth_sendTransaction = 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) => { if (error) { return cb(error) @@ -70,22 +68,13 @@ Transactions.prototype.eth_estimateGas = function (payload, cb) { } Transactions.prototype.eth_getCode = function (payload, cb) { - console.dir("== eth_getCode") - console.dir(payload.params) 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) => { if (error) { console.dir("error getting code"); console.dir(error); } - //cb(error, hexConvert(result)) cb(error, result) }) } @@ -107,8 +96,6 @@ Transactions.prototype.eth_getTransactionCount = function (payload, cb) { } Transactions.prototype.eth_getTransactionByHash = function (payload, cb) { - console.dir("== eth_getTransactionByHash") - console.dir(payload.params) const address = payload.params[0] executionContext.web3().eth.getTransactionReceipt(address, (error, receipt) => { @@ -116,14 +103,11 @@ Transactions.prototype.eth_getTransactionByHash = function (payload, cb) { return cb(error) } - console.dir("== receipt") - console.dir(receipt) - var test = executionContext.web3(); var txBlock = executionContext.txs[receipt.transactionHash]; - // executionContext.web3().eth.getBlock(receipt.hash).then((block) => { + // TODO: params to add later let r = { 'blockHash': "0x" + txBlock.hash().toString('hex'), 'blockNumber': "0x" + txBlock.header.number.toString('hex'), @@ -151,14 +135,10 @@ Transactions.prototype.eth_getTransactionByHash = function (payload, cb) { } cb(null, r) - // }) }) } 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] var txBlock = executionContext.blocks[payload.params[0]] @@ -169,7 +149,7 @@ Transactions.prototype.eth_getTransactionByBlockHashAndIndex = function (payload return cb(error) } - // executionContext.web3().eth.getBlock(receipt.hash).then((block) => { + // TODO: params to add later let r = { 'blockHash': "0x" + txBlock.hash().toString('hex'), 'blockNumber': "0x" + txBlock.header.number.toString('hex'), @@ -197,14 +177,10 @@ Transactions.prototype.eth_getTransactionByBlockHashAndIndex = function (payload } cb(null, r) - // }) }) } 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] var txBlock = executionContext.blocks[payload.params[0]] @@ -215,7 +191,7 @@ Transactions.prototype.eth_getTransactionByBlockNumberAndIndex = function (paylo return cb(error) } - // executionContext.web3().eth.getBlock(receipt.hash).then((block) => { + // TODO: params to add later let r = { 'blockHash': "0x" + txBlock.hash().toString('hex'), 'blockNumber': "0x" + txBlock.header.number.toString('hex'), @@ -243,7 +219,6 @@ Transactions.prototype.eth_getTransactionByBlockNumberAndIndex = function (paylo } cb(null, r) - // }) }) }