get artefacts using fully qualified name

pull/2112/head
aniket-engg 3 years ago committed by Aniket
parent dd4b937cd5
commit cd3a3c4b46
  1. 39
      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) {

Loading…
Cancel
Save