Skip to content

Commit

Permalink
Fix: Added Contract Name to the KeyDeploymentFields structure (#56)
Browse files Browse the repository at this point in the history
* Added name to the KeyDeploymentFields

* Deleted only in test

* Refactor Reporter contract. Fix lag during Truffle tx report (#57)

* Refactored Reporter contract. Fixed lag.

* Added missed new lines

* Resolved issue with encapsulation

* Update versions

* Cleaned up new lines

* Risen up a sleep time between attempts to 2500ms
  • Loading branch information
KyrylR authored Nov 9, 2023
1 parent 1dc46dd commit baaa997
Show file tree
Hide file tree
Showing 14 changed files with 239 additions and 181 deletions.
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.13",
"version": "2.0.0-alpha.14",
"description": "Automatic deployment and verification of smart contracts",
"main": "dist/src/index.js",
"types": "dist/src/index.d.ts",
Expand Down
4 changes: 2 additions & 2 deletions src/deployer/Deployer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import { EthersContractAdapter } from "./adapters/EthersContractAdapter";
import { EthersFactoryAdapter } from "./adapters/EthersFactoryAdapter";

import { OverridesAndLibs } from "../types/deployer";
import { KeyTransactionFields, MigrationMetadata } from "../types/tools";
import { Instance, TypedArgs } from "../types/adapter";
import { KeyTransactionFields, MigrationMetadata } from "../types/tools";
import { isContractFactory, isEthersContract, isBytecodeFactory, isTruffleFactory } from "../types/type-checks";

import { Stats } from "../tools/Stats";
Expand Down Expand Up @@ -94,7 +94,7 @@ export class Deployer {

const [receipt] = await Promise.all([
txResponse.wait(this._hre.config.migrate.wait),
Reporter.reportTransaction(txResponse, methodString),
Reporter.reportTransactionResponse(txResponse, methodString),
]);

const saveMetadata: MigrationMetadata = {
Expand Down
34 changes: 6 additions & 28 deletions src/deployer/MinimalContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { MigrateError } from "../errors";

import { MigrationMetadata } from "../types/tools";
import { MigrateConfig } from "../types/migrations";
import { ContractDeployTransactionWithContractName, OverridesAndLibs } from "../types/deployer";
import { ContractDeployTxWithName, OverridesAndLibs } from "../types/deployer";

import { Stats } from "../tools/Stats";
import { Reporter } from "../tools/reporters/Reporter";
Expand Down Expand Up @@ -69,10 +69,7 @@ export class MinimalContract {
}
}

private async _createDeployTransaction(
args: any[],
txOverrides: Overrides,
): Promise<ContractDeployTransactionWithContractName> {
private async _createDeployTransaction(args: any[], txOverrides: Overrides): Promise<ContractDeployTxWithName> {
const factory = new ethers.ContractFactory(this._interface, this._bytecode);

return {
Expand All @@ -83,19 +80,7 @@ export class MinimalContract {
};
}

private async _recoverContractAddress(tx: ContractDeployTransactionWithContractName, args: any[]): Promise<string> {
try {
const contractAddress = await TransactionProcessor.tryRestoreContractAddressByName(tx.contractName);

Reporter.notifyContractRecovery(tx.contractName, contractAddress);

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

return contractAddress;
} catch {
/* empty */
}

private async _recoverContractAddress(tx: ContractDeployTxWithName, args: any[]): Promise<string> {
try {
const contractAddress = await TransactionProcessor.tryRestoreContractAddressByKeyFields(tx);

Expand All @@ -113,15 +98,12 @@ export class MinimalContract {
return this._processContractDeploymentTransaction(tx, args);
}

private async _processContractDeploymentTransaction(
tx: ContractDeployTransactionWithContractName,
args: any[],
): Promise<string> {
private async _processContractDeploymentTransaction(tx: ContractDeployTxWithName, args: any[]): Promise<string> {
const signer: Signer = await getSignerHelper(tx.from);

const txResponse = await signer.sendTransaction(tx);

await Reporter.reportTransaction(txResponse, tx.contractName);
await Reporter.reportTransactionResponse(txResponse, tx.contractName);

const contractAddress = (await txResponse.wait(0))!.contractAddress;

Expand All @@ -141,11 +123,7 @@ export class MinimalContract {
return contractAddress;
}

private async _saveContractForVerification(
contractAddress: string,
tx: ContractDeployTransactionWithContractName,
args: any[],
) {
private async _saveContractForVerification(contractAddress: string, tx: ContractDeployTxWithName, args: any[]) {
if (VerificationProcessor.isVerificationDataSaved(contractAddress)) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/deployer/adapters/AbstractEthersAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export abstract class AbstractEthersAdapter extends Adapter {

TransactionProcessor.saveTransaction(tx, (await txResponse.wait())!, saveMetadata);

await Reporter.reportTransaction(txResponse, methodString);
await Reporter.reportTransactionResponse(txResponse, methodString);

return txResponse;
}
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import { Provider } from "./tools/Provider";
import { Verifier } from "./verifier/Verifier";

export { Deployer } from "./deployer/Deployer";
export { Reporter } from "./tools/reporters/Reporter";
export { DefaultStorage } from "./tools/storage/MigrateStorage";
export { PublicReporter as Reporter } from "./tools/reporters/PublicReporter";

extendConfig(migrateConfigExtender);

Expand Down
28 changes: 28 additions & 0 deletions src/tools/reporters/PublicReporter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* eslint-disable no-console */
import { Reporter } from "./Reporter";

import { Provider } from "../Provider";

import { MigrateError } from "../../errors";

export class PublicReporter {
public static async reportTransactionByHash(txHash: string, instanceName: string) {
const tx = await Provider.provider.getTransaction(txHash);

if (!tx) {
throw new MigrateError("Transaction not found.");
}

await Reporter.reportTransactionResponse(tx, instanceName);
}

public static reportContracts(...contracts: [string, string][]): void {
const table: { Contract: string; Address: string }[] = contracts.map(([contract, address]) => ({
Contract: contract,
Address: address,
}));
console.log();
console.table(table);
console.log();
}
}
Loading

0 comments on commit baaa997

Please sign in to comment.