parent
45e865d542
commit
02fbc04375
@ -0,0 +1,74 @@ |
||||
var crypto = require('crypto') |
||||
|
||||
class LogsManager { |
||||
|
||||
constructor() { |
||||
this.notificationCallbacks = [] |
||||
this.subscriptions = {} |
||||
} |
||||
|
||||
checkBlock(blockNumber, block) { |
||||
let subscriptionId = Object.keys(this.subscriptions)[0]; |
||||
|
||||
let result = { |
||||
"logIndex": "0x1", // 1
|
||||
"blockNumber": "0x1b4", // 436
|
||||
"blockHash": "0x8216c5785ac562ff41e2dcfdf5785ac562ff41e2dcfdf829c5a142f1fccd7d", |
||||
"transactionHash": "0xdf829c5a142f1fccd7d8216c5785ac562ff41e2dcfdf5785ac562ff41e2dcf", |
||||
"transactionIndex": "0x0", // 0
|
||||
"address": "0x16c5785ac562ff41e2dcfdf829c5a142f1fccd7d", |
||||
"data": "0x0000000000000000000000000000000000000000000000000000000000000000", |
||||
"topics": ["0x59ebeb90bc63057b6515673c3ecf9438e5058bca0f92585014eced636878c9a5"] |
||||
} |
||||
|
||||
let response = { 'jsonrpc': '2.0', "method": "eth_subscription", params: { 'result': result, 'subscription': subscriptionId } }; |
||||
this.transmit(response); |
||||
} |
||||
|
||||
transmit(result) { |
||||
console.dir("-----------------") |
||||
console.dir("---- transmit") |
||||
console.dir(this.notificationCallbacks) |
||||
console.dir(result) |
||||
|
||||
// TODO: manage subscriptions
|
||||
|
||||
this.notificationCallbacks.forEach((callback) => { |
||||
callback(result) |
||||
}); |
||||
} |
||||
|
||||
addListener(type, cb) { |
||||
this.notificationCallbacks.push(cb) |
||||
console.dir("--------------------------------------------------------->") |
||||
console.dir("==========================") |
||||
console.dir("==========================") |
||||
console.dir(this.notificationCallbacks) |
||||
console.dir("==========================") |
||||
console.dir("==========================") |
||||
} |
||||
|
||||
subscribe(params) { |
||||
let subscriptionId = "0x" + crypto.randomBytes(16).toString('hex') |
||||
this.subscriptions[subscriptionId] = params |
||||
return subscriptionId |
||||
} |
||||
|
||||
getLogsFor(params) { |
||||
let results = [{ |
||||
"logIndex": "0x1", // 1
|
||||
"blockNumber": "0x1b4", // 436
|
||||
"blockHash": "0x8216c5785ac562ff41e2dcfdf5785ac562ff41e2dcfdf829c5a142f1fccd7d", |
||||
"transactionHash": "0xdf829c5a142f1fccd7d8216c5785ac562ff41e2dcfdf5785ac562ff41e2dcf", |
||||
"transactionIndex": "0x0", // 0
|
||||
"address": "0x16c5785ac562ff41e2dcfdf829c5a142f1fccd7d", |
||||
"data": "0x0000000000000000000000000000000000000000000000000000000000000000", |
||||
"topics": ["0x59ebeb90bc63057b6515673c3ecf9438e5058bca0f92585014eced636878c9a5"] |
||||
}] |
||||
|
||||
return results |
||||
} |
||||
|
||||
} |
||||
|
||||
module.exports = LogsManager; |
@ -0,0 +1,48 @@ |
||||
var RemixLib = require('remix-lib') |
||||
var executionContext = RemixLib.execution.executionContext |
||||
|
||||
var Filters = function (_options) { |
||||
const options = _options || {} |
||||
} |
||||
|
||||
Filters.prototype.methods = function () { |
||||
return { |
||||
eth_getLogs: this.eth_getLogs.bind(this), |
||||
eth_subscribe: this.eth_subscribe.bind(this) |
||||
} |
||||
} |
||||
|
||||
// https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getlogs
|
||||
Filters.prototype.eth_getLogs = function (payload, cb) { |
||||
console.dir("===============================") |
||||
console.dir("===============================") |
||||
console.dir("=== eth_getLogs") |
||||
console.dir(payload.params) |
||||
// [ { fromBlock: '0x0',
|
||||
// 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) |
||||
} |
||||
|
||||
Filters.prototype.eth_subscribe = function (payload, cb) { |
||||
console.dir("===============================") |
||||
console.dir("===============================") |
||||
console.dir("=== eth_subscribe") |
||||
console.dir(payload.params) |
||||
|
||||
let subscriptionId = executionContext.logsManager.subscribe(payload.params); |
||||
|
||||
cb(null, subscriptionId) |
||||
} |
||||
|
||||
module.exports = Filters |
Loading…
Reference in new issue