linting passed

toaster-react
aniket-engg 4 years ago committed by Aniket
parent 6704b46bc2
commit 2e9b71485e
  1. 5
      libs/remix-lib/.eslintrc
  2. 10
      libs/remix-lib/src/eventManager.ts
  3. 14
      libs/remix-lib/src/execution/eventsDecoder.ts
  4. 26
      libs/remix-lib/src/execution/execution-context.ts
  5. 66
      libs/remix-lib/src/execution/logsManager.ts
  6. 14
      libs/remix-lib/src/execution/txExecution.ts
  7. 32
      libs/remix-lib/src/execution/txFormat.ts
  8. 20
      libs/remix-lib/src/execution/txHelper.ts
  9. 23
      libs/remix-lib/src/execution/txListener.ts
  10. 17
      libs/remix-lib/src/execution/txRunner.ts
  11. 8
      libs/remix-lib/src/execution/typeConversion.ts
  12. 4
      libs/remix-lib/src/helpers/compilerHelper.ts
  13. 4
      libs/remix-lib/src/helpers/uiHelper.ts
  14. 82
      libs/remix-lib/src/init.ts
  15. 29
      libs/remix-lib/src/universalDapp.ts
  16. 27
      libs/remix-lib/src/util.ts
  17. 6
      libs/remix-lib/src/web3Provider/dummyProvider.ts
  18. 3
      libs/remix-lib/src/web3Provider/web3Providers.ts
  19. 37
      libs/remix-lib/src/web3Provider/web3VmProvider.ts
  20. 6
      libs/remix-lib/tsconfig.lib.json
  21. 2
      workspace.json

@ -4,7 +4,10 @@
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/no-this-alias": "off"
"@typescript-eslint/no-this-alias": "off",
"standard/no-callback-literal": "off",
"camelcase": "off",
"no-unused-vars": "off"
},
"env": {
"browser": true,

@ -1,11 +1,10 @@
'use strict'
export class EventManager {
registered
anonymous
constructor() {
constructor () {
this.registered = {}
this.anonymous = {}
}
@ -26,7 +25,7 @@ export class EventManager {
func = obj
obj = this.anonymous
}
for (let reg in this.registered[eventName]) {
for (const reg in this.registered[eventName]) {
if (this.registered[eventName][reg].obj === obj && this.registered[eventName][reg].func === func) {
this.registered[eventName].splice(reg, 1)
}
@ -49,7 +48,7 @@ export class EventManager {
func = obj
obj = this.anonymous
}
this.registered[eventName].push({obj, func})
this.registered[eventName].push({ obj, func })
}
/*
@ -63,10 +62,9 @@ export class EventManager {
if (!this.registered[eventName]) {
return
}
for (let listener in this.registered[eventName]) {
for (const listener in this.registered[eventName]) {
const l = this.registered[eventName][listener]
l.func.apply(l.obj === this.anonymous ? {} : l.obj, args)
}
}
}

@ -9,11 +9,11 @@ import { visitContracts } from './txHelper'
export class EventsDecoder {
resolveReceipt
constructor ({resolveReceipt}) {
constructor ({ resolveReceipt }) {
this.resolveReceipt = resolveReceipt
}
/**
/**
* use Transaction Receipt to decode logs. assume that the transaction as already been resolved by txListener.
* logs are decoded only if the contract if known by remix.
*
@ -41,7 +41,7 @@ export class EventsDecoder {
_eventABI (contract) {
const eventABI = {}
const abi = new ethers.utils.Interface(contract.abi)
for (let e in abi.events) {
for (const e in abi.events) {
const event = abi.getEvent(e)
eventABI[abi.getEventTopic(e).replace('0x', '')] = { event: event.name, inputs: event.inputs, object: event, abi: abi }
}
@ -57,10 +57,10 @@ export class EventsDecoder {
}
_event (hash, eventsABI) {
for (let k in eventsABI) {
for (const k in eventsABI) {
if (eventsABI[k][hash]) {
let event = eventsABI[k][hash]
for (let input of event.inputs) {
const event = eventsABI[k][hash]
for (const input of event.inputs) {
if (input.type === 'function') {
input.type = 'bytes24'
input.baseType = 'bytes24'
@ -90,7 +90,7 @@ export class EventsDecoder {
_decodeEvents (tx, logs, contractName, compiledContracts, cb) {
const eventsABI = this._eventsABI(compiledContracts)
const events = []
for (let i in logs) {
for (const i in logs) {
// [address, topics, mem]
const log = logs[i]
const topicId = log.topics[0]

@ -2,17 +2,17 @@
'use strict'
import Web3 from 'web3'
import { EventManager } from '../eventManager'
const EthJSVM = require('ethereumjs-vm').default
import { rlp, keccak, bufferToHex } from 'ethereumjs-util'
const StateManager = require('ethereumjs-vm/dist/state/stateManager').default
import { Web3VmProvider } from '../web3Provider/web3VmProvider'
const EthJSVM = require('ethereumjs-vm').default
const StateManager = require('ethereumjs-vm/dist/state/stateManager').default
const LogsManager = require('./logsManager.js')
declare let ethereum: any;
declare let ethereum: any
let web3
if (typeof window !== 'undefined' && typeof window['ethereum'] !== 'undefined') {
var injectedProvider = window['ethereum']
if (typeof window !== 'undefined' && typeof window.ethereum !== 'undefined') {
var injectedProvider = window.ethereum
web3 = new Web3(injectedProvider)
} else {
web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8545'))
@ -65,7 +65,7 @@ class StateManagerCommonStorageDump extends StateManager {
}
setStateRoot (stateRoot, cb) {
let checkpoint = this._checkpointCount
const checkpoint = this._checkpointCount
this._checkpointCount = 0
super.setStateRoot(stateRoot, (err) => {
this._checkpointCount = checkpoint
@ -116,7 +116,7 @@ export class ExecutionContext {
executionContext
listenOnLastBlockId
constructor() {
constructor () {
this.event = new EventManager()
this.logsManager = new LogsManager()
this.executionContext = null
@ -306,13 +306,12 @@ export class ExecutionContext {
}
txDetailsLink (network, hash) {
const transactionDetailsLinks = {
'Main': 'https://www.etherscan.io/tx/',
'Rinkeby': 'https://rinkeby.etherscan.io/tx/',
'Ropsten': 'https://ropsten.etherscan.io/tx/',
'Kovan': 'https://kovan.etherscan.io/tx/',
'Goerli': 'https://goerli.etherscan.io/tx/'
Main: 'https://www.etherscan.io/tx/',
Rinkeby: 'https://rinkeby.etherscan.io/tx/',
Ropsten: 'https://ropsten.etherscan.io/tx/',
Kovan: 'https://kovan.etherscan.io/tx/',
Goerli: 'https://goerli.etherscan.io/tx/'
}
if (transactionDetailsLinks[network]) {
@ -338,4 +337,3 @@ export class ExecutionContext {
this.txs[tx] = block
}
}

@ -2,7 +2,6 @@ import { eachOf } from 'async'
import { randomBytes } from 'crypto'
export class LogsManager {
notificationCallbacks
subscriptions
filters
@ -19,31 +18,31 @@ export class LogsManager {
checkBlock (blockNumber, block, web3) {
eachOf(block.transactions, (tx, i, next) => {
let txHash = '0x' + tx.hash().toString('hex')
const txHash = '0x' + tx.hash().toString('hex')
web3.eth.getTransactionReceipt(txHash, (_error, receipt) => {
for (let log of receipt.logs) {
for (const log of receipt.logs) {
this.oldLogs.push({ type: 'block', blockNumber, block, tx, log, txNumber: i })
let subscriptions = this.getSubscriptionsFor({ type: 'block', blockNumber, block, tx, log })
for (let subscriptionId of subscriptions) {
let result = {
'logIndex': '0x1', // 1
'blockNumber': blockNumber,
'blockHash': ('0x' + block.hash().toString('hex')),
'transactionHash': ('0x' + tx.hash().toString('hex')),
'transactionIndex': '0x' + i.toString(16),
const subscriptions = this.getSubscriptionsFor({ type: 'block', blockNumber, block, tx, log })
for (const subscriptionId of subscriptions) {
const result = {
logIndex: '0x1', // 1
blockNumber: blockNumber,
blockHash: ('0x' + block.hash().toString('hex')),
transactionHash: ('0x' + tx.hash().toString('hex')),
transactionIndex: '0x' + i.toString(16),
// TODO: if it's a contract deploy, it should be that address instead
'address': log.address,
'data': log.data,
'topics': log.topics
address: log.address,
data: log.data,
topics: log.topics
}
if (result.address === '0x') {
delete result.address
}
let response = { 'jsonrpc': '2.0', 'method': 'eth_subscription', params: { 'result': result, 'subscription': subscriptionId } }
const response = { jsonrpc: '2.0', method: 'eth_subscription', params: { result: result, subscription: subscriptionId } }
this.transmit(response)
}
}
@ -69,12 +68,12 @@ export class LogsManager {
}
getSubscriptionsFor (changeEvent) {
let matchedSubscriptions = []
for (let subscriptionId of Object.keys(this.subscriptions)) {
const matchedSubscriptions = []
for (const subscriptionId of Object.keys(this.subscriptions)) {
const subscriptionParams = this.subscriptions[subscriptionId]
const [queryType, queryFilter] = subscriptionParams
if (this.eventMatchesFilter(changeEvent, queryType, queryFilter || {topics: []})) {
if (this.eventMatchesFilter(changeEvent, queryType, queryFilter || { topics: [] })) {
matchedSubscriptions.push(subscriptionId)
}
}
@ -103,7 +102,7 @@ export class LogsManager {
}
subscribe (params) {
let subscriptionId = '0x' + randomBytes(16).toString('hex')
const subscriptionId = '0x' + randomBytes(16).toString('hex')
this.subscriptions[subscriptionId] = params
return subscriptionId
}
@ -129,14 +128,14 @@ export class LogsManager {
}
getLogsForFilter (filterId, logsOnly) {
const {filterType, params} = this.filters[filterId]
const { filterType, params } = this.filters[filterId]
const tracking = this.filterTracking[filterId]
if (logsOnly || filterType === 'filter') {
return this.getLogsFor(params || {topics: []})
return this.getLogsFor(params || { topics: [] })
}
if (filterType === 'block') {
let blocks = this.oldLogs.filter(x => x.type === 'block').filter(x => tracking.block === undefined || x.blockNumber >= tracking.block)
const blocks = this.oldLogs.filter(x => x.type === 'block').filter(x => tracking.block === undefined || x.blockNumber >= tracking.block)
tracking.block = blocks[blocks.length - 1]
return blocks.map(block => ('0x' + block.hash().toString('hex')))
}
@ -146,24 +145,23 @@ export class LogsManager {
}
getLogsFor (params) {
let results = []
for (let log of this.oldLogs) {
const results = []
for (const log of this.oldLogs) {
if (this.eventMatchesFilter(log, 'logs', params)) {
results.push({
'logIndex': '0x1', // 1
'blockNumber': log.blockNumber,
'blockHash': ('0x' + log.block.hash().toString('hex')),
'transactionHash': ('0x' + log.tx.hash().toString('hex')),
'transactionIndex': '0x' + log.txNumber.toString(16),
logIndex: '0x1', // 1
blockNumber: log.blockNumber,
blockHash: ('0x' + log.block.hash().toString('hex')),
transactionHash: ('0x' + log.tx.hash().toString('hex')),
transactionIndex: '0x' + log.txNumber.toString(16),
// TODO: if it's a contract deploy, it should be that address instead
'address': log.log.address,
'data': log.log.data,
'topics': log.log.topics
address: log.log.address,
data: log.log.data,
topics: log.log.topics
})
}
}
return results
}
}

@ -15,7 +15,7 @@ import { ethers } from 'ethers'
* [personal mode enabled, need password to continue] promptCb (okCb, cancelCb)
* @param {Function} finalCallback - last callback.
*/
export function createContract (from, data, value, gasLimit, txRunner, callbacks, finalCallback) {
export function createContract (from, data, value, gasLimit, txRunner, callbacks, finalCallback) {
if (!callbacks.confirmationCb || !callbacks.gasEstimationForceSend || !callbacks.promptCb) {
return finalCallback('all the callbacks must have been defined')
}
@ -56,7 +56,7 @@ export function callFunction (from, to, data, value, gasLimit, funAbi, txRunner,
* @param {Object} txResult - the value returned by the vm
* @return {Object} - { error: true/false, message: DOMNode }
*/
export function checkVMError (txResult) {
export function checkVMError (txResult) {
const errorCode = {
OUT_OF_GAS: 'out of gas',
STACK_UNDERFLOW: 'stack underflow',
@ -81,10 +81,10 @@ export function callFunction (from, to, data, value, gasLimit, funAbi, txRunner,
const error = `VM error: ${exceptionError}.\n`
let msg
if (exceptionError === errorCode.INVALID_OPCODE) {
msg = `\t\n\tThe execution might have thrown.\n`
msg = '\t\n\tThe execution might have thrown.\n'
ret.error = true
} else if (exceptionError === errorCode.OUT_OF_GAS) {
msg = `\tThe transaction ran out of gas. Please increase the Gas Limit.\n`
msg = '\tThe transaction ran out of gas. Please increase the Gas Limit.\n'
ret.error = true
} else if (exceptionError === errorCode.REVERT) {
const returnData = txResult.result.execResult.returnValue
@ -94,15 +94,13 @@ export function callFunction (from, to, data, value, gasLimit, funAbi, txRunner,
const reason = abiCoder.decode(['string'], returnData.slice(4))[0]
msg = `\tThe transaction has been reverted to the initial state.\nReason provided by the contract: "${reason}".`
} else {
msg = `\tThe transaction has been reverted to the initial state.\nNote: The called function should be payable if you send value and the value you send should be less than your current balance.`
msg = '\tThe transaction has been reverted to the initial state.\nNote: The called function should be payable if you send value and the value you send should be less than your current balance.'
}
ret.error = true
} else if (exceptionError === errorCode.STATIC_STATE_CHANGE) {
msg = `\tState changes is not allowed in Static Call context\n`
msg = '\tState changes is not allowed in Static Call context\n'
ret.error = true
}
ret.message = `${error}${exceptionError}${msg}\tDebug the transaction to get more information.`
return ret
}

@ -1,9 +1,9 @@
'use strict'
import { ethers } from 'ethers'
import { encodeParams as encodeParamsHelper, encodeFunctionId, makeFullTypeDefinition} from './txHelper'
import { encodeParams as encodeParamsHelper, encodeFunctionId, makeFullTypeDefinition } from './txHelper'
import { eachOfSeries } from 'async'
import { linkBytecode } from 'solc/linker'
import { isValidAddress, addHexPrefix } from 'ethereumjs-util'
import { linkBytecode as linkBytecodeSolc } from 'solc/linker'
import { isValidAddress, addHexPrefix } from 'ethereumjs-util'
/**
* build the transaction data
@ -99,8 +99,8 @@ export function encodeConstructorCallAndLinkLibraries (contract, params, funAbi,
let bytecodeToDeploy = contract.evm.bytecode.object
if (bytecodeToDeploy.indexOf('_') >= 0) {
if (linkLibraries && linkReferences) {
for (let libFile in linkLibraries) {
for (let lib in linkLibraries[libFile]) {
for (const libFile in linkLibraries) {
for (const lib in linkLibraries[libFile]) {
const address = linkLibraries[libFile][lib]
if (!isValidAddress(address)) return callback(address + ' is not a valid address. Please check the provided address is valid.')
bytecodeToDeploy = this.linkLibraryStandardFromlinkReferences(lib, address.replace('0x', ''), bytecodeToDeploy, linkReferences)
@ -140,14 +140,14 @@ export function encodeConstructorCallAndDeployLibraries (contractName, contract,
callback('Error deploying required libraries: ' + err)
} else {
bytecodeToDeploy = bytecode + dataHex
return callback(null, {dataHex: bytecodeToDeploy, funAbi, funArgs: encodedParam.funArgs, contractBytecode, contractName: contractName})
return callback(null, { dataHex: bytecodeToDeploy, funAbi, funArgs: encodedParam.funArgs, contractBytecode, contractName: contractName })
}
}, callbackStep, callbackDeployLibrary)
return
} else {
dataHex = bytecodeToDeploy + encodedParam.dataHex
}
callback(null, {dataHex: bytecodeToDeploy, funAbi, funArgs: encodedParam.funArgs, contractBytecode, contractName: contractName})
callback(null, { dataHex: bytecodeToDeploy, funAbi, funArgs: encodedParam.funArgs, contractBytecode, contractName: contractName })
})
}
@ -204,7 +204,7 @@ export function buildData (contractName, contract, contracts, isConstructor, fun
callback('Error deploying required libraries: ' + err)
} else {
bytecodeToDeploy = bytecode + dataHex
return callback(null, {dataHex: bytecodeToDeploy, funAbi, funArgs, contractBytecode, contractName: contractName})
return callback(null, { dataHex: bytecodeToDeploy, funAbi, funArgs, contractBytecode, contractName: contractName })
}
}, callbackStep, callbackDeployLibrary)
return
@ -309,7 +309,7 @@ export function deployLibrary (libraryName, libraryShortName, library, contracts
}, callbackStep, callbackDeployLibrary)
} else {
callbackStep(`creation of library ${libraryName} pending...`)
const data = {dataHex: bytecode, funAbi: {type: 'constructor'}, funArgs: [], contractBytecode: bytecode, contractName: libraryShortName}
const data = { dataHex: bytecode, funAbi: { type: 'constructor' }, funArgs: [], contractBytecode: bytecode, contractName: libraryShortName }
callbackDeployLibrary({ data: data, useCall: false }, (err, txResult) => {
if (err) {
return callback(err)
@ -322,8 +322,8 @@ export function deployLibrary (libraryName, libraryShortName, library, contracts
}
export function linkLibraryStandardFromlinkReferences (libraryName, address, bytecode, linkReferences) {
for (let file in linkReferences) {
for (let libName in linkReferences[file]) {
for (const file in linkReferences) {
for (const libName in linkReferences[file]) {
if (libraryName === libName) {
bytecode = this.setLibraryAddress(address, bytecode, linkReferences[file][libName])
}
@ -338,7 +338,7 @@ export function linkLibraryStandard (libraryName, address, bytecode, contract) {
export function setLibraryAddress (address, bytecodeToLink, positions) {
if (positions) {
for (let pos of positions) {
for (const pos of positions) {
const regpos = bytecodeToLink.match(new RegExp(`(.{${2 * pos.start}})(.{${2 * pos.length}})(.*)`))
if (regpos) {
bytecodeToLink = regpos[1] + address + regpos[3]
@ -349,7 +349,7 @@ export function setLibraryAddress (address, bytecodeToLink, positions) {
}
export function linkLibrary (libraryName, address, bytecodeToLink) {
return linkBytecode(bytecodeToLink, { [libraryName]: addHexPrefix(address) })
return linkBytecodeSolc(bytecodeToLink, { [libraryName]: addHexPrefix(address) })
}
export function decodeResponse (response, fnabi) {
@ -404,7 +404,7 @@ export function parseFunctionParams (params) {
throw new Error('invalid params')
}
}
} else if (params.charAt(i) === '[') { // If an array/struct opening bracket is received
} else if (params.charAt(i) === '[') { // If an array/struct opening bracket is received
startIndex = -1
let bracketCount = 1
let j
@ -412,7 +412,7 @@ export function parseFunctionParams (params) {
// Increase count if another array opening bracket is received (To handle nested array)
if (params.charAt(j) === '[') {
bracketCount++
} else if (params.charAt(j) === ']') { // // Decrease count if an array closing bracket is received (To handle nested array)
} else if (params.charAt(j) === ']') { // // Decrease count if an array closing bracket is received (To handle nested array)
bracketCount--
}
// Throw error if end of params string is arrived but couldn't get end of tuple
@ -448,5 +448,3 @@ export function parseFunctionParams (params) {
export function isArrayOrStringStart (str, index) {
return str.charAt(index) === '"' || str.charAt(index) === '['
}

@ -34,13 +34,13 @@ export function encodeParams (funABI, args) {
export function encodeFunctionId (funABI) {
if (funABI.type === 'fallback' || funABI.type === 'receive') return '0x'
let abi = new ethers.utils.Interface([funABI])
const abi = new ethers.utils.Interface([funABI])
return abi.getSighash(funABI.name)
}
export function sortAbiFunction (contractabi) {
// Check if function is constant (introduced with Solidity 0.6.0)
const isConstant = ({stateMutability}) => stateMutability === 'view' || stateMutability === 'pure'
const isConstant = ({ stateMutability }) => stateMutability === 'view' || stateMutability === 'pure'
// Sorts the list of ABI entries. Constant functions will appear first,
// followed by non-constant functions. Within those t wo groupings, functions
// will be sorted by their names.
@ -61,7 +61,7 @@ export function sortAbiFunction (contractabi) {
}
export function getConstructorInterface (abi) {
const funABI = { 'name': '', 'inputs': [], 'type': 'constructor', 'payable': false, 'outputs': [] }
const funABI = { name: '', inputs: [], type: 'constructor', payable: false, outputs: [] }
if (typeof abi === 'string') {
try {
abi = JSON.parse(abi)
@ -75,7 +75,7 @@ export function getConstructorInterface (abi) {
if (abi[i].type === 'constructor') {
funABI.inputs = abi[i].inputs || []
funABI.payable = abi[i].payable
funABI['stateMutability'] = abi[i].stateMutability
funABI.stateMutability = abi[i].stateMutability
break
}
}
@ -102,7 +102,7 @@ export function getFunction (abi, fnName) {
const fn = abi[i]
if (fn.type === 'function' && fnName === fn.name + '(' + fn.inputs.map((value) => {
if (value.components) {
let fullType = this.makeFullTypeDefinition(value)
const fullType = this.makeFullTypeDefinition(value)
return fullType.replace(/tuple/g, '') // return of makeFullTypeDefinition might contain `tuple`, need to remove it cause `methodIdentifier` (fnName) does not include `tuple` keyword
} else {
return value.type
@ -136,8 +136,8 @@ export function getReceiveInterface (abi) {
* @param {String} name - contract name
* @returns contract obj and associated file: { contract, file } or null
*/
export function getContract(contractName, contracts) {
for (let file in contracts) {
export function getContract (contractName, contracts) {
for (const file in contracts) {
if (contracts[file][contractName]) {
return { object: contracts[file][contractName], file: file }
}
@ -150,9 +150,9 @@ export function getReceiveInterface (abi) {
* stop visiting when cb return true
* @param {Function} cb - callback
*/
export function visitContracts (contracts, cb) {
for (let file in contracts) {
for (let name in contracts[file]) {
export function visitContracts (contracts, cb) {
for (const file in contracts) {
for (const name in contracts[file]) {
if (cb({ name: name, object: contracts[file][name], file: file })) return
}
}

@ -4,11 +4,11 @@ import { ethers } from 'ethers'
import { toBuffer } from 'ethereumjs-util'
import { EventManager } from '../eventManager'
import { compareByteCode } from '../util'
import { ExecutionContext } from './execution-context'
import { decodeResponse } from './txFormat'
import { getFunction, getReceiveInterface, getConstructorInterface, visitContracts, makeFullTypeDefinition } from './txHelper'
import { ExecutionContext } from './execution-context'
import { decodeResponse } from './txFormat'
import { getFunction, getReceiveInterface, getConstructorInterface, visitContracts, makeFullTypeDefinition } from './txHelper'
function addExecutionCosts(txResult, tx) {
function addExecutionCosts (txResult, tx) {
if (txResult && txResult.result) {
if (txResult.result.execResult) {
tx.returnValue = txResult.result.execResult.returnValue
@ -26,7 +26,6 @@ function addExecutionCosts(txResult, tx) {
*
*/
export class TxListener {
event
executionContext
_resolvedTransactions
@ -139,7 +138,7 @@ export class TxListener {
}
}
/**
/**
* stop listening for incoming transactions. do not reset the recorded pool.
*
* @param {String} type - type/name of the provider to add
@ -179,7 +178,7 @@ export class TxListener {
_manageBlock (blockNumber) {
this.executionContext.web3().eth.getBlock(blockNumber, true, (error, result) => {
if (!error) {
this._newBlock(Object.assign({type: 'web3'}, result))
this._newBlock(Object.assign({ type: 'web3' }, result))
}
})
}
@ -242,13 +241,13 @@ export class TxListener {
const code = tx.input
contract = this._tryResolveContract(code, contracts, true)
if (contract) {
let address = receipt.contractAddress
const address = receipt.contractAddress
this._resolvedContracts[address] = contract
fun = this._resolveFunction(contract, tx, true)
if (this._resolvedTransactions[tx.hash]) {
this._resolvedTransactions[tx.hash].contractAddress = address
}
return cb(null, {to: null, contractName: contract.name, function: fun, creationAddress: address})
return cb(null, { to: null, contractName: contract.name, function: fun, creationAddress: address })
}
return cb()
} else {
@ -262,7 +261,7 @@ export class TxListener {
if (contract) {
this._resolvedContracts[tx.to] = contract
const fun = this._resolveFunction(contract, tx, false)
return cb(null, {to: tx.to, contractName: contract.name, function: fun})
return cb(null, { to: tx.to, contractName: contract.name, function: fun })
}
}
return cb()
@ -271,7 +270,7 @@ export class TxListener {
}
if (contract) {
fun = this._resolveFunction(contract, tx, false)
return cb(null, {to: tx.to, contractName: contract.name, function: fun})
return cb(null, { to: tx.to, contractName: contract.name, function: fun })
}
return cb()
}
@ -286,7 +285,7 @@ export class TxListener {
const inputData = tx.input.replace('0x', '')
if (!isCtor) {
const methodIdentifiers = contract.object.evm.methodIdentifiers
for (let fn in methodIdentifiers) {
for (const fn in methodIdentifiers) {
if (methodIdentifiers[fn] === inputData.substring(0, 8)) {
const fnabi = getFunction(abi, fn)
this._resolvedTransactions[tx.hash] = {

@ -6,7 +6,6 @@ import { ExecutionContext } from './execution-context'
import { EventManager } from '../eventManager'
export class TxRunner {
event
executionContext
_api
@ -73,7 +72,7 @@ export class TxRunner {
resolve({
result,
tx,
transactionHash: result ? result['transactionHash'] : null
transactionHash: result ? result.transactionHash : null
})
})
}
@ -87,7 +86,7 @@ export class TxRunner {
}
}
execute(args, confirmationCb, gasEstimationForceSend, promptCb, callback) {
execute (args, confirmationCb, gasEstimationForceSend, promptCb, callback) {
let data = args.data
if (data.slice(0, 2) !== '0x') {
data = '0x' + data
@ -157,7 +156,7 @@ export class TxRunner {
runBlockInVm (tx, block, callback) {
this.executionContext.vm().runBlock({ block: block, generate: true, skipBlockValidation: true, skipBalance: false }).then((results) => {
let result = results.results[0]
const result = results.results[0]
if (result) {
const status = result.execResult.exceptionError ? 0 : 1
result.status = `0x${status}`
@ -177,7 +176,7 @@ export class TxRunner {
const tx = { from: from, to: to, data: data, value: value }
if (useCall) {
tx['gas'] = gasLimit
tx.gas = gasLimit
return this.executionContext.web3().eth.call(tx, function (error, result) {
callback(error, {
result: result,
@ -192,7 +191,7 @@ export class TxRunner {
}
gasEstimationForceSend(err, () => {
// callback is called whenever no error
tx['gas'] = !gasEstimation ? gasLimit : gasEstimation
tx.gas = !gasEstimation ? gasLimit : gasEstimation
if (this._api.config.getUnpersistedProperty('doNotShowTransactionConfirmationAgain')) {
return this._executeTx(tx, null, this._api, promptCb, callback)
@ -204,7 +203,7 @@ export class TxRunner {
return
}
confirmCb(network, tx, tx['gas'], (gasPrice) => {
confirmCb(network, tx, tx.gas, (gasPrice) => {
return this._executeTx(tx, gasPrice, this._api, promptCb, callback)
}, (error) => {
callback(error)
@ -258,7 +257,7 @@ async function tryTillTxAvailable (txhash, executionContext) {
async function pause () { return new Promise((resolve, reject) => { setTimeout(resolve, 500) }) }
function run(self, tx, stamp, confirmationCb, gasEstimationForceSend = null, promptCb = null, callback = null) {
function run (self, tx, stamp, confirmationCb, gasEstimationForceSend = null, promptCb = null, callback = null) {
if (!self.runAsync && Object.keys(self.pendingTxs).length) {
return self.queusTxs.push({ tx, stamp, callback })
}
@ -271,4 +270,4 @@ function run(self, tx, stamp, confirmationCb, gasEstimationForceSend = null, pro
run(self, next.tx, next.stamp, next.callback)
}
})
}
}

@ -1,15 +1,15 @@
'use strict'
import { BN, bufferToHex } from 'ethereumjs-util'
import { BN, bufferToHex } from 'ethereumjs-util'
export function toInt (h) {
if (h.indexOf && h.indexOf('0x') === 0) {
return (new BN(h.replace('0x', ''), 16)).toString(10)
} else if (h.constructor && h.constructor.name === 'BigNumber' || BN.isBN(h)) {
} else if ((h.constructor && h.constructor.name === 'BigNumber') || BN.isBN(h)) {
return h.toString(10)
}
return h
}
export var stringify = convertToString
function convertToString (v) {
@ -26,7 +26,7 @@ function convertToString (v) {
return bufferToHex(v)
} else if (typeof v === 'object') {
const retObject = {}
for (let i in v) {
for (const i in v) {
retObject[i] = convertToString(v[i])
}
return retObject

@ -13,8 +13,8 @@ export function compilerInput (contracts) {
},
outputSelection: {
'*': {
'': [ 'ast' ],
'*': [ 'abi', 'metadata', 'evm.legacyAssembly', 'evm.bytecode', 'evm.deployedBytecode', 'evm.methodIdentifiers', 'evm.gasEstimates' ]
'': ['ast'],
'*': ['abi', 'metadata', 'evm.legacyAssembly', 'evm.bytecode', 'evm.deployedBytecode', 'evm.methodIdentifiers', 'evm.gasEstimates']
}
}
}

@ -45,8 +45,8 @@ export function tryConvertAsciiFormat (memorySlot) {
*/
export function formatCss (css1, css2) {
let ret = ''
for (let arg in arguments) {
for (let k in arguments[arg]) {
for (const arg in arguments) {
for (const k in arguments[arg]) {
if (arguments[arg][k] && ret.indexOf(k) === -1) {
if (k.indexOf('*') === 0) {
ret += arguments[arg][k]

@ -18,11 +18,11 @@ export function setProvider (web3, url) {
export function web3DebugNode (network) {
const web3DebugNodes = {
'Main': 'https://gethmainnet.komputing.org',
'Rinkeby': 'https://remix-rinkeby.ethdevops.io',
'Ropsten': 'https://remix-ropsten.ethdevops.io',
'Goerli': 'https://remix-goerli.ethdevops.io',
'Kovan': 'https://remix-kovan.ethdevops.io'
Main: 'https://gethmainnet.komputing.org',
Rinkeby: 'https://remix-rinkeby.ethdevops.io',
Ropsten: 'https://remix-ropsten.ethdevops.io',
Goerli: 'https://remix-goerli.ethdevops.io',
Kovan: 'https://remix-kovan.ethdevops.io'
}
if (web3DebugNodes[network]) {
return this.loadWeb3(web3DebugNodes[network])
@ -31,42 +31,42 @@ export function web3DebugNode (network) {
}
export function extend (web3) {
if (!web3.extend) {
return
}
// DEBUG
const methods = []
if (!(web3.debug && web3.debug.preimage)) {
methods.push(new web3.extend.Method({
name: 'preimage',
call: 'debug_preimage',
inputFormatter: [null],
params: 1
}))
}
if (!web3.extend) {
return
}
// DEBUG
const methods = []
if (!(web3.debug && web3.debug.preimage)) {
methods.push(new web3.extend.Method({
name: 'preimage',
call: 'debug_preimage',
inputFormatter: [null],
params: 1
}))
}
if (!(web3.debug && web3.debug.traceTransaction)) {
methods.push(new web3.extend.Method({
name: 'traceTransaction',
call: 'debug_traceTransaction',
inputFormatter: [null, null],
params: 2
}))
}
if (!(web3.debug && web3.debug.traceTransaction)) {
methods.push(new web3.extend.Method({
name: 'traceTransaction',
call: 'debug_traceTransaction',
inputFormatter: [null, null],
params: 2
}))
}
if (!(web3.debug && web3.debug.storageRangeAt)) {
methods.push(new web3.extend.Method({
name: 'storageRangeAt',
call: 'debug_storageRangeAt',
inputFormatter: [null, null, null, null, null],
params: 5
}))
}
if (methods.length > 0) {
web3.extend({
property: 'debug',
methods: methods,
properties: []
})
}
if (!(web3.debug && web3.debug.storageRangeAt)) {
methods.push(new web3.extend.Method({
name: 'storageRangeAt',
call: 'debug_storageRangeAt',
inputFormatter: [null, null, null, null, null],
params: 5
}))
}
if (methods.length > 0) {
web3.extend({
property: 'debug',
methods: methods,
properties: []
})
}
}

@ -1,4 +1,4 @@
import { waterfall } from 'async'
import { waterfall } from 'async'
import { BN, privateToAddress, isValidPrivate, toChecksumAddress } from 'ethereumjs-util'
import { stripHexPrefix } from 'ethjs-util'
import { randomBytes } from 'crypto'
@ -10,7 +10,6 @@ import { ExecutionContext } from './execution/execution-context'
import { resultToRemixTx } from './helpers/txResultHelper'
export class UniversalDApp {
events
event
executionContext
@ -124,11 +123,11 @@ export class UniversalDApp {
const address = privateToAddress(privateKey)
// FIXME: we don't care about the callback, but we should still make this proper
let stateManager = this.executionContext.vm().stateManager
const stateManager = this.executionContext.vm().stateManager
stateManager.getAccount(address, (error, account) => {
if (error) return console.log(error)
account.balance = balance || '0xf00000000000000001'
stateManager.putAccount(address, account, function cb(error) {
stateManager.putAccount(address, account, function cb (error) {
if (error) console.log(error)
})
})
@ -141,17 +140,16 @@ export class UniversalDApp {
return new Promise((resolve, reject) => {
const provider = this.executionContext.getProvider()
switch (provider) {
case 'vm': {
case 'vm':
if (!this.accounts) {
if (cb) cb('No accounts?')
reject('No accounts?')
reject(new Error('No accounts?'))
return
}
if (cb) cb(null, Object.keys(this.accounts))
resolve(Object.keys(this.accounts))
}
break
case 'web3': {
case 'web3':
if (this.config.get('settings/personal-mode')) {
return this.executionContext.web3().personal.getListAccounts((error, accounts) => {
if (cb) cb(error, accounts)
@ -165,7 +163,6 @@ export class UniversalDApp {
resolve(accounts)
})
}
}
break
case 'injected': {
this.executionContext.web3().eth.getAccounts((error, accounts) => {
@ -179,7 +176,7 @@ export class UniversalDApp {
}
/** Get the balance of an address */
getBalance(address, cb) {
getBalance (address, cb) {
address = stripHexPrefix(address)
if (!this.executionContext.isVM()) {
@ -223,7 +220,7 @@ export class UniversalDApp {
* @param {Function} callback - callback.
*/
createContract (data, confirmationCb, continueCb, promptCb, callback) {
this.runTx({data: data, useCall: false}, confirmationCb, continueCb, promptCb, callback)
this.runTx({ data: data, useCall: false }, confirmationCb, continueCb, promptCb, callback)
}
/**
@ -236,10 +233,10 @@ export class UniversalDApp {
*/
callFunction (to, data, funAbi, confirmationCb, continueCb, promptCb, callback) {
const useCall = funAbi.stateMutability === 'view' || funAbi.stateMutability === 'pure'
this.runTx({to, data, useCall}, confirmationCb, continueCb, promptCb, callback)
this.runTx({ to, data, useCall }, confirmationCb, continueCb, promptCb, callback)
}
/**
/**
* call the current given contract
*
* @param {String} to - address of the contract to call.
@ -247,7 +244,7 @@ export class UniversalDApp {
* @param {Function} callback - callback.
*/
sendRawTransaction (to, data, confirmationCb, continueCb, promptCb, callback) {
this.runTx({to, data, useCall: false}, confirmationCb, continueCb, promptCb, callback)
this.runTx({ to, data, useCall: false }, confirmationCb, continueCb, promptCb, callback)
}
context () {
@ -345,7 +342,7 @@ export class UniversalDApp {
})
}
self.getAccounts(function (err, accounts) {
let address = accounts[0]
const address = accounts[0]
if (err) return next(err)
if (!address) return next('No accounts available')
@ -366,7 +363,7 @@ export class UniversalDApp {
self.event.trigger('initiatingTransaction', [timestamp, tx, payLoad])
self.txRunner.rawRun(tx, confirmationCb, continueCb, promptCb,
function (error, result) {
let eventName = (tx.useCall ? 'callExecuted' : 'transactionExecuted')
const eventName = (tx.useCall ? 'callExecuted' : 'transactionExecuted')
self.event.trigger(eventName, [error, tx.from, tx.to, tx.data, tx.useCall, result, timestamp, payLoad])
if (error && (typeof (error) !== 'string')) {

@ -10,7 +10,7 @@ import { BN, bufferToHex, keccak, setLengthLeft } from 'ethereumjs-util'
- swarm hash extraction
- bytecode comparison
*/
/*
/*
ints: IntArray
*/
export function hexConvert (ints) {
@ -26,7 +26,7 @@ export function hexConvert (ints) {
return ret
}
/**
/**
* Converts a hex string to an array of integers.
*/
export function hexToIntArray (hexString) {
@ -40,12 +40,12 @@ export function hexToIntArray (hexString) {
return integers
}
/*
/*
ints: list of BNs
*/
export function hexListFromBNs (bnList) {
const ret = []
for (let k in bnList) {
for (const k in bnList) {
const v = bnList[k]
if (BN.isBN(v)) {
ret.push('0x' + v.toString('hex', 64))
@ -61,7 +61,7 @@ export function hexListFromBNs (bnList) {
*/
export function hexListConvert (intsList) {
const ret = []
for (let k in intsList) {
for (const k in intsList) {
ret.push(this.hexConvert(intsList[k]))
}
return ret
@ -139,12 +139,12 @@ export function findClosestIndex (target, array): number {
* @param {Object} rootCall - call tree, built by the trace analyser
* @return {Object} - return the call which include the @args index
*/
export function findCall (index, rootCall) {
export function findCall (index, rootCall) {
const ret = buildCallPath(index, rootCall)
return ret[ret.length - 1]
}
/**
/**
* Find calls path from @args rootCall which leads to @args index (recursive)
*
* @param {Int} index - index of the vmtrace
@ -157,13 +157,13 @@ export function buildCallPath (index, rootCall) {
return ret
}
/**
/**
* sha3 the given @arg value (left pad to 32 bytes)
*
* @param {String} value - value to sha3
* @return {Object} - return sha3ied value
*/
export function sha3_256 (value) {
export function sha3_256 (value) {
if (typeof value === 'string' && value.indexOf('0x') !== 0) {
value = '0x' + value
}
@ -186,7 +186,7 @@ export function swarmHashExtraction () {
*
* @return {RegEx}
*/
export function swarmHashExtractionPOC31 () {
export function swarmHashExtractionPOC31 () {
return /a265627a7a72315820([0-9a-f]{64})64736f6c6343([0-9a-f]{6})0032$/
}
@ -227,7 +227,7 @@ export function extractSwarmHash (value) {
*
* @return {bool}
*/
export function compareByteCode (code1, code2) {
export function compareByteCode (code1, code2) {
if (code1 === code2) return true
if (code2 === '0x') return false // abstract contract. see comment
@ -271,7 +271,6 @@ export function escapeRegExp (str) {
return str.replace(/[-[\]/{}()+?.\\^$|]/g, '\\$&')
}
function replaceLibReference (code, pos) {
return code.substring(0, pos) + '0000000000000000000000000000000000000000' + code.substring(pos + 40)
}
@ -280,8 +279,8 @@ function findCallInternal (index, rootCall, callsPath) {
const calls = Object.keys(rootCall.calls)
const ret = rootCall
callsPath.push(rootCall)
for (let k in calls) {
let subCall = rootCall.calls[calls[k]]
for (const k in calls) {
const subCall = rootCall.calls[calls[k]]
if (index >= subCall.start && index <= subCall.return) {
findCallInternal(index, subCall, callsPath)
break

@ -4,7 +4,7 @@ export class DummyProvider {
providers
currentProvider
constructor() {
constructor () {
this.eth = {}
this.debug = {}
this.eth.getCode = (address, cb) => { return this.getCode(address, cb) }
@ -13,8 +13,8 @@ export class DummyProvider {
this.eth.getBlockNumber = (cb) => { return this.getBlockNumber(cb) }
this.debug.traceTransaction = (hash, options, cb) => { return this.traceTransaction(hash, options, cb) }
this.debug.storageRangeAt = (blockNumber, txIndex, address, start, end, maxLength, cb) => { return this.storageRangeAt(blockNumber, txIndex, address, start, end, maxLength, cb) }
this.providers = { 'HttpProvider': function (url) {} }
this.currentProvider = {'host': ''}
this.providers = { HttpProvider: function (url) {} }
this.currentProvider = { host: '' }
}
getCode (address, cb) {

@ -2,9 +2,8 @@ import { Web3VmProvider } from './web3VmProvider'
import { loadWeb3, extendWeb3 } from '../init'
export class Web3Providers {
modes
constructor() {
constructor () {
this.modes = {}
}

@ -1,10 +1,9 @@
import { hexConvert, hexListFromBNs, formatMemory } from '../util'
import { normalizeHexAddress } from '../helpers/uiHelper'
import { toChecksumAddress, BN, toBuffer, } from 'ethereumjs-util'
import { toChecksumAddress, BN, toBuffer } from 'ethereumjs-util'
import Web3 from 'web3'
export class Web3VmProvider {
web3
vm
vmTraces
@ -54,8 +53,8 @@ export class Web3VmProvider {
this.debug.traceTransaction = this.traceTransaction
this.debug.storageRangeAt = this.storageRangeAt
this.debug.preimage = this.preimage
this.providers = { 'HttpProvider': function (url) {} }
this.currentProvider = { 'host': 'vm provider' }
this.providers = { HttpProvider: function (url) {} }
this.currentProvider = { host: 'vm provider' }
this.storageCache = {}
this.lastProcessedStorageTxHash = {}
this.sha3Preimages = {}
@ -100,27 +99,27 @@ export class Web3VmProvider {
return: '0x0',
structLogs: []
}
let tx = {}
tx['hash'] = self.processingHash
tx['from'] = toChecksumAddress(hexConvert(data.getSenderAddress()))
const tx = {}
tx.hash = self.processingHash
tx.from = toChecksumAddress(hexConvert(data.getSenderAddress()))
if (data.to && data.to.length) {
tx['to'] = toChecksumAddress(hexConvert(data.to))
tx.to = toChecksumAddress(hexConvert(data.to))
}
this.processingAddress = tx['to']
tx['data'] = hexConvert(data.data)
tx['input'] = hexConvert(data.input)
tx['gas'] = (new BN(hexConvert(data.gas).replace('0x', ''), 16)).toString(10)
this.processingAddress = tx.to
tx.data = hexConvert(data.data)
tx.input = hexConvert(data.input)
tx.gas = (new BN(hexConvert(data.gas).replace('0x', ''), 16)).toString(10)
if (data.value) {
tx['value'] = hexConvert(data.value)
tx.value = hexConvert(data.value)
}
self.txs[self.processingHash] = tx
self.txsReceipt[self.processingHash] = tx
self.storageCache[self.processingHash] = {}
if (tx['to']) {
const account = toBuffer(tx['to'])
if (tx.to) {
const account = toBuffer(tx.to)
self.vm.stateManager.dumpStorage(account, (storage) => {
self.storageCache[self.processingHash][tx['to']] = storage
self.lastProcessedStorageTxHash[tx['to']] = self.processingHash
self.storageCache[self.processingHash][tx.to] = storage
self.lastProcessedStorageTxHash[tx.to] = self.processingHash
})
}
this.processingIndex = 0
@ -134,7 +133,7 @@ export class Web3VmProvider {
self.vmTraces[self.processingHash].gas = '0x' + data.gasUsed.toString(16)
const logs = []
for (let l in data.execResult.logs) {
for (const l in data.execResult.logs) {
const log = data.execResult.logs[l]
const topics = []
if (log[1].length > 0) {
@ -218,7 +217,7 @@ export class Web3VmProvider {
const preimage = this.getSha3Input(previousopcode.stack, previousopcode.memory)
const imageHash = step.stack[step.stack.length - 1].replace('0x', '')
self.sha3Preimages[imageHash] = {
'preimage': preimage
preimage: preimage
}
}

@ -3,7 +3,6 @@
"compilerOptions": {
"module": "commonjs",
"outDir": "../../dist/out-tsc",
"allowJs": true,
"declaration": true,
"rootDir": "./",
"types": ["node"]
@ -12,9 +11,6 @@
"**/*.spec.js",
"test/"
],
"include": [
"src/**/*.js",
"./index.js"
]
"include": ["**/*.ts"]
}

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

Loading…
Cancel
Save