diff --git a/remix-lib/src/execution/execution-context.js b/remix-lib/src/execution/execution-context.js index fd785d4e35..ff5fb3cda7 100644 --- a/remix-lib/src/execution/execution-context.js +++ b/remix-lib/src/execution/execution-context.js @@ -310,7 +310,7 @@ function ExecutionContext () { self.blocks['0x' + block.hash().toString('hex')] = block self.blocks[blockNumber] = block - this.logsManager.checkBlock(blockNumber, block) + this.logsManager.checkBlock(blockNumber, block, this.web3()) } this.trackTx = function (tx, block) { diff --git a/remix-lib/src/execution/logsManager.js b/remix-lib/src/execution/logsManager.js index 1b6fcd8638..a6d82837cc 100644 --- a/remix-lib/src/execution/logsManager.js +++ b/remix-lib/src/execution/logsManager.js @@ -1,4 +1,5 @@ -var crypto = require('crypto') +const async = require('async') +const crypto = require('crypto') class LogsManager { @@ -7,34 +8,53 @@ class LogsManager { this.subscriptions = {} } - checkBlock(blockNumber, block) { - for (let i = 0; i < block.transactions.length; i++) { - let tx = block.transactions[i] + checkBlock(blockNumber, block, web3) { + async.eachOf(block.transactions, (tx, i, next) => { + let txHash = "0x" + tx.hash().toString('hex') let subscriptions = this.getSubscriptionsFor({ type: 'block', block: block, tx: tx }) - for (let subscriptionId of subscriptions) { - let result = { - "logIndex": "0x1", // 1 - // "blockNumber": ("0x" + blockNumber), - "blockNumber": blockNumber, - "blockHash": ('0x' + block.hash().toString('hex')), - "transactionHash": ('0x' + tx.hash().toString('hex')), - "transactionIndex": "0x" + i.toString(16), - // TODO: if it's a contract deploy, it should be that address instead - "address": ('0x' + tx.to.toString('hex')), - "data": "0x0000000000000000000000000000000000000000000000000000000000000000", - // "topics": ["0x59ebeb90bc63057b6515673c3ecf9438e5058bca0f92585014eced636878c9a5"] - "topics": [] - } - if (result.address === "0x") { - delete result.address + // console.dir("====================================================") + // console.dir(block) + // console.dir("====================================================") + + web3.eth.getTransactionReceipt(txHash, (error, receipt) => { + console.dir("====================================================") + console.dir("====================================================") + console.dir("====================================================") + console.dir(receipt) + // web3.eth.abi.decodeLog(inputs_abi, receipt.logs[0].data, receipt.logs[0].topics) + // console.dir(process.exit(0)) + // // web3.eth.abi.decodeLog(inputs_abi, receipt.logs[0].data, receipt.logs[0].topics) + + for (let log of receipt.logs) { + for (let subscriptionId of subscriptions) { + let result = { + "logIndex": "0x1", // 1 + // "blockNumber": ("0x" + blockNumber), + "blockNumber": blockNumber, + "blockHash": ('0x' + block.hash().toString('hex')), + "transactionHash": ('0x' + tx.hash().toString('hex')), + "transactionIndex": "0x" + i.toString(16), + // TODO: if it's a contract deploy, it should be that address instead + // "address": ('0x' + tx.to.toString('hex')), + "address": log.address, + // "data": "0x0000000000000000000000000000000000000000000000000000000000000000", + "data": log.data, + "topics": log.topics, + } + + if (result.address === "0x") { + delete result.address + } + + let response = { 'jsonrpc': '2.0', "method": "eth_subscription", params: { 'result': result, 'subscription': subscriptionId } }; + this.transmit(response); + } } - - let response = { 'jsonrpc': '2.0', "method": "eth_subscription", params: { 'result': result, 'subscription': subscriptionId } }; - this.transmit(response); - } - } + }) + }, (err) => { + }); } // TODO: @@ -91,7 +111,6 @@ class LogsManager { } unsubscribe(subscriptionId) { - let subscriptionId = "0x" + crypto.randomBytes(16).toString('hex') delete this.subscriptions[subscriptionId] } diff --git a/remix-simulator/package.json b/remix-simulator/package.json index dff56aef6c..46f87e402f 100644 --- a/remix-simulator/package.json +++ b/remix-simulator/package.json @@ -15,6 +15,7 @@ "main": "./index.js", "dependencies": { "ansi-gray": "^0.1.1", + "async": "^3.1.0", "body-parser": "^1.18.2", "color-support": "^1.1.3", "commander": "^2.19.0", @@ -28,7 +29,7 @@ "remix-lib": "0.4.12", "standard": "^10.0.3", "time-stamp": "^2.0.0", - "web3": "1.0.0-beta.27" + "web3": "^1.0.0-beta.37" }, "devDependencies": { "@babel/core": "^7.4.5", diff --git a/remix-simulator/src/methods/filters.js b/remix-simulator/src/methods/filters.js index a167cc4257..2b630be0ad 100644 --- a/remix-simulator/src/methods/filters.js +++ b/remix-simulator/src/methods/filters.js @@ -23,13 +23,6 @@ Filters.prototype.eth_getLogs = function (payload, cb) { // address: '0xdb2eb1480cb3ac3a5c0ee957045d1ad9dcd34f01', // topics: [] } ] - // console.dir(executionContext.vm().stateManager) - // console.dir(executionContext.vm().blockchain) - - // var block = executionContext.blocks[payload.params[0]] - - // executionContext.vm().stateManager.getLogs(address, (err, account) => { - let results = executionContext.logsManager.getLogsFor(payload.params); cb(null, results)