pull/5370/head
Iuri Matias 6 years ago
parent 9d88fb70e7
commit 7882c2340f
  1. 5
      remix-lib/src/execution/execution-context.js
  2. 100
      remix-lib/src/execution/txRunner.js
  3. 2
      remix-lib/src/web3Provider/web3VmProvider.js
  4. 6
      remix-simulator/src/methods/blocks.js
  5. 31
      remix-simulator/src/methods/transactions.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()
}

@ -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()

@ -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))

@ -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 = {

@ -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)
// })
})
}

Loading…
Cancel
Save