check for artifacts in all dirs

pull/2074/head^2
aniket-engg 3 years ago committed by Aniket
parent 9a9e34df2a
commit f13ccf1822
  1. 48
      libs/remix-core-plugin/src/lib/compiler-artefacts.ts

@ -74,17 +74,31 @@ export class CompilerArtefacts extends Plugin {
async getArtefactsFromFE (path, contractName) {
const dirList = await this.call('fileManager', 'dirList', path)
if(dirList.includes(path + '/artifacts')) {
const fileList = await this.call('fileManager', 'fileList', path + '/artifacts')
const artefactsFilePaths = fileList.filter(filePath => {
const filenameArr = filePath.split('/')
const filename = filenameArr[filenameArr.length - 1]
if (filename === `${contractName}.json` || filename === `${contractName}_metadata.json`) return true
})
const content = await this.call('fileManager', 'readFile', artefactsFilePaths[1])
const artifacts = JSON.parse(content)
return { abi: artifacts.abi, bytecode: artifacts.data.bytecode.object }
}
if(dirList && dirList.length) {
if(dirList.includes(path + '/artifacts')) {
const fileList = await this.call('fileManager', 'fileList', path + '/artifacts')
const artefactsFilePaths = fileList.filter(filePath => {
const filenameArr = filePath.split('/')
const filename = filenameArr[filenameArr.length - 1]
if (filename === `${contractName}.json` || filename === `${contractName}_metadata.json`) return true
})
if (artefactsFilePaths && artefactsFilePaths.length) {
const content = await this.call('fileManager', 'readFile', artefactsFilePaths[1])
const artifacts = JSON.parse(content)
return { abi: artifacts.abi, bytecode: artifacts.data.bytecode.object }
} else {
for (const dirPath of dirList) {
const result = await this.getArtefactsFromFE (dirPath, contractName)
if (result) return result
}
}
} else {
for (const dirPath of dirList) {
const result = await this.getArtefactsFromFE (dirPath, contractName)
if (result) return result
}
}
} else return
}
async getArtefactsByContractName (contractName) {
@ -93,8 +107,16 @@ export class CompilerArtefacts extends Plugin {
if (contractsData && contractsData.length) {
const index = contractsData.findIndex((contractsObj) => Object.keys(contractsObj).includes(contractName))
if (index !== -1) return { abi: contractsData[index][contractName].abi, bytecode: contractsData[index][contractName].evm.bytecode.object }
else throw new Error(`Could not find artifacts for ${contractName}. Make sure it is compiled.`)
} else await this.getArtefactsFromFE ('contracts', contractName)
else {
const result = await this.getArtefactsFromFE ('contracts', contractName)
if (result) return result
else throw new Error(`Could not find artifacts for ${contractName}. Compile contract to generate artifacts.`)
}
} else {
const result = await this.getArtefactsFromFE ('contracts', contractName)
if (result) return result
else throw new Error(`Could not find artifacts for ${contractName}. Compile contract to generate artifacts.`)
}
}
getCompilerAbstract (file) {

Loading…
Cancel
Save