From cd3a3c4b462e6dd2cd01448d704b024ef96c6c10 Mon Sep 17 00:00:00 2001 From: aniket-engg Date: Thu, 24 Feb 2022 14:43:28 +0530 Subject: [PATCH] get artefacts using fully qualified name --- .../src/lib/compiler-artefacts.ts | 39 ++++++++++++------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/libs/remix-core-plugin/src/lib/compiler-artefacts.ts b/libs/remix-core-plugin/src/lib/compiler-artefacts.ts index aeede49839..f2b3535f65 100644 --- a/libs/remix-core-plugin/src/lib/compiler-artefacts.ts +++ b/libs/remix-core-plugin/src/lib/compiler-artefacts.ts @@ -100,20 +100,33 @@ export class CompilerArtefacts extends Plugin { async getArtefactsByContractName (contractName) { const contractsDataByFilename = this.getAllContractDatas() - // let contractArtefacts - const contractArtefacts = this.getAllContractArtefactsfromOutput(contractsDataByFilename, contractName) - let keys = Object.keys(contractArtefacts) - if (!keys.length) { - await this.getArtefactsFromFE ('contracts', contractName, contractArtefacts) - keys = Object.keys(contractArtefacts) + if (contractName.includes(':')) { + const nameArr = contractName.split(':') + const filename = nameArr[0] + const contract = nameArr[1] + if(Object.keys(contractsDataByFilename).includes(filename) && contractsDataByFilename[filename][contract]) + return contractsDataByFilename[filename][contract] + else { + let allContractsData = {} + await this.getArtefactsFromFE ('contracts', contract, allContractsData) + if(allContractsData[contractName]) return allContractsData[contractName] + else throw new Error(`Could not find artifacts for ${contractName}. Compile contract to generate artifacts.`) + } + } else { + const contractArtefacts = this.getAllContractArtefactsfromOutput(contractsDataByFilename, contractName) + let keys = Object.keys(contractArtefacts) + if (!keys.length) { + await this.getArtefactsFromFE ('contracts', contractName, contractArtefacts) + keys = Object.keys(contractArtefacts) + } + if (keys.length === 1) return contractArtefacts[keys[0]] + else if (keys.length > 1) { + throw new Error(`There are multiple artifacts for contract "${contractName}", please use a fully qualified name.\n + Please replace ${contractName} for one of these options wherever you are trying to read its artifact: \n + ${keys.join()}\n + OR just compile the required contract again`) + } else throw new Error(`Could not find artifacts for ${contractName}. Compile contract to generate artifacts.`) } - if (keys.length === 1) return contractArtefacts[keys[0]] - else if (keys.length > 1) { - throw new Error(`There are multiple artifacts for contract "${contractName}", please use a fully qualified name.\n - Please replace ${contractName} for one of these options wherever you are trying to read its artifact: \n - ${keys.join()}\n - OR just compile the required contract again`) - } else throw new Error(`Could not find artifacts for ${contractName}. Compile contract to generate artifacts.`) } getCompilerAbstract (file) {