@solarity/hardhat-migrate
Version:
The simplest way to deploy smart contracts
78 lines • 3.95 kB
JavaScript
;
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ArtifactProcessor = void 0;
const contract_names_1 = require("hardhat/utils/contract-names");
const MigrateStorage_1 = require("./MigrateStorage");
const errors_1 = require("../../errors");
const utils_1 = require("../../utils");
let BaseArtifactProcessor = class BaseArtifactProcessor {
async parseArtifacts(_hre) {
MigrateStorage_1.ArtifactStorage.clear();
const names = await _hre.artifacts.getAllFullyQualifiedNames();
for (const name of names) {
const artifact = await _hre.artifacts.readArtifact(name);
const contract = { ...artifact, neededLibraries: this._parseLibrariesOfArtifact(artifact) };
if (this._isNotDeployableArtifact(artifact)) {
continue;
}
MigrateStorage_1.ArtifactStorage.set(name, contract);
// Forcing the overwriting of the existing bytecode value in the Artifacts storage is necessary to prevent
// failure in edge cases, such as with internal libraries or disabled bytecode metadata hash generation.
MigrateStorage_1.ArtifactStorage.set((0, utils_1.bytecodeHash)(artifact.bytecode), contract, true);
}
}
async saveArtifactIfNotExist(_hre, contractName, bytecode) {
if (!(0, contract_names_1.isFullyQualifiedName)(contractName) || (bytecode ? true : MigrateStorage_1.ArtifactStorage.get((0, utils_1.bytecodeHash)(bytecode)))) {
return;
}
const artifact = await _hre.artifacts.readArtifact(contractName);
const contract = { ...artifact, neededLibraries: this._parseLibrariesOfArtifact(artifact) };
MigrateStorage_1.ArtifactStorage.set(bytecode ? (0, utils_1.bytecodeHash)(bytecode) : (0, utils_1.bytecodeHash)(artifact.bytecode), contract, true);
}
tryGetArtifactByName(contractName) {
const artifact = MigrateStorage_1.ArtifactStorage.get(contractName);
if (!artifact) {
throw new errors_1.MigrateError(`Artifact not found`);
}
return artifact;
}
tryGetArtifactByBytecode(bytecode) {
const artifact = MigrateStorage_1.ArtifactStorage.get((0, utils_1.bytecodeHash)(bytecode));
if (!artifact) {
throw new errors_1.MigrateError(`Artifact not found`);
}
return artifact;
}
tryGetContractName(bytecode) {
const artifact = this.tryGetArtifactByBytecode(bytecode);
return `${artifact.sourceName}:${artifact.contractName}`;
}
_parseLibrariesOfArtifact(artifact) {
const libraries = artifact.linkReferences;
const neededLibraries = [];
for (const libraryFileName of Object.keys(libraries)) {
const library = libraries[libraryFileName];
for (const libraryName of Object.keys(library)) {
neededLibraries.push({
sourceName: libraryFileName,
libName: libraryName,
});
}
}
return neededLibraries;
}
_isNotDeployableArtifact(artifact) {
return artifact.deployedBytecode === "0x";
}
};
BaseArtifactProcessor = __decorate([
utils_1.catchError
], BaseArtifactProcessor);
exports.ArtifactProcessor = new BaseArtifactProcessor();
//# sourceMappingURL=ArtifactProcessor.js.map