Commit af2d59af authored by Iuri Matias's avatar Iuri Matias

cleanup

cleanup update README cleanup
parent 572dbb0e
......@@ -7,7 +7,7 @@ var ethUtil = require('ethereumjs-util')
var StateManager = require('ethereumjs-vm/dist/stateManager')
var Web3VMProvider = require('../web3Provider/web3VmProvider')
var LogsManager = require('./logsManager.js');
var LogsManager = require('./logsManager.js')
var rlp = ethUtil.rlp
......@@ -302,8 +302,8 @@ function ExecutionContext () {
this.addBlock = function (block) {
let blockNumber = '0x' + block.header.number.toString('hex')
if (blockNumber === "0x") {
blockNumber = "0x0"
if (blockNumber === '0x') {
blockNumber = '0x0'
}
blockNumber = web3.toHex(web3.toBigNumber(blockNumber))
......
......@@ -3,15 +3,15 @@ const crypto = require('crypto')
class LogsManager {
constructor() {
constructor () {
this.notificationCallbacks = []
this.subscriptions = {}
this.oldLogs = []
}
checkBlock(blockNumber, block, web3) {
checkBlock (blockNumber, block, web3) {
async.eachOf(block.transactions, (tx, i, next) => {
let txHash = "0x" + tx.hash().toString('hex')
let txHash = '0x' + tx.hash().toString('hex')
web3.eth.getTransactionReceipt(txHash, (_error, receipt) => {
for (let log of receipt.logs) {
......@@ -20,52 +20,47 @@ class LogsManager {
for (let subscriptionId of subscriptions) {
let result = {
"logIndex": "0x1", // 1
"blockNumber": blockNumber,
"blockHash": ('0x' + block.hash().toString('hex')),
"transactionHash": ('0x' + tx.hash().toString('hex')),
"transactionIndex": "0x" + i.toString(16),
'logIndex': '0x1', // 1
'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": log.address,
"data": log.data,
"topics": log.topics,
'address': log.address,
'data': log.data,
'topics': log.topics
}
if (result.address === "0x") {
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) => {
});
}, (_err) => {
})
}
eventMatchesFilter(changeEvent, queryType, queryFilter) {
console.dir("--> matching topics")
eventMatchesFilter (changeEvent, queryType, queryFilter) {
if (queryFilter.topics.filter((logTopic) => changeEvent.log.topics.indexOf(logTopic) >= 0).length === 0) return false
console.dir("topic matched")
if (queryType === 'logs') {
if ((queryFilter.address === ("0x" + changeEvent.tx.to.toString('hex')))
&& (queryFilter.address === ('0x' + changeEvent.tx.from.toString('hex')))) {
if ((queryFilter.address === ('0x' + changeEvent.tx.to.toString('hex'))) && (queryFilter.address === ('0x' + changeEvent.tx.from.toString('hex')))) {
if (!queryFilter.toBlock) {
return true;
return true
} else if (parseInt(queryFilter.toBlock) > parseInt(changeEvent.blockNumber)) {
return true;
return true
}
}
}
return false;
return false
}
// TODO:
// * need to get address of deployed contract if it's a tx that create a contract
getSubscriptionsFor(changeEvent) {
getSubscriptionsFor (changeEvent) {
let matchedSubscriptions = []
for (let subscriptionId of Object.keys(this.subscriptions)) {
const subscriptionParams = this.subscriptions[subscriptionId]
......@@ -75,67 +70,47 @@ class LogsManager {
matchedSubscriptions.push(subscriptionId)
}
}
return matchedSubscriptions;
return matchedSubscriptions
}
transmit(result) {
console.dir("-----------------")
console.dir("---- transmit")
console.dir(this.notificationCallbacks)
console.dir(result)
// TODO: manage subscriptions
// need to associate subscriptions to notificationCallbacks
transmit (result) {
this.notificationCallbacks.forEach((callback) => {
if (result.params.result.raw) {
result.params.result.data = result.params.result.raw.data
result.params.result.topics = result.params.result.raw.topics
}
console.dir("transmitting back")
console.dir(result)
// console.dir(result.params.result.returnValues)
// console.dir(result.params.result.raw)
callback(result)
});
})
}
addListener(type, cb) {
console.dir("<<<<<<<<<<<------------------------->>>>>>>>>>>>>");
console.dir("adding listener...");
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')
subscribe (params) {
let subscriptionId = '0x' + crypto.randomBytes(16).toString('hex')
this.subscriptions[subscriptionId] = params
return subscriptionId
}
unsubscribe(subscriptionId) {
unsubscribe (subscriptionId) {
delete this.subscriptions[subscriptionId]
}
getLogsFor(params) {
getLogsFor (params) {
let results = []
for (let log of this.oldLogs) {
if (this.eventMatchesFilter(log, 'logs', params)) {
results.push({
"logIndex": "0x1", // 1
"blockNumber": log.blockNumber,
"blockHash": ('0x' + log.block.hash().toString('hex')),
"transactionHash": ('0x' + log.tx.hash().toString('hex')),
"transactionIndex": "0x" + logs.txNumber.toString(16),
'logIndex': '0x1', // 1
'blockNumber': log.blockNumber,
'blockHash': ('0x' + log.block.hash().toString('hex')),
'transactionHash': ('0x' + log.tx.hash().toString('hex')),
'transactionIndex': '0x' + log.txNumber.toString(16),
// TODO: if it's a contract deploy, it should be that address instead
"address": log.log.address,
"data": log.log.data,
"topics": log.log.topics,
'address': log.log.address,
'data': log.log.data,
'topics': log.log.topics
})
}
}
......@@ -145,4 +120,4 @@ class LogsManager {
}
module.exports = LogsManager;
\ No newline at end of file
module.exports = LogsManager
......@@ -46,7 +46,7 @@ Implemented:
* [_] eth_uninstallFilter
* [_] eth_getFilterChanges
* [_] eth_getFilterLogs
* [_] eth_getLogs
* [X] eth_getLogs
* [_] eth_getWork
* [_] eth_submitWork
* [_] eth_submitHashrate
......
......@@ -2,7 +2,7 @@ var RemixLib = require('remix-lib')
var executionContext = RemixLib.execution.executionContext
var Filters = function (_options) {
const options = _options || {}
// const options = _options || {}
}
Filters.prototype.methods = function () {
......@@ -15,39 +15,17 @@ Filters.prototype.methods = function () {
// 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")
// payload.params[0].topics = payload.params[0].topics.filter((x) => x)
console.dir(payload.params)
let results = executionContext.logsManager.getLogsFor(payload.params[0]);
console.dir("results are ---")
console.dir(results)
let results = executionContext.logsManager.getLogsFor(payload.params[0])
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);
let subscriptionId = executionContext.logsManager.subscribe(payload.params)
cb(null, subscriptionId)
}
Filters.prototype.eth_unsubscribe = function (payload, cb) {
console.dir("===============================")
console.dir("===============================")
console.dir("=== eth_unsubscribe")
console.dir(payload.params)
executionContext.logsManager.unsubscribe(payload.params[0])
cb(null, true)
}
......
......@@ -41,7 +41,7 @@ function createContract (payload, from, data, value, gasLimit, txRunner, callbac
TxExecution.createContract(from, data, value, gasLimit, txRunner, callbacks, finalCallback)
}
let txRunner_instance;
let txRunnerInstance
function processTx (accounts, payload, isCall, callback) {
let api = {
......@@ -68,10 +68,10 @@ function processTx (accounts, payload, isCall, callback) {
executionContext.init(api.config)
// let txRunner = new TxRunner(accounts, api)
if (!txRunner_instance) {
txRunner_instance = new TxRunner(accounts, api)
if (!txRunnerInstance) {
txRunnerInstance = new TxRunner(accounts, api)
}
txRunner_instance.vmaccounts = accounts;
txRunnerInstance.vmaccounts = accounts
let { from, to, data, value, gas } = payload.params[0]
gas = gas || 3000000
......@@ -91,11 +91,11 @@ function processTx (accounts, payload, isCall, callback) {
}
if (isCall) {
runCall(payload, from, to, data, value, gas, txRunner_instance, callbacks, callback)
runCall(payload, from, to, data, value, gas, txRunnerInstance, callbacks, callback)
} else if (to) {
runTx(payload, from, to, data, value, gas, txRunner_instance, callbacks, callback)
runTx(payload, from, to, data, value, gas, txRunnerInstance, callbacks, callback)
} else {
createContract(payload, from, data, value, gas, txRunner_instance, callbacks, callback)
createContract(payload, from, data, value, gas, txRunnerInstance, callbacks, callback)
}
}
......
......@@ -28,10 +28,6 @@ var Provider = function (options) {
this.methods = merge(this.methods, (new Whisper()).methods())
generateBlock()
// setTimeout(() => {
// console.dir("hello!")
// }, 10 * 1000)
}
Provider.prototype.init = async function () {
......@@ -41,19 +37,14 @@ Provider.prototype.init = async function () {
Provider.prototype.sendAsync = function (payload, callback) {
log.info('payload method is ', payload.method)
console.dir(payload)
let method = this.methods[payload.method]
if (method) {
return method.call(method, payload, (err, result) => {
if (err) {
console.dir("====== error")
console.dir(err)
return callback(err)
}
let response = {'id': payload.id, 'jsonrpc': '2.0', 'result': result}
console.dir("response")
console.dir(response)
callback(null, response)
})
}
......@@ -69,8 +60,6 @@ Provider.prototype.isConnected = function () {
}
Provider.prototype.on = function (type, cb) {
console.dir("on")
console.dir(arguments)
executionContext.logsManager.addListener(type, cb)
}
......
......@@ -14,7 +14,7 @@ class Server {
}).catch((error) => {
log(error)
})
this.rpcOnly = options.rpc;
this.rpcOnly = options.rpc
}
start (host, port) {
......@@ -25,7 +25,6 @@ class Server {
app.use(bodyParser.json())
app.get('/', (req, res) => {
console.dir("/ request")
res.send('Welcome to remix-simulator')
})
......@@ -50,9 +49,7 @@ class Server {
})
this.provider.on('data', (result) => {
console.dir("-----> sending")
console.dir(JSON.stringify(result))
ws.send(JSON.stringify(result));
ws.send(JSON.stringify(result))
})
})
}
......
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