linting passed

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

@ -3,7 +3,9 @@
"rules": {
"@typescript-eslint/no-var-requires": "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": {
"browser": true,

@ -1,3 +1,3 @@
import {Provider} from './provider'
import { Provider } from './provider'
export { Provider }

@ -1,23 +1,22 @@
import { BN, privateToAddress, toChecksumAddress, isValidPrivate} from 'ethereumjs-util'
import { BN, privateToAddress, toChecksumAddress, isValidPrivate } from 'ethereumjs-util'
import { stripHexPrefix } from 'ethjs-util'
import Web3 from 'web3'
import * as crypto from 'crypto'
export class Accounts {
web3
accounts
accountsKeys
executionContext
constructor(executionContext) {
constructor (executionContext) {
this.web3 = new Web3()
this.executionContext = executionContext
// TODO: make it random and/or use remix-libs
this.accounts = {}
this.accountsKeys = {}
this.executionContext.init({get: () => { return true }})
this.executionContext.init({ get: () => { return true } })
}
async resetAccounts () {
@ -49,7 +48,7 @@ export class Accounts {
this.accounts[toChecksumAddress('0x' + address.toString('hex'))] = { privateKey, nonce: 0 }
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) => {
if (error) {
console.log(error)
@ -60,7 +59,6 @@ export class Accounts {
resolve()
})
})
}
newAccount (cb) {
@ -110,4 +108,4 @@ export class Accounts {
cb(null, data.signature)
}
}
}

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

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

@ -1,8 +1,7 @@
export class Filters {
export class Filters {
executionContext
constructor(executionContext) {
constructor (executionContext) {
this.executionContext = executionContext
}
@ -15,12 +14,12 @@ export class Filters {
}
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)
}
eth_subscribe (payload, cb) {
let subscriptionId = this.executionContext.logsManager.subscribe(payload.params)
const subscriptionId = this.executionContext.logsManager.subscribe(payload.params)
cb(null, subscriptionId)
}
@ -51,13 +50,13 @@ export class Filters {
eth_getFilterChanges (payload, cb) {
const filterId = payload.params[0]
let results = this.executionContext.logsManager.getLogsForFilter(filterId)
const results = this.executionContext.logsManager.getLogsForFilter(filterId)
cb(null, results)
}
eth_getFilterLogs (payload, cb) {
const filterId = payload.params[0]
let results = this.executionContext.logsManager.getLogsForFilter(filterId, true)
const results = this.executionContext.logsManager.getLogsForFilter(filterId, true)
cb(null, results)
}
}

@ -2,12 +2,11 @@ import Web3 from 'web3'
import { toChecksumAddress, BN } from 'ethereumjs-util'
import { processTx } from './txProcess'
class Transactions{
export class Transactions {
executionContext
accounts
constructor(executionContext) {
constructor (executionContext) {
this.executionContext = executionContext
}
@ -46,16 +45,16 @@ class Transactions{
const txBlock = this.executionContext.txs[receipt.hash]
const 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),
'contractAddress': receipt.contractAddress,
'logs': receipt.logs,
'status': receipt.status,
'to': receipt.to
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),
contractAddress: receipt.contractAddress,
logs: receipt.logs,
status: receipt.status,
to: receipt.to
}
if (r.blockNumber === '0x') {
@ -71,7 +70,7 @@ class Transactions{
}
eth_getCode (payload, cb) {
let address = payload.params[0]
const address = payload.params[0]
this.executionContext.web3().eth.getCode(address, (error, result) => {
if (error) {
@ -97,13 +96,13 @@ class Transactions{
}
eth_getTransactionCount (payload, cb) {
let address = payload.params[0]
const address = payload.params[0]
this.executionContext.vm().stateManager.getAccount(address, (err, account) => {
if (err) {
return cb(err)
}
let nonce = new BN(account.nonce).toString(10)
const nonce = new BN(account.nonce).toString(10)
cb(null, nonce)
})
}
@ -120,17 +119,17 @@ class Transactions{
// TODO: params to add later
const r = {
'blockHash': '0x' + txBlock.hash().toString('hex'),
'blockNumber': '0x' + txBlock.header.number.toString('hex'),
'from': receipt.from,
'gas': Web3.utils.toHex(receipt.gas),
blockHash: '0x' + txBlock.hash().toString('hex'),
blockNumber: '0x' + txBlock.header.number.toString('hex'),
from: receipt.from,
gas: Web3.utils.toHex(receipt.gas),
// 'gasPrice': '2000000000000', // 0x123
'gasPrice': '0x4a817c800', // 20000000000
'hash': receipt.transactionHash,
'input': receipt.input,
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",
@ -165,18 +164,18 @@ class Transactions{
}
// TODO: params to add later
let r = {
'blockHash': '0x' + txBlock.hash().toString('hex'),
'blockNumber': '0x' + txBlock.header.number.toString('hex'),
'from': receipt.from,
'gas': Web3.utils.toHex(receipt.gas),
const r = {
blockHash: '0x' + txBlock.hash().toString('hex'),
blockNumber: '0x' + txBlock.header.number.toString('hex'),
from: receipt.from,
gas: Web3.utils.toHex(receipt.gas),
// 'gasPrice': '2000000000000', // 0x123
'gasPrice': '0x4a817c800', // 20000000000
'hash': receipt.transactionHash,
'input': receipt.input,
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",
@ -208,17 +207,17 @@ class Transactions{
// TODO: params to add later
const r = {
'blockHash': '0x' + txBlock.hash().toString('hex'),
'blockNumber': '0x' + txBlock.header.number.toString('hex'),
'from': receipt.from,
'gas': Web3.utils.toHex(receipt.gas),
blockHash: '0x' + txBlock.hash().toString('hex'),
blockNumber: '0x' + txBlock.header.number.toString('hex'),
from: receipt.from,
gas: Web3.utils.toHex(receipt.gas),
// 'gasPrice': '2000000000000', // 0x123
'gasPrice': '0x4a817c800', // 20000000000
'hash': receipt.transactionHash,
'input': receipt.input,
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",
@ -236,4 +235,4 @@ class Transactions{
cb(null, r)
})
}
}
}

@ -12,7 +12,7 @@ function runCall (payload, from, to, data, value, gasLimit, txRunner, callbacks,
return callback(null, toReturn)
}
TxExecution.callFunction(from, to, data, value, gasLimit, {constant: true}, txRunner, callbacks, finalCallback, true)
TxExecution.callFunction(from, to, data, value, gasLimit, { constant: true }, txRunner, callbacks, finalCallback, true)
}
function runTx (payload, from, to, data, value, gasLimit, txRunner, callbacks, callback) {
@ -23,7 +23,7 @@ function runTx (payload, from, to, data, value, gasLimit, txRunner, callbacks, c
callback(null, result.transactionHash)
}
TxExecution.callFunction(from, to, data, value, gasLimit, {constant: false}, txRunner, callbacks, finalCallback, false)
TxExecution.callFunction(from, to, data, value, gasLimit, { constant: false }, txRunner, callbacks, finalCallback, false)
}
function createContract (payload, from, data, value, gasLimit, txRunner, callbacks, callback) {
@ -71,7 +71,7 @@ export function processTx (executionContext, accounts, payload, isCall, callback
let { from, to, data, value, gas } = payload.params[0]
gas = gas || 3000000
let callbacks = {
const callbacks = {
confirmationCb: (network, tx, gasEstimation, continueTxExecution, cancelCb) => {
continueTxExecution(null)
},

@ -1,3 +1,4 @@
import { Blocks } from './methods/blocks'
const RemixLib = require('@remix-project/remix-lib')
const executionContext = RemixLib.execution.executionContext
@ -5,7 +6,6 @@ const log = require('./utils/logs.js')
const merge = require('merge')
const Accounts = require('./methods/accounts.js')
import { Blocks } from './methods/blocks'
const Filters = require('./methods/filters.js')
const Misc = require('./methods/misc.js')
const Net = require('./methods/net.js')
@ -15,14 +15,13 @@ const Debug = require('./methods/debug.js')
const generateBlock = require('./genesis.js')
export class Provider {
options
executionContext
Accounts
Transactions
methods
constructor(options = {}) {
constructor (options = {}) {
this.options = options
// TODO: init executionContext here
this.executionContext = executionContext
@ -63,7 +62,7 @@ export class Provider {
if (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)
})
}
@ -81,4 +80,4 @@ export class Provider {
on (type, cb) {
this.executionContext.logsManager.addListener(type, cb)
}
}
}

@ -21,7 +21,7 @@ class Server {
expressWs(app)
app.use(cors())
app.use(bodyParser.urlencoded({extended: true}))
app.use(bodyParser.urlencoded({ extended: true }))
app.use(bodyParser.json())
app.get('/', (req, res) => {

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

Loading…
Cancel
Save