From 38b2e3933a4fe7ea503479c01942a6c24accec28 Mon Sep 17 00:00:00 2001 From: yann300 Date: Thu, 18 Apr 2024 16:01:59 +0200 Subject: [PATCH] fix cli integ --- libs/remixd/src/services/foundryClient.ts | 30 +++++++++++++++++------ 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/libs/remixd/src/services/foundryClient.ts b/libs/remixd/src/services/foundryClient.ts index 95b4f0a168..e652f6624d 100644 --- a/libs/remixd/src/services/foundryClient.ts +++ b/libs/remixd/src/services/foundryClient.ts @@ -1,5 +1,6 @@ import * as WS from 'ws' // eslint-disable-line import { PluginClient } from '@remixproject/plugin' +import { CompilerAbstract } from '@remix-project/remix-solidity' import * as chokidar from 'chokidar' import * as utils from '../utils' import * as fs from 'fs-extra' @@ -115,11 +116,14 @@ export class FoundryClient extends PluginClient { contracts: {}, sources: {} }, + inputSources: { sources: {}, target: ''}, solcVersion: null, compilationTarget: null } + compilationResult.inputSources.target = file await this.readContract(path, compilationResult, cache) this.emit('compilationFinished', compilationResult.compilationTarget, { sources: compilationResult.input }, 'soljson', compilationResult.output, compilationResult.solcVersion) + this.call('compilerArtefacts' as any, 'saveCompilerAbstract', file, new CompilerAbstract(compilationResult.solcVersion, compilationResult.output, compilationResult.inputSources)) } clearTimeout(this.logTimeout) @@ -154,11 +158,11 @@ export class FoundryClient extends PluginClient { } async readContract(contractFolder, compilationResultPart, cache) { - const files = await fs.readdir(contractFolder) - + const files = await fs.readdir(contractFolder) for (const file of files) { const path = join(contractFolder, file) const content = await fs.readFile(path, { encoding: 'utf-8' }) + compilationResultPart.inputSources.sources[file] = { content } await this.feedContractArtifactFile(file, content, compilationResultPart, cache) } } @@ -167,7 +171,16 @@ export class FoundryClient extends PluginClient { const contentJSON = JSON.parse(content) const contractName = basename(path).replace('.json', '') - const currentCache = cache.files[contentJSON.ast.absolutePath] + let sourcePath = '' + for (let key in contentJSON.metadata.settings.compilationTarget) { + if (contentJSON.metadata.settings.compilationTarget[key] === contractName) { + sourcePath = key + break + } + } + if (!sourcePath) return + + const currentCache = cache.files[sourcePath] if (!currentCache.artifacts[contractName]) return // extract source and version @@ -193,18 +206,19 @@ export class FoundryClient extends PluginClient { console.log('\x1b[32m%s\x1b[0m', 'sources input not found, please update Foundry to the latest version.') } - compilationResultPart.compilationTarget = contentJSON.ast.absolutePath + + compilationResultPart.compilationTarget = sourcePath // extract data - if (!compilationResultPart.output['sources'][contentJSON.ast.absolutePath]) compilationResultPart.output['sources'][contentJSON.ast.absolutePath] = {} - compilationResultPart.output['sources'][contentJSON.ast.absolutePath] = { + if (!compilationResultPart.output['sources'][sourcePath]) compilationResultPart.output['sources'][sourcePath] = {} + compilationResultPart.output['sources'][sourcePath] = { ast: contentJSON['ast'], id: contentJSON['id'] } - if (!compilationResultPart.output['contracts'][contentJSON.ast.absolutePath]) compilationResultPart.output['contracts'][contentJSON.ast.absolutePath] = {} + if (!compilationResultPart.output['contracts'][sourcePath]) compilationResultPart.output['contracts'][sourcePath] = {} contentJSON.bytecode.object = contentJSON.bytecode.object.replace('0x', '') contentJSON.deployedBytecode.object = contentJSON.deployedBytecode.object.replace('0x', '') - compilationResultPart.output['contracts'][contentJSON.ast.absolutePath][contractName] = { + compilationResultPart.output['contracts'][sourcePath][contractName] = { abi: contentJSON.abi, evm: { bytecode: contentJSON.bytecode,