Skip to content

Commit

Permalink
Made Verifier non static
Browse files Browse the repository at this point in the history
  • Loading branch information
KyrylR committed Oct 20, 2023
1 parent 6b6e4f9 commit 7eed6ad
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
4 changes: 3 additions & 1 deletion src/deployer/DeployerCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ import { TransactionProcessor } from "../tools/storage/TransactionProcessor";
@catchError
export class DeployerCore {
private _config: MigrateConfig;
private _verifier: Verifier;

constructor(private _hre: HardhatRuntimeEnvironment) {
this._config = _hre.config.migrate;
this._verifier = new Verifier(_hre);
}

public async deploy(deployParams: ContractDeployParams, args: Args, parameters: OverridesAndLibs): Promise<string> {
Expand Down Expand Up @@ -94,7 +96,7 @@ export class DeployerCore {

TransactionProcessor.saveDeploymentTransaction(tx, tx.contractName, contractAddress);

await Verifier.processVerification({
await this._verifier.processVerification({
contractAddress,
contractName: tx.contractName,
constructorArguments: args,
Expand Down
2 changes: 0 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { ArtifactProcessor } from "./tools/storage/ArtifactProcessor";
import { DefaultStorage } from "./tools/storage/MigrateStorage";

import { MigrateConfig } from "./types/migrations";
import { Verifier } from "./verifier/Verifier";

export { Deployer } from "./deployer/Deployer";
export { Verifier } from "./verifier/Verifier";
Expand All @@ -35,7 +34,6 @@ const migrate: ActionType<MigrateConfig> = async (taskArgs, env) => {
await ArtifactProcessor.parseArtifacts(env);

Reporter.init(env);
Verifier.init(env);

await new Migrator(env).migrate();
};
Expand Down
6 changes: 4 additions & 2 deletions src/migrator/migrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { VerificationProcessor } from "../tools/storage/VerificationProcessor";

export class Migrator {
private readonly _deployer: Deployer;
private readonly _verifier: Verifier;

private readonly _migrationFiles: string[];

Expand All @@ -28,6 +29,7 @@ export class Migrator {
private _config: MigrateConfig = _hre.config.migrate,
) {
this._deployer = new Deployer(_hre);
this._verifier = new Verifier(_hre);

this._migrationFiles = this._getMigrationFiles();
}
Expand All @@ -41,7 +43,7 @@ export class Migrator {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const migration = require(resolvePathToFile(this._config.pathToMigrations, element));

await migration(this._deployer, Verifier);
await migration(this._deployer, this._verifier);
} catch (e: unknown) {
if (e instanceof MigrateError) {
throw new HardhatPluginError(pluginName, e.message, e);
Expand All @@ -51,7 +53,7 @@ export class Migrator {
}
}

await Verifier.verifyBatch(VerificationProcessor.restoreSavedVerificationFunctions());
await this._verifier.verifyBatch(VerificationProcessor.restoreSavedVerificationFunctions());

await Reporter.summary();
}
Expand Down
28 changes: 13 additions & 15 deletions src/verifier/Verifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,15 @@ import { Reporter } from "../tools/reporter/Reporter";
import { VerificationProcessor } from "../tools/storage/VerificationProcessor";

export class Verifier {
private static _etherscanConfig: any;
private static _config: MigrateConfig;
private static _hre: HardhatRuntimeEnvironment;

public static init(hre: HardhatRuntimeEnvironment) {
this._hre = hre;
this._etherscanConfig = (hre.config as any).etherscan;
this._config = hre.config.migrate;
private _etherscanConfig: any;
private _config: MigrateConfig;

constructor(private _hre: HardhatRuntimeEnvironment) {
this._etherscanConfig = (_hre.config as any).etherscan;
this._config = _hre.config.migrate;
}

public static async processVerification(verifierArgs: VerifierArgs): Promise<void> {
public async processVerification(verifierArgs: VerifierArgs): Promise<void> {
if (!this._config) {
return;
}
Expand All @@ -43,7 +41,7 @@ export class Verifier {
}

@catchError
public static async verify(verifierArgs: VerifierArgs): Promise<void> {
public async verify(verifierArgs: VerifierArgs): Promise<void> {
const { contractAddress, contractName, constructorArguments } = verifierArgs;

const instance = await this._getEtherscanInstance(this._hre);
Expand All @@ -64,7 +62,7 @@ export class Verifier {
}

@catchError
public static async verifyBatch(verifierButchArgs: VerifierArgs[]) {
public async verifyBatch(verifierButchArgs: VerifierArgs[]) {
if (!this._config.verify) {
return;
}
Expand All @@ -79,7 +77,7 @@ export class Verifier {
}

@catchError
private static async _tryVerify(
private async _tryVerify(
instance: Etherscan,
contractAddress: string,
contractName: string,
Expand All @@ -98,7 +96,7 @@ export class Verifier {
}

@catchError
private static _handleVerificationError(contractAddress: string, contractName: string, error: any) {
private _handleVerificationError(contractAddress: string, contractName: string, error: any) {
if (error.message.toLowerCase().includes("already verified")) {
Reporter.reportAlreadyVerified(contractAddress, contractName);
return;
Expand All @@ -108,7 +106,7 @@ export class Verifier {
}

@catchError
private static async _getEtherscanInstance(hre: HardhatRuntimeEnvironment): Promise<Etherscan> {
private async _getEtherscanInstance(hre: HardhatRuntimeEnvironment): Promise<Etherscan> {
const chainConfig = await Etherscan.getCurrentChainConfig(
hre.network.name,
hre.network.provider,
Expand All @@ -119,7 +117,7 @@ export class Verifier {
}

@suppressLogs
private static async _tryRunVerificationTask(contractAddress: string, contractName: string, args: Args) {
private async _tryRunVerificationTask(contractAddress: string, contractName: string, args: Args) {
await this._hre.run("verify:verify", {
address: contractAddress,
constructorArguments: args,
Expand Down

0 comments on commit 7eed6ad

Please sign in to comment.