fix cli integ

pull/4896/head
yann300 7 months ago committed by Aniket
parent c307125d4f
commit 69ce2d2cc5
  1. 30
      libs/remixd/src/services/foundryClient.ts

@ -1,5 +1,6 @@
import * as WS from 'ws' // eslint-disable-line import * as WS from 'ws' // eslint-disable-line
import { PluginClient } from '@remixproject/plugin' import { PluginClient } from '@remixproject/plugin'
import { CompilerAbstract } from '@remix-project/remix-solidity'
import * as chokidar from 'chokidar' import * as chokidar from 'chokidar'
import * as utils from '../utils' import * as utils from '../utils'
import * as fs from 'fs-extra' import * as fs from 'fs-extra'
@ -115,11 +116,14 @@ export class FoundryClient extends PluginClient {
contracts: {}, contracts: {},
sources: {} sources: {}
}, },
inputSources: { sources: {}, target: ''},
solcVersion: null, solcVersion: null,
compilationTarget: null compilationTarget: null
} }
compilationResult.inputSources.target = file
await this.readContract(path, compilationResult, cache) await this.readContract(path, compilationResult, cache)
this.emit('compilationFinished', compilationResult.compilationTarget, { sources: compilationResult.input }, 'soljson', compilationResult.output, compilationResult.solcVersion) 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) clearTimeout(this.logTimeout)
@ -154,11 +158,11 @@ export class FoundryClient extends PluginClient {
} }
async readContract(contractFolder, compilationResultPart, cache) { async readContract(contractFolder, compilationResultPart, cache) {
const files = await fs.readdir(contractFolder) const files = await fs.readdir(contractFolder)
for (const file of files) { for (const file of files) {
const path = join(contractFolder, file) const path = join(contractFolder, file)
const content = await fs.readFile(path, { encoding: 'utf-8' }) const content = await fs.readFile(path, { encoding: 'utf-8' })
compilationResultPart.inputSources.sources[file] = { content }
await this.feedContractArtifactFile(file, content, compilationResultPart, cache) await this.feedContractArtifactFile(file, content, compilationResultPart, cache)
} }
} }
@ -167,7 +171,16 @@ export class FoundryClient extends PluginClient {
const contentJSON = JSON.parse(content) const contentJSON = JSON.parse(content)
const contractName = basename(path).replace('.json', '') 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 if (!currentCache.artifacts[contractName]) return
// extract source and version // 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.') 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 // extract data
if (!compilationResultPart.output['sources'][contentJSON.ast.absolutePath]) compilationResultPart.output['sources'][contentJSON.ast.absolutePath] = {} if (!compilationResultPart.output['sources'][sourcePath]) compilationResultPart.output['sources'][sourcePath] = {}
compilationResultPart.output['sources'][contentJSON.ast.absolutePath] = { compilationResultPart.output['sources'][sourcePath] = {
ast: contentJSON['ast'], ast: contentJSON['ast'],
id: contentJSON['id'] 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.bytecode.object = contentJSON.bytecode.object.replace('0x', '')
contentJSON.deployedBytecode.object = contentJSON.deployedBytecode.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, abi: contentJSON.abi,
evm: { evm: {
bytecode: contentJSON.bytecode, bytecode: contentJSON.bytecode,

Loading…
Cancel
Save