Commit 517f6db8 authored by Iuri Matias's avatar Iuri Matias

match subscription to toBlock filter

parent 9524741a
...@@ -12,34 +12,19 @@ class LogsManager { ...@@ -12,34 +12,19 @@ class LogsManager {
async.eachOf(block.transactions, (tx, i, next) => { async.eachOf(block.transactions, (tx, i, next) => {
let txHash = "0x" + tx.hash().toString('hex') let txHash = "0x" + tx.hash().toString('hex')
let subscriptions = this.getSubscriptionsFor({ type: 'block', block: block, tx: tx }) web3.eth.getTransactionReceipt(txHash, (_error, receipt) => {
// 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 log of receipt.logs) {
let subscriptions = this.getSubscriptionsFor({ type: 'block', blockNumber, block, tx, log })
for (let subscriptionId of subscriptions) { for (let subscriptionId of subscriptions) {
let result = { let result = {
"logIndex": "0x1", // 1 "logIndex": "0x1", // 1
// "blockNumber": ("0x" + blockNumber),
"blockNumber": blockNumber, "blockNumber": blockNumber,
"blockHash": ('0x' + block.hash().toString('hex')), "blockHash": ('0x' + block.hash().toString('hex')),
"transactionHash": ('0x' + tx.hash().toString('hex')), "transactionHash": ('0x' + tx.hash().toString('hex')),
"transactionIndex": "0x" + i.toString(16), "transactionIndex": "0x" + i.toString(16),
// TODO: if it's a contract deploy, it should be that address instead // TODO: if it's a contract deploy, it should be that address instead
// "address": ('0x' + tx.to.toString('hex')),
"address": log.address, "address": log.address,
// "data": "0x0000000000000000000000000000000000000000000000000000000000000000",
"data": log.data, "data": log.data,
"topics": log.topics, "topics": log.topics,
} }
...@@ -65,18 +50,21 @@ class LogsManager { ...@@ -65,18 +50,21 @@ class LogsManager {
const subscriptionParams = this.subscriptions[subscriptionId] const subscriptionParams = this.subscriptions[subscriptionId]
const [queryType, queryFilter] = subscriptionParams const [queryType, queryFilter] = subscriptionParams
if (queryType === 'logs') { if (queryType === 'logs') {
if (queryFilter.address === changeEvent.tx.toJSON().to) { if (queryFilter.address === ("0x" + changeEvent.tx.to.toString('hex'))) {
matchedSubscriptions.push(subscriptionId) if (!queryFilter.toBlock) {
matchedSubscriptions.push(subscriptionId)
} else if (parseInt(queryFilter.toBlock) > parseInt(changeEvent.blockNumber)) {
matchedSubscriptions.push(subscriptionId)
}
} }
if (queryFilter.address === ('0x' + changeEvent.tx.from.toString('hex'))) { if (queryFilter.address === ('0x' + changeEvent.tx.from.toString('hex'))) {
matchedSubscriptions.push(subscriptionId) if (!queryFilter.toBlock) {
matchedSubscriptions.push(subscriptionId)
} else if (parseInt(queryFilter.toBlock) > parseInt(changeEvent.blockNumber)) {
matchedSubscriptions.push(subscriptionId)
}
} }
} }
console.dir("-----------------------> ")
console.dir(subscriptionParams)
matchedSubscriptions.push(subscriptionId)
} }
return matchedSubscriptions; return matchedSubscriptions;
} }
......
...@@ -41,6 +41,8 @@ function createContract (payload, from, data, value, gasLimit, txRunner, callbac ...@@ -41,6 +41,8 @@ function createContract (payload, from, data, value, gasLimit, txRunner, callbac
TxExecution.createContract(from, data, value, gasLimit, txRunner, callbacks, finalCallback) TxExecution.createContract(from, data, value, gasLimit, txRunner, callbacks, finalCallback)
} }
let txRunner_instance;
function processTx (accounts, payload, isCall, callback) { function processTx (accounts, payload, isCall, callback) {
let api = { let api = {
logMessage: (msg) => { logMessage: (msg) => {
...@@ -65,7 +67,11 @@ function processTx (accounts, payload, isCall, callback) { ...@@ -65,7 +67,11 @@ function processTx (accounts, payload, isCall, callback) {
executionContext.init(api.config) executionContext.init(api.config)
let txRunner = new TxRunner(accounts, api) // let txRunner = new TxRunner(accounts, api)
if (!txRunner_instance) {
txRunner_instance = new TxRunner(accounts, api)
}
txRunner_instance.vmaccounts = accounts;
let { from, to, data, value, gas } = payload.params[0] let { from, to, data, value, gas } = payload.params[0]
gas = gas || 3000000 gas = gas || 3000000
...@@ -85,11 +91,11 @@ function processTx (accounts, payload, isCall, callback) { ...@@ -85,11 +91,11 @@ function processTx (accounts, payload, isCall, callback) {
} }
if (isCall) { if (isCall) {
runCall(payload, from, to, data, value, gas, txRunner, callbacks, callback) runCall(payload, from, to, data, value, gas, txRunner_instance, callbacks, callback)
} else if (to) { } else if (to) {
runTx(payload, from, to, data, value, gas, txRunner, callbacks, callback) runTx(payload, from, to, data, value, gas, txRunner_instance, callbacks, callback)
} else { } else {
createContract(payload, from, data, value, gas, txRunner, callbacks, callback) createContract(payload, from, data, value, gas, txRunner_instance, callbacks, callback)
} }
} }
......
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