private methods

pull/2112/head
aniket-engg 3 years ago committed by Aniket
parent 5da0623ca7
commit a86acd861a
  1. 20
      libs/remix-core-plugin/src/lib/compiler-artefacts.ts

@ -72,7 +72,7 @@ export class CompilerArtefacts extends Plugin {
return contractsData return contractsData
} }
getAllContractArtefactsfromOutput (contractsOutput, contractName) { _getAllContractArtefactsfromOutput (contractsOutput, contractName) {
const contractArtefacts = {} const contractArtefacts = {}
for (const filename in contractsOutput) { for (const filename in contractsOutput) {
if(Object.keys(contractsOutput[filename]).includes(contractName)) contractArtefacts[filename + ':' + contractName] = contractsOutput[filename][contractName] if(Object.keys(contractsOutput[filename]).includes(contractName)) contractArtefacts[filename + ':' + contractName] = contractsOutput[filename][contractName]
@ -80,7 +80,7 @@ export class CompilerArtefacts extends Plugin {
return contractArtefacts return contractArtefacts
} }
async getArtefactsFromFE (path, contractName, contractArtefacts) { async _getArtefactsFromFE (path, contractName, contractArtefacts) {
const dirList = await this.call('fileManager', 'dirList', path) const dirList = await this.call('fileManager', 'dirList', path)
if(dirList && dirList.length) { if(dirList && dirList.length) {
for (const dirPath of dirList) { for (const dirPath of dirList) {
@ -90,13 +90,13 @@ export class CompilerArtefacts extends Plugin {
let content = await this.call('fileManager', 'readFile', buildFile) let content = await this.call('fileManager', 'readFile', buildFile)
if (content) content = JSON.parse(content) if (content) content = JSON.parse(content)
const contracts = content.output.contracts const contracts = content.output.contracts
const artefacts = this.getAllContractArtefactsfromOutput(contracts, contractName) const artefacts = this._getAllContractArtefactsfromOutput(contracts, contractName)
Object.assign(contractArtefacts, artefacts) Object.assign(contractArtefacts, artefacts)
} }
} else await this.getArtefactsFromFE (dirPath, contractName, contractArtefacts) } else await this._getArtefactsFromFE (dirPath, contractName, contractArtefacts)
} }
} else return } else return
} }
async getArtefactsByContractName (contractName) { async getArtefactsByContractName (contractName) {
const contractsDataByFilename = this.getAllContractDatas() const contractsDataByFilename = this.getAllContractDatas()
@ -108,15 +108,15 @@ export class CompilerArtefacts extends Plugin {
return contractsDataByFilename[filename][contract] return contractsDataByFilename[filename][contract]
else { else {
const allContractsData = {} const allContractsData = {}
await this.getArtefactsFromFE ('contracts', contract, allContractsData) await this._getArtefactsFromFE ('contracts', contract, allContractsData)
if(allContractsData[contractName]) return allContractsData[contractName] if(allContractsData[contractName]) return allContractsData[contractName]
else throw new Error(`Could not find artifacts for ${contractName}. Compile contract to generate artifacts.`) else throw new Error(`Could not find artifacts for ${contractName}. Compile contract to generate artifacts.`)
} }
} else { } else {
const contractArtefacts = this.getAllContractArtefactsfromOutput(contractsDataByFilename, contractName) const contractArtefacts = this._getAllContractArtefactsfromOutput(contractsDataByFilename, contractName)
let keys = Object.keys(contractArtefacts) let keys = Object.keys(contractArtefacts)
if (!keys.length) { if (!keys.length) {
await this.getArtefactsFromFE ('contracts', contractName, contractArtefacts) await this._getArtefactsFromFE ('contracts', contractName, contractArtefacts)
keys = Object.keys(contractArtefacts) keys = Object.keys(contractArtefacts)
} }
if (keys.length === 1) return contractArtefacts[keys[0]] if (keys.length === 1) return contractArtefacts[keys[0]]

Loading…
Cancel
Save