type def and self removal

pull/5370/head
aniket-engg 4 years ago committed by Aniket
parent 86939e7e51
commit 94018bce85
  1. 4
      libs/remix-lib/src/execution/eventsDecoder.ts
  2. 1
      libs/remix-lib/src/execution/execution-context.ts
  3. 70
      libs/remix-lib/src/web3Provider/web3VmProvider.ts

@ -38,8 +38,8 @@ export class EventsDecoder {
this._decodeEvents(tx, receipt.logs, contract, contracts, cb) this._decodeEvents(tx, receipt.logs, contract, contracts, cb)
} }
_eventABI (contract): Record<string, unknown> { _eventABI (contract): Record<string, { event, inputs, object, abi }> {
const eventABI: Record<string, unknown> = {} const eventABI: Record<string, { event, inputs, object, abi }> = {}
const abi = new ethers.utils.Interface(contract.abi) const abi = new ethers.utils.Interface(contract.abi)
for (const e in abi.events) { for (const e in abi.events) {
const event = abi.getEvent(e) const event = abi.getEvent(e)

@ -284,7 +284,6 @@ export class ExecutionContext {
} }
// TODO: remove this when this function is moved // TODO: remove this when this function is moved
// const self = this
setProviderFromEndpoint (endpoint, context, cb) { setProviderFromEndpoint (endpoint, context, cb) {
const oldProvider = web3.currentProvider const oldProvider = web3.currentProvider

@ -75,13 +75,13 @@ export class Web3VmProvider {
if (this.vm === vm) return if (this.vm === vm) return
this.vm = vm this.vm = vm
this.vm.on('step', (data) => { this.vm.on('step', (data) => {
this.pushTrace(this, data) this.pushTrace(data)
}) })
this.vm.on('afterTx', (data) => { this.vm.on('afterTx', (data) => {
this.txProcessed(this, data) this.txProcessed(data)
}) })
this.vm.on('beforeTx', (data) => { this.vm.on('beforeTx', (data) => {
this.txWillProcess(this, data) this.txWillProcess(data)
}) })
} }
@ -91,16 +91,16 @@ export class Web3VmProvider {
return ret return ret
} }
txWillProcess (self, data) { txWillProcess (data) {
self.incr++ this.incr++
self.processingHash = hexConvert(data.hash()) this.processingHash = hexConvert(data.hash())
self.vmTraces[self.processingHash] = { this.vmTraces[this.processingHash] = {
gas: '0x0', gas: '0x0',
return: '0x0', return: '0x0',
structLogs: [] structLogs: []
} }
const tx = {} const tx = {}
tx['hash'] = self.processingHash tx['hash'] = this.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))
@ -112,25 +112,25 @@ export class Web3VmProvider {
if (data.value) { if (data.value) {
tx['value'] = hexConvert(data.value) tx['value'] = hexConvert(data.value)
} }
self.txs[self.processingHash] = tx this.txs[this.processingHash] = tx
self.txsReceipt[self.processingHash] = tx this.txsReceipt[this.processingHash] = tx
self.storageCache[self.processingHash] = {} this.storageCache[this.processingHash] = {}
if (tx['to']) { if (tx['to']) {
const account = toBuffer(tx['to']) const account = toBuffer(tx['to'])
self.vm.stateManager.dumpStorage(account, (storage) => { this.vm.stateManager.dumpStorage(account, (storage) => {
self.storageCache[self.processingHash][tx['to']] = storage this.storageCache[this.processingHash][tx['to']] = storage
self.lastProcessedStorageTxHash[tx['to']] = self.processingHash this.lastProcessedStorageTxHash[tx['to']] = this.processingHash
}) })
} }
this.processingIndex = 0 this.processingIndex = 0
} }
txProcessed (self, data) { txProcessed (data) {
const lastOp = self.vmTraces[self.processingHash].structLogs[self.processingIndex - 1] const lastOp = this.vmTraces[this.processingHash].structLogs[this.processingIndex - 1]
if (lastOp) { if (lastOp) {
lastOp.error = lastOp.op !== 'RETURN' && lastOp.op !== 'STOP' && lastOp.op !== 'SELFDESTRUCT' lastOp.error = lastOp.op !== 'RETURN' && lastOp.op !== 'STOP' && lastOp.op !== 'thisDESTRUCT'
} }
self.vmTraces[self.processingHash].gas = '0x' + data.gasUsed.toString(16) this.vmTraces[this.processingHash].gas = '0x' + data.gasUsed.toString(16)
const logs = [] const logs = []
for (const l in data.execResult.logs) { for (const l in data.execResult.logs) {
@ -150,34 +150,34 @@ export class Web3VmProvider {
rawVMResponse: log rawVMResponse: log
}) })
} }
self.txsReceipt[self.processingHash].logs = logs this.txsReceipt[this.processingHash].logs = logs
self.txsReceipt[self.processingHash].transactionHash = self.processingHash this.txsReceipt[this.processingHash].transactionHash = this.processingHash
const status = data.execResult.exceptionError ? 0 : 1 const status = data.execResult.exceptionError ? 0 : 1
self.txsReceipt[self.processingHash].status = `0x${status}` this.txsReceipt[this.processingHash].status = `0x${status}`
if (data.createdAddress) { if (data.createdAddress) {
const address = hexConvert(data.createdAddress) const address = hexConvert(data.createdAddress)
self.vmTraces[self.processingHash].return = toChecksumAddress(address) this.vmTraces[this.processingHash].return = toChecksumAddress(address)
self.txsReceipt[self.processingHash].contractAddress = toChecksumAddress(address) this.txsReceipt[this.processingHash].contractAddress = toChecksumAddress(address)
} else if (data.execResult.returnValue) { } else if (data.execResult.returnValue) {
self.vmTraces[self.processingHash].return = hexConvert(data.execResult.returnValue) this.vmTraces[this.processingHash].return = hexConvert(data.execResult.returnValue)
} else { } else {
self.vmTraces[self.processingHash].return = '0x' this.vmTraces[this.processingHash].return = '0x'
} }
this.processingIndex = null this.processingIndex = null
this.processingAddress = null this.processingAddress = null
this.previousDepth = 0 this.previousDepth = 0
} }
pushTrace (self, data) { pushTrace (data) {
const depth = data.depth + 1 // geth starts the depth from 1 const depth = data.depth + 1 // geth starts the depth from 1
if (!self.processingHash) { if (!this.processingHash) {
console.log('no tx processing') console.log('no tx processing')
return return
} }
let previousopcode let previousopcode
if (self.vmTraces[self.processingHash] && self.vmTraces[self.processingHash].structLogs[this.processingIndex - 1]) { if (this.vmTraces[this.processingHash] && this.vmTraces[this.processingHash].structLogs[this.processingIndex - 1]) {
previousopcode = self.vmTraces[self.processingHash].structLogs[this.processingIndex - 1] previousopcode = this.vmTraces[this.processingHash].structLogs[this.processingIndex - 1]
} }
if (this.previousDepth > depth && previousopcode) { if (this.previousDepth > depth && previousopcode) {
@ -195,7 +195,7 @@ export class Web3VmProvider {
depth: depth, depth: depth,
error: data.error === false ? undefined : data.error error: data.error === false ? undefined : data.error
} }
self.vmTraces[self.processingHash].structLogs.push(step) this.vmTraces[this.processingHash].structLogs.push(step)
if (step.op === 'CREATE' || step.op === 'CALL') { if (step.op === 'CREATE' || step.op === 'CALL') {
if (step.op === 'CREATE') { if (step.op === 'CREATE') {
this.processingAddress = '(Contract Creation - Step ' + this.processingIndex + ')' this.processingAddress = '(Contract Creation - Step ' + this.processingIndex + ')'
@ -204,11 +204,11 @@ export class Web3VmProvider {
} else { } else {
this.processingAddress = normalizeHexAddress(step.stack[step.stack.length - 2]) this.processingAddress = normalizeHexAddress(step.stack[step.stack.length - 2])
this.processingAddress = toChecksumAddress(this.processingAddress) this.processingAddress = toChecksumAddress(this.processingAddress)
if (!self.storageCache[self.processingHash][this.processingAddress]) { if (!this.storageCache[this.processingHash][this.processingAddress]) {
const account = toBuffer(this.processingAddress) const account = toBuffer(this.processingAddress)
self.vm.stateManager.dumpStorage(account, function (storage) { this.vm.stateManager.dumpStorage(account, function (storage) {
self.storageCache[self.processingHash][self.processingAddress] = storage this.storageCache[this.processingHash][this.processingAddress] = storage
self.lastProcessedStorageTxHash[self.processingAddress] = self.processingHash this.lastProcessedStorageTxHash[this.processingAddress] = this.processingHash
}) })
} }
} }
@ -216,7 +216,7 @@ export class Web3VmProvider {
if (previousopcode && previousopcode.op === 'SHA3') { if (previousopcode && previousopcode.op === 'SHA3') {
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] = { this.sha3Preimages[imageHash] = {
preimage: preimage preimage: preimage
} }
} }

Loading…
Cancel
Save