diff --git a/libs/remix-core-plugin/src/lib/helpers/fetch-etherscan.ts b/libs/remix-core-plugin/src/lib/helpers/fetch-etherscan.ts index 25ddfc44ef..32264c32fa 100644 --- a/libs/remix-core-plugin/src/lib/helpers/fetch-etherscan.ts +++ b/libs/remix-core-plugin/src/lib/helpers/fetch-etherscan.ts @@ -10,7 +10,7 @@ export const fetchContractFromEtherscan = async (plugin, network, contractAddres // etherscan api doc https://docs.etherscan.io/api-endpoints/contracts if (data.message === 'OK' && data.status === "1") { if (data.result.length) { - if (data.result[0].SourceCode === '') throw new Error('contract not verified') + if (data.result[0].SourceCode === '') throw new Error('contract not verified in Etherscan') if (data.result[0].SourceCode.startsWith('{')) { data.result[0].SourceCode = JSON.parse(data.result[0].SourceCode.replace(/(?:\r\n|\r|\n)/g, '').replace(/^{{/,'{').replace(/}}$/,'}')) } diff --git a/libs/remix-debug/src/debugger/VmDebugger.ts b/libs/remix-debug/src/debugger/VmDebugger.ts index d064fc51a9..b639a48375 100644 --- a/libs/remix-debug/src/debugger/VmDebugger.ts +++ b/libs/remix-debug/src/debugger/VmDebugger.ts @@ -65,14 +65,13 @@ export class VmDebuggerLogic { } listenToTraceManagerEvents () { + let triggerStorageUpdateStampId this.event.register('indexChanged', this, (index) => { if (index < 0) return if (this.stepManager.currentStepIndex !== index) return this.event.trigger('indexUpdate', [index]) - this.event.trigger('functionsStackUpdate', [this._callTree.retrieveFunctionsStack(index)]) - try { const calldata = this._traceManager.getCallDataAt(index) if (this.stepManager.currentStepIndex === index) { @@ -82,15 +81,6 @@ export class VmDebuggerLogic { this.event.trigger('traceManagerCallDataUpdate', [{}]) } - try { - const memory = this._traceManager.getMemoryAt(index) - if (this.stepManager.currentStepIndex === index) { - this.event.trigger('traceManagerMemoryUpdate', [ui.formatMemory(memory, 16)]) - } - } catch (error) { - this.event.trigger('traceManagerMemoryUpdate', [{}]) - } - try { const callstack = this._traceManager.getCallStackAt(index) if (this.stepManager.currentStepIndex === index) { @@ -109,23 +99,55 @@ export class VmDebuggerLogic { this.event.trigger('traceManagerStackUpdate', [{}]) } - try { - const address = this._traceManager.getCurrentCalledAddressAt(index) - if (!this.storageResolver) return + if (triggerStorageUpdateStampId) { + clearTimeout(triggerStorageUpdateStampId) + triggerStorageUpdateStampId = null + } + triggerStorageUpdateStampId = setTimeout(() => { + (() => { + try { + this.event.trigger('functionsStackUpdate', [this._callTree.retrieveFunctionsStack(index)]) + } catch (e) { + console.log(e) + } + + try { + const memory = this._traceManager.getMemoryAt(index) + if (this.stepManager.currentStepIndex === index) { + this.event.trigger('traceManagerMemoryUpdate', [ui.formatMemory(memory, 16)]) + } + } catch (error) { + this.event.trigger('traceManagerMemoryUpdate', [{}]) + } - const storageViewer = new StorageViewer({ stepIndex: this.stepManager.currentStepIndex, tx: this.tx, address: address }, this.storageResolver, this._traceManager) + try { + const address = this._traceManager.getCurrentCalledAddressAt(index) + if (!this.storageResolver) return + + const storageViewer = new StorageViewer({ stepIndex: this.stepManager.currentStepIndex, tx: this.tx, address: address }, this.storageResolver, this._traceManager) + + storageViewer.storageRange().then((storage) => { + if (this.stepManager.currentStepIndex === index) { + const header = storageViewer.isComplete(address) ? '[Completely Loaded]' : '[Partially Loaded]' + this.event.trigger('traceManagerStorageUpdate', [storage, header]) + } + }).catch((_error) => { + this.event.trigger('traceManagerStorageUpdate', [{}]) + }) + } catch (error) { + this.event.trigger('traceManagerStorageUpdate', [{}]) + } - storageViewer.storageRange().then((storage) => { - if (this.stepManager.currentStepIndex === index) { - const header = storageViewer.isComplete(address) ? '[Completely Loaded]' : '[Partially Loaded]' - this.event.trigger('traceManagerStorageUpdate', [storage, header]) + try { + const returnValue = this._traceManager.getReturnValue(index) + if (this.stepManager.currentStepIndex === index) { + this.event.trigger('traceReturnValueUpdate', [[returnValue]]) + } + } catch (error) { + this.event.trigger('traceReturnValueUpdate', [[error]]) } - }).catch((_error) => { - this.event.trigger('traceManagerStorageUpdate', [{}]) - }) - } catch (error) { - this.event.trigger('traceManagerStorageUpdate', [{}]) - } + })() + }, 1000) try { const step = this._traceManager.getCurrentStep(index) @@ -161,15 +183,6 @@ export class VmDebuggerLogic { } catch (error) { this.event.trigger('traceRemainingGasUpdate', [error]) } - - try { - const returnValue = this._traceManager.getReturnValue(index) - if (this.stepManager.currentStepIndex === index) { - this.event.trigger('traceReturnValueUpdate', [[returnValue]]) - } - } catch (error) { - this.event.trigger('traceReturnValueUpdate', [[error]]) - } }) } diff --git a/libs/remix-debug/src/debugger/debugger.ts b/libs/remix-debug/src/debugger/debugger.ts index ae04204a5e..41c846b937 100644 --- a/libs/remix-debug/src/debugger/debugger.ts +++ b/libs/remix-debug/src/debugger/debugger.ts @@ -89,15 +89,19 @@ export class Debugger { } const lineColumnPos = await this.offsetToLineColumnConverter.offsetToLineColumn(rawLocation, rawLocation.file, sources, astSources) this.event.trigger('newSourceLocation', [lineColumnPos, rawLocation, generatedSources, address]) + this.vmDebuggerLogic.event.trigger('sourceLocationChanged', [rawLocation]) } else { this.event.trigger('newSourceLocation', [null]) + this.vmDebuggerLogic.event.trigger('sourceLocationChanged', [null]) } }).catch((_error) => { this.event.trigger('newSourceLocation', [null]) + this.vmDebuggerLogic.event.trigger('sourceLocationChanged', [null]) }) // }) } catch (error) { this.event.trigger('newSourceLocation', [null]) + this.vmDebuggerLogic.event.trigger('sourceLocationChanged', [null]) return console.log(error) } } @@ -133,13 +137,6 @@ export class Debugger { async debugTx (tx, loadingCb) { this.step_manager = new DebuggerStepManager(this.debugger, this.debugger.traceManager) - this.debugger.codeManager.event.register('changed', this, (code, address, instIndex) => { - if (!this.debugger.solidityProxy.contracts) return - this.debugger.callTree.sourceLocationTracker.getValidSourceLocationFromVMTraceIndex(address, this.step_manager.currentStepIndex, this.debugger.solidityProxy.contracts).then((sourceLocation) => { - this.vmDebuggerLogic.event.trigger('sourceLocationChanged', [sourceLocation]) - }) - }) - this.vmDebuggerLogic = new VmDebuggerLogic(this.debugger, tx, this.step_manager, this.debugger.traceManager, this.debugger.codeManager, this.debugger.solidityProxy, this.debugger.callTree) this.vmDebuggerLogic.start() diff --git a/libs/remix-debug/src/debugger/solidityLocals.ts b/libs/remix-debug/src/debugger/solidityLocals.ts index ca173e4abd..bbc9afd179 100644 --- a/libs/remix-debug/src/debugger/solidityLocals.ts +++ b/libs/remix-debug/src/debugger/solidityLocals.ts @@ -10,6 +10,7 @@ export class DebuggerSolidityLocals { traceManager tx _sourceLocation + decodeTimeout constructor (tx, _stepManager, _traceManager, _internalTreeCall) { this.event = new EventManager() @@ -18,21 +19,21 @@ export class DebuggerSolidityLocals { this.storageResolver = null this.traceManager = _traceManager this.tx = tx + this.decodeTimeout = null } init (sourceLocation) { this._sourceLocation = sourceLocation - let decodeTimeout = null if (!this.storageResolver) { return this.event.trigger('solidityLocalsMessage', ['storage not ready']) } - if (decodeTimeout) { - window.clearTimeout(decodeTimeout) + if (this.decodeTimeout) { + window.clearTimeout(this.decodeTimeout) } this.event.trigger('solidityLocalsUpdating') - decodeTimeout = setTimeout(() => { + this.decodeTimeout = setTimeout(() => { this.decode(sourceLocation) - }, 500) + }, 1000) } decode (sourceLocation, cursor?) { diff --git a/libs/remix-debug/src/debugger/solidityState.ts b/libs/remix-debug/src/debugger/solidityState.ts index 4a68fa4d02..43a8349c85 100644 --- a/libs/remix-debug/src/debugger/solidityState.ts +++ b/libs/remix-debug/src/debugger/solidityState.ts @@ -1,3 +1,4 @@ +import { timeStamp } from 'console' import { EventManager } from '../eventManager' import { decodeState } from '../solidity-decoder/stateDecoder' import { StorageViewer } from '../storage/storageViewer' @@ -11,6 +12,7 @@ export class DebuggerSolidityState { solidityProxy stateVariablesByAddresses tx + decodeTimeout constructor (tx, _stepManager, _traceManager, _codeManager, _solidityProxy) { this.event = new EventManager() @@ -21,10 +23,10 @@ export class DebuggerSolidityState { this.solidityProxy = _solidityProxy this.stateVariablesByAddresses = {} this.tx = tx + this.decodeTimeout = null } init (index) { - let decodeTimeout = null if (index < 0) { return this.event.trigger('solidityStateMessage', ['invalid step index']) } @@ -37,19 +39,18 @@ export class DebuggerSolidityState { if (!this.storageResolver) { return } - if (decodeTimeout) { - window.clearTimeout(decodeTimeout) + if (this.decodeTimeout) { + window.clearTimeout(this.decodeTimeout) } this.event.trigger('solidityStateUpdating') - decodeTimeout = setTimeout(() => { + this.decodeTimeout = setTimeout(() => { // necessary due to some states that can crash the debugger try { this.decode(index) } catch (err) { - console.dir('====> error') console.dir(err) } - }, 500) + }, 1000) } reset () {