Commit 2f3651a5 authored by yann300's avatar yann300

add Listen on last block API

parent 9d4cbb79
...@@ -83,6 +83,9 @@ function ExecutionContext () { ...@@ -83,6 +83,9 @@ function ExecutionContext () {
var executionContext = null var executionContext = null
this.blockGasLimitDefault = 4300000
this.blockGasLimit = this.blockGasLimitDefault
this.init = function (config) { this.init = function (config) {
if (config.get('settings/always-use-vm')) { if (config.get('settings/always-use-vm')) {
executionContext = 'vm' executionContext = 'vm'
...@@ -184,17 +187,22 @@ function ExecutionContext () { ...@@ -184,17 +187,22 @@ function ExecutionContext () {
return this.blockGasLimit return this.blockGasLimit
} }
this.blockGasLimitDefault = 4300000 this.stopListenOnLastBlock = function () {
this.blockGasLimit = this.blockGasLimitDefault if (this.listenOnLastBlockId) clearInterval(this.listenOnLastBlockId)
// removing the setinterval cause it cause tape test to hang and we don't need this. this.listenOnLastBlockId = null
// there's a copy of this file in remix-ide repo @TODO to refactor }
if (this.getProvider() !== 'vm') {
web3.eth.getBlock('latest', (err, block) => { this.listenOnLastBlock = function () {
if (!err) { this.listenOnLastBlockId = setInterval(() => {
// we can't use the blockGasLimit cause the next blocks could have a lower limit : https://github.com/ethereum/remix/issues/506 if (this.getProvider() !== 'vm') {
this.blockGasLimit = (block && block.gasLimit) ? Math.floor(block.gasLimit - (5 * block.gasLimit) / 1024) : this.blockGasLimitDefault web3.eth.getBlock('latest', (err, block) => {
} else { if (!err) {
this.blockGasLimit = this.blockGasLimitDefault // we can't use the blockGasLimit cause the next blocks could have a lower limit : https://github.com/ethereum/remix/issues/506
this.blockGasLimit = (block && block.gasLimit) ? Math.floor(block.gasLimit - (5 * block.gasLimit) / 1024) : this.blockGasLimitDefault
} else {
this.blockGasLimit = this.blockGasLimitDefault
}
}, 15000)
} }
}) })
} }
...@@ -224,4 +232,3 @@ function ExecutionContext () { ...@@ -224,4 +232,3 @@ function ExecutionContext () {
} }
module.exports = new ExecutionContext() module.exports = new ExecutionContext()
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