Commit 9524741a authored by Iuri Matias's avatar Iuri Matias

return tx logs with in subscription

parent 7b8d7951
...@@ -310,7 +310,7 @@ function ExecutionContext () { ...@@ -310,7 +310,7 @@ function ExecutionContext () {
self.blocks['0x' + block.hash().toString('hex')] = block self.blocks['0x' + block.hash().toString('hex')] = block
self.blocks[blockNumber] = block self.blocks[blockNumber] = block
this.logsManager.checkBlock(blockNumber, block) this.logsManager.checkBlock(blockNumber, block, this.web3())
} }
this.trackTx = function (tx, block) { this.trackTx = function (tx, block) {
......
var crypto = require('crypto') const async = require('async')
const crypto = require('crypto')
class LogsManager { class LogsManager {
...@@ -7,34 +8,53 @@ class LogsManager { ...@@ -7,34 +8,53 @@ class LogsManager {
this.subscriptions = {} this.subscriptions = {}
} }
checkBlock(blockNumber, block) { checkBlock(blockNumber, block, web3) {
for (let i = 0; i < block.transactions.length; i++) { async.eachOf(block.transactions, (tx, i, next) => {
let tx = block.transactions[i] let txHash = "0x" + tx.hash().toString('hex')
let subscriptions = this.getSubscriptionsFor({ type: 'block', block: block, tx: tx }) 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") { // console.dir("====================================================")
delete result.address // 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 } }; }, (err) => {
this.transmit(response); });
}
}
} }
// TODO: // TODO:
...@@ -91,7 +111,6 @@ class LogsManager { ...@@ -91,7 +111,6 @@ class LogsManager {
} }
unsubscribe(subscriptionId) { unsubscribe(subscriptionId) {
let subscriptionId = "0x" + crypto.randomBytes(16).toString('hex')
delete this.subscriptions[subscriptionId] delete this.subscriptions[subscriptionId]
} }
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
"main": "./index.js", "main": "./index.js",
"dependencies": { "dependencies": {
"ansi-gray": "^0.1.1", "ansi-gray": "^0.1.1",
"async": "^3.1.0",
"body-parser": "^1.18.2", "body-parser": "^1.18.2",
"color-support": "^1.1.3", "color-support": "^1.1.3",
"commander": "^2.19.0", "commander": "^2.19.0",
...@@ -28,7 +29,7 @@ ...@@ -28,7 +29,7 @@
"remix-lib": "0.4.12", "remix-lib": "0.4.12",
"standard": "^10.0.3", "standard": "^10.0.3",
"time-stamp": "^2.0.0", "time-stamp": "^2.0.0",
"web3": "1.0.0-beta.27" "web3": "^1.0.0-beta.37"
}, },
"devDependencies": { "devDependencies": {
"@babel/core": "^7.4.5", "@babel/core": "^7.4.5",
......
...@@ -23,13 +23,6 @@ Filters.prototype.eth_getLogs = function (payload, cb) { ...@@ -23,13 +23,6 @@ Filters.prototype.eth_getLogs = function (payload, cb) {
// address: '0xdb2eb1480cb3ac3a5c0ee957045d1ad9dcd34f01', // address: '0xdb2eb1480cb3ac3a5c0ee957045d1ad9dcd34f01',
// topics: [] } ] // 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); let results = executionContext.logsManager.getLogsFor(payload.params);
cb(null, results) cb(null, results)
......
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