diff --git a/libs/remix-core-plugin/src/lib/compiler-artefacts.ts b/libs/remix-core-plugin/src/lib/compiler-artefacts.ts index 8c57021252..0d3ed3202e 100644 --- a/libs/remix-core-plugin/src/lib/compiler-artefacts.ts +++ b/libs/remix-core-plugin/src/lib/compiler-artefacts.ts @@ -63,6 +63,16 @@ export class CompilerArtefacts extends Plugin { this.compilersArtefacts.__last = new CompilerAbstract(languageVersion, data, source) saveCompilationPerFileResult(file, source, languageVersion, data) }) + + this.on('truffle', 'compilationFinished', (file, source, languageVersion, data) => { + this.compilersArtefacts.__last = new CompilerAbstract(languageVersion, data, source) + saveCompilationPerFileResult(file, source, languageVersion, data) + }) + + this.on('foundry', 'compilationFinished', (file, source, languageVersion, data) => { + this.compilersArtefacts.__last = new CompilerAbstract(languageVersion, data, source) + saveCompilationPerFileResult(file, source, languageVersion, data) + }) } /** diff --git a/libs/remixd/src/services/foundryClient.ts b/libs/remixd/src/services/foundryClient.ts index 9dd89a8049..7ecf60cd98 100644 --- a/libs/remixd/src/services/foundryClient.ts +++ b/libs/remixd/src/services/foundryClient.ts @@ -81,7 +81,7 @@ export class FoundryClient extends PluginClient { this.call('terminal', 'log', 'receiving compilation result from foundry') this.warnlog = true } - this.emit('compilationFinished', '', compilationResult.input, 'soljson', compilationResult.output, compilationResult.solcVersion) + this.emit('compilationFinished', '', { sources: compilationResult.input } , 'soljson', compilationResult.output, compilationResult.solcVersion) } this.watcher.on('change', async (f: string) => processArtifact()) this.watcher.on('add', async (f: string) => processArtifact()) @@ -123,6 +123,8 @@ export class FoundryClient extends PluginClient { } if (!compilationResultPart.output['contracts'][contentJSON.ast.absolutePath]) compilationResultPart.output['contracts'][contentJSON.ast.absolutePath] = {} // delete contentJSON['ast'] + contentJSON.bytecode.object = contentJSON.bytecode.object.replace('0x', '') + contentJSON.deployedBytecode.object = contentJSON.deployedBytecode.object.replace('0x', '') compilationResultPart.output['contracts'][contentJSON.ast.absolutePath][contractName] = { abi: contentJSON.abi, evm: { diff --git a/libs/remixd/src/services/hardhatClient.ts b/libs/remixd/src/services/hardhatClient.ts index 6e804aae19..db0870725c 100644 --- a/libs/remixd/src/services/hardhatClient.ts +++ b/libs/remixd/src/services/hardhatClient.ts @@ -71,7 +71,7 @@ export class HardhatClient extends PluginClient { this.call('terminal', 'log', 'receiving compilation result from hardhat') this.warnlog = true } - this.emit('compilationFinished', '', compilationResult.input, 'soljson', compilationResult.output, compilationResult.solcVersion) + this.emit('compilationFinished', '', { sources: compilationResult.input.sources }, 'soljson', compilationResult.output, compilationResult.solcVersion) } } diff --git a/libs/remixd/src/services/truffleClient.ts b/libs/remixd/src/services/truffleClient.ts index cad09119dd..f5df4613d7 100644 --- a/libs/remixd/src/services/truffleClient.ts +++ b/libs/remixd/src/services/truffleClient.ts @@ -84,7 +84,7 @@ export class TruffleClient extends PluginClient { this.call('terminal', 'log', 'receiving compilation result from truffle') this.warnLog = true } - this.emit('compilationFinished', '', compilationResult.input, 'soljson', compilationResult.output, compilationResult.solcVersion) + this.emit('compilationFinished', '', { sources: compilationResult.input }, 'soljson', compilationResult.output, compilationResult.solcVersion) } this.watcher.on('change', async (f: string) => processArtifact()) this.watcher.on('add', async (f: string) => processArtifact()) @@ -99,23 +99,28 @@ export class TruffleClient extends PluginClient { compilationResultPart.solcVersion = contentJSON.compiler.version compilationResultPart.input[path] = { content: contentJSON.source } // extract data - if (!compilationResultPart.output['sources'][contentJSON.ast.absolutePath]) compilationResultPart.output['sources'][contentJSON.ast.absolutePath] = {} - compilationResultPart.output['sources'][contentJSON.ast.absolutePath] = { - ast: contentJSON['ast'], - id: contentJSON['id'] + const relPath = utils.relativePath(contentJSON.ast.absolutePath, this.currentSharedFolder) + if (!compilationResultPart.output['sources'][relPath]) compilationResultPart.output['sources'][relPath] = {} + + const location = contentJSON.ast.src.split(':') + const id = parseInt(location[location.length - 1]) + + compilationResultPart.output['sources'][relPath] = { + ast: contentJSON.ast, + id } - if (!compilationResultPart.output['contracts'][contentJSON.ast.absolutePath]) compilationResultPart.output['contracts'][contentJSON.ast.absolutePath] = {} + if (!compilationResultPart.output['contracts'][relPath]) compilationResultPart.output['contracts'][relPath] = {} // delete contentJSON['ast'] - compilationResultPart.output['contracts'][contentJSON.ast.absolutePath][contractName] = { + compilationResultPart.output['contracts'][relPath][contractName] = { abi: contentJSON.abi, evm: { bytecode: { - object: contentJSON.bytecode, + object: contentJSON.bytecode.replace('0x', ''), sourceMap: contentJSON.sourceMap, linkReferences: contentJSON.linkReferences }, deployedBytecode: { - object: contentJSON.deployedBytecode, + object: contentJSON.deployedBytecode.replace('0x', ''), sourceMap: contentJSON.deployedSourceMap, linkReferences: contentJSON.deployedLinkReferences }