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