getArtefactsByContractName added

pull/5370/head
aniket-engg 3 years ago committed by Aniket
parent 9670a31108
commit 48e1d671be
  1. 12
      libs/remix-core-plugin/src/lib/compiler-artefacts.ts

@ -4,7 +4,7 @@ import { CompilerAbstract } from '@remix-project/remix-solidity'
const profile = { const profile = {
name: 'compilerArtefacts', name: 'compilerArtefacts',
methods: ['get', 'addResolvedContract', 'getCompilerAbstract', 'getAllContractDatas', 'getLastCompilationResult'], methods: ['get', 'addResolvedContract', 'getCompilerAbstract', 'getAllContractDatas', 'getLastCompilationResult', 'getArtefactsByContractName'],
events: [], events: [],
version: '0.0.1' version: '0.0.1'
} }
@ -72,6 +72,16 @@ export class CompilerArtefacts extends Plugin {
return contractsData 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) { getCompilerAbstract (file) {
return this.compilersArtefactsPerFile[file] return this.compilersArtefactsPerFile[file]
} }

Loading…
Cancel
Save