get artifacts from file explorer

pull/2074/head^2
aniket-engg 3 years ago committed by Aniket
parent e23d824c33
commit 9a9e34df2a
  1. 4
      apps/remix-ide/src/app/files/fileManager.ts
  2. 19
      libs/remix-core-plugin/src/lib/compiler-artefacts.ts

@ -19,7 +19,7 @@ const profile = {
icon: 'assets/img/fileManager.webp', icon: 'assets/img/fileManager.webp',
permission: true, permission: true,
version: packageJson.version, 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' kind: 'file-system'
} }
const errorMsg = { const errorMsg = {
@ -708,7 +708,7 @@ class FileManager extends Plugin {
const paths: any = await this.readdir(dirPath) const paths: any = await this.readdir(dirPath)
for( const path in paths) for( const path in paths)
if(paths[path].isDirectory) delete paths[path] if(paths[path].isDirectory) delete paths[path]
return paths return Object.keys(paths)
} }
isRemixDActive () { isRemixDActive () {

@ -72,14 +72,29 @@ export class CompilerArtefacts extends Plugin {
return contractsData 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 contractsDataByFilename = this.getAllContractDatas()
const contractsData = Object.values(contractsDataByFilename) const contractsData = Object.values(contractsDataByFilename)
if (contractsData && contractsData.length) { if (contractsData && contractsData.length) {
const index = contractsData.findIndex((contractsObj) => Object.keys(contractsObj).includes(contractName)) 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 } 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(`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) { getCompilerAbstract (file) {

Loading…
Cancel
Save