|
|
@ -8,21 +8,57 @@ class LogsManager { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
checkBlock(blockNumber, block) { |
|
|
|
checkBlock(blockNumber, block) { |
|
|
|
let subscriptionId = Object.keys(this.subscriptions)[0]; |
|
|
|
for (let i = 0; i < block.transactions.length; i++) { |
|
|
|
|
|
|
|
let tx = block.transactions[i] |
|
|
|
|
|
|
|
|
|
|
|
let result = { |
|
|
|
let subscriptions = this.getSubscriptionsFor({ type: 'block', block: block, tx: tx }) |
|
|
|
"logIndex": "0x1", // 1
|
|
|
|
for (let subscriptionId of subscriptions) { |
|
|
|
"blockNumber": "0x1b4", // 436
|
|
|
|
let result = { |
|
|
|
"blockHash": "0x8216c5785ac562ff41e2dcfdf5785ac562ff41e2dcfdf829c5a142f1fccd7d", |
|
|
|
"logIndex": "0x1", // 1
|
|
|
|
"transactionHash": "0xdf829c5a142f1fccd7d8216c5785ac562ff41e2dcfdf5785ac562ff41e2dcf", |
|
|
|
// "blockNumber": ("0x" + blockNumber),
|
|
|
|
"transactionIndex": "0x0", // 0
|
|
|
|
"blockNumber": blockNumber, |
|
|
|
"address": "0x16c5785ac562ff41e2dcfdf829c5a142f1fccd7d", |
|
|
|
"blockHash": ('0x' + block.hash().toString('hex')), |
|
|
|
"data": "0x0000000000000000000000000000000000000000000000000000000000000000", |
|
|
|
"transactionHash": ('0x' + tx.hash().toString('hex')), |
|
|
|
"topics": ["0x59ebeb90bc63057b6515673c3ecf9438e5058bca0f92585014eced636878c9a5"] |
|
|
|
"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 |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 } }; |
|
|
|
// TODO:
|
|
|
|
this.transmit(response); |
|
|
|
// * need to get address of deployed contract if it's a tx that create a contract
|
|
|
|
|
|
|
|
getSubscriptionsFor(changeEvent) { |
|
|
|
|
|
|
|
let matchedSubscriptions = [] |
|
|
|
|
|
|
|
for (let subscriptionId of Object.keys(this.subscriptions)) { |
|
|
|
|
|
|
|
const subscriptionParams = this.subscriptions[subscriptionId] |
|
|
|
|
|
|
|
const [queryType, queryFilter] = subscriptionParams |
|
|
|
|
|
|
|
if (queryType === 'logs') { |
|
|
|
|
|
|
|
if (queryFilter.address === changeEvent.tx.toJSON().to) { |
|
|
|
|
|
|
|
matchedSubscriptions.push(subscriptionId) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (queryFilter.address === ('0x' + changeEvent.tx.from.toString('hex'))) { |
|
|
|
|
|
|
|
matchedSubscriptions.push(subscriptionId) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
console.dir("-----------------------> ") |
|
|
|
|
|
|
|
console.dir(subscriptionParams) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
matchedSubscriptions.push(subscriptionId) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return matchedSubscriptions; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
transmit(result) { |
|
|
|
transmit(result) { |
|
|
|