Commit 2e9b7148 authored by aniket-engg's avatar aniket-engg Committed by Aniket

linting passed

parent 6704b46b
...@@ -4,7 +4,10 @@ ...@@ -4,7 +4,10 @@
"@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",
"@typescript-eslint/no-this-alias": "off" "@typescript-eslint/no-this-alias": "off",
"standard/no-callback-literal": "off",
"camelcase": "off",
"no-unused-vars": "off"
}, },
"env": { "env": {
"browser": true, "browser": true,
......
'use strict' 'use strict'
export class EventManager { export class EventManager {
registered registered
anonymous anonymous
constructor() { constructor () {
this.registered = {} this.registered = {}
this.anonymous = {} this.anonymous = {}
} }
...@@ -26,7 +25,7 @@ export class EventManager { ...@@ -26,7 +25,7 @@ export class EventManager {
func = obj func = obj
obj = this.anonymous 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) { if (this.registered[eventName][reg].obj === obj && this.registered[eventName][reg].func === func) {
this.registered[eventName].splice(reg, 1) this.registered[eventName].splice(reg, 1)
} }
...@@ -49,7 +48,7 @@ export class EventManager { ...@@ -49,7 +48,7 @@ export class EventManager {
func = obj func = obj
obj = this.anonymous obj = this.anonymous
} }
this.registered[eventName].push({obj, func}) this.registered[eventName].push({ obj, func })
} }
/* /*
...@@ -63,10 +62,9 @@ export class EventManager { ...@@ -63,10 +62,9 @@ export class EventManager {
if (!this.registered[eventName]) { if (!this.registered[eventName]) {
return return
} }
for (let listener in this.registered[eventName]) { for (const listener in this.registered[eventName]) {
const l = this.registered[eventName][listener] const l = this.registered[eventName][listener]
l.func.apply(l.obj === this.anonymous ? {} : l.obj, args) l.func.apply(l.obj === this.anonymous ? {} : l.obj, args)
} }
} }
} }
...@@ -9,11 +9,11 @@ import { visitContracts } from './txHelper' ...@@ -9,11 +9,11 @@ import { visitContracts } from './txHelper'
export class EventsDecoder { export class EventsDecoder {
resolveReceipt resolveReceipt
constructor ({resolveReceipt}) { constructor ({ resolveReceipt }) {
this.resolveReceipt = resolveReceipt this.resolveReceipt = resolveReceipt
} }
/** /**
* use Transaction Receipt to decode logs. assume that the transaction as already been resolved by txListener. * 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. * logs are decoded only if the contract if known by remix.
* *
...@@ -41,7 +41,7 @@ export class EventsDecoder { ...@@ -41,7 +41,7 @@ export class EventsDecoder {
_eventABI (contract) { _eventABI (contract) {
const eventABI = {} const eventABI = {}
const abi = new ethers.utils.Interface(contract.abi) 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) const event = abi.getEvent(e)
eventABI[abi.getEventTopic(e).replace('0x', '')] = { event: event.name, inputs: event.inputs, object: event, abi: abi } eventABI[abi.getEventTopic(e).replace('0x', '')] = { event: event.name, inputs: event.inputs, object: event, abi: abi }
} }
...@@ -57,10 +57,10 @@ export class EventsDecoder { ...@@ -57,10 +57,10 @@ export class EventsDecoder {
} }
_event (hash, eventsABI) { _event (hash, eventsABI) {
for (let k in eventsABI) { for (const k in eventsABI) {
if (eventsABI[k][hash]) { if (eventsABI[k][hash]) {
let event = eventsABI[k][hash] const event = eventsABI[k][hash]
for (let input of event.inputs) { for (const input of event.inputs) {
if (input.type === 'function') { if (input.type === 'function') {
input.type = 'bytes24' input.type = 'bytes24'
input.baseType = 'bytes24' input.baseType = 'bytes24'
...@@ -90,7 +90,7 @@ export class EventsDecoder { ...@@ -90,7 +90,7 @@ export class EventsDecoder {
_decodeEvents (tx, logs, contractName, compiledContracts, cb) { _decodeEvents (tx, logs, contractName, compiledContracts, cb) {
const eventsABI = this._eventsABI(compiledContracts) const eventsABI = this._eventsABI(compiledContracts)
const events = [] const events = []
for (let i in logs) { for (const i in logs) {
// [address, topics, mem] // [address, topics, mem]
const log = logs[i] const log = logs[i]
const topicId = log.topics[0] const topicId = log.topics[0]
......
...@@ -2,17 +2,17 @@ ...@@ -2,17 +2,17 @@
'use strict' 'use strict'
import Web3 from 'web3' import Web3 from 'web3'
import { EventManager } from '../eventManager' import { EventManager } from '../eventManager'
const EthJSVM = require('ethereumjs-vm').default
import { rlp, keccak, bufferToHex } from 'ethereumjs-util' import { rlp, keccak, bufferToHex } from 'ethereumjs-util'
const StateManager = require('ethereumjs-vm/dist/state/stateManager').default
import { Web3VmProvider } from '../web3Provider/web3VmProvider' 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') const LogsManager = require('./logsManager.js')
declare let ethereum: any; declare let ethereum: any
let web3 let web3
if (typeof window !== 'undefined' && typeof window['ethereum'] !== 'undefined') { if (typeof window !== 'undefined' && typeof window.ethereum !== 'undefined') {
var injectedProvider = window['ethereum'] var injectedProvider = window.ethereum
web3 = new Web3(injectedProvider) web3 = new Web3(injectedProvider)
} else { } else {
web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8545')) web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8545'))
...@@ -65,7 +65,7 @@ class StateManagerCommonStorageDump extends StateManager { ...@@ -65,7 +65,7 @@ class StateManagerCommonStorageDump extends StateManager {
} }
setStateRoot (stateRoot, cb) { setStateRoot (stateRoot, cb) {
let checkpoint = this._checkpointCount const checkpoint = this._checkpointCount
this._checkpointCount = 0 this._checkpointCount = 0
super.setStateRoot(stateRoot, (err) => { super.setStateRoot(stateRoot, (err) => {
this._checkpointCount = checkpoint this._checkpointCount = checkpoint
...@@ -116,7 +116,7 @@ export class ExecutionContext { ...@@ -116,7 +116,7 @@ export class ExecutionContext {
executionContext executionContext
listenOnLastBlockId listenOnLastBlockId
constructor() { constructor () {
this.event = new EventManager() this.event = new EventManager()
this.logsManager = new LogsManager() this.logsManager = new LogsManager()
this.executionContext = null this.executionContext = null
...@@ -306,13 +306,12 @@ export class ExecutionContext { ...@@ -306,13 +306,12 @@ export class ExecutionContext {
} }
txDetailsLink (network, hash) { txDetailsLink (network, hash) {
const transactionDetailsLinks = { const transactionDetailsLinks = {
'Main': 'https://www.etherscan.io/tx/', Main: 'https://www.etherscan.io/tx/',
'Rinkeby': 'https://rinkeby.etherscan.io/tx/', Rinkeby: 'https://rinkeby.etherscan.io/tx/',
'Ropsten': 'https://ropsten.etherscan.io/tx/', Ropsten: 'https://ropsten.etherscan.io/tx/',
'Kovan': 'https://kovan.etherscan.io/tx/', Kovan: 'https://kovan.etherscan.io/tx/',
'Goerli': 'https://goerli.etherscan.io/tx/' Goerli: 'https://goerli.etherscan.io/tx/'
} }
if (transactionDetailsLinks[network]) { if (transactionDetailsLinks[network]) {
...@@ -338,4 +337,3 @@ export class ExecutionContext { ...@@ -338,4 +337,3 @@ export class ExecutionContext {
this.txs[tx] = block this.txs[tx] = block
} }
} }
...@@ -2,7 +2,6 @@ import { eachOf } from 'async' ...@@ -2,7 +2,6 @@ import { eachOf } from 'async'
import { randomBytes } from 'crypto' import { randomBytes } from 'crypto'
export class LogsManager { export class LogsManager {
notificationCallbacks notificationCallbacks
subscriptions subscriptions
filters filters
...@@ -19,31 +18,31 @@ export class LogsManager { ...@@ -19,31 +18,31 @@ export class LogsManager {
checkBlock (blockNumber, block, web3) { checkBlock (blockNumber, block, web3) {
eachOf(block.transactions, (tx, i, next) => { 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) => { 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 }) this.oldLogs.push({ type: 'block', blockNumber, block, tx, log, txNumber: i })
let subscriptions = this.getSubscriptionsFor({ type: 'block', blockNumber, block, tx, log }) const subscriptions = this.getSubscriptionsFor({ type: 'block', blockNumber, block, tx, log })
for (let subscriptionId of subscriptions) { for (const subscriptionId of subscriptions) {
let result = { const result = {
'logIndex': '0x1', // 1 logIndex: '0x1', // 1
'blockNumber': blockNumber, blockNumber: blockNumber,
'blockHash': ('0x' + block.hash().toString('hex')), blockHash: ('0x' + block.hash().toString('hex')),
'transactionHash': ('0x' + tx.hash().toString('hex')), transactionHash: ('0x' + tx.hash().toString('hex')),
'transactionIndex': '0x' + i.toString(16), transactionIndex: '0x' + i.toString(16),
// TODO: if it's a contract deploy, it should be that address instead // TODO: if it's a contract deploy, it should be that address instead
'address': log.address, address: log.address,
'data': log.data, data: log.data,
'topics': log.topics topics: log.topics
} }
if (result.address === '0x') { if (result.address === '0x') {
delete result.address 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) this.transmit(response)
} }
} }
...@@ -69,12 +68,12 @@ export class LogsManager { ...@@ -69,12 +68,12 @@ export class LogsManager {
} }
getSubscriptionsFor (changeEvent) { getSubscriptionsFor (changeEvent) {
let matchedSubscriptions = [] const matchedSubscriptions = []
for (let subscriptionId of Object.keys(this.subscriptions)) { for (const subscriptionId of Object.keys(this.subscriptions)) {
const subscriptionParams = this.subscriptions[subscriptionId] const subscriptionParams = this.subscriptions[subscriptionId]
const [queryType, queryFilter] = subscriptionParams const [queryType, queryFilter] = subscriptionParams
if (this.eventMatchesFilter(changeEvent, queryType, queryFilter || {topics: []})) { if (this.eventMatchesFilter(changeEvent, queryType, queryFilter || { topics: [] })) {
matchedSubscriptions.push(subscriptionId) matchedSubscriptions.push(subscriptionId)
} }
} }
...@@ -103,7 +102,7 @@ export class LogsManager { ...@@ -103,7 +102,7 @@ export class LogsManager {
} }
subscribe (params) { subscribe (params) {
let subscriptionId = '0x' + randomBytes(16).toString('hex') const subscriptionId = '0x' + randomBytes(16).toString('hex')
this.subscriptions[subscriptionId] = params this.subscriptions[subscriptionId] = params
return subscriptionId return subscriptionId
} }
...@@ -129,14 +128,14 @@ export class LogsManager { ...@@ -129,14 +128,14 @@ export class LogsManager {
} }
getLogsForFilter (filterId, logsOnly) { getLogsForFilter (filterId, logsOnly) {
const {filterType, params} = this.filters[filterId] const { filterType, params } = this.filters[filterId]
const tracking = this.filterTracking[filterId] const tracking = this.filterTracking[filterId]
if (logsOnly || filterType === 'filter') { if (logsOnly || filterType === 'filter') {
return this.getLogsFor(params || {topics: []}) return this.getLogsFor(params || { topics: [] })
} }
if (filterType === 'block') { 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] tracking.block = blocks[blocks.length - 1]
return blocks.map(block => ('0x' + block.hash().toString('hex'))) return blocks.map(block => ('0x' + block.hash().toString('hex')))
} }
...@@ -146,24 +145,23 @@ export class LogsManager { ...@@ -146,24 +145,23 @@ export class LogsManager {
} }
getLogsFor (params) { getLogsFor (params) {
let results = [] const results = []
for (let log of this.oldLogs) { for (const log of this.oldLogs) {
if (this.eventMatchesFilter(log, 'logs', params)) { if (this.eventMatchesFilter(log, 'logs', params)) {
results.push({ results.push({
'logIndex': '0x1', // 1 logIndex: '0x1', // 1
'blockNumber': log.blockNumber, blockNumber: log.blockNumber,
'blockHash': ('0x' + log.block.hash().toString('hex')), blockHash: ('0x' + log.block.hash().toString('hex')),
'transactionHash': ('0x' + log.tx.hash().toString('hex')), transactionHash: ('0x' + log.tx.hash().toString('hex')),
'transactionIndex': '0x' + log.txNumber.toString(16), transactionIndex: '0x' + log.txNumber.toString(16),
// TODO: if it's a contract deploy, it should be that address instead // TODO: if it's a contract deploy, it should be that address instead
'address': log.log.address, address: log.log.address,
'data': log.log.data, data: log.log.data,
'topics': log.log.topics topics: log.log.topics
}) })
} }
} }
return results return results
} }
} }
...@@ -56,7 +56,7 @@ export function callFunction (from, to, data, value, gasLimit, funAbi, txRunner, ...@@ -56,7 +56,7 @@ export function callFunction (from, to, data, value, gasLimit, funAbi, txRunner,
* @param {Object} txResult - the value returned by the vm * @param {Object} txResult - the value returned by the vm
* @return {Object} - { error: true/false, message: DOMNode } * @return {Object} - { error: true/false, message: DOMNode }
*/ */
export function checkVMError (txResult) { export function checkVMError (txResult) {
const errorCode = { const errorCode = {
OUT_OF_GAS: 'out of gas', OUT_OF_GAS: 'out of gas',
STACK_UNDERFLOW: 'stack underflow', STACK_UNDERFLOW: 'stack underflow',
...@@ -81,10 +81,10 @@ export function callFunction (from, to, data, value, gasLimit, funAbi, txRunner, ...@@ -81,10 +81,10 @@ export function callFunction (from, to, data, value, gasLimit, funAbi, txRunner,
const error = `VM error: ${exceptionError}.\n` const error = `VM error: ${exceptionError}.\n`
let msg let msg
if (exceptionError === errorCode.INVALID_OPCODE) { 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 ret.error = true
} else if (exceptionError === errorCode.OUT_OF_GAS) { } 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 ret.error = true
} else if (exceptionError === errorCode.REVERT) { } else if (exceptionError === errorCode.REVERT) {
const returnData = txResult.result.execResult.returnValue const returnData = txResult.result.execResult.returnValue
...@@ -94,15 +94,13 @@ export function callFunction (from, to, data, value, gasLimit, funAbi, txRunner, ...@@ -94,15 +94,13 @@ export function callFunction (from, to, data, value, gasLimit, funAbi, txRunner,
const reason = abiCoder.decode(['string'], returnData.slice(4))[0] 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}".` msg = `\tThe transaction has been reverted to the initial state.\nReason provided by the contract: "${reason}".`
} else { } 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 ret.error = true
} else if (exceptionError === errorCode.STATIC_STATE_CHANGE) { } 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.error = true
} }
ret.message = `${error}${exceptionError}${msg}\tDebug the transaction to get more information.` ret.message = `${error}${exceptionError}${msg}\tDebug the transaction to get more information.`
return ret return ret
} }
'use strict' 'use strict'
import { ethers } from 'ethers' 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 { eachOfSeries } from 'async'
import { linkBytecode } from 'solc/linker' import { linkBytecode as linkBytecodeSolc } from 'solc/linker'
import { isValidAddress, addHexPrefix } from 'ethereumjs-util' import { isValidAddress, addHexPrefix } from 'ethereumjs-util'
/** /**
...@@ -99,8 +99,8 @@ export function encodeConstructorCallAndLinkLibraries (contract, params, funAbi, ...@@ -99,8 +99,8 @@ export function encodeConstructorCallAndLinkLibraries (contract, params, funAbi,
let bytecodeToDeploy = contract.evm.bytecode.object let bytecodeToDeploy = contract.evm.bytecode.object
if (bytecodeToDeploy.indexOf('_') >= 0) { if (bytecodeToDeploy.indexOf('_') >= 0) {
if (linkLibraries && linkReferences) { if (linkLibraries && linkReferences) {
for (let libFile in linkLibraries) { for (const libFile in linkLibraries) {
for (let lib in linkLibraries[libFile]) { for (const lib in linkLibraries[libFile]) {
const address = linkLibraries[libFile][lib] const address = linkLibraries[libFile][lib]
if (!isValidAddress(address)) return callback(address + ' is not a valid address. Please check the provided address is valid.') 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) bytecodeToDeploy = this.linkLibraryStandardFromlinkReferences(lib, address.replace('0x', ''), bytecodeToDeploy, linkReferences)
...@@ -140,14 +140,14 @@ export function encodeConstructorCallAndDeployLibraries (contractName, contract, ...@@ -140,14 +140,14 @@ export function encodeConstructorCallAndDeployLibraries (contractName, contract,
callback('Error deploying required libraries: ' + err) callback('Error deploying required libraries: ' + err)
} else { } else {
bytecodeToDeploy = bytecode + dataHex 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) }, callbackStep, callbackDeployLibrary)
return return
} else { } else {
dataHex = bytecodeToDeploy + encodedParam.dataHex 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 ...@@ -204,7 +204,7 @@ export function buildData (contractName, contract, contracts, isConstructor, fun
callback('Error deploying required libraries: ' + err) callback('Error deploying required libraries: ' + err)
} else { } else {
bytecodeToDeploy = bytecode + dataHex 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) }, callbackStep, callbackDeployLibrary)
return return
...@@ -309,7 +309,7 @@ export function deployLibrary (libraryName, libraryShortName, library, contracts ...@@ -309,7 +309,7 @@ export function deployLibrary (libraryName, libraryShortName, library, contracts
}, callbackStep, callbackDeployLibrary) }, callbackStep, callbackDeployLibrary)
} else { } else {
callbackStep(`creation of library ${libraryName} pending...`) 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) => { callbackDeployLibrary({ data: data, useCall: false }, (err, txResult) => {
if (err) { if (err) {
return callback(err) return callback(err)
...@@ -322,8 +322,8 @@ export function deployLibrary (libraryName, libraryShortName, library, contracts ...@@ -322,8 +322,8 @@ export function deployLibrary (libraryName, libraryShortName, library, contracts
} }
export function linkLibraryStandardFromlinkReferences (libraryName, address, bytecode, linkReferences) { export function linkLibraryStandardFromlinkReferences (libraryName, address, bytecode, linkReferences) {
for (let file in linkReferences) { for (const file in linkReferences) {
for (let libName in linkReferences[file]) { for (const libName in linkReferences[file]) {
if (libraryName === libName) { if (libraryName === libName) {
bytecode = this.setLibraryAddress(address, bytecode, linkReferences[file][libName]) bytecode = this.setLibraryAddress(address, bytecode, linkReferences[file][libName])
} }
...@@ -338,7 +338,7 @@ export function linkLibraryStandard (libraryName, address, bytecode, contract) { ...@@ -338,7 +338,7 @@ export function linkLibraryStandard (libraryName, address, bytecode, contract) {
export function setLibraryAddress (address, bytecodeToLink, positions) { export function setLibraryAddress (address, bytecodeToLink, positions) {
if (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}})(.*)`)) const regpos = bytecodeToLink.match(new RegExp(`(.{${2 * pos.start}})(.{${2 * pos.length}})(.*)`))
if (regpos) { if (regpos) {
bytecodeToLink = regpos[1] + address + regpos[3] bytecodeToLink = regpos[1] + address + regpos[3]
...@@ -349,7 +349,7 @@ export function setLibraryAddress (address, bytecodeToLink, positions) { ...@@ -349,7 +349,7 @@ export function setLibraryAddress (address, bytecodeToLink, positions) {
} }
export function linkLibrary (libraryName, address, bytecodeToLink) { export function linkLibrary (libraryName, address, bytecodeToLink) {
return linkBytecode(bytecodeToLink, { [libraryName]: addHexPrefix(address) }) return linkBytecodeSolc(bytecodeToLink, { [libraryName]: addHexPrefix(address) })
} }
export function decodeResponse (response, fnabi) { export function decodeResponse (response, fnabi) {
...@@ -448,5 +448,3 @@ export function parseFunctionParams (params) { ...@@ -448,5 +448,3 @@ export function parseFunctionParams (params) {
export function isArrayOrStringStart (str, index) { export function isArrayOrStringStart (str, index) {
return str.charAt(index) === '"' || str.charAt(index) === '[' return str.charAt(index) === '"' || str.charAt(index) === '['
} }
...@@ -34,13 +34,13 @@ export function encodeParams (funABI, args) { ...@@ -34,13 +34,13 @@ export function encodeParams (funABI, args) {
export function encodeFunctionId (funABI) { export function encodeFunctionId (funABI) {
if (funABI.type === 'fallback' || funABI.type === 'receive') return '0x' 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) return abi.getSighash(funABI.name)
} }
export function sortAbiFunction (contractabi) { export function sortAbiFunction (contractabi) {
// Check if function is constant (introduced with Solidity 0.6.0) // 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, // Sorts the list of ABI entries. Constant functions will appear first,
// followed by non-constant functions. Within those t wo groupings, functions // followed by non-constant functions. Within those t wo groupings, functions
// will be sorted by their names. // will be sorted by their names.
...@@ -61,7 +61,7 @@ export function sortAbiFunction (contractabi) { ...@@ -61,7 +61,7 @@ export function sortAbiFunction (contractabi) {
} }
export function getConstructorInterface (abi) { 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') { if (typeof abi === 'string') {
try { try {
abi = JSON.parse(abi) abi = JSON.parse(abi)
...@@ -75,7 +75,7 @@ export function getConstructorInterface (abi) { ...@@ -75,7 +75,7 @@ export function getConstructorInterface (abi) {
if (abi[i].type === 'constructor') { if (abi[i].type === 'constructor') {
funABI.inputs = abi[i].inputs || [] funABI.inputs = abi[i].inputs || []
funABI.payable = abi[i].payable funABI.payable = abi[i].payable
funABI['stateMutability'] = abi[i].stateMutability funABI.stateMutability = abi[i].stateMutability
break break
} }
} }
...@@ -102,7 +102,7 @@ export function getFunction (abi, fnName) { ...@@ -102,7 +102,7 @@ export function getFunction (abi, fnName) {
const fn = abi[i] const fn = abi[i]
if (fn.type === 'function' && fnName === fn.name + '(' + fn.inputs.map((value) => { if (fn.type === 'function' && fnName === fn.name + '(' + fn.inputs.map((value) => {
if (value.components) { 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 return fullType.replace(/tuple/g, '') // return of makeFullTypeDefinition might contain `tuple`, need to remove it cause `methodIdentifier` (fnName) does not include `tuple` keyword
} else { } else {
return value.type return value.type
...@@ -136,8 +136,8 @@ export function getReceiveInterface (abi) { ...@@ -136,8 +136,8 @@ export function getReceiveInterface (abi) {
* @param {String} name - contract name * @param {String} name - contract name
* @returns contract obj and associated file: { contract, file } or null * @returns contract obj and associated file: { contract, file } or null
*/ */
export function getContract(contractName, contracts) { export function getContract (contractName, contracts) {
for (let file in contracts) { for (const file in contracts) {
if (contracts[file][contractName]) { if (contracts[file][contractName]) {
return { object: contracts[file][contractName], file: file } return { object: contracts[file][contractName], file: file }
} }
...@@ -150,9 +150,9 @@ export function getReceiveInterface (abi) { ...@@ -150,9 +150,9 @@ export function getReceiveInterface (abi) {
* stop visiting when cb return true * stop visiting when cb return true
* @param {Function} cb - callback * @param {Function} cb - callback
*/ */
export function visitContracts (contracts, cb) { export function visitContracts (contracts, cb) {
for (let file in contracts) { for (const file in contracts) {
for (let name in contracts[file]) { for (const name in contracts[file]) {
if (cb({ name: name, object: contracts[file][name], file: file })) return if (cb({ name: name, object: contracts[file][name], file: file })) return
} }
} }
......
...@@ -8,7 +8,7 @@ import { ExecutionContext } from './execution-context' ...@@ -8,7 +8,7 @@ import { ExecutionContext } from './execution-context'
import { decodeResponse } from './txFormat' import { decodeResponse } from './txFormat'
import { getFunction, getReceiveInterface, getConstructorInterface, visitContracts, makeFullTypeDefinition } from './txHelper' import { getFunction, getReceiveInterface, getConstructorInterface, visitContracts, makeFullTypeDefinition } from './txHelper'
function addExecutionCosts(txResult, tx) { function addExecutionCosts (txResult, tx) {
if (txResult && txResult.result) { if (txResult && txResult.result) {
if (txResult.result.execResult) { if (txResult.result.execResult) {
tx.returnValue = txResult.result.execResult.returnValue tx.returnValue = txResult.result.execResult.returnValue
...@@ -26,7 +26,6 @@ function addExecutionCosts(txResult, tx) { ...@@ -26,7 +26,6 @@ function addExecutionCosts(txResult, tx) {
* *
*/ */
export class TxListener { export class TxListener {
event event
executionContext executionContext
_resolvedTransactions _resolvedTransactions
...@@ -179,7 +178,7 @@ export class TxListener { ...@@ -179,7 +178,7 @@ export class TxListener {
_manageBlock (blockNumber) { _manageBlock (blockNumber) {
this.executionContext.web3().eth.getBlock(blockNumber, true, (error, result) => { this.executionContext.web3().eth.getBlock(blockNumber, true, (error, result) => {
if (!error) { if (!error) {
this._newBlock(Object.assign({type: 'web3'}, result)) this._newBlock(Object.assign({ type: 'web3' }, result))
} }
}) })
} }
...@@ -242,13 +241,13 @@ export class TxListener { ...@@ -242,13 +241,13 @@ export class TxListener {
const code = tx.input const code = tx.input
contract = this._tryResolveContract(code, contracts, true) contract = this._tryResolveContract(code, contracts, true)
if (contract) { if (contract) {
let address = receipt.contractAddress const address = receipt.contractAddress
this._resolvedContracts[address] = contract this._resolvedContracts[address] = contract
fun = this._resolveFunction(contract, tx, true) fun = this._resolveFunction(contract, tx, true)
if (this._resolvedTransactions[tx.hash]) { if (this._resolvedTransactions[tx.hash]) {
this._resolvedTransactions[tx.hash].contractAddress = address 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() return cb()
} else { } else {
...@@ -262,7 +261,7 @@ export class TxListener { ...@@ -262,7 +261,7 @@ export class TxListener {
if (contract) { if (contract) {
this._resolvedContracts[tx.to] = contract this._resolvedContracts[tx.to] = contract
const fun = this._resolveFunction(contract, tx, false) 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() return cb()
...@@ -271,7 +270,7 @@ export class TxListener { ...@@ -271,7 +270,7 @@ export class TxListener {
} }
if (contract) { if (contract) {
fun = this._resolveFunction(contract, tx, false) 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() return cb()
} }
...@@ -286,7 +285,7 @@ export class TxListener { ...@@ -286,7 +285,7 @@ export class TxListener {
const inputData = tx.input.replace('0x', '') const inputData = tx.input.replace('0x', '')
if (!isCtor) { if (!isCtor) {
const methodIdentifiers = contract.object.evm.methodIdentifiers const methodIdentifiers = contract.object.evm.methodIdentifiers
for (let fn in methodIdentifiers) { for (const fn in methodIdentifiers) {
if (methodIdentifiers[fn] === inputData.substring(0, 8)) { if (methodIdentifiers[fn] === inputData.substring(0, 8)) {
const fnabi = getFunction(abi, fn) const fnabi = getFunction(abi, fn)
this._resolvedTransactions[tx.hash] = { this._resolvedTransactions[tx.hash] = {
......
...@@ -6,7 +6,6 @@ import { ExecutionContext } from './execution-context' ...@@ -6,7 +6,6 @@ import { ExecutionContext } from './execution-context'
import { EventManager } from '../eventManager' import { EventManager } from '../eventManager'
export class TxRunner { export class TxRunner {
event event
executionContext executionContext
_api _api
...@@ -73,7 +72,7 @@ export class TxRunner { ...@@ -73,7 +72,7 @@ export class TxRunner {
resolve({ resolve({
result, result,
tx, tx,
transactionHash: result ? result['transactionHash'] : null transactionHash: result ? result.transactionHash : null
}) })
}) })
} }
...@@ -87,7 +86,7 @@ export class TxRunner { ...@@ -87,7 +86,7 @@ export class TxRunner {
} }
} }
execute(args, confirmationCb, gasEstimationForceSend, promptCb, callback) { execute (args, confirmationCb, gasEstimationForceSend, promptCb, callback) {
let data = args.data let data = args.data
if (data.slice(0, 2) !== '0x') { if (data.slice(0, 2) !== '0x') {
data = '0x' + data data = '0x' + data
...@@ -157,7 +156,7 @@ export class TxRunner { ...@@ -157,7 +156,7 @@ export class TxRunner {
runBlockInVm (tx, block, callback) { runBlockInVm (tx, block, callback) {
this.executionContext.vm().runBlock({ block: block, generate: true, skipBlockValidation: true, skipBalance: false }).then((results) => { 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) { if (result) {
const status = result.execResult.exceptionError ? 0 : 1 const status = result.execResult.exceptionError ? 0 : 1
result.status = `0x${status}` result.status = `0x${status}`
...@@ -177,7 +176,7 @@ export class TxRunner { ...@@ -177,7 +176,7 @@ export class TxRunner {
const tx = { from: from, to: to, data: data, value: value } const tx = { from: from, to: to, data: data, value: value }
if (useCall) { if (useCall) {
tx['gas'] = gasLimit tx.gas = gasLimit
return this.executionContext.web3().eth.call(tx, function (error, result) { return this.executionContext.web3().eth.call(tx, function (error, result) {
callback(error, { callback(error, {
result: result, result: result,
...@@ -192,7 +191,7 @@ export class TxRunner { ...@@ -192,7 +191,7 @@ export class TxRunner {
} }
gasEstimationForceSend(err, () => { gasEstimationForceSend(err, () => {
// callback is called whenever no error // callback is called whenever no error
tx['gas'] = !gasEstimation ? gasLimit : gasEstimation tx.gas = !gasEstimation ? gasLimit : gasEstimation
if (this._api.config.getUnpersistedProperty('doNotShowTransactionConfirmationAgain')) { if (this._api.config.getUnpersistedProperty('doNotShowTransactionConfirmationAgain')) {
return this._executeTx(tx, null, this._api, promptCb, callback) return this._executeTx(tx, null, this._api, promptCb, callback)
...@@ -204,7 +203,7 @@ export class TxRunner { ...@@ -204,7 +203,7 @@ export class TxRunner {
return return
} }
confirmCb(network, tx, tx['gas'], (gasPrice) => { confirmCb(network, tx, tx.gas, (gasPrice) => {
return this._executeTx(tx, gasPrice, this._api, promptCb, callback) return this._executeTx(tx, gasPrice, this._api, promptCb, callback)
}, (error) => { }, (error) => {
callback(error) callback(error)
...@@ -258,7 +257,7 @@ async function tryTillTxAvailable (txhash, executionContext) { ...@@ -258,7 +257,7 @@ async function tryTillTxAvailable (txhash, executionContext) {
async function pause () { return new Promise((resolve, reject) => { setTimeout(resolve, 500) }) } 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) { if (!self.runAsync && Object.keys(self.pendingTxs).length) {
return self.queusTxs.push({ tx, stamp, callback }) return self.queusTxs.push({ tx, stamp, callback })
} }
......
...@@ -4,7 +4,7 @@ import { BN, bufferToHex } from 'ethereumjs-util' ...@@ -4,7 +4,7 @@ import { BN, bufferToHex } from 'ethereumjs-util'
export function toInt (h) { export function toInt (h) {
if (h.indexOf && h.indexOf('0x') === 0) { if (h.indexOf && h.indexOf('0x') === 0) {
return (new BN(h.replace('0x', ''), 16)).toString(10) 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.toString(10)
} }
return h return h
...@@ -26,7 +26,7 @@ function convertToString (v) { ...@@ -26,7 +26,7 @@ function convertToString (v) {
return bufferToHex(v) return bufferToHex(v)
} else if (typeof v === 'object') { } else if (typeof v === 'object') {
const retObject = {} const retObject = {}
for (let i in v) { for (const i in v) {
retObject[i] = convertToString(v[i]) retObject[i] = convertToString(v[i])
} }
return retObject return retObject
......
...@@ -13,8 +13,8 @@ export function compilerInput (contracts) { ...@@ -13,8 +13,8 @@ export function compilerInput (contracts) {
}, },
outputSelection: { outputSelection: {
'*': { '*': {
'': [ 'ast' ], '': ['ast'],
'*': [ 'abi', 'metadata', 'evm.legacyAssembly', 'evm.bytecode', 'evm.deployedBytecode', 'evm.methodIdentifiers', 'evm.gasEstimates' ] '*': ['abi', 'metadata', 'evm.legacyAssembly', 'evm.bytecode', 'evm.deployedBytecode', 'evm.methodIdentifiers', 'evm.gasEstimates']
} }
} }
} }
......
...@@ -45,8 +45,8 @@ export function tryConvertAsciiFormat (memorySlot) { ...@@ -45,8 +45,8 @@ export function tryConvertAsciiFormat (memorySlot) {
*/ */
export function formatCss (css1, css2) { export function formatCss (css1, css2) {
let ret = '' let ret = ''
for (let arg in arguments) { for (const arg in arguments) {
for (let k in arguments[arg]) { for (const k in arguments[arg]) {
if (arguments[arg][k] && ret.indexOf(k) === -1) { if (arguments[arg][k] && ret.indexOf(k) === -1) {
if (k.indexOf('*') === 0) { if (k.indexOf('*') === 0) {
ret += arguments[arg][k] ret += arguments[arg][k]
......
...@@ -18,11 +18,11 @@ export function setProvider (web3, url) { ...@@ -18,11 +18,11 @@ export function setProvider (web3, url) {
export function web3DebugNode (network) { export function web3DebugNode (network) {
const web3DebugNodes = { const web3DebugNodes = {
'Main': 'https://gethmainnet.komputing.org', Main: 'https://gethmainnet.komputing.org',
'Rinkeby': 'https://remix-rinkeby.ethdevops.io', Rinkeby: 'https://remix-rinkeby.ethdevops.io',
'Ropsten': 'https://remix-ropsten.ethdevops.io', Ropsten: 'https://remix-ropsten.ethdevops.io',
'Goerli': 'https://remix-goerli.ethdevops.io', Goerli: 'https://remix-goerli.ethdevops.io',
'Kovan': 'https://remix-kovan.ethdevops.io' Kovan: 'https://remix-kovan.ethdevops.io'
} }
if (web3DebugNodes[network]) { if (web3DebugNodes[network]) {
return this.loadWeb3(web3DebugNodes[network]) return this.loadWeb3(web3DebugNodes[network])
...@@ -69,4 +69,4 @@ export function extend (web3) { ...@@ -69,4 +69,4 @@ export function extend (web3) {
properties: [] properties: []
}) })
} }
} }
...@@ -10,7 +10,6 @@ import { ExecutionContext } from './execution/execution-context' ...@@ -10,7 +10,6 @@ import { ExecutionContext } from './execution/execution-context'
import { resultToRemixTx } from './helpers/txResultHelper' import { resultToRemixTx } from './helpers/txResultHelper'
export class UniversalDApp { export class UniversalDApp {
events events
event event
executionContext executionContext
...@@ -124,11 +123,11 @@ export class UniversalDApp { ...@@ -124,11 +123,11 @@ export class UniversalDApp {
const address = privateToAddress(privateKey) const address = privateToAddress(privateKey)
// FIXME: we don't care about the callback, but we should still make this proper // 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) => { stateManager.getAccount(address, (error, account) => {
if (error) return console.log(error) if (error) return console.log(error)
account.balance = balance || '0xf00000000000000001' account.balance = balance || '0xf00000000000000001'
stateManager.putAccount(address, account, function cb(error) { stateManager.putAccount(address, account, function cb (error) {
if (error) console.log(error) if (error) console.log(error)
}) })
}) })
...@@ -141,17 +140,16 @@ export class UniversalDApp { ...@@ -141,17 +140,16 @@ export class UniversalDApp {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const provider = this.executionContext.getProvider() const provider = this.executionContext.getProvider()
switch (provider) { switch (provider) {
case 'vm': { case 'vm':
if (!this.accounts) { if (!this.accounts) {
if (cb) cb('No accounts?') if (cb) cb('No accounts?')
reject('No accounts?') reject(new Error('No accounts?'))
return return
} }
if (cb) cb(null, Object.keys(this.accounts)) if (cb) cb(null, Object.keys(this.accounts))
resolve(Object.keys(this.accounts)) resolve(Object.keys(this.accounts))
}
break break
case 'web3': { case 'web3':
if (this.config.get('settings/personal-mode')) { if (this.config.get('settings/personal-mode')) {
return this.executionContext.web3().personal.getListAccounts((error, accounts) => { return this.executionContext.web3().personal.getListAccounts((error, accounts) => {
if (cb) cb(error, accounts) if (cb) cb(error, accounts)
...@@ -165,7 +163,6 @@ export class UniversalDApp { ...@@ -165,7 +163,6 @@ export class UniversalDApp {
resolve(accounts) resolve(accounts)
}) })
} }
}
break break
case 'injected': { case 'injected': {
this.executionContext.web3().eth.getAccounts((error, accounts) => { this.executionContext.web3().eth.getAccounts((error, accounts) => {
...@@ -179,7 +176,7 @@ export class UniversalDApp { ...@@ -179,7 +176,7 @@ export class UniversalDApp {
} }
/** Get the balance of an address */ /** Get the balance of an address */
getBalance(address, cb) { getBalance (address, cb) {
address = stripHexPrefix(address) address = stripHexPrefix(address)
if (!this.executionContext.isVM()) { if (!this.executionContext.isVM()) {
...@@ -223,7 +220,7 @@ export class UniversalDApp { ...@@ -223,7 +220,7 @@ export class UniversalDApp {
* @param {Function} callback - callback. * @param {Function} callback - callback.
*/ */
createContract (data, confirmationCb, continueCb, promptCb, 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,7 +233,7 @@ export class UniversalDApp { ...@@ -236,7 +233,7 @@ export class UniversalDApp {
*/ */
callFunction (to, data, funAbi, confirmationCb, continueCb, promptCb, callback) { callFunction (to, data, funAbi, confirmationCb, continueCb, promptCb, callback) {
const useCall = funAbi.stateMutability === 'view' || funAbi.stateMutability === 'pure' 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)
} }
/** /**
...@@ -247,7 +244,7 @@ export class UniversalDApp { ...@@ -247,7 +244,7 @@ export class UniversalDApp {
* @param {Function} callback - callback. * @param {Function} callback - callback.
*/ */
sendRawTransaction (to, data, confirmationCb, continueCb, promptCb, 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 () { context () {
...@@ -345,7 +342,7 @@ export class UniversalDApp { ...@@ -345,7 +342,7 @@ export class UniversalDApp {
}) })
} }
self.getAccounts(function (err, accounts) { self.getAccounts(function (err, accounts) {
let address = accounts[0] const address = accounts[0]
if (err) return next(err) if (err) return next(err)
if (!address) return next('No accounts available') if (!address) return next('No accounts available')
...@@ -366,7 +363,7 @@ export class UniversalDApp { ...@@ -366,7 +363,7 @@ export class UniversalDApp {
self.event.trigger('initiatingTransaction', [timestamp, tx, payLoad]) self.event.trigger('initiatingTransaction', [timestamp, tx, payLoad])
self.txRunner.rawRun(tx, confirmationCb, continueCb, promptCb, self.txRunner.rawRun(tx, confirmationCb, continueCb, promptCb,
function (error, result) { 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]) self.event.trigger(eventName, [error, tx.from, tx.to, tx.data, tx.useCall, result, timestamp, payLoad])
if (error && (typeof (error) !== 'string')) { if (error && (typeof (error) !== 'string')) {
......
...@@ -10,7 +10,7 @@ import { BN, bufferToHex, keccak, setLengthLeft } from 'ethereumjs-util' ...@@ -10,7 +10,7 @@ import { BN, bufferToHex, keccak, setLengthLeft } from 'ethereumjs-util'
- swarm hash extraction - swarm hash extraction
- bytecode comparison - bytecode comparison
*/ */
/* /*
ints: IntArray ints: IntArray
*/ */
export function hexConvert (ints) { export function hexConvert (ints) {
...@@ -26,7 +26,7 @@ export function hexConvert (ints) { ...@@ -26,7 +26,7 @@ export function hexConvert (ints) {
return ret return ret
} }
/** /**
* Converts a hex string to an array of integers. * Converts a hex string to an array of integers.
*/ */
export function hexToIntArray (hexString) { export function hexToIntArray (hexString) {
...@@ -40,12 +40,12 @@ export function hexToIntArray (hexString) { ...@@ -40,12 +40,12 @@ export function hexToIntArray (hexString) {
return integers return integers
} }
/* /*
ints: list of BNs ints: list of BNs
*/ */
export function hexListFromBNs (bnList) { export function hexListFromBNs (bnList) {
const ret = [] const ret = []
for (let k in bnList) { for (const k in bnList) {
const v = bnList[k] const v = bnList[k]
if (BN.isBN(v)) { if (BN.isBN(v)) {
ret.push('0x' + v.toString('hex', 64)) ret.push('0x' + v.toString('hex', 64))
...@@ -61,7 +61,7 @@ export function hexListFromBNs (bnList) { ...@@ -61,7 +61,7 @@ export function hexListFromBNs (bnList) {
*/ */
export function hexListConvert (intsList) { export function hexListConvert (intsList) {
const ret = [] const ret = []
for (let k in intsList) { for (const k in intsList) {
ret.push(this.hexConvert(intsList[k])) ret.push(this.hexConvert(intsList[k]))
} }
return ret return ret
...@@ -144,7 +144,7 @@ export function findCall (index, rootCall) { ...@@ -144,7 +144,7 @@ export function findCall (index, rootCall) {
return ret[ret.length - 1] return ret[ret.length - 1]
} }
/** /**
* Find calls path from @args rootCall which leads to @args index (recursive) * Find calls path from @args rootCall which leads to @args index (recursive)
* *
* @param {Int} index - index of the vmtrace * @param {Int} index - index of the vmtrace
...@@ -157,13 +157,13 @@ export function buildCallPath (index, rootCall) { ...@@ -157,13 +157,13 @@ export function buildCallPath (index, rootCall) {
return ret return ret
} }
/** /**
* sha3 the given @arg value (left pad to 32 bytes) * sha3 the given @arg value (left pad to 32 bytes)
* *
* @param {String} value - value to sha3 * @param {String} value - value to sha3
* @return {Object} - return sha3ied value * @return {Object} - return sha3ied value
*/ */
export function sha3_256 (value) { export function sha3_256 (value) {
if (typeof value === 'string' && value.indexOf('0x') !== 0) { if (typeof value === 'string' && value.indexOf('0x') !== 0) {
value = '0x' + value value = '0x' + value
} }
...@@ -186,7 +186,7 @@ export function swarmHashExtraction () { ...@@ -186,7 +186,7 @@ export function swarmHashExtraction () {
* *
* @return {RegEx} * @return {RegEx}
*/ */
export function swarmHashExtractionPOC31 () { export function swarmHashExtractionPOC31 () {
return /a265627a7a72315820([0-9a-f]{64})64736f6c6343([0-9a-f]{6})0032$/ return /a265627a7a72315820([0-9a-f]{64})64736f6c6343([0-9a-f]{6})0032$/
} }
...@@ -227,7 +227,7 @@ export function extractSwarmHash (value) { ...@@ -227,7 +227,7 @@ export function extractSwarmHash (value) {
* *
* @return {bool} * @return {bool}
*/ */
export function compareByteCode (code1, code2) { export function compareByteCode (code1, code2) {
if (code1 === code2) return true if (code1 === code2) return true
if (code2 === '0x') return false // abstract contract. see comment if (code2 === '0x') return false // abstract contract. see comment
...@@ -271,7 +271,6 @@ export function escapeRegExp (str) { ...@@ -271,7 +271,6 @@ export function escapeRegExp (str) {
return str.replace(/[-[\]/{}()+?.\\^$|]/g, '\\$&') return str.replace(/[-[\]/{}()+?.\\^$|]/g, '\\$&')
} }
function replaceLibReference (code, pos) { function replaceLibReference (code, pos) {
return code.substring(0, pos) + '0000000000000000000000000000000000000000' + code.substring(pos + 40) return code.substring(0, pos) + '0000000000000000000000000000000000000000' + code.substring(pos + 40)
} }
...@@ -280,8 +279,8 @@ function findCallInternal (index, rootCall, callsPath) { ...@@ -280,8 +279,8 @@ function findCallInternal (index, rootCall, callsPath) {
const calls = Object.keys(rootCall.calls) const calls = Object.keys(rootCall.calls)
const ret = rootCall const ret = rootCall
callsPath.push(rootCall) callsPath.push(rootCall)
for (let k in calls) { for (const k in calls) {
let subCall = rootCall.calls[calls[k]] const subCall = rootCall.calls[calls[k]]
if (index >= subCall.start && index <= subCall.return) { if (index >= subCall.start && index <= subCall.return) {
findCallInternal(index, subCall, callsPath) findCallInternal(index, subCall, callsPath)
break break
......
...@@ -4,7 +4,7 @@ export class DummyProvider { ...@@ -4,7 +4,7 @@ export class DummyProvider {
providers providers
currentProvider currentProvider
constructor() { constructor () {
this.eth = {} this.eth = {}
this.debug = {} this.debug = {}
this.eth.getCode = (address, cb) => { return this.getCode(address, cb) } this.eth.getCode = (address, cb) => { return this.getCode(address, cb) }
...@@ -13,8 +13,8 @@ export class DummyProvider { ...@@ -13,8 +13,8 @@ export class DummyProvider {
this.eth.getBlockNumber = (cb) => { return this.getBlockNumber(cb) } this.eth.getBlockNumber = (cb) => { return this.getBlockNumber(cb) }
this.debug.traceTransaction = (hash, options, cb) => { return this.traceTransaction(hash, options, 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.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.providers = { HttpProvider: function (url) {} }
this.currentProvider = {'host': ''} this.currentProvider = { host: '' }
} }
getCode (address, cb) { getCode (address, cb) {
......
...@@ -2,9 +2,8 @@ import { Web3VmProvider } from './web3VmProvider' ...@@ -2,9 +2,8 @@ import { Web3VmProvider } from './web3VmProvider'
import { loadWeb3, extendWeb3 } from '../init' import { loadWeb3, extendWeb3 } from '../init'
export class Web3Providers { export class Web3Providers {
modes modes
constructor() { constructor () {
this.modes = {} this.modes = {}
} }
......
import { hexConvert, hexListFromBNs, formatMemory } from '../util' import { hexConvert, hexListFromBNs, formatMemory } from '../util'
import { normalizeHexAddress } from '../helpers/uiHelper' import { normalizeHexAddress } from '../helpers/uiHelper'
import { toChecksumAddress, BN, toBuffer, } from 'ethereumjs-util' import { toChecksumAddress, BN, toBuffer } from 'ethereumjs-util'
import Web3 from 'web3' import Web3 from 'web3'
export class Web3VmProvider { export class Web3VmProvider {
web3 web3
vm vm
vmTraces vmTraces
...@@ -54,8 +53,8 @@ export class Web3VmProvider { ...@@ -54,8 +53,8 @@ export class Web3VmProvider {
this.debug.traceTransaction = this.traceTransaction this.debug.traceTransaction = this.traceTransaction
this.debug.storageRangeAt = this.storageRangeAt this.debug.storageRangeAt = this.storageRangeAt
this.debug.preimage = this.preimage this.debug.preimage = this.preimage
this.providers = { 'HttpProvider': function (url) {} } this.providers = { HttpProvider: function (url) {} }
this.currentProvider = { 'host': 'vm provider' } this.currentProvider = { host: 'vm provider' }
this.storageCache = {} this.storageCache = {}
this.lastProcessedStorageTxHash = {} this.lastProcessedStorageTxHash = {}
this.sha3Preimages = {} this.sha3Preimages = {}
...@@ -100,27 +99,27 @@ export class Web3VmProvider { ...@@ -100,27 +99,27 @@ export class Web3VmProvider {
return: '0x0', return: '0x0',
structLogs: [] structLogs: []
} }
let tx = {} const tx = {}
tx['hash'] = self.processingHash tx.hash = self.processingHash
tx['from'] = toChecksumAddress(hexConvert(data.getSenderAddress())) tx.from = toChecksumAddress(hexConvert(data.getSenderAddress()))
if (data.to && data.to.length) { if (data.to && data.to.length) {
tx['to'] = toChecksumAddress(hexConvert(data.to)) tx.to = toChecksumAddress(hexConvert(data.to))
} }
this.processingAddress = tx['to'] this.processingAddress = tx.to
tx['data'] = hexConvert(data.data) tx.data = hexConvert(data.data)
tx['input'] = hexConvert(data.input) tx.input = hexConvert(data.input)
tx['gas'] = (new BN(hexConvert(data.gas).replace('0x', ''), 16)).toString(10) tx.gas = (new BN(hexConvert(data.gas).replace('0x', ''), 16)).toString(10)
if (data.value) { if (data.value) {
tx['value'] = hexConvert(data.value) tx.value = hexConvert(data.value)
} }
self.txs[self.processingHash] = tx self.txs[self.processingHash] = tx
self.txsReceipt[self.processingHash] = tx self.txsReceipt[self.processingHash] = tx
self.storageCache[self.processingHash] = {} self.storageCache[self.processingHash] = {}
if (tx['to']) { if (tx.to) {
const account = toBuffer(tx['to']) const account = toBuffer(tx.to)
self.vm.stateManager.dumpStorage(account, (storage) => { self.vm.stateManager.dumpStorage(account, (storage) => {
self.storageCache[self.processingHash][tx['to']] = storage self.storageCache[self.processingHash][tx.to] = storage
self.lastProcessedStorageTxHash[tx['to']] = self.processingHash self.lastProcessedStorageTxHash[tx.to] = self.processingHash
}) })
} }
this.processingIndex = 0 this.processingIndex = 0
...@@ -134,7 +133,7 @@ export class Web3VmProvider { ...@@ -134,7 +133,7 @@ export class Web3VmProvider {
self.vmTraces[self.processingHash].gas = '0x' + data.gasUsed.toString(16) self.vmTraces[self.processingHash].gas = '0x' + data.gasUsed.toString(16)
const logs = [] const logs = []
for (let l in data.execResult.logs) { for (const l in data.execResult.logs) {
const log = data.execResult.logs[l] const log = data.execResult.logs[l]
const topics = [] const topics = []
if (log[1].length > 0) { if (log[1].length > 0) {
...@@ -218,7 +217,7 @@ export class Web3VmProvider { ...@@ -218,7 +217,7 @@ export class Web3VmProvider {
const preimage = this.getSha3Input(previousopcode.stack, previousopcode.memory) const preimage = this.getSha3Input(previousopcode.stack, previousopcode.memory)
const imageHash = step.stack[step.stack.length - 1].replace('0x', '') const imageHash = step.stack[step.stack.length - 1].replace('0x', '')
self.sha3Preimages[imageHash] = { self.sha3Preimages[imageHash] = {
'preimage': preimage preimage: preimage
} }
} }
......
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
"compilerOptions": { "compilerOptions": {
"module": "commonjs", "module": "commonjs",
"outDir": "../../dist/out-tsc", "outDir": "../../dist/out-tsc",
"allowJs": true,
"declaration": true, "declaration": true,
"rootDir": "./", "rootDir": "./",
"types": ["node"] "types": ["node"]
...@@ -12,9 +11,6 @@ ...@@ -12,9 +11,6 @@
"**/*.spec.js", "**/*.spec.js",
"test/" "test/"
], ],
"include": [ "include": ["**/*.ts"]
"src/**/*.js",
"./index.js"
]
} }
\ No newline at end of file
...@@ -234,7 +234,7 @@ ...@@ -234,7 +234,7 @@
"options": { "options": {
"linter": "eslint", "linter": "eslint",
"config": "libs/remix-lib/.eslintrc", "config": "libs/remix-lib/.eslintrc",
"files": ["libs/remix-lib/**/*.js"], "tsConfig": ["libs/remix-lib/tsconfig.lib.json"],
"exclude": ["**/node_modules/**", "libs/remix-lib/test/**/*"] "exclude": ["**/node_modules/**", "libs/remix-lib/test/**/*"]
} }
}, },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment