-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fetch and compile before debugging #2755
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
bc35cbe
fetch and compile before debugging
yann300 9e6ccea
bump remix lib
yann300 b354154
new remix libs
yann300 ee5c9a7
make fetchAndCompileAPlugin
yann300 57a8bb4
remove autoactivation of udapp
yann300 944ab58
update remix libs
yann300 1e02929
add e2e test - debug with source verifier
yann300 fb7ce37
remve unneeded prop
yann300 d20b101
fix metamask
yann300 5d36088
activate source-verifier plugin & try/catch
yann300 1051185
fix e2e tests
yann300 1ca80d1
make sure contract creation are handled properly (address from the re…
yann300 884a562
path contain the networkname
yann300 d85b6a7
standard
yann300 a785e04
ensure using checksum address
yann300 13b32a8
fix path
yann300 6b9ce1f
fix styling
yann300 94a86ef
bump remix libs
yann300 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
'use strict' | ||
import { canUseWorker } from './compiler-utils' | ||
import { Compiler } from 'remix-solidity' | ||
import CompilerAbstract from './compiler-abstract' | ||
|
||
export const compile = async (compilationTargets, settings) => { | ||
return await (() => { | ||
return new Promise((resolve, reject) => { | ||
const compiler = new Compiler(() => {}) | ||
compiler.set('evmVersion', settings.evmVersion) | ||
compiler.set('optimize', settings.optimize) | ||
compiler.loadVersion(canUseWorker(settings.version), settings.compilerUrl) | ||
compiler.event.register('compilationFinished', (success, compilationData, source) => { | ||
if (!success) return reject(compilationData) | ||
resolve(new CompilerAbstract(settings.version, compilationData, source)) | ||
}) | ||
compiler.event.register('compilerLoaded', _ => compiler.compile(compilationTargets, '')) | ||
}) | ||
})() | ||
} |
125 changes: 125 additions & 0 deletions
125
src/app/compiler/compiler-sourceVerifier-fetchAndCompile.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
const ethutil = require('ethereumjs-util') | ||
import * as packageJson from '../../../package.json' | ||
import { Plugin } from '@remixproject/engine' | ||
import { urlFromVersion } from './compiler-utils' | ||
import { compile } from './compiler-helpers' | ||
import globalRegistry from '../../global/registry' | ||
|
||
import remixLib from 'remix-lib' | ||
|
||
const profile = { | ||
name: 'fetchAndCompile', | ||
methods: ['resolve'], | ||
version: packageJson.version | ||
} | ||
|
||
export default class FetchAndCompile extends Plugin { | ||
|
||
constructor () { | ||
super(profile) | ||
this.unresolvedAddresses = [] | ||
this.sourceVerifierNetWork = ['Main', 'Rinkeby', 'Ropsten', 'Goerli'] | ||
} | ||
|
||
/** | ||
* Fetch compiliation metadata from source-Verify from a given @arg contractAddress - https://github.com/ethereum/source-verify | ||
* Put the artifacts in the file explorer | ||
* Compile the code using Solidity compiler | ||
* Returns compilation data | ||
* | ||
* @param {string} contractAddress - Address of the contrac to resolve | ||
* @param {string} compilersartefacts - Object containing a mapping of compilation results (byContractAddress and __last) | ||
* @return {CompilerAbstract} - compilation data targeting the given @arg contractAddress | ||
*/ | ||
async resolve (contractAddress, targetPath, web3) { | ||
contractAddress = ethutil.toChecksumAddress(contractAddress) | ||
const compilersartefacts = globalRegistry.get('compilersartefacts').api | ||
|
||
const localCompilation = () => compilersartefacts.get('__last') ? compilersartefacts.get('__last') : null | ||
|
||
const resolved = compilersartefacts.get(contractAddress) | ||
if (resolved) return resolved | ||
if (this.unresolvedAddresses.includes(contractAddress)) return localCompilation() | ||
|
||
// sometimes when doing an internal call, the only available artifact is the Solidity interface. | ||
// resolving addresses of internal call would allow to step over the source code, even if the declaration was made using an Interface. | ||
|
||
let network | ||
try { | ||
network = await this.call('network', 'detectNetwork') | ||
} catch (e) { | ||
return localCompilation() | ||
} | ||
if (!network) return localCompilation() | ||
if (!this.sourceVerifierNetWork.includes(network.name)) return localCompilation() | ||
|
||
// check if the contract if part of the local compilation result | ||
const codeAtAddress = await web3.eth.getCode(contractAddress) | ||
const compilation = localCompilation() | ||
if (compilation) { | ||
let found = false | ||
compilation.visitContracts((contract) => { | ||
found = remixLib.util.compareByteCode('0x' + contract.object.evm.deployedBytecode.object, codeAtAddress) | ||
return found | ||
}) | ||
if (found) { | ||
compilersartefacts.addResolvedContract(contractAddress, compilation) | ||
setTimeout(_ => this.emit('usingLocalCompilation', contractAddress), 0) | ||
return compilation | ||
} | ||
} | ||
|
||
let name = network.name.toLowerCase() | ||
name === 'main' ? 'mainnet' : name // source-verifier api expect "mainnet" and not "main" | ||
let data | ||
try { | ||
data = await this.call('source-verification', 'fetch', contractAddress, name.toLowerCase()) | ||
} catch (e) { | ||
setTimeout(_ => this.emit('sourceVerificationNotAvailable'), 0) | ||
this.unresolvedAddresses.push(contractAddress) | ||
return localCompilation() | ||
} | ||
if (!data || !data.metadata) { | ||
setTimeout(_ => this.emit('notFound', contractAddress), 0) | ||
this.unresolvedAddresses.push(contractAddress) | ||
return localCompilation() | ||
} | ||
|
||
// set the solidity contract code using metadata | ||
await this.call('fileManager', 'setFile', `${targetPath}/${name}/${contractAddress}/metadata.json`, JSON.stringify(data.metadata, null, '\t')) | ||
let compilationTargets = {} | ||
for (let file in data.metadata.sources) { | ||
const urls = data.metadata.sources[file].urls | ||
for (let url of urls) { | ||
if (url.includes('ipfs')) { | ||
let stdUrl = `ipfs://${url.split('/')[2]}` | ||
const source = await this.call('contentImport', 'resolve', stdUrl) | ||
file = file.replace('browser/', '') // should be fixed in the remix IDE end. | ||
const path = `${targetPath}/${name}/${contractAddress}/${file}` | ||
await this.call('fileManager', 'setFile', path, source.content) | ||
compilationTargets[path] = { content: source.content } | ||
break | ||
} | ||
} | ||
} | ||
|
||
// compile | ||
const settings = { | ||
version: data.metadata.compiler.version, | ||
languageName: data.metadata.language, | ||
evmVersion: data.metadata.settings.evmVersion, | ||
optimize: data.metadata.settings.optimizer.enabled, | ||
compilerUrl: urlFromVersion(data.metadata.compiler.version) | ||
} | ||
try { | ||
setTimeout(_ => this.emit('compiling', settings), 0) | ||
const compData = await compile(compilationTargets, settings) | ||
compilersartefacts.addResolvedContract(contractAddress, compData) | ||
return compData | ||
} catch (e) { | ||
this.unresolvedAddresses.push(contractAddress) | ||
setTimeout(_ => this.emit('compilationFailed'), 0) | ||
return localCompilation() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here is the format {id:network.id, name}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@LianaHus you don't need to do toLowerCase it will be handled on the API level.