getArtefactsByContractName added

pull/2074/head^2
aniket-engg 3 years ago committed by Aniket
parent 61304156b9
commit b4e702e7ee
  1. 12
      libs/remix-core-plugin/src/lib/compiler-artefacts.ts

@ -4,7 +4,7 @@ import { CompilerAbstract } from '@remix-project/remix-solidity'
const profile = {
name: 'compilerArtefacts',
methods: ['get', 'addResolvedContract', 'getCompilerAbstract', 'getAllContractDatas', 'getLastCompilationResult'],
methods: ['get', 'addResolvedContract', 'getCompilerAbstract', 'getAllContractDatas', 'getLastCompilationResult', 'getArtefactsByContractName'],
events: [],
version: '0.0.1'
}
@ -72,6 +72,16 @@ export class CompilerArtefacts extends Plugin {
return contractsData
}
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 contractsData[index][contractName]
else throw new Error(`Could not find artifacts for ${contractName}. Make sure it is compiled.`)
} else throw new Error(`No contract compiled`)
}
getCompilerAbstract (file) {
return this.compilersArtefactsPerFile[file]
}

Loading…
Cancel
Save