From 48e1d671be2a004923a063add34df4033cc74984 Mon Sep 17 00:00:00 2001 From: aniket-engg Date: Tue, 15 Feb 2022 13:59:27 +0530 Subject: [PATCH] getArtefactsByContractName added --- libs/remix-core-plugin/src/lib/compiler-artefacts.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/libs/remix-core-plugin/src/lib/compiler-artefacts.ts b/libs/remix-core-plugin/src/lib/compiler-artefacts.ts index 1198a012db..1732337394 100644 --- a/libs/remix-core-plugin/src/lib/compiler-artefacts.ts +++ b/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] }