linting passed

revert-603-optF
aniket-engg 4 years ago committed by Aniket
parent 533e0626a5
commit d71e581b85
  1. 4
      libs/remix-simulator/.eslintrc
  2. 4
      libs/remix-simulator/src/methods/accounts.ts
  3. 81
      libs/remix-simulator/src/methods/blocks.ts
  4. 3
      libs/remix-simulator/src/methods/debug.ts
  5. 9
      libs/remix-simulator/src/methods/filters.ts
  6. 79
      libs/remix-simulator/src/methods/transactions.ts
  7. 2
      libs/remix-simulator/src/methods/txProcess.ts
  8. 5
      libs/remix-simulator/src/provider.ts
  9. 2
      workspace.json

@ -3,7 +3,9 @@
"rules": { "rules": {
"@typescript-eslint/no-var-requires": "off", "@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/no-empty-function": "off", "@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/no-unused-vars": "off" "@typescript-eslint/no-unused-vars": "off",
"camelcase": "off",
"dot-notation": "off"
}, },
"env": { "env": {
"browser": true, "browser": true,

@ -4,7 +4,6 @@ import Web3 from 'web3'
import * as crypto from 'crypto' import * as crypto from 'crypto'
export class Accounts { export class Accounts {
web3 web3
accounts accounts
accountsKeys accountsKeys
@ -49,7 +48,7 @@ export class Accounts {
this.accounts[toChecksumAddress('0x' + address.toString('hex'))] = { privateKey, nonce: 0 } this.accounts[toChecksumAddress('0x' + address.toString('hex'))] = { privateKey, nonce: 0 }
this.accountsKeys[toChecksumAddress('0x' + address.toString('hex'))] = '0x' + privateKey.toString('hex') this.accountsKeys[toChecksumAddress('0x' + address.toString('hex'))] = '0x' + privateKey.toString('hex')
let stateManager = this.executionContext.vm().stateManager const stateManager = this.executionContext.vm().stateManager
stateManager.getAccount(address, (error, account) => { stateManager.getAccount(address, (error, account) => {
if (error) { if (error) {
console.log(error) console.log(error)
@ -60,7 +59,6 @@ export class Accounts {
resolve() resolve()
}) })
}) })
} }
newAccount (cb) { newAccount (cb) {

@ -1,5 +1,4 @@
export class Blocks { export class Blocks {
executionContext executionContext
coinbase coinbase
blockNumber blockNumber
@ -38,25 +37,25 @@ export class Blocks {
return cb(new Error('block not found')) return cb(new Error('block not found'))
} }
let b = { const b = {
'number': this.toHex(block.header.number), number: this.toHex(block.header.number),
'hash': this.toHex(block.hash()), hash: this.toHex(block.hash()),
'parentHash': this.toHex(block.header.parentHash), parentHash: this.toHex(block.header.parentHash),
'nonce': this.toHex(block.header.nonce), nonce: this.toHex(block.header.nonce),
'sha3Uncles': '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347', sha3Uncles: '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347',
'logsBloom': '0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331', logsBloom: '0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331',
'transactionsRoot': '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421', transactionsRoot: '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421',
'stateRoot': this.toHex(block.header.stateRoot), stateRoot: this.toHex(block.header.stateRoot),
'miner': this.coinbase, miner: this.coinbase,
'difficulty': this.toHex(block.header.difficulty), difficulty: this.toHex(block.header.difficulty),
'totalDifficulty': this.toHex(block.header.totalDifficulty), totalDifficulty: this.toHex(block.header.totalDifficulty),
'extraData': this.toHex(block.header.extraData), extraData: this.toHex(block.header.extraData),
'size': '0x027f07', // 163591 size: '0x027f07', // 163591
'gasLimit': this.toHex(block.header.gasLimit), gasLimit: this.toHex(block.header.gasLimit),
'gasUsed': this.toHex(block.header.gasUsed), gasUsed: this.toHex(block.header.gasUsed),
'timestamp': this.toHex(block.header.timestamp), timestamp: this.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)
@ -64,32 +63,32 @@ export class Blocks {
toHex (value) { toHex (value) {
if (!value) return '0x0' if (!value) return '0x0'
let v = value.toString('hex') const v = value.toString('hex')
return ((v === '0x' || v === '') ? '0x0' : ('0x' + v)) return ((v === '0x' || v === '') ? '0x0' : ('0x' + v))
} }
eth_getBlockByHash (payload, cb) { eth_getBlockByHash (payload, cb) {
var block = this.executionContext.blocks[payload.params[0]] var block = this.executionContext.blocks[payload.params[0]]
let b = { const b = {
'number': this.toHex(block.header.number), number: this.toHex(block.header.number),
'hash': this.toHex(block.hash()), hash: this.toHex(block.hash()),
'parentHash': this.toHex(block.header.parentHash), parentHash: this.toHex(block.header.parentHash),
'nonce': this.toHex(block.header.nonce), nonce: this.toHex(block.header.nonce),
'sha3Uncles': '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347', sha3Uncles: '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347',
'logsBloom': '0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331', logsBloom: '0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331',
'transactionsRoot': '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421', transactionsRoot: '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421',
'stateRoot': this.toHex(block.header.stateRoot), stateRoot: this.toHex(block.header.stateRoot),
'miner': this.coinbase, miner: this.coinbase,
'difficulty': this.toHex(block.header.difficulty), difficulty: this.toHex(block.header.difficulty),
'totalDifficulty': this.toHex(block.header.totalDifficulty), totalDifficulty: this.toHex(block.header.totalDifficulty),
'extraData': this.toHex(block.header.extraData), extraData: this.toHex(block.header.extraData),
'size': '0x027f07', // 163591 size: '0x027f07', // 163591
'gasLimit': this.toHex(block.header.gasLimit), gasLimit: this.toHex(block.header.gasLimit),
'gasUsed': this.toHex(block.header.gasUsed), gasUsed: this.toHex(block.header.gasUsed),
'timestamp': this.toHex(block.header.timestamp), timestamp: this.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)
@ -135,7 +134,7 @@ export class Blocks {
return cb(err, '') return cb(err, '')
} }
let value = Object.values(result.storage)[0]['value'] const value = Object.values(result.storage)[0]['value']
cb(err, value) cb(err, value)
}) })
} }

@ -1,5 +1,4 @@
export class Debug { export class Debug {
executionContext executionContext
constructor (executionContext) { constructor (executionContext) {
@ -10,7 +9,7 @@ export class Debug {
return { return {
debug_traceTransaction: this.debug_traceTransaction.bind(this), debug_traceTransaction: this.debug_traceTransaction.bind(this),
debug_preimage: this.debug_preimage.bind(this), debug_preimage: this.debug_preimage.bind(this),
debug_storageRangeAt: this.debug_storageRangeAt.bind(this), debug_storageRangeAt: this.debug_storageRangeAt.bind(this)
} }
} }

@ -1,5 +1,4 @@
export class Filters { export class Filters {
executionContext executionContext
constructor (executionContext) { constructor (executionContext) {
@ -15,12 +14,12 @@ export class Filters {
} }
eth_getLogs (payload, cb) { eth_getLogs (payload, cb) {
let results = this.executionContext.logsManager.getLogsFor(payload.params[0]) const results = this.executionContext.logsManager.getLogsFor(payload.params[0])
cb(null, results) cb(null, results)
} }
eth_subscribe (payload, cb) { eth_subscribe (payload, cb) {
let subscriptionId = this.executionContext.logsManager.subscribe(payload.params) const subscriptionId = this.executionContext.logsManager.subscribe(payload.params)
cb(null, subscriptionId) cb(null, subscriptionId)
} }
@ -51,13 +50,13 @@ export class Filters {
eth_getFilterChanges (payload, cb) { eth_getFilterChanges (payload, cb) {
const filterId = payload.params[0] const filterId = payload.params[0]
let results = this.executionContext.logsManager.getLogsForFilter(filterId) const results = this.executionContext.logsManager.getLogsForFilter(filterId)
cb(null, results) cb(null, results)
} }
eth_getFilterLogs (payload, cb) { eth_getFilterLogs (payload, cb) {
const filterId = payload.params[0] const filterId = payload.params[0]
let results = this.executionContext.logsManager.getLogsForFilter(filterId, true) const results = this.executionContext.logsManager.getLogsForFilter(filterId, true)
cb(null, results) cb(null, results)
} }
} }

@ -2,8 +2,7 @@ import Web3 from 'web3'
import { toChecksumAddress, BN } from 'ethereumjs-util' import { toChecksumAddress, BN } from 'ethereumjs-util'
import { processTx } from './txProcess' import { processTx } from './txProcess'
class Transactions{ export class Transactions {
executionContext executionContext
accounts accounts
@ -46,16 +45,16 @@ class Transactions{
const txBlock = this.executionContext.txs[receipt.hash] const txBlock = this.executionContext.txs[receipt.hash]
const r = { const 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,
'to': receipt.to to: receipt.to
} }
if (r.blockNumber === '0x') { if (r.blockNumber === '0x') {
@ -71,7 +70,7 @@ class Transactions{
} }
eth_getCode (payload, cb) { eth_getCode (payload, cb) {
let address = payload.params[0] const address = payload.params[0]
this.executionContext.web3().eth.getCode(address, (error, result) => { this.executionContext.web3().eth.getCode(address, (error, result) => {
if (error) { if (error) {
@ -97,13 +96,13 @@ class Transactions{
} }
eth_getTransactionCount (payload, cb) { eth_getTransactionCount (payload, cb) {
let address = payload.params[0] const address = payload.params[0]
this.executionContext.vm().stateManager.getAccount(address, (err, account) => { this.executionContext.vm().stateManager.getAccount(address, (err, account) => {
if (err) { if (err) {
return cb(err) return cb(err)
} }
let nonce = new BN(account.nonce).toString(10) const nonce = new BN(account.nonce).toString(10)
cb(null, nonce) cb(null, nonce)
}) })
} }
@ -120,17 +119,17 @@ class Transactions{
// TODO: params to add later // TODO: params to add later
const r = { const 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",
@ -165,18 +164,18 @@ class Transactions{
} }
// TODO: params to add later // TODO: params to add later
let r = { const 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",
@ -208,17 +207,17 @@ class Transactions{
// TODO: params to add later // TODO: params to add later
const r = { const 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",

@ -71,7 +71,7 @@ export function processTx (executionContext, accounts, payload, isCall, callback
let { from, to, data, value, gas } = payload.params[0] let { from, to, data, value, gas } = payload.params[0]
gas = gas || 3000000 gas = gas || 3000000
let callbacks = { const callbacks = {
confirmationCb: (network, tx, gasEstimation, continueTxExecution, cancelCb) => { confirmationCb: (network, tx, gasEstimation, continueTxExecution, cancelCb) => {
continueTxExecution(null) continueTxExecution(null)
}, },

@ -1,3 +1,4 @@
import { Blocks } from './methods/blocks'
const RemixLib = require('@remix-project/remix-lib') const RemixLib = require('@remix-project/remix-lib')
const executionContext = RemixLib.execution.executionContext const executionContext = RemixLib.execution.executionContext
@ -5,7 +6,6 @@ const log = require('./utils/logs.js')
const merge = require('merge') const merge = require('merge')
const Accounts = require('./methods/accounts.js') const Accounts = require('./methods/accounts.js')
import { Blocks } from './methods/blocks'
const Filters = require('./methods/filters.js') const Filters = require('./methods/filters.js')
const Misc = require('./methods/misc.js') const Misc = require('./methods/misc.js')
const Net = require('./methods/net.js') const Net = require('./methods/net.js')
@ -15,7 +15,6 @@ const Debug = require('./methods/debug.js')
const generateBlock = require('./genesis.js') const generateBlock = require('./genesis.js')
export class Provider { export class Provider {
options options
executionContext executionContext
Accounts Accounts
@ -63,7 +62,7 @@ export class Provider {
if (err) { if (err) {
return callback(err) return callback(err)
} }
const response = {'id': payload.id, 'jsonrpc': '2.0', 'result': result} const response = { id: payload.id, jsonrpc: '2.0', result: result }
callback(null, response) callback(null, response)
}) })
} }

@ -301,7 +301,7 @@
"options": { "options": {
"linter": "eslint", "linter": "eslint",
"config": "libs/remix-simulator/.eslintrc", "config": "libs/remix-simulator/.eslintrc",
"files": ["libs/remix-simulator/**/*.js"], "tsConfig": ["libs/remix-simulator/tsconfig.lib.json"],
"exclude": ["**/node_modules/**", "libs/remix-simulator/test/**/*"] "exclude": ["**/node_modules/**", "libs/remix-simulator/test/**/*"]
} }
}, },

Loading…
Cancel
Save