diff --git a/apps/remix-ide/src/app/files/fileManager.ts b/apps/remix-ide/src/app/files/fileManager.ts index aff574f5a8..df40820b27 100644 --- a/apps/remix-ide/src/app/files/fileManager.ts +++ b/apps/remix-ide/src/app/files/fileManager.ts @@ -19,7 +19,7 @@ const profile = { icon: 'assets/img/fileManager.webp', permission: true, version: packageJson.version, - methods: ['closeAllFiles', 'closeFile', 'file', 'exists', 'open', 'writeFile', 'readFile', 'copyFile', 'copyDir', 'rename', 'mkdir', 'readdir', 'remove', 'getCurrentFile', 'getFile', 'getFolder', 'setFile', 'switchFile', 'refresh', 'getProviderOf', 'getProviderByName', 'getPathFromUrl', 'getUrlFromPath', 'saveCurrentFile', 'setBatchFiles'], + methods: ['closeAllFiles', 'closeFile', 'file', 'exists', 'open', 'writeFile', 'readFile', 'copyFile', 'copyDir', 'rename', 'mkdir', 'readdir', 'dirList', 'fileList', 'remove', 'getCurrentFile', 'getFile', 'getFolder', 'setFile', 'switchFile', 'refresh', 'getProviderOf', 'getProviderByName', 'getPathFromUrl', 'getUrlFromPath', 'saveCurrentFile', 'setBatchFiles'], kind: 'file-system' } const errorMsg = { @@ -708,7 +708,7 @@ class FileManager extends Plugin { const paths: any = await this.readdir(dirPath) for( const path in paths) if(paths[path].isDirectory) delete paths[path] - return paths + return Object.keys(paths) } isRemixDActive () { diff --git a/libs/remix-core-plugin/src/lib/compiler-artefacts.ts b/libs/remix-core-plugin/src/lib/compiler-artefacts.ts index 99abe5b7d8..21f2d29b1a 100644 --- a/libs/remix-core-plugin/src/lib/compiler-artefacts.ts +++ b/libs/remix-core-plugin/src/lib/compiler-artefacts.ts @@ -72,14 +72,29 @@ export class CompilerArtefacts extends Plugin { return contractsData } - getArtefactsByContractName (contractName) { + 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 } + } + } + + async getArtefactsByContractName (contractName) { const contractsDataByFilename = this.getAllContractDatas() const contractsData = Object.values(contractsDataByFilename) 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 throw new Error('No contract compiled') + } else await this.getArtefactsFromFE ('contracts', contractName) } getCompilerAbstract (file) {