Merge branch 'master' into readd_gist_prefix

pull/5370/head
Rob 3 years ago committed by GitHub
commit 5b7bbbcdb9
  1. 5
      apps/debugger/src/app/debugger-api.ts
  2. 22
      libs/remix-core-plugin/src/lib/compiler-fetch-and-compile.ts
  3. 4
      libs/remix-core-plugin/src/lib/helpers/fetch-etherscan.ts
  4. 4
      libs/remix-core-plugin/src/lib/helpers/fetch-sourcify.ts
  5. 1
      libs/remix-debug/src/Ethdebugger.ts
  6. 7
      libs/remix-debug/src/code/breakpointManager.ts
  7. 13
      libs/remix-debug/src/debugger/debugger.ts
  8. 9
      libs/remix-debug/test/debugger.ts
  9. 12
      libs/remix-ui/debugger-ui/src/lib/debugger-ui.tsx

@ -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

@ -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) {

@ -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 }

@ -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 }
}

@ -64,7 +64,6 @@ export class Ethdebugger {
this.solidityProxy,
this.codeManager,
{ ...this.opts, includeLocalVariables })
this.event.trigger('managersChanged')
}
resolveStep (index) {

@ -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: '<file index>', row: '<line number' }
*/
add (sourceLocation) {
sourceLocation.row -= 1
if (!this.breakpoints[sourceLocation.fileName]) {
this.breakpoints[sourceLocation.fileName] = []
}
@ -185,6 +187,7 @@ export class BreakpointManager {
* @param {Object} sourceLocation - position of the breakpoint { file: '<file index>', row: '<line number' }
*/
remove (sourceLocation) {
sourceLocation.row -= 1
const sources = this.breakpoints[sourceLocation.fileName]
if (!sources) {
return

@ -41,15 +41,18 @@ export class Debugger {
}
})
this.breakPointManager.event.register('managersChanged', () => {
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, () => {

@ -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)
})

@ -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()

Loading…
Cancel
Save