Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolved verification save error: failed to fetch contract name by bytecode #52

Merged
merged 6 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@solarity/hardhat-migrate",
"version": "2.0.0-alpha.8",
"version": "2.0.0-alpha.9",
"description": "Automatic deployment and verification of smart contracts",
"main": "dist/src/index.js",
"types": "dist/src/index.d.ts",
Expand Down
32 changes: 29 additions & 3 deletions src/deployer/MinimalContract.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { ethers, InterfaceAbi, Overrides, Signer } from "ethers";

import { isFullyQualifiedName } from "hardhat/utils/contract-names";

import { Linker } from "./Linker";

import { catchError, fillParameters, getChainId, getInterfaceOnlyWithConstructor, getSignerHelper } from "../utils";
Expand All @@ -16,6 +18,7 @@ import { VerificationProcessor } from "../tools/storage/VerificationProcessor";

@catchError
export class MinimalContract {
private readonly _rawBytecode: string;
private readonly _interface;

constructor(
Expand All @@ -25,6 +28,7 @@ export class MinimalContract {
private readonly _contractName: string = "",
) {
this._interface = getInterfaceOnlyWithConstructor(this._abi);
this._rawBytecode = this._bytecode;

if (_contractName === "") {
try {
Expand Down Expand Up @@ -83,6 +87,8 @@ export class MinimalContract {

Reporter.notifyContractRecovery(tx.contractName, contractAddress);

await this._saveContractForVerification(contractAddress, tx, args);

return contractAddress;
} catch {
/* empty */
Expand All @@ -93,6 +99,8 @@ export class MinimalContract {

Reporter.notifyContractRecovery(tx.contractName, contractAddress);

await this._saveContractForVerification(contractAddress, tx, args);

return contractAddress;
} catch {
/* empty */
Expand All @@ -119,19 +127,37 @@ export class MinimalContract {
throw new MigrateError("Contract deployment failed. Invalid contract address conversion.");
}

await this._saveContractForVerification(contractAddress, tx, args);

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

return contractAddress;
}

private async _saveContractForVerification(
contractAddress: string,
tx: ContractDeployTransactionWithContractName,
args: any[],
) {
if (VerificationProcessor.isVerificationDataSaved(contractAddress)) {
return;
}

try {
let contractName = tx.contractName;

if (!isFullyQualifiedName(contractName)) {
contractName = ArtifactProcessor.tryGetContractName(this._rawBytecode);
}

VerificationProcessor.saveVerificationFunction({
contractAddress,
contractName: ArtifactProcessor.tryGetContractName(this._bytecode),
contractName: contractName,
constructorArguments: args,
chainId: Number(await getChainId()),
});
} catch {
Reporter.reportVerificationFailedToSave(tx.contractName);
}

return contractAddress;
}
}
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ const migrate: ActionType<MigrateConfig> = async (taskArgs, env) => {
};

const migrateVerify: ActionType<MigrateVerifyConfig> = async (taskArgs, env) => {
await Provider.init(env);

const config = extendVerifyConfigs(taskArgs);

await Reporter.init(env.config.migrate);
Expand Down
4 changes: 4 additions & 0 deletions src/tools/storage/VerificationProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,8 @@ export class VerificationProcessor {

return Object.values(data);
}

public static isVerificationDataSaved(contractAddress: string): boolean {
return VerificationStorage.has(contractAddress);
}
}