Skip to content

Commit

Permalink
fix cli integ
Browse files Browse the repository at this point in the history
  • Loading branch information
yann300 committed Apr 18, 2024
1 parent 890d631 commit 3abd2a0
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions libs/remixd/src/services/foundryClient.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
}
Expand All @@ -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
Expand All @@ -194,18 +207,18 @@ export class FoundryClient extends PluginClient {
}


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,
Expand Down

0 comments on commit 3abd2a0

Please sign in to comment.