fix linting issues

pull/5370/head
Iuri Matias 6 years ago
parent 7882c2340f
commit c6f72c4eda
  1. 53
      remix-simulator/src/methods/blocks.js
  2. 6
      remix-simulator/src/methods/misc.js
  3. 96
      remix-simulator/src/methods/transactions.js

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

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

@ -1,22 +1,10 @@
var Web3 = require('web3')
var RemixLib = require('remix-lib')
var executionContext = RemixLib.execution.executionContext
var ethJSUtil = require('ethereumjs-util')
var processTx = require('./txProcess.js')
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) {
this.accounts = accounts
}
@ -45,15 +33,15 @@ Transactions.prototype.eth_getTransactionReceipt = function (payload, cb) {
return cb(error)
}
var txBlock = executionContext.txs[receipt.hash];
var txBlock = executionContext.txs[receipt.hash]
var r = {
'transactionHash': receipt.hash,
'transactionIndex': '0x00',
'blockHash': "0x" + txBlock.hash().toString('hex'),
'blockNumber': "0x" + txBlock.header.number.toString('hex'),
'gasUsed': web3.utils.toHex(receipt.gas),
'cumulativeGasUsed': web3.utils.toHex(receipt.gas),
'blockHash': '0x' + txBlock.hash().toString('hex'),
'blockNumber': '0x' + txBlock.header.number.toString('hex'),
'gasUsed': Web3.utils.toHex(receipt.gas),
'cumulativeGasUsed': Web3.utils.toHex(receipt.gas),
'contractAddress': receipt.contractAddress,
'logs': receipt.logs,
'status': receipt.status
@ -70,13 +58,13 @@ Transactions.prototype.eth_estimateGas = function (payload, cb) {
Transactions.prototype.eth_getCode = function (payload, cb) {
let address = payload.params[0]
executionContext.web3().eth.getCode(address, (error, result) => {
if (error) {
console.dir("error getting code");
console.dir(error);
}
cb(error, result)
})
executionContext.web3().eth.getCode(address, (error, result) => {
if (error) {
console.dir('error getting code')
console.dir(error)
}
cb(error, result)
})
}
Transactions.prototype.eth_call = function (payload, cb) {
@ -103,35 +91,33 @@ Transactions.prototype.eth_getTransactionByHash = function (payload, cb) {
return cb(error)
}
var test = executionContext.web3();
var txBlock = executionContext.txs[receipt.transactionHash];
var txBlock = executionContext.txs[receipt.transactionHash]
// TODO: params to add later
let r = {
'blockHash': "0x" + txBlock.hash().toString('hex'),
'blockNumber': "0x" + txBlock.header.number.toString('hex'),
'blockHash': '0x' + txBlock.hash().toString('hex'),
'blockNumber': '0x' + txBlock.header.number.toString('hex'),
'from': receipt.from,
'gas': web3.utils.toHex(receipt.gas),
'gas': Web3.utils.toHex(receipt.gas),
// 'gasPrice': '2000000000000', // 0x123
"gasPrice":"0x4a817c800", // 20000000000
'gasPrice': '0x4a817c800', // 20000000000
'hash': receipt.transactionHash,
'input': receipt.input,
// "nonce": 2, // 0x15
// "transactionIndex": 0,
"value": receipt.value
'value': receipt.value
// "value":"0xf3dbb76162000" // 4290000000000000
// "v": "0x25", // 37
// "r": "0x1b5e176d927f8e9ab405058b2d2457392da3e20f328b16ddabcebc33eaac5fea",
// "s": "0x4ba69724e8f69de52f0125ad8b3c5c2cef33019bac3249e2c0a2192766d1721c"
// "v": "0x25", // 37
// "r": "0x1b5e176d927f8e9ab405058b2d2457392da3e20f328b16ddabcebc33eaac5fea",
// "s": "0x4ba69724e8f69de52f0125ad8b3c5c2cef33019bac3249e2c0a2192766d1721c"
}
if (receipt.to) {
r.to = receipt.to
}
if (r.value === "0x") {
r.value = "0x0"
if (r.value === '0x') {
r.value = '0x0'
}
cb(null, r)
@ -142,7 +128,7 @@ Transactions.prototype.eth_getTransactionByBlockHashAndIndex = function (payload
const txIndex = payload.params[1]
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) => {
if (error) {
@ -151,17 +137,17 @@ Transactions.prototype.eth_getTransactionByBlockHashAndIndex = function (payload
// TODO: params to add later
let r = {
'blockHash': "0x" + txBlock.hash().toString('hex'),
'blockNumber': "0x" + txBlock.header.number.toString('hex'),
'blockHash': '0x' + txBlock.hash().toString('hex'),
'blockNumber': '0x' + txBlock.header.number.toString('hex'),
'from': receipt.from,
'gas': web3.utils.toHex(receipt.gas),
'gas': Web3.utils.toHex(receipt.gas),
// 'gasPrice': '2000000000000', // 0x123
"gasPrice": "0x4a817c800", // 20000000000
'gasPrice': '0x4a817c800', // 20000000000
'hash': receipt.transactionHash,
'input': receipt.input,
// "nonce": 2, // 0x15
// "transactionIndex": 0,
"value": receipt.value
'value': receipt.value
// "value":"0xf3dbb76162000" // 4290000000000000
// "v": "0x25", // 37
// "r": "0x1b5e176d927f8e9ab405058b2d2457392da3e20f328b16ddabcebc33eaac5fea",
@ -172,8 +158,8 @@ Transactions.prototype.eth_getTransactionByBlockHashAndIndex = function (payload
r.to = receipt.to
}
if (r.value === "0x") {
r.value = "0x0"
if (r.value === '0x') {
r.value = '0x0'
}
cb(null, r)
@ -184,7 +170,7 @@ Transactions.prototype.eth_getTransactionByBlockNumberAndIndex = function (paylo
const txIndex = payload.params[1]
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) => {
if (error) {
@ -193,17 +179,17 @@ Transactions.prototype.eth_getTransactionByBlockNumberAndIndex = function (paylo
// TODO: params to add later
let r = {
'blockHash': "0x" + txBlock.hash().toString('hex'),
'blockNumber': "0x" + txBlock.header.number.toString('hex'),
'blockHash': '0x' + txBlock.hash().toString('hex'),
'blockNumber': '0x' + txBlock.header.number.toString('hex'),
'from': receipt.from,
'gas': web3.utils.toHex(receipt.gas),
'gas': Web3.utils.toHex(receipt.gas),
// 'gasPrice': '2000000000000', // 0x123
"gasPrice": "0x4a817c800", // 20000000000
'gasPrice': '0x4a817c800', // 20000000000
'hash': receipt.transactionHash,
'input': receipt.input,
// "nonce": 2, // 0x15
// "transactionIndex": 0,
"value": receipt.value
'value': receipt.value
// "value":"0xf3dbb76162000" // 4290000000000000
// "v": "0x25", // 37
// "r": "0x1b5e176d927f8e9ab405058b2d2457392da3e20f328b16ddabcebc33eaac5fea",
@ -214,12 +200,12 @@ Transactions.prototype.eth_getTransactionByBlockNumberAndIndex = function (paylo
r.to = receipt.to
}
if (r.value === "0x") {
r.value = "0x0"
if (r.value === '0x') {
r.value = '0x0'
}
cb(null, r)
})
}
module.exports = Transactions
module.exports = Transactions

Loading…
Cancel
Save