diff --git a/apps/debugger/src/app/debugger-api.ts b/apps/debugger/src/app/debugger-api.ts index 6163ee766c..3a4a0f5145 100644 --- a/apps/debugger/src/app/debugger-api.ts +++ b/apps/debugger/src/app/debugger-api.ts @@ -127,6 +127,11 @@ export const DebuggerApiMixin = (Base) => class extends Base { } debug (hash, web3?) { + try { + this.call('fetchAndCompile', 'clearCache') + } catch (e) { + console.error(e) + } this.debugHash = hash if (web3) this._web3 = web3 else this._web3 = this.initialWeb3 diff --git a/libs/remix-core-plugin/src/lib/compiler-fetch-and-compile.ts b/libs/remix-core-plugin/src/lib/compiler-fetch-and-compile.ts index bf8b87bf55..3d5910d377 100644 --- a/libs/remix-core-plugin/src/lib/compiler-fetch-and-compile.ts +++ b/libs/remix-core-plugin/src/lib/compiler-fetch-and-compile.ts @@ -1,4 +1,3 @@ - import { Plugin } from '@remixproject/engine' import { compile } from '@remix-project/remix-solidity' import { util } from '@remix-project/remix-lib' @@ -8,7 +7,7 @@ import { fetchContractFromSourcify } from './helpers/fetch-sourcify' const profile = { name: 'fetchAndCompile', - methods: ['resolve'], + methods: ['resolve', 'clearCache'], version: '0.0.1' } @@ -21,6 +20,14 @@ export class FetchAndCompile extends Plugin { this.sourceVerifierNetWork = ['Main', 'Rinkeby', 'Ropsten', 'Goerli'] } + /** + * Clear the cache + * + */ + async clearCache () { + this.unresolvedAddresses = [] + } + /** * Fetch compiliation metadata from source-Verify from a given @arg contractAddress - https://github.com/ethereum/source-verify * Put the artifacts in the file explorer @@ -68,6 +75,7 @@ export class FetchAndCompile extends Plugin { } } + targetPath = `${targetPath}/${network.id}/${contractAddress}` let data try { data = await fetchContractFromSourcify(this, network, contractAddress, targetPath) @@ -100,7 +108,15 @@ export class FetchAndCompile extends Plugin { const compData = await compile( compilationTargets, settings, - async (url, cb) => await this.call('contentImport', 'resolveAndSave', url).then((result) => cb(null, result)).catch((error) => cb(error.message))) + async (url, cb) => { + // we first try to resolve the content from the compilation target using a more appropiate path + const path = `${targetPath}/${url}` + if (compilationTargets[path] && compilationTargets[path].content) { + return cb(null, compilationTargets[path].content) + } else { + await this.call('contentImport', 'resolveAndSave', url).then((result) => cb(null, result)).catch((error) => cb(error.message)) + } + }) await this.call('compilerArtefacts', 'addResolvedContract', contractAddress, compData) return compData } catch (e) { 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 647547ba47..25ddfc44ef 100644 --- a/libs/remix-core-plugin/src/lib/helpers/fetch-etherscan.ts +++ b/libs/remix-core-plugin/src/lib/helpers/fetch-etherscan.ts @@ -23,7 +23,7 @@ export const fetchContractFromEtherscan = async (plugin, network, contractAddres } if (typeof data.result[0].SourceCode === 'string') { - const fileName = `${targetPath}/${network.id}/${contractAddress}/${data.result[0].ContractName}.sol` + const fileName = `${targetPath}/${data.result[0].ContractName}.sol` await plugin.call('fileManager', 'setFile', fileName , data.result[0].SourceCode) compilationTargets[fileName] = { content: data.result[0].SourceCode } } else if (data.result[0].SourceCode && typeof data.result[0].SourceCode == 'object') { @@ -34,7 +34,7 @@ export const fetchContractFromEtherscan = async (plugin, network, contractAddres if (await plugin.call('contentImport', 'isExternalUrl', file)) { // nothing to do, the compiler callback will handle those } else { - const path = `${targetPath}/${network.id}/${contractAddress}/${file}` + const path = `${targetPath}/${file}` const content = (source as any).content await plugin.call('fileManager', 'setFile', path, content) compilationTargets[path] = { content } diff --git a/libs/remix-core-plugin/src/lib/helpers/fetch-sourcify.ts b/libs/remix-core-plugin/src/lib/helpers/fetch-sourcify.ts index 698c062b44..5765e7e9d6 100644 --- a/libs/remix-core-plugin/src/lib/helpers/fetch-sourcify.ts +++ b/libs/remix-core-plugin/src/lib/helpers/fetch-sourcify.ts @@ -13,7 +13,7 @@ export const fetchContractFromSourcify = async (plugin, network, contractAddress } // set the solidity contract code using metadata - await plugin.call('fileManager', 'setFile', `${targetPath}/${network.id}/${contractAddress}/metadata.json`, JSON.stringify(data.metadata, null, '\t')) + await plugin.call('fileManager', 'setFile', `${targetPath}/metadata.json`, JSON.stringify(data.metadata, null, '\t')) for (let file in data.metadata.sources) { const urls = data.metadata.sources[file].urls for (const url of urls) { @@ -24,7 +24,7 @@ export const fetchContractFromSourcify = async (plugin, network, contractAddress if (await plugin.call('contentImport', 'isExternalUrl', file)) { // nothing to do, the compiler callback will handle those } else { - const path = `${targetPath}/${network.id}/${contractAddress}/${file}` + const path = `${targetPath}/${file}` await plugin.call('fileManager', 'setFile', path, source.content) compilationTargets[path] = { content: source.content } } diff --git a/libs/remix-debug/src/Ethdebugger.ts b/libs/remix-debug/src/Ethdebugger.ts index e0f1a92ab5..644a98e57a 100644 --- a/libs/remix-debug/src/Ethdebugger.ts +++ b/libs/remix-debug/src/Ethdebugger.ts @@ -64,7 +64,6 @@ export class Ethdebugger { this.solidityProxy, this.codeManager, { ...this.opts, includeLocalVariables }) - this.event.trigger('managersChanged') } resolveStep (index) { diff --git a/libs/remix-debug/src/code/breakpointManager.ts b/libs/remix-debug/src/code/breakpointManager.ts index f6f20e6f45..dff9d639dc 100644 --- a/libs/remix-debug/src/code/breakpointManager.ts +++ b/libs/remix-debug/src/code/breakpointManager.ts @@ -87,6 +87,7 @@ export class BreakpointManager { * */ async jump (fromStep, direction, defaultToLimit, trace) { + this.event.trigger('locatingBreakpoint', []) let sourceLocation let previousSourceLocation let currentStep = fromStep + direction @@ -113,14 +114,14 @@ export class BreakpointManager { } if (this.hasBreakpointAtLine(sourceLocation.file, lineColumn.start.line)) { lineHadBreakpoint = true - if (direction === 1 && this.hitLine(currentStep, sourceLocation, previousSourceLocation, trace)) { + if (this.hitLine(currentStep, sourceLocation, previousSourceLocation, trace)) { return } } } currentStep += direction } - this.event.trigger('NoBreakpointHit', []) + this.event.trigger('noBreakpointHit', []) if (!defaultToLimit) { return } @@ -172,6 +173,7 @@ export class BreakpointManager { * @param {Object} sourceLocation - position of the breakpoint { file: '', row: '', row: ' { - const { traceManager, callTree, solidityProxy } = this.debugger - this.breakPointManager.setManagers({ traceManager, callTree, solidityProxy }) - }) - this.breakPointManager.event.register('breakpointStep', (step) => { this.step_manager.jumpTo(step) }) + this.breakPointManager.event.register('noBreakpointHit', (step) => { + this.event.trigger('noBreakpointHit', []) + }) + + this.breakPointManager.event.register('locatingBreakpoint', () => { + this.event.trigger('locatingBreakpoint', []) + }) + this.debugger.setBreakpointManager(this.breakPointManager) this.debugger.event.register('newTraceLoaded', this, () => { diff --git a/libs/remix-debug/test/debugger.ts b/libs/remix-debug/test/debugger.ts index 8ce4bed268..4486760f1b 100644 --- a/libs/remix-debug/test/debugger.ts +++ b/libs/remix-debug/test/debugger.ts @@ -277,22 +277,15 @@ function testDebugging (debugManager) { return sourceMappingDecoder.convertOffsetToLineColumn(rawLocation, sourceMappingDecoder.getLinebreakPositions(ballot)) }}) - breakPointManager.event.register('managersChanged', () => { - const {traceManager, callTree, solidityProxy} = debugManager - breakPointManager.setManagers({traceManager, callTree, solidityProxy}) - }) - - breakPointManager.add({fileName: 'test.sol', row: 38}) + breakPointManager.add({fileName: 'test.sol', row: 39}) breakPointManager.event.register('breakpointHit', function (sourceLocation, step) { - console.log('breakpointHit') t.equal(JSON.stringify(sourceLocation), JSON.stringify({ start: 1153, length: 6, file: 0, jump: '-' })) t.equal(step, 212) }) breakPointManager.event.register('noBreakpointHit', function () { t.end('noBreakpointHit') - console.log('noBreakpointHit') }) breakPointManager.jumpNextBreakpoint(0, true) }) diff --git a/libs/remix-ui/debugger-ui/src/lib/debugger-ui.tsx b/libs/remix-ui/debugger-ui/src/lib/debugger-ui.tsx index 0524f22170..25dd08705b 100644 --- a/libs/remix-ui/debugger-ui/src/lib/debugger-ui.tsx +++ b/libs/remix-ui/debugger-ui/src/lib/debugger-ui.tsx @@ -87,6 +87,18 @@ export const DebuggerUI = (props: DebuggerUIProps) => { }) }) + debuggerInstance.event.register('locatingBreakpoint', async (isActive) => { + setState(prevState => { + return { ...prevState, sourceLocationStatus: 'Locating breakpoint, this might take a while...' } + }) + }) + + debuggerInstance.event.register('noBreakpointHit', async (isActive) => { + setState(prevState => { + return { ...prevState, sourceLocationStatus: '' } + }) + }) + debuggerInstance.event.register('newSourceLocation', async (lineColumnPos, rawLocation, generatedSources, address) => { if (!lineColumnPos) { await debuggerModule.discardHighlight()