hardhat
Version:
Hardhat is an extensible developer tool that helps smart contract developers increase productivity by reliably bringing together the tools they want.
104 lines (87 loc) • 3.42 kB
text/typescript
import type {
ArtifactManager,
GetArtifactByName,
StringWithArtifactContractNamesAutocompletion,
} from "../../../../types/artifacts.js";
import type { HardhatRuntimeEnvironmentHooks } from "../../../../types/hooks.js";
class LazyArtifactManager implements ArtifactManager {
readonly
constructor(artifactsPath: string) {
this.
this.
}
public async readArtifact<
ContractNameT extends StringWithArtifactContractNamesAutocompletion,
>(
contractNameOrFullyQualifiedName: ContractNameT,
): Promise<GetArtifactByName<ContractNameT>> {
const artifactManager = await this.
return artifactManager.readArtifact(contractNameOrFullyQualifiedName);
}
public async getArtifactPath(
contractNameOrFullyQualifiedName: string,
): Promise<string> {
const artifactManager = await this.
return artifactManager.getArtifactPath(contractNameOrFullyQualifiedName);
}
public async artifactExists(
contractNameOrFullyQualifiedName: string,
): Promise<boolean> {
const artifactManager = await this.
return artifactManager.artifactExists(contractNameOrFullyQualifiedName);
}
public async getAllFullyQualifiedNames(): Promise<ReadonlySet<string>> {
const artifactManager = await this.
return artifactManager.getAllFullyQualifiedNames();
}
public async getAllArtifactPaths(): Promise<ReadonlySet<string>> {
const artifactManager = await this.
return artifactManager.getAllArtifactPaths();
}
public async getBuildInfoId(
contractNameOrFullyQualifiedName: string,
): Promise<string | undefined> {
const artifactManager = await this.
return artifactManager.getBuildInfoId(contractNameOrFullyQualifiedName);
}
public async getAllBuildInfoIds(): Promise<ReadonlySet<string>> {
const artifactManager = await this.
return artifactManager.getAllBuildInfoIds();
}
public async getBuildInfoPath(
buildInfoId: string,
): Promise<string | undefined> {
const artifactManager = await this.
return artifactManager.getBuildInfoPath(buildInfoId);
}
public async getBuildInfoOutputPath(
buildInfoId: string,
): Promise<string | undefined> {
const artifactManager = await this.
return artifactManager.getBuildInfoOutputPath(buildInfoId);
}
public async clearCache(): Promise<void> {
const artifactManager = await this.
return artifactManager.clearCache();
}
async
if (this.
const { ArtifactManagerImplementation } = await import(
"../artifact-manager.js"
);
this.
this.
);
}
return this.
}
}
export default async (): Promise<Partial<HardhatRuntimeEnvironmentHooks>> => {
const handlers: Partial<HardhatRuntimeEnvironmentHooks> = {
created: async (_context, hre): Promise<void> => {
hre.artifacts = new LazyArtifactManager(hre.config.paths.artifacts);
},
};
return handlers;
};