fix linting issues

pull/7/head
Iuri Matias 6 years ago
parent 39c5e31ed5
commit 8f2abe7860
  1. 49
      remix-simulator/src/methods/blocks.js
  2. 6
      remix-simulator/src/methods/misc.js
  3. 78
      remix-simulator/src/methods/transactions.js

@ -1,4 +1,3 @@
var Web3 = require('web3')
var RemixLib = require('remix-lib') var RemixLib = require('remix-lib')
var executionContext = RemixLib.execution.executionContext var executionContext = RemixLib.execution.executionContext
@ -25,34 +24,38 @@ Blocks.prototype.methods = function () {
Blocks.prototype.eth_getBlockByNumber = function (payload, cb) { Blocks.prototype.eth_getBlockByNumber = function (payload, cb) {
var block = executionContext.blocks[payload.params[0]] var block = executionContext.blocks[payload.params[0]]
if (!block) {
return cb(new Error('block not found'))
}
let b = { let b = {
'number': toHex(block.header.number), 'number': toHex(block.header.number),
"hash": toHex(block.hash()), 'hash': toHex(block.hash()),
'parentHash': toHex(block.header.parentHash), 'parentHash': toHex(block.header.parentHash),
'nonce': toHex(block.header.nonce), 'nonce': toHex(block.header.nonce),
"sha3Uncles": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", 'sha3Uncles': '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347',
"logsBloom": "0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331", 'logsBloom': '0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331',
"transactionsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", 'transactionsRoot': '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421',
"stateRoot": toHex(block.header.stateRoot), 'stateRoot': toHex(block.header.stateRoot),
'miner': this.coinbase, 'miner': this.coinbase,
'difficulty': toHex(block.header.difficulty), 'difficulty': toHex(block.header.difficulty),
"totalDifficulty": toHex(block.header.totalDifficulty), 'totalDifficulty': toHex(block.header.totalDifficulty),
'extraData': toHex(block.header.extraData), 'extraData': toHex(block.header.extraData),
"size": "0x027f07", // 163591 'size': '0x027f07', // 163591
'gasLimit': toHex(block.header.gasLimit), 'gasLimit': toHex(block.header.gasLimit),
'gasUsed': toHex(block.header.gasUsed), 'gasUsed': toHex(block.header.gasUsed),
"timestamp": toHex(block.header.timestamp), 'timestamp': toHex(block.header.timestamp),
"transactions": block.transactions.map((t) => "0x" + t.hash().toString('hex')), 'transactions': block.transactions.map((t) => '0x' + t.hash().toString('hex')),
"uncles": [] 'uncles': []
} }
cb(null, b) cb(null, b)
} }
function toHex (value) { function toHex (value) {
if (!value) return "0x0" if (!value) return '0x0'
let v = value.toString('hex') let v = value.toString('hex')
return ((v === "0x" || v === "") ? "0x0" : ("0x" + v)) return ((v === '0x' || v === '') ? '0x0' : ('0x' + v))
} }
Blocks.prototype.eth_getBlockByHash = function (payload, cb) { Blocks.prototype.eth_getBlockByHash = function (payload, cb) {
@ -60,23 +63,23 @@ Blocks.prototype.eth_getBlockByHash = function (payload, cb) {
let b = { let b = {
'number': toHex(block.header.number), 'number': toHex(block.header.number),
"hash": toHex(block.hash()), 'hash': toHex(block.hash()),
'parentHash': toHex(block.header.parentHash), 'parentHash': toHex(block.header.parentHash),
'nonce': toHex(block.header.nonce), 'nonce': toHex(block.header.nonce),
"sha3Uncles": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", 'sha3Uncles': '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347',
"logsBloom": "0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331", 'logsBloom': '0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331',
"transactionsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", 'transactionsRoot': '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421',
"stateRoot": toHex(block.header.stateRoot), 'stateRoot': toHex(block.header.stateRoot),
'miner': this.coinbase, 'miner': this.coinbase,
'difficulty': toHex(block.header.difficulty), 'difficulty': toHex(block.header.difficulty),
"totalDifficulty": toHex(block.header.totalDifficulty), 'totalDifficulty': toHex(block.header.totalDifficulty),
'extraData': toHex(block.header.extraData), 'extraData': toHex(block.header.extraData),
"size": "0x027f07", // 163591 'size': '0x027f07', // 163591
'gasLimit': toHex(block.header.gasLimit), 'gasLimit': toHex(block.header.gasLimit),
'gasUsed': toHex(block.header.gasUsed), 'gasUsed': toHex(block.header.gasUsed),
"timestamp": toHex(block.header.timestamp), 'timestamp': toHex(block.header.timestamp),
"transactions": block.transactions.map((t) => "0x" + t.hash().toString('hex')), 'transactions': block.transactions.map((t) => '0x' + t.hash().toString('hex')),
"uncles": [] 'uncles': []
} }
cb(null, b) cb(null, b)

@ -50,15 +50,15 @@ Misc.prototype.eth_getCompilers = function (payload, cb) {
} }
Misc.prototype.eth_compileSolidity = function (payload, cb) { Misc.prototype.eth_compileSolidity = function (payload, cb) {
cb(null, "unsupported") cb(null, 'unsupported')
} }
Misc.prototype.eth_compileLLL = function (payload, cb) { Misc.prototype.eth_compileLLL = function (payload, cb) {
cb(null, "unsupported") cb(null, 'unsupported')
} }
Misc.prototype.eth_compileSerpent = function (payload, cb) { Misc.prototype.eth_compileSerpent = function (payload, cb) {
cb(null, "unsupported") cb(null, 'unsupported')
} }
module.exports = Misc module.exports = Misc

@ -1,22 +1,10 @@
var Web3 = require('web3')
var RemixLib = require('remix-lib') var RemixLib = require('remix-lib')
var executionContext = RemixLib.execution.executionContext var executionContext = RemixLib.execution.executionContext
var ethJSUtil = require('ethereumjs-util') var ethJSUtil = require('ethereumjs-util')
var processTx = require('./txProcess.js') var processTx = require('./txProcess.js')
var BN = ethJSUtil.BN var BN = ethJSUtil.BN
function hexConvert (ints) {
var ret = '0x'
for (var i = 0; i < ints.length; i++) {
var h = ints[i]
if (h) {
ret += (h <= 0xf ? '0' : '') + h.toString(16)
} else {
ret += '00'
}
}
return ret
}
var Transactions = function (accounts) { var Transactions = function (accounts) {
this.accounts = accounts this.accounts = accounts
} }
@ -45,15 +33,15 @@ Transactions.prototype.eth_getTransactionReceipt = function (payload, cb) {
return cb(error) return cb(error)
} }
var txBlock = executionContext.txs[receipt.hash]; var txBlock = executionContext.txs[receipt.hash]
var r = { var r = {
'transactionHash': receipt.hash, 'transactionHash': receipt.hash,
'transactionIndex': '0x00', 'transactionIndex': '0x00',
'blockHash': "0x" + txBlock.hash().toString('hex'), 'blockHash': '0x' + txBlock.hash().toString('hex'),
'blockNumber': "0x" + txBlock.header.number.toString('hex'), 'blockNumber': '0x' + txBlock.header.number.toString('hex'),
'gasUsed': web3.utils.toHex(receipt.gas), 'gasUsed': Web3.utils.toHex(receipt.gas),
'cumulativeGasUsed': web3.utils.toHex(receipt.gas), 'cumulativeGasUsed': Web3.utils.toHex(receipt.gas),
'contractAddress': receipt.contractAddress, 'contractAddress': receipt.contractAddress,
'logs': receipt.logs, 'logs': receipt.logs,
'status': receipt.status 'status': receipt.status
@ -72,8 +60,8 @@ Transactions.prototype.eth_getCode = function (payload, cb) {
executionContext.web3().eth.getCode(address, (error, result) => { executionContext.web3().eth.getCode(address, (error, result) => {
if (error) { if (error) {
console.dir("error getting code"); console.dir('error getting code')
console.dir(error); console.dir(error)
} }
cb(error, result) cb(error, result)
}) })
@ -103,23 +91,21 @@ Transactions.prototype.eth_getTransactionByHash = function (payload, cb) {
return cb(error) return cb(error)
} }
var test = executionContext.web3(); var txBlock = executionContext.txs[receipt.transactionHash]
var txBlock = executionContext.txs[receipt.transactionHash];
// TODO: params to add later // TODO: params to add later
let r = { let r = {
'blockHash': "0x" + txBlock.hash().toString('hex'), 'blockHash': '0x' + txBlock.hash().toString('hex'),
'blockNumber': "0x" + txBlock.header.number.toString('hex'), 'blockNumber': '0x' + txBlock.header.number.toString('hex'),
'from': receipt.from, 'from': receipt.from,
'gas': web3.utils.toHex(receipt.gas), 'gas': Web3.utils.toHex(receipt.gas),
// 'gasPrice': '2000000000000', // 0x123 // 'gasPrice': '2000000000000', // 0x123
"gasPrice":"0x4a817c800", // 20000000000 'gasPrice': '0x4a817c800', // 20000000000
'hash': receipt.transactionHash, 'hash': receipt.transactionHash,
'input': receipt.input, 'input': receipt.input,
// "nonce": 2, // 0x15 // "nonce": 2, // 0x15
// "transactionIndex": 0, // "transactionIndex": 0,
"value": receipt.value 'value': receipt.value
// "value":"0xf3dbb76162000" // 4290000000000000 // "value":"0xf3dbb76162000" // 4290000000000000
// "v": "0x25", // 37 // "v": "0x25", // 37
// "r": "0x1b5e176d927f8e9ab405058b2d2457392da3e20f328b16ddabcebc33eaac5fea", // "r": "0x1b5e176d927f8e9ab405058b2d2457392da3e20f328b16ddabcebc33eaac5fea",
@ -130,8 +116,8 @@ Transactions.prototype.eth_getTransactionByHash = function (payload, cb) {
r.to = receipt.to r.to = receipt.to
} }
if (r.value === "0x") { if (r.value === '0x') {
r.value = "0x0" r.value = '0x0'
} }
cb(null, r) cb(null, r)
@ -142,7 +128,7 @@ Transactions.prototype.eth_getTransactionByBlockHashAndIndex = function (payload
const txIndex = payload.params[1] const txIndex = payload.params[1]
var txBlock = executionContext.blocks[payload.params[0]] var txBlock = executionContext.blocks[payload.params[0]]
const txHash = "0x" + txBlock.transactions[web3.utils.toDecimal(txIndex)].hash().toString('hex') const txHash = '0x' + txBlock.transactions[Web3.utils.toDecimal(txIndex)].hash().toString('hex')
executionContext.web3().eth.getTransactionReceipt(txHash, (error, receipt) => { executionContext.web3().eth.getTransactionReceipt(txHash, (error, receipt) => {
if (error) { if (error) {
@ -151,17 +137,17 @@ Transactions.prototype.eth_getTransactionByBlockHashAndIndex = function (payload
// TODO: params to add later // TODO: params to add later
let r = { let r = {
'blockHash': "0x" + txBlock.hash().toString('hex'), 'blockHash': '0x' + txBlock.hash().toString('hex'),
'blockNumber': "0x" + txBlock.header.number.toString('hex'), 'blockNumber': '0x' + txBlock.header.number.toString('hex'),
'from': receipt.from, 'from': receipt.from,
'gas': web3.utils.toHex(receipt.gas), 'gas': Web3.utils.toHex(receipt.gas),
// 'gasPrice': '2000000000000', // 0x123 // 'gasPrice': '2000000000000', // 0x123
"gasPrice": "0x4a817c800", // 20000000000 'gasPrice': '0x4a817c800', // 20000000000
'hash': receipt.transactionHash, 'hash': receipt.transactionHash,
'input': receipt.input, 'input': receipt.input,
// "nonce": 2, // 0x15 // "nonce": 2, // 0x15
// "transactionIndex": 0, // "transactionIndex": 0,
"value": receipt.value 'value': receipt.value
// "value":"0xf3dbb76162000" // 4290000000000000 // "value":"0xf3dbb76162000" // 4290000000000000
// "v": "0x25", // 37 // "v": "0x25", // 37
// "r": "0x1b5e176d927f8e9ab405058b2d2457392da3e20f328b16ddabcebc33eaac5fea", // "r": "0x1b5e176d927f8e9ab405058b2d2457392da3e20f328b16ddabcebc33eaac5fea",
@ -172,8 +158,8 @@ Transactions.prototype.eth_getTransactionByBlockHashAndIndex = function (payload
r.to = receipt.to r.to = receipt.to
} }
if (r.value === "0x") { if (r.value === '0x') {
r.value = "0x0" r.value = '0x0'
} }
cb(null, r) cb(null, r)
@ -184,7 +170,7 @@ Transactions.prototype.eth_getTransactionByBlockNumberAndIndex = function (paylo
const txIndex = payload.params[1] const txIndex = payload.params[1]
var txBlock = executionContext.blocks[payload.params[0]] var txBlock = executionContext.blocks[payload.params[0]]
const txHash = "0x" + txBlock.transactions[web3.utils.toDecimal(txIndex)].hash().toString('hex') const txHash = '0x' + txBlock.transactions[Web3.utils.toDecimal(txIndex)].hash().toString('hex')
executionContext.web3().eth.getTransactionReceipt(txHash, (error, receipt) => { executionContext.web3().eth.getTransactionReceipt(txHash, (error, receipt) => {
if (error) { if (error) {
@ -193,17 +179,17 @@ Transactions.prototype.eth_getTransactionByBlockNumberAndIndex = function (paylo
// TODO: params to add later // TODO: params to add later
let r = { let r = {
'blockHash': "0x" + txBlock.hash().toString('hex'), 'blockHash': '0x' + txBlock.hash().toString('hex'),
'blockNumber': "0x" + txBlock.header.number.toString('hex'), 'blockNumber': '0x' + txBlock.header.number.toString('hex'),
'from': receipt.from, 'from': receipt.from,
'gas': web3.utils.toHex(receipt.gas), 'gas': Web3.utils.toHex(receipt.gas),
// 'gasPrice': '2000000000000', // 0x123 // 'gasPrice': '2000000000000', // 0x123
"gasPrice": "0x4a817c800", // 20000000000 'gasPrice': '0x4a817c800', // 20000000000
'hash': receipt.transactionHash, 'hash': receipt.transactionHash,
'input': receipt.input, 'input': receipt.input,
// "nonce": 2, // 0x15 // "nonce": 2, // 0x15
// "transactionIndex": 0, // "transactionIndex": 0,
"value": receipt.value 'value': receipt.value
// "value":"0xf3dbb76162000" // 4290000000000000 // "value":"0xf3dbb76162000" // 4290000000000000
// "v": "0x25", // 37 // "v": "0x25", // 37
// "r": "0x1b5e176d927f8e9ab405058b2d2457392da3e20f328b16ddabcebc33eaac5fea", // "r": "0x1b5e176d927f8e9ab405058b2d2457392da3e20f328b16ddabcebc33eaac5fea",
@ -214,8 +200,8 @@ Transactions.prototype.eth_getTransactionByBlockNumberAndIndex = function (paylo
r.to = receipt.to r.to = receipt.to
} }
if (r.value === "0x") { if (r.value === '0x') {
r.value = "0x0" r.value = '0x0'
} }
cb(null, r) cb(null, r)

Loading…
Cancel
Save