From 734e28153060dbd1fd0030987f008b0434007919 Mon Sep 17 00:00:00 2001 From: yann300 Date: Tue, 20 Feb 2018 15:30:40 +0100 Subject: [PATCH] add Listen on last block API --- remix-lib/src/execution/execution-context.js | 31 ++++++++++++-------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/remix-lib/src/execution/execution-context.js b/remix-lib/src/execution/execution-context.js index f4b81dd17a..b30221c75c 100644 --- a/remix-lib/src/execution/execution-context.js +++ b/remix-lib/src/execution/execution-context.js @@ -83,6 +83,9 @@ function ExecutionContext () { var executionContext = null + this.blockGasLimitDefault = 4300000 + this.blockGasLimit = this.blockGasLimitDefault + this.init = function (config) { if (config.get('settings/always-use-vm')) { executionContext = 'vm' @@ -184,17 +187,22 @@ function ExecutionContext () { return this.blockGasLimit } - this.blockGasLimitDefault = 4300000 - this.blockGasLimit = this.blockGasLimitDefault - // removing the setinterval cause it cause tape test to hang and we don't need this. - // there's a copy of this file in remix-ide repo @TODO to refactor - if (this.getProvider() !== 'vm') { - web3.eth.getBlock('latest', (err, block) => { - if (!err) { - // 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 + this.stopListenOnLastBlock = function () { + if (this.listenOnLastBlockId) clearInterval(this.listenOnLastBlockId) + this.listenOnLastBlockId = null + } + + this.listenOnLastBlock = function () { + this.listenOnLastBlockId = setInterval(() => { + if (this.getProvider() !== 'vm') { + web3.eth.getBlock('latest', (err, block) => { + if (!err) { + // 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 () { } module.exports = new ExecutionContext() -